Add Gioui scaffolding with Label and ListView rendering
- Element interface with Region() and Visible() methods - Label and ListView element types with constructors - Renderer that clips and draws elements in slice order - Main app loop with Gioui window and frame events Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"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)
|
||||
}
|
||||
}()
|
||||
app.Main()
|
||||
}
|
||||
|
||||
func run(w *app.Window) error {
|
||||
var ops op.Ops
|
||||
|
||||
shaper := text.NewShaper()
|
||||
renderer := ui.New(ui.Theme{FontSize: 14}, shaper)
|
||||
|
||||
elems := starterElements()
|
||||
|
||||
for {
|
||||
switch e := w.Event().(type) {
|
||||
case app.DestroyEvent:
|
||||
return e.Err
|
||||
case app.FrameEvent:
|
||||
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