Pad/cmd/pad/main.go
Greg Pomerantz 869f0b13ac 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>
2026-05-08 16:22:46 -04:00

72 lines
1.4 KiB
Go

package main
import (
"log"
"os"
"gioui.org/app"
"gioui.org/op"
"gioui.org/text"
"gioui.org/unit"
"pad/internal/ui"
)
func main() {
go func() {
w := new(app.Window)
w.Option(app.Title("Pad"))
w.Option(app.Size(unit.Dp(390), unit.Dp(844)))
if err := run(w); err != nil {
log.Fatal(err)
}
os.Exit(0)
}()
app.Main()
}
func run(w *app.Window) error {
var ops op.Ops
shaper := text.NewShaper()
renderer := ui.New(ui.Theme{FontSize: 14}, shaper)
// 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)
}
}
}