Icon example now shows icon details when one is clicked

This commit is contained in:
Sasha Koshka 2024-05-20 13:58:07 -04:00
parent a514e99d51
commit 4557769cb4

View File

@ -5,14 +5,16 @@ import "image"
import "git.tebibyte.media/tomo/tomo" import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/nasin" import "git.tebibyte.media/tomo/nasin"
import "git.tebibyte.media/tomo/objects" import "git.tebibyte.media/tomo/objects"
import "git.tebibyte.media/tomo/tomo/input"
import "git.tebibyte.media/tomo/tomo/theme" import "git.tebibyte.media/tomo/tomo/theme"
import "git.tebibyte.media/tomo/objects/layouts" import "git.tebibyte.media/tomo/objects/layouts"
const scrollIcons = true const scrollIcons = true
type Application struct { type Application struct {
size theme.IconSize window tomo.Window
grid tomo.ContainerBox size theme.IconSize
grid tomo.ContainerBox
} }
func (this *Application) Describe () nasin.ApplicationDescription { func (this *Application) Describe () nasin.ApplicationDescription {
@ -25,6 +27,7 @@ func (this *Application) Describe () nasin.ApplicationDescription {
func (this *Application) Init () error { func (this *Application) Init () error {
window, err := nasin.NewApplicationWindow(this, image.Rect(0, 0, 128, 256)) window, err := nasin.NewApplicationWindow(this, image.Rect(0, 0, 128, 256))
if err != nil { return err } if err != nil { return err }
this.window = window
this.grid = objects.NewSunkenContainer(layouts.FlowVertical) this.grid = objects.NewSunkenContainer(layouts.FlowVertical)
this.resizeIcons(theme.IconSizeSmall) this.resizeIcons(theme.IconSizeSmall)
@ -186,10 +189,55 @@ func (this *Application) resizeIcons (size theme.IconSize) {
} }
for _, icon := range icons { for _, icon := range icons {
this.grid.Add(objects.NewIcon(icon, size)) iconObject := objects.NewIcon(icon, size)
this.grid.Add(iconObject)
icon := icon
iconObject.OnMouseDown(func (button input.Button) {
if button != input.ButtonLeft { return }
this.iconPopup(icon)
})
} }
} }
func (this *Application) iconPopup (icon theme.Icon) error {
popup, err := this.window.NewModal(image.Rectangle { })
if err != nil { return err }
// FIXME: remove this once https://git.tebibyte.media/tomo/tomo/issues/8
// is addressed and objects.Icon makes use of it
valign := func (child tomo.Object) tomo.Object {
container := objects.NewInnerContainer (
layouts.ContractVertical,
child)
container.SetAlign(tomo.AlignMiddle, tomo.AlignMiddle)
return container
}
sizesRow := objects.NewInnerContainer (
layouts.ContractHorizontal,
valign(objects.NewIcon(icon, theme.IconSizeSmall)),
valign(objects.NewIcon(icon, theme.IconSizeMedium)),
valign(objects.NewIcon(icon, theme.IconSizeLarge)))
okButton := objects.NewButton("OK")
okButton.OnClick(popup.Close)
okButton.SetIcon(theme.IconStatusOkay)
controlRow := objects.NewInnerContainer (
layouts.ContractHorizontal,
okButton)
controlRow.SetAlign(tomo.AlignEnd, tomo.AlignMiddle)
popup.SetRoot(objects.NewOuterContainer (
layouts.NewGrid([]bool { true }, []bool { true, false }),
objects.NewLabel("Icon ID: " + string(icon)),
sizesRow,
controlRow,
))
popup.SetTitle(string(icon) + ": Properties")
popup.Show()
return nil
}
func main () { func main () {
nasin.RunApplication(&Application { }) nasin.RunApplication(&Application { })
} }