Pad/internal/editor/state.go
Greg Pomerantz 013416ee08 Move logic into separate internal/editor package
- Create internal/editor/state.go with State struct and EditorLayout
- Create internal/editor/logic.go with Logic struct and Run method
- Logic owns all state, provides channels for config, frames, input, results
- Main goroutine uses editor.NewLogic() and logic.Run()
- Proper separation for testing later

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-05-08 17:06:00 -04:00

71 lines
1.5 KiB
Go

package editor
import (
"gioui.org/unit"
"pad/internal/ui"
)
// State holds all application state owned by the logic goroutine.
type State struct {
ScreenWidth unit.Dp
ScreenHeight unit.Dp
Elems []ui.Element
}
// NewState creates a new State with initial editor layout.
func NewState(screenWidth, screenHeight unit.Dp) *State {
return &State{
ScreenWidth: screenWidth,
ScreenHeight: screenHeight,
Elems: EditorLayout(screenWidth, screenHeight),
}
}
// EditorLayout computes regions for the editor page.
// It takes screen dimensions and returns []Element.
func EditorLayout(screenWidth, screenHeight unit.Dp) []ui.Element {
// Compute StatusBar region
// Line 1: filename (24 DP)
// Line 2: icons (24 DP)
statusBarHeight := unit.Dp(48)
statusBarRegion := ui.Region{
X: 0,
Y: 0,
W: screenWidth,
H: statusBarHeight,
}
// Compute BottomBar region (fixed height, at bottom of screen)
bottomBarHeight := unit.Dp(24)
bottomBarY := screenHeight - bottomBarHeight
bottomBarRegion := ui.Region{
X: 0,
Y: bottomBarY,
W: screenWidth,
H: bottomBarHeight,
}
// Create StatusBar with mocked filename
statusBar := ui.NewStatusBar(
statusBarRegion,
"very_long_filename_that_does_not_fit_on_a_single_line.txt",
false, // FilenameExp
true, // CutCopy
false, // Copy
true, // Paste
false, // ConflictIcon
true, // Search
)
// Create BottomBar with mocked data
bottomBar := ui.NewBottomBar(
bottomBarRegion,
"Ln 47, Col 12",
"1024 / 50000",
true, // WordWrap
)
return []ui.Element{statusBar, bottomBar}
}