Icon example now shows icon details when one is clicked
This commit is contained in:
parent
a514e99d51
commit
4557769cb4
@ -5,12 +5,14 @@ import "image"
|
||||
import "git.tebibyte.media/tomo/tomo"
|
||||
import "git.tebibyte.media/tomo/nasin"
|
||||
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/objects/layouts"
|
||||
|
||||
const scrollIcons = true
|
||||
|
||||
type Application struct {
|
||||
window tomo.Window
|
||||
size theme.IconSize
|
||||
grid tomo.ContainerBox
|
||||
}
|
||||
@ -25,6 +27,7 @@ func (this *Application) Describe () nasin.ApplicationDescription {
|
||||
func (this *Application) Init () error {
|
||||
window, err := nasin.NewApplicationWindow(this, image.Rect(0, 0, 128, 256))
|
||||
if err != nil { return err }
|
||||
this.window = window
|
||||
|
||||
this.grid = objects.NewSunkenContainer(layouts.FlowVertical)
|
||||
this.resizeIcons(theme.IconSizeSmall)
|
||||
@ -186,10 +189,55 @@ func (this *Application) resizeIcons (size theme.IconSize) {
|
||||
}
|
||||
|
||||
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 () {
|
||||
nasin.RunApplication(&Application { })
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user