// Example icons demonstrates the use of icons, and buttons with icons. package main 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 } func (this *Application) Describe () nasin.ApplicationDescription { return nasin.ApplicationDescription { Name: "Tomo Icon Example", ID: "xyz.holanet.TomoIconExample", } } 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) iconButtons := objects.NewInnerContainer(layouts.NewGrid([]bool { true, true, true}, []bool { false })) button := objects.NewButton("small") button.SetIcon(theme.IconActionZoomOut) button.OnClick(func () { this.resizeIcons(theme.IconSizeSmall) }) iconButtons.Add(button) button = objects.NewButton("medium") button.SetIcon(theme.IconActionZoomReset) button.OnClick(func () { this.resizeIcons(theme.IconSizeMedium) }) iconButtons.Add(button) button = objects.NewButton("large") button.SetIcon(theme.IconActionZoomIn) button.OnClick(func () { this.resizeIcons(theme.IconSizeLarge) }) iconButtons.Add(button) container := objects.NewOuterContainer ( layouts.NewGrid([]bool { true }, []bool { false, true, false }), objects.NewLabel("A smorgasbord of icons:")) if scrollIcons { iconScroller := objects.NewScrollContainer(objects.ScrollVertical) this.grid.SetOverflow(false, true) iconScroller.SetRoot(this.grid) container.Add(iconScroller) } else { container.Add(this.grid) } container.Add(iconButtons) window.SetRoot(container) window.OnClose(tomo.Stop) window.Show() return nil } func (this *Application) resizeIcons (size theme.IconSize) { this.size = size this.grid.Clear() icons := []theme.Icon { theme.IconUnknown, theme.IconFile, theme.IconDirectory, theme.IconStorage, theme.IconApplication, theme.IconNetwork, theme.IconDevice, theme.IconPeripheral, theme.IconPort, theme.IconActionOpen, theme.IconActionOpenIn, theme.IconActionSave, theme.IconActionSaveAs, theme.IconActionPrint, theme.IconActionNew, theme.IconActionNewDirectory, theme.IconActionDelete, theme.IconActionRename, theme.IconActionGetInformation, theme.IconActionChangePermissions, theme.IconActionRevert, theme.IconActionAdd, theme.IconActionRemove, theme.IconActionAddBookmark, theme.IconActionRemoveBookmark, theme.IconActionAddFavorite, theme.IconActionRemoveFavorite, theme.IconActionPlay, theme.IconActionPause, theme.IconActionStop, theme.IconActionFastForward, theme.IconActionRewind, theme.IconActionToBeginning, theme.IconActionToEnd, theme.IconActionRecord, theme.IconActionVolumeUp, theme.IconActionVolumeDown, theme.IconActionMute, theme.IconActionUndo, theme.IconActionRedo, theme.IconActionCut, theme.IconActionCopy, theme.IconActionPaste, theme.IconActionFind, theme.IconActionReplace, theme.IconActionSelectAll, theme.IconActionSelectNone, theme.IconActionIncrement, theme.IconActionDecrement, theme.IconActionClose, theme.IconActionQuit, theme.IconActionIconify, theme.IconActionShade, theme.IconActionMaximize, theme.IconActionFullScreen, theme.IconActionRestore, theme.IconActionExpand, theme.IconActionContract, theme.IconActionBack, theme.IconActionForward, theme.IconActionUp, theme.IconActionDown, theme.IconActionReload, theme.IconActionZoomIn, theme.IconActionZoomOut, theme.IconActionZoomReset, theme.IconActionMove, theme.IconActionResize, theme.IconActionGoTo, theme.IconActionTransform, theme.IconActionTranslate, theme.IconActionRotate, theme.IconActionScale, theme.IconActionWarp, theme.IconActionCornerPin, theme.IconActionSelectRectangle, theme.IconActionSelectEllipse, theme.IconActionSelectLasso, theme.IconActionSelectGeometric, theme.IconActionSelectAuto, theme.IconActionCrop, theme.IconActionFill, theme.IconActionGradient, theme.IconActionPencil, theme.IconActionBrush, theme.IconActionEraser, theme.IconActionText, theme.IconActionEyedropper, theme.IconStatusInformation, theme.IconStatusQuestion, theme.IconStatusWarning, theme.IconStatusError, theme.IconStatusCancel, theme.IconStatusOkay, theme.IconStatusCellSignal0, theme.IconStatusCellSignal1, theme.IconStatusCellSignal2, theme.IconStatusCellSignal3, theme.IconStatusWirelessSignal0, theme.IconStatusWirelessSignal1, theme.IconStatusWirelessSignal2, theme.IconStatusWirelessSignal3, theme.IconStatusBattery0, theme.IconStatusBattery1, theme.IconStatusBattery2, theme.IconStatusBattery3, theme.IconStatusBrightness0, theme.IconStatusBrightness1, theme.IconStatusBrightness2, theme.IconStatusBrightness3, theme.IconStatusVolume0, theme.IconStatusVolume1, theme.IconStatusVolume2, theme.IconStatusVolume3, } for _, icon := range icons { 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 { }) }