refactor: unified Element interface with Draw method and Container type
- Add Draw(gtx, r *Renderer) to Element interface - Add Container type that implements Element and holds []Element children - Leaf types (Label, Icon, Button) implement Draw themselves - Single recursive drawElement function in Renderer — no switch/case - Remove StatusBar/BottomBar — replaced by Container - Remove shaper.go — no longer needed with Gio material labels - Simplify main.go — scale via ScaleProvider interface - 5 files changed, shaper.go deleted
This commit is contained in:
+24
-30
@@ -14,8 +14,6 @@ type State struct {
|
||||
}
|
||||
|
||||
// NewState creates a new State with initial editor layout.
|
||||
// screenWidth and screenHeight are in device-independent pixels (Dp).
|
||||
// scale defaults to 1.0 until updated by ScaleEvent.
|
||||
func NewState(screenWidth, screenHeight ui.Dp) *State {
|
||||
return &State{
|
||||
ScreenWidth: screenWidth,
|
||||
@@ -36,50 +34,46 @@ func (s *State) Scale() float32 {
|
||||
return s.scale
|
||||
}
|
||||
|
||||
// EditorLayout computes regions for the editor page.
|
||||
// It takes screen dimensions in Dp and returns []Element with regions in Dp.
|
||||
// This function works exclusively in Dp — no pixel conversions.
|
||||
// EditorLayout computes the element tree for the editor page.
|
||||
// It takes screen dimensions in Dp and returns []Element.
|
||||
func EditorLayout(screenWidth, screenHeight ui.Dp) []ui.Element {
|
||||
// Margin to avoid clipping on macOS round corners
|
||||
margin := ui.Dp(10)
|
||||
|
||||
// Compute StatusBar region
|
||||
statusBarHeight := ui.Dp(80)
|
||||
// --- Top container: status bar ---
|
||||
statusBarHeight := ui.Dp(52)
|
||||
statusBarRegion := ui.Region{
|
||||
X: margin,
|
||||
Y: margin,
|
||||
X: margin, Y: margin,
|
||||
W: screenWidth - margin*2,
|
||||
H: statusBarHeight,
|
||||
}
|
||||
|
||||
// Compute BottomBar region (fixed height, at bottom of screen)
|
||||
statusBar := ui.NewContainer(
|
||||
statusBarRegion,
|
||||
ui.Color{R: 230, G: 230, B: 230, A: 255},
|
||||
[]ui.Element{
|
||||
ui.NewIcon("cut", ui.Region{X: ui.Dp(8), Y: ui.Dp(2), W: ui.Dp(16), H: ui.Dp(16)}, ui.Dp(16)),
|
||||
ui.NewLabel("Ln 47, Col 12", 12, ui.Region{X: ui.Dp(32), Y: ui.Dp(2)}),
|
||||
ui.NewLabel("Ready", 12, ui.Region{X: ui.Dp(8), Y: ui.Dp(28)}),
|
||||
},
|
||||
)
|
||||
|
||||
// --- Bottom container: bottom bar ---
|
||||
bottomBarHeight := ui.Dp(24)
|
||||
bottomBarY := screenHeight - margin - bottomBarHeight
|
||||
bottomBarRegion := ui.Region{
|
||||
X: margin,
|
||||
Y: bottomBarY,
|
||||
X: margin, Y: bottomBarY,
|
||||
W: screenWidth - margin*2,
|
||||
H: bottomBarHeight,
|
||||
}
|
||||
|
||||
// Create StatusBar with mocked filename
|
||||
statusBar := ui.NewStatusBar(
|
||||
statusBarRegion,
|
||||
"very_long_filename_that_does_not_fit_on_a_single_line_and_it_just_keeps_on_going_and_going_and_going_and_going_and_going.txt",
|
||||
false, // FilenameExp
|
||||
true, // CutCopy
|
||||
false, // Copy
|
||||
true, // Paste
|
||||
false, // ConflictIcon
|
||||
true, // Search
|
||||
)
|
||||
|
||||
// Create BottomBar with mocked data
|
||||
bottomBar := ui.NewBottomBar(
|
||||
bottomBar := ui.NewContainer(
|
||||
bottomBarRegion,
|
||||
"Ln 47, Col 12",
|
||||
"1024 / 50000",
|
||||
true, // WordWrap
|
||||
ui.Color{R: 230, G: 230, B: 230, A: 255},
|
||||
[]ui.Element{
|
||||
ui.NewLabel("Ln 47, Col 12", 12, ui.Region{X: ui.Dp(8), Y: ui.Dp(2)}),
|
||||
ui.NewLabel("1024 / 50000", 12, ui.Region{X: ui.Dp(150), Y: ui.Dp(2)}),
|
||||
ui.NewLabel("Wrap: On", 12, ui.Region{X: screenWidth - margin - ui.Dp(60), Y: ui.Dp(2)}),
|
||||
},
|
||||
)
|
||||
|
||||
return []ui.Element{statusBar, bottomBar}
|
||||
|
||||
Reference in New Issue
Block a user