Break import cycle: use StateReader interface instead of direct State reference
- StateReader interface in ui package (Scale(), ScreenWidth(), ScreenHeight()) - State implements StateReader - Renderer reads scale/window size via interface, never imports editor - State fields are private (screenWidth, screenHeight, scale) with accessor methods - No SetScale/SetWindowSize calls from main.go — Renderer reads from State directly
This commit is contained in:
@@ -25,9 +25,7 @@ type ConfigUpdate interface {
|
||||
}
|
||||
|
||||
func (e ConfigEvent) apply(s *State) {
|
||||
s.ScreenWidth = e.Width
|
||||
s.ScreenHeight = e.Height
|
||||
s.Elems = EditorLayout(e.Width, e.Height)
|
||||
s.SetSize(e.Width, e.Height)
|
||||
}
|
||||
|
||||
func (e ScaleEvent) apply(s *State) {
|
||||
@@ -93,14 +91,14 @@ func (l *Logic) ResultChan() <-chan ResultEvent {
|
||||
func (l *Logic) ScreenSize() (ui.Dp, ui.Dp) {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
return l.state.ScreenWidth, l.state.ScreenHeight
|
||||
return l.state.ScreenWidth(), l.state.ScreenHeight()
|
||||
}
|
||||
|
||||
// Scale returns the current scale factor (pixels per DP).
|
||||
func (l *Logic) Scale() float32 {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
return l.state.Scale
|
||||
return l.state.Scale()
|
||||
}
|
||||
|
||||
// Run runs the logic goroutine loop.
|
||||
|
||||
@@ -7,9 +7,9 @@ import (
|
||||
// State holds all application state owned by the logic goroutine.
|
||||
// All dimensions are in device-independent pixels (Dp).
|
||||
type State struct {
|
||||
ScreenWidth ui.Dp
|
||||
ScreenHeight ui.Dp
|
||||
Scale float32 // pixels per DP, default 1.0
|
||||
screenWidth ui.Dp
|
||||
screenHeight ui.Dp
|
||||
scale float32 // pixels per DP, default 1.0
|
||||
Elems []ui.Element
|
||||
}
|
||||
|
||||
@@ -18,17 +18,33 @@ type State struct {
|
||||
// scale defaults to 1.0 until updated by ScaleEvent.
|
||||
func NewState(screenWidth, screenHeight ui.Dp) *State {
|
||||
return &State{
|
||||
ScreenWidth: screenWidth,
|
||||
ScreenHeight: screenHeight,
|
||||
Scale: 1.0,
|
||||
screenWidth: screenWidth,
|
||||
screenHeight: screenHeight,
|
||||
scale: 1.0,
|
||||
Elems: EditorLayout(screenWidth, screenHeight),
|
||||
}
|
||||
}
|
||||
|
||||
// Scale returns the current scale factor (pixels per DP).
|
||||
func (s *State) Scale() float32 { return s.scale }
|
||||
|
||||
// ScreenWidth returns the current screen width in Dp.
|
||||
func (s *State) ScreenWidth() ui.Dp { return s.screenWidth }
|
||||
|
||||
// ScreenHeight returns the current screen height in Dp.
|
||||
func (s *State) ScreenHeight() ui.Dp { return s.screenHeight }
|
||||
|
||||
// SetScale updates the scale factor and recomputes layout.
|
||||
func (s *State) SetScale(scale float32) {
|
||||
s.Scale = scale
|
||||
s.Elems = EditorLayout(s.ScreenWidth, s.ScreenHeight)
|
||||
s.scale = scale
|
||||
s.Elems = EditorLayout(s.screenWidth, s.screenHeight)
|
||||
}
|
||||
|
||||
// SetSize updates the screen dimensions and recomputes layout.
|
||||
func (s *State) SetSize(width, height ui.Dp) {
|
||||
s.screenWidth = width
|
||||
s.screenHeight = height
|
||||
s.Elems = EditorLayout(width, height)
|
||||
}
|
||||
|
||||
// EditorLayout computes regions for the editor page.
|
||||
|
||||
Reference in New Issue
Block a user