Implement initial editor mockup with StatusBar, BottomBar, window resize
Elements implemented: - StatusBar (top bar with filename, action icons, conflict/search icons) - BottomBar (bottom bar with cursor position, byte position, word wrap button) - Button (interactive button element) - AlphaIndex, SearchBar, Cursor, MergeHunk, Toast, Spacer (stubs) Layout: - EditorLayout function computes regions for StatusBar and BottomBar - Filename truncation with ellipsis (mocked filename for testing) - Mocked data: "very_long_filename...", "Ln 47, Col 12", "1024 / 50000" Renderer: - drawStatusBar: draws filename line + icon line - drawBottomBar: draws cursor pos, byte pos, word wrap button - drawButton: draws button text - drawIconButton: draws icon buttons Window resize: - configChan setup in main.go - ConfigEvent handling in event loop - Layout recomputation on resize Builds and runs successfully. Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
+28
-14
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"gioui.org/app"
|
||||
"gioui.org/op"
|
||||
@@ -19,6 +20,7 @@ func main() {
|
||||
if err := run(w); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
os.Exit(0)
|
||||
}()
|
||||
app.Main()
|
||||
}
|
||||
@@ -29,29 +31,41 @@ func run(w *app.Window) error {
|
||||
shaper := text.NewShaper()
|
||||
renderer := ui.New(ui.Theme{FontSize: 14}, shaper)
|
||||
|
||||
elems := starterElements()
|
||||
// Channel for window configuration events (resize, orientation)
|
||||
configChan := make(chan ui.ConfigEvent)
|
||||
|
||||
// Initial screen size
|
||||
screenWidth := unit.Dp(390)
|
||||
screenHeight := unit.Dp(844)
|
||||
|
||||
// Compute initial elements
|
||||
elems := ui.EditorLayout(screenWidth, screenHeight)
|
||||
|
||||
for {
|
||||
switch e := w.Event().(type) {
|
||||
case app.DestroyEvent:
|
||||
return e.Err
|
||||
case app.ConfigEvent:
|
||||
// Send config event to logic goroutine (here, the main goroutine)
|
||||
configChan <- ui.ConfigEvent{
|
||||
Width: unit.Dp(e.Config.Size.X),
|
||||
Height: unit.Dp(e.Config.Size.Y),
|
||||
}
|
||||
case app.FrameEvent:
|
||||
// Process any pending config events
|
||||
select {
|
||||
case cfg := <-configChan:
|
||||
// Update screen size and recompute layout
|
||||
screenWidth = cfg.Width
|
||||
screenHeight = cfg.Height
|
||||
elems = ui.EditorLayout(screenWidth, screenHeight)
|
||||
default:
|
||||
// No config event, use existing elements
|
||||
}
|
||||
|
||||
gtx := app.NewContext(&ops, e)
|
||||
renderer.Draw(gtx, elems)
|
||||
e.Frame(&ops)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// starterElements returns a hardcoded set of elements for initial testing.
|
||||
func starterElements() []ui.Element {
|
||||
return []ui.Element{
|
||||
ui.NewLabel("Pad", 20, ui.Region{X: 0, Y: 0, W: 390, H: 48}),
|
||||
ui.NewListView(ui.Region{X: 0, Y: 48, W: 390, H: 700},
|
||||
[]ui.ListItem{
|
||||
{Text: "notes.txt"},
|
||||
{Text: "ideas.txt"},
|
||||
{Text: "todo.txt"},
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user