- Add ui.Dp and ui.Px as distinct named types - Logic layer works exclusively in Dp (positions, sizes, regions) - Renderer converts Dp→Px at Gio interop boundaries - Capture gtx.Constraints once at start of Draw() for consistent positioning - main.go converts app.ConfigEvent pixels to Dp before passing to logic layer - Update documentation with new coordinate system architecture
91 lines
2.3 KiB
Go
91 lines
2.3 KiB
Go
package editor
|
|
|
|
import (
|
|
"pad/internal/ui"
|
|
)
|
|
|
|
// ConfigEvent represents a window configuration change (resize, orientation).
|
|
// Width and Height are in device-independent pixels (Dp).
|
|
type ConfigEvent struct {
|
|
Width ui.Dp
|
|
Height ui.Dp
|
|
}
|
|
|
|
// InputEvent represents a user input event routed to an element.
|
|
type InputEvent struct {
|
|
ElementID string
|
|
Type ui.InputType
|
|
Data any
|
|
}
|
|
|
|
// ResultEvent represents a completed async task result.
|
|
type ResultEvent struct {
|
|
// Future: add result fields here
|
|
}
|
|
|
|
// Logic runs the logic goroutine and provides channels for communication.
|
|
type Logic struct {
|
|
state *State
|
|
configChan chan ConfigEvent
|
|
frameChan chan []ui.Element
|
|
inputChan chan []InputEvent
|
|
resultChan chan ResultEvent
|
|
}
|
|
|
|
// NewLogic creates a new Logic instance.
|
|
// screenWidth and screenHeight are in device-independent pixels (Dp).
|
|
func NewLogic(screenWidth, screenHeight ui.Dp) *Logic {
|
|
return &Logic{
|
|
state: NewState(screenWidth, screenHeight),
|
|
configChan: make(chan ConfigEvent),
|
|
frameChan: make(chan []ui.Element),
|
|
inputChan: make(chan []InputEvent),
|
|
resultChan: make(chan ResultEvent),
|
|
}
|
|
}
|
|
|
|
// ConfigChan returns the config channel for the logic goroutine.
|
|
func (l *Logic) ConfigChan() chan<- ConfigEvent {
|
|
return l.configChan
|
|
}
|
|
|
|
// FrameChan returns the frame channel for the logic goroutine.
|
|
func (l *Logic) FrameChan() <-chan []ui.Element {
|
|
return l.frameChan
|
|
}
|
|
|
|
// InputChan returns the input channel for the logic goroutine.
|
|
func (l *Logic) InputChan() chan<- []InputEvent {
|
|
return l.inputChan
|
|
}
|
|
|
|
// ResultChan returns the result channel for the logic goroutine.
|
|
func (l *Logic) ResultChan() <-chan ResultEvent {
|
|
return l.resultChan
|
|
}
|
|
|
|
// Run runs the logic goroutine loop.
|
|
func (l *Logic) Run() {
|
|
for {
|
|
select {
|
|
case cfg := <-l.configChan:
|
|
// Update screen size and recompute layout
|
|
l.state.ScreenWidth = cfg.Width
|
|
l.state.ScreenHeight = cfg.Height
|
|
l.state.Elems = EditorLayout(cfg.Width, cfg.Height)
|
|
l.frameChan <- l.state.Elems
|
|
case <-l.inputChan:
|
|
// Process input (not implemented in mockup)
|
|
l.frameChan <- l.state.Elems
|
|
case <-l.resultChan:
|
|
// Handle result (not implemented in mockup)
|
|
l.frameChan <- l.state.Elems
|
|
}
|
|
}
|
|
}
|
|
|
|
// State returns the current state.
|
|
func (l *Logic) State() *State {
|
|
return l.state
|
|
}
|