Introduce distinct Dp/Px types to prevent coordinate mixing at compile time
- 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
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
package editor
|
||||
|
||||
import (
|
||||
"gioui.org/unit"
|
||||
|
||||
"pad/internal/ui"
|
||||
)
|
||||
|
||||
// ConfigEvent represents a window configuration change (resize, orientation).
|
||||
// Width and Height are in device-independent pixels (Dp).
|
||||
type ConfigEvent struct {
|
||||
Width unit.Dp
|
||||
Height unit.Dp
|
||||
Width ui.Dp
|
||||
Height ui.Dp
|
||||
}
|
||||
|
||||
// InputEvent represents a user input event routed to an element.
|
||||
@@ -34,7 +33,8 @@ type Logic struct {
|
||||
}
|
||||
|
||||
// NewLogic creates a new Logic instance.
|
||||
func NewLogic(screenWidth, screenHeight unit.Dp) *Logic {
|
||||
// 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),
|
||||
|
||||
+11
-12
@@ -1,20 +1,20 @@
|
||||
package editor
|
||||
|
||||
import (
|
||||
"gioui.org/unit"
|
||||
|
||||
"pad/internal/ui"
|
||||
)
|
||||
|
||||
// State holds all application state owned by the logic goroutine.
|
||||
// All dimensions are in device-independent pixels (Dp).
|
||||
type State struct {
|
||||
ScreenWidth unit.Dp
|
||||
ScreenHeight unit.Dp
|
||||
ScreenWidth ui.Dp
|
||||
ScreenHeight ui.Dp
|
||||
Elems []ui.Element
|
||||
}
|
||||
|
||||
// NewState creates a new State with initial editor layout.
|
||||
func NewState(screenWidth, screenHeight unit.Dp) *State {
|
||||
// screenWidth and screenHeight are in device-independent pixels (Dp).
|
||||
func NewState(screenWidth, screenHeight ui.Dp) *State {
|
||||
return &State{
|
||||
ScreenWidth: screenWidth,
|
||||
ScreenHeight: screenHeight,
|
||||
@@ -23,15 +23,14 @@ func NewState(screenWidth, screenHeight unit.Dp) *State {
|
||||
}
|
||||
|
||||
// EditorLayout computes regions for the editor page.
|
||||
// It takes screen dimensions and returns []Element.
|
||||
func EditorLayout(screenWidth, screenHeight unit.Dp) []ui.Element {
|
||||
// It takes screen dimensions in Dp and returns []Element with regions in Dp.
|
||||
// This function works exclusively in Dp — no pixel conversions.
|
||||
func EditorLayout(screenWidth, screenHeight ui.Dp) []ui.Element {
|
||||
// Margin to avoid clipping on macOS round corners
|
||||
margin := unit.Dp(10)
|
||||
margin := ui.Dp(10)
|
||||
|
||||
// Compute StatusBar region
|
||||
// Line 1: filename (24 DP)
|
||||
// Line 2: icons (24 DP)
|
||||
statusBarHeight := unit.Dp(48)
|
||||
statusBarHeight := ui.Dp(48)
|
||||
statusBarRegion := ui.Region{
|
||||
X: margin,
|
||||
Y: margin,
|
||||
@@ -40,7 +39,7 @@ func EditorLayout(screenWidth, screenHeight unit.Dp) []ui.Element {
|
||||
}
|
||||
|
||||
// Compute BottomBar region (fixed height, at bottom of screen)
|
||||
bottomBarHeight := unit.Dp(24)
|
||||
bottomBarHeight := ui.Dp(24)
|
||||
bottomBarY := screenHeight - margin - bottomBarHeight
|
||||
bottomBarRegion := ui.Region{
|
||||
X: margin,
|
||||
|
||||
Reference in New Issue
Block a user