63 lines
1.6 KiB
Go
63 lines
1.6 KiB
Go
package ui
|
|
|
|
import (
|
|
"gioui.org/layout"
|
|
"gioui.org/widget"
|
|
"gioui.org/widget/material"
|
|
)
|
|
|
|
type HomePage struct {
|
|
searchButton *widget.Clickable
|
|
searchField *widget.Editor
|
|
theme *material.Theme
|
|
}
|
|
|
|
func NewHomePage(theme *material.Theme) *HomePage {
|
|
return &HomePage{
|
|
searchButton: &widget.Clickable{},
|
|
theme: theme,
|
|
searchField: &widget.Editor{SingleLine: true},
|
|
}
|
|
}
|
|
|
|
func searchClicked(searchField *widget.Editor) {
|
|
query := searchField.Text()
|
|
searchField.SetText("")
|
|
println("Search query:", query)
|
|
}
|
|
|
|
func (h *HomePage) Layout(gtx layout.Context) layout.Dimensions {
|
|
return layout.UniformInset(16).Layout(gtx, func(gtx layout.Context) layout.Dimensions {
|
|
return layout.Flex{
|
|
Axis: layout.Vertical,
|
|
}.Layout(gtx,
|
|
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
|
return layout.Center.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
|
|
return layout.Flex{
|
|
Axis: layout.Vertical,
|
|
}.Layout(gtx,
|
|
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
|
return layout.Flex{
|
|
Axis: layout.Horizontal,
|
|
}.Layout(gtx,
|
|
layout.Flexed(0.5, func(gtx layout.Context) layout.Dimensions {
|
|
return material.Editor(h.theme, h.searchField, "Search...").Layout(gtx)
|
|
}),
|
|
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
|
if h.searchButton.Clicked(gtx) {
|
|
searchClicked(h.searchField)
|
|
}
|
|
return material.Button(h.theme, h.searchButton, "Search").Layout(gtx)
|
|
}),
|
|
)
|
|
}),
|
|
)
|
|
})
|
|
}),
|
|
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
|
|
|
return layout.Dimensions{}
|
|
}),
|
|
)
|
|
})
|
|
}
|