nasin/examples/icons/main.go

424 lines
11 KiB
Go
Raw Normal View History

2024-05-06 23:30:12 -06:00
// 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"
2024-05-06 23:30:12 -06:00
import "git.tebibyte.media/tomo/objects/layouts"
2024-06-03 01:04:29 -06:00
import "git.tebibyte.media/tomo/nasin/internal/theme/icons/xdg"
2024-05-06 23:30:12 -06:00
2024-05-13 18:11:24 -06:00
const scrollIcons = true
2024-05-07 18:22:07 -06:00
2024-05-06 23:30:12 -06:00
type Application struct {
2024-05-27 14:01:50 -06:00
window tomo.MainWindow
size tomo.IconSize
grid tomo.ContainerBox
2024-05-06 23:30:12 -06:00
}
func (this *Application) Describe () nasin.ApplicationDescription {
return nasin.ApplicationDescription {
Name: "Tomo Icon Example",
ID: "xyz.holanet.TomoIconExample",
}
}
func (this *Application) Init () error {
2024-05-13 18:11:24 -06:00
window, err := nasin.NewApplicationWindow(this, image.Rect(0, 0, 128, 256))
2024-05-06 23:30:12 -06:00
if err != nil { return err }
this.window = window
2024-05-06 23:30:12 -06:00
2024-05-17 13:22:05 -06:00
this.grid = objects.NewSunkenContainer(layouts.FlowVertical)
2024-05-27 14:01:50 -06:00
this.resizeIcons(tomo.IconSizeSmall)
2024-05-06 23:30:12 -06:00
iconButtons := objects.NewInnerContainer(layouts.NewGrid([]bool { true, true, true}, []bool { false }))
button := objects.NewButton("small")
2024-05-27 14:01:50 -06:00
button.SetIcon(tomo.IconZoomOut)
button.OnClick(func () { this.resizeIcons(tomo.IconSizeSmall) })
2024-05-06 23:30:12 -06:00
iconButtons.Add(button)
button = objects.NewButton("medium")
2024-05-27 14:01:50 -06:00
button.SetIcon(tomo.IconZoomOriginal)
button.OnClick(func () { this.resizeIcons(tomo.IconSizeMedium) })
2024-05-06 23:30:12 -06:00
iconButtons.Add(button)
button = objects.NewButton("large")
2024-05-27 14:01:50 -06:00
button.SetIcon(tomo.IconZoomIn)
button.OnClick(func () { this.resizeIcons(tomo.IconSizeLarge) })
2024-05-06 23:30:12 -06:00
iconButtons.Add(button)
container := objects.NewOuterContainer (
layouts.NewGrid([]bool { true }, []bool { false, true, false }),
2024-05-07 18:22:07 -06:00
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)
2024-05-06 23:30:12 -06:00
window.SetRoot(container)
window.OnClose(tomo.Stop)
2024-05-27 14:01:50 -06:00
window.SetVisible(true)
2024-05-06 23:30:12 -06:00
return nil
}
2024-05-27 14:01:50 -06:00
func (this *Application) resizeIcons (size tomo.IconSize) {
2024-05-06 23:30:12 -06:00
this.size = size
this.grid.Clear()
2024-05-27 14:01:50 -06:00
icons := []tomo.Icon {
tomo.IconUnknown,
tomo.IconAddressBookNew,
tomo.IconApplicationExit,
tomo.IconAppointmentNew,
tomo.IconCallStart,
tomo.IconCallStop,
tomo.IconContactNew,
tomo.IconDialogOkay,
tomo.IconDialogCancel,
tomo.IconEditClear,
tomo.IconEditCopy,
tomo.IconEditCut,
tomo.IconEditDelete,
tomo.IconEditFind,
tomo.IconEditFindReplace,
tomo.IconEditPaste,
tomo.IconEditRedo,
tomo.IconEditSelectAll,
tomo.IconEditUndo,
tomo.IconFileNew,
tomo.IconDirectoryNew,
tomo.IconFileOpen,
tomo.IconFileOpenRecent,
tomo.IconFilePageSetup,
tomo.IconFilePrint,
tomo.IconFilePrintPreview,
tomo.IconFilePermissions,
tomo.IconFileProperties,
tomo.IconFileRename,
tomo.IconFileRevert,
tomo.IconFileSave,
tomo.IconFileSaveAs,
tomo.IconFileSend,
tomo.IconFormatIndentLess,
tomo.IconFormatIndentMore,
tomo.IconFormatAlignCenter,
tomo.IconFormatAlignEven,
tomo.IconFormatAlignLeft,
tomo.IconFormatAlignRight,
tomo.IconFormatTextDirectionLtr,
tomo.IconFormatTextDirectionRtl,
tomo.IconFormatTextBold,
tomo.IconFormatTextItalic,
tomo.IconFormatTextUnderline,
tomo.IconFormatTextStrikethrough,
tomo.IconGoBottom,
tomo.IconGoDown,
tomo.IconGoFirst,
tomo.IconGoHome,
tomo.IconGoJump,
tomo.IconGoLast,
tomo.IconGoNext,
tomo.IconGoPrevious,
tomo.IconGoTop,
tomo.IconGoUp,
tomo.IconHelpAbout,
tomo.IconHelpContents,
tomo.IconHelpFaq,
tomo.IconInsertImage,
tomo.IconInsertLink,
tomo.IconInsertObject,
tomo.IconInsertText,
tomo.IconListAdd,
tomo.IconListRemove,
tomo.IconMailForward,
tomo.IconMailMarkImportant,
tomo.IconMailMarkJunk,
tomo.IconMailMarkNotJunk,
tomo.IconMailMarkRead,
tomo.IconMailMarkUnread,
tomo.IconMailMessageNew,
tomo.IconMailReplyAll,
tomo.IconMailReplySender,
tomo.IconMailSend,
tomo.IconMailReceive,
tomo.IconMediaEject,
tomo.IconMediaPlaybackPause,
tomo.IconMediaPlaybackStart,
tomo.IconMediaPlaybackStop,
tomo.IconMediaRecord,
tomo.IconMediaSeekBackward,
tomo.IconMediaSeekForward,
tomo.IconMediaSkipBackward,
tomo.IconMediaSkipForward,
tomo.IconObjectFlipHorizontal,
tomo.IconObjectFlipVertical,
tomo.IconObjectRotateLeft,
tomo.IconObjectRotateRight,
tomo.IconProcessStop,
tomo.IconSystemLockScreen,
tomo.IconSystemLogOut,
tomo.IconSystemRun,
tomo.IconSystemSearch,
tomo.IconSystemReboot,
tomo.IconSystemShutdown,
tomo.IconToolsCheckSpelling,
tomo.IconValueIncrement,
tomo.IconValueDecrement,
tomo.IconValueReset,
tomo.IconViewFullscreen,
tomo.IconViewRefresh,
tomo.IconViewRestore,
tomo.IconViewSortAscending,
tomo.IconViewSortDescending,
tomo.IconWindowClose,
tomo.IconWindowNew,
tomo.IconZoomFitBest,
tomo.IconZoomIn,
tomo.IconZoomOriginal,
tomo.IconZoomOut,
tomo.IconApplication,
tomo.IconApplicationWebBrowser,
tomo.IconApplicationMesssanger,
tomo.IconApplicationPhone,
tomo.IconApplicationMail,
tomo.IconApplicationTerminalEmulator,
tomo.IconApplicationFileBrowser,
tomo.IconApplicationTextEditor,
tomo.IconApplicationDocumentViewer,
tomo.IconApplicationWordProcessor,
tomo.IconApplicationSpreadsheet,
tomo.IconApplicationSlideshow,
tomo.IconApplicationCalculator,
tomo.IconApplicationPreferences,
tomo.IconApplicationProcessManager,
tomo.IconApplicationSystemInformation,
tomo.IconApplicationManual,
tomo.IconApplicationCamera,
tomo.IconApplicationImageViewer,
tomo.IconApplicationMediaPlayer,
tomo.IconApplicationImageEditor,
tomo.IconApplicationAudioEditor,
tomo.IconApplicationVideoEditor,
tomo.IconApplicationClock,
tomo.IconApplicationCalendar,
tomo.IconApplicationChecklist,
tomo.IconApplications,
tomo.IconApplicationsAccessories,
tomo.IconApplicationsDevelopment,
tomo.IconApplicationsEngineering,
tomo.IconApplicationsGames,
tomo.IconApplicationsGraphics,
tomo.IconApplicationsInternet,
tomo.IconApplicationsMultimedia,
tomo.IconApplicationsOffice,
tomo.IconApplicationsScience,
tomo.IconApplicationsSystem,
tomo.IconApplicationsUtilities,
tomo.IconPreferences,
tomo.IconPreferencesDesktop,
tomo.IconPreferencesPeripherals,
tomo.IconPreferencesPersonal,
tomo.IconPreferencesSystem,
tomo.IconPreferencesNetwork,
tomo.IconDevice,
tomo.IconDeviceCamera,
tomo.IconDeviceWebCamera,
tomo.IconDeviceComputer,
tomo.IconDevicePda,
tomo.IconDevicePhone,
tomo.IconDevicePrinter,
tomo.IconDeviceScanner,
tomo.IconDeviceMultimediaPlayer,
tomo.IconDeviceVideoDisplay,
tomo.IconDeviceAudioInput,
tomo.IconDeviceAudioOutput,
tomo.IconHardware,
tomo.IconHardwareCPU,
tomo.IconHardwareGPU,
tomo.IconHardwareRAM,
tomo.IconHardwareSoundCard,
tomo.IconHardwareNetworkAdapter,
tomo.IconPowerBattery,
tomo.IconStorageHardDisk,
tomo.IconStorageFloppyDisk,
tomo.IconStorageSolidState,
tomo.IconStorageOptical,
tomo.IconStorageFlashStick,
tomo.IconStorageFlashCard,
tomo.IconStorageMagneticTape,
tomo.IconInputGaming,
tomo.IconInputKeyboard,
tomo.IconInputMouse,
tomo.IconInputTablet,
tomo.IconNetworkWired,
tomo.IconNetworkWireless,
tomo.IconNetworkCellular,
tomo.IconNetworkLocal,
tomo.IconNetworkInternet,
tomo.IconNetworkVPN,
tomo.IconNetworkServer,
tomo.IconNetworkWorkgroup,
tomo.IconEmblemDefault,
tomo.IconEmblemEncrypted,
tomo.IconEmblemFavorite,
tomo.IconEmblemImportant,
tomo.IconEmblemReadOnly,
tomo.IconEmblemShared,
tomo.IconEmblemSymbolicLink,
tomo.IconEmblemSynchronized,
tomo.IconEmblemSystem,
tomo.IconEmblemUnreadable,
tomo.IconPlaceDirectory,
tomo.IconPlaceRemote,
tomo.IconPlaceHome,
tomo.IconPlaceDownloads,
tomo.IconPlaceDesktop,
tomo.IconPlacePhotos,
tomo.IconPlaceBooks,
tomo.IconPlaceBookmarks,
tomo.IconPlaceTrash,
tomo.IconPlaceDocuments,
tomo.IconPlaceRepositories,
tomo.IconPlaceMusic,
tomo.IconPlaceArchives,
tomo.IconPlaceFonts,
tomo.IconPlaceBinaries,
tomo.IconPlaceVideos,
tomo.IconPlace3DObjects,
tomo.IconPlaceHistory,
tomo.IconPlacePreferences,
tomo.IconCheckboxChecked,
tomo.IconCheckboxUnchecked,
tomo.IconAppointmentMissed,
tomo.IconAppointmentSoon,
tomo.IconDialogError,
tomo.IconDialogInformation,
tomo.IconDialogPassword,
tomo.IconDialogQuestion,
tomo.IconDialogWarning,
tomo.IconDirectoryDragAccept,
tomo.IconDirectoryFull,
tomo.IconDirectoryOpen,
tomo.IconDirectoryVisiting,
tomo.IconTrashFull,
tomo.IconResourceLoading,
tomo.IconResourceMissing,
tomo.IconMailAttachment,
tomo.IconMailUnread,
tomo.IconMailReplied,
tomo.IconMailSigned,
tomo.IconMailSignedVerified,
tomo.IconCellularSignal0,
tomo.IconCellularSignal1,
tomo.IconCellularSignal2,
tomo.IconCellularSignal3,
tomo.IconWirelessSignal0,
tomo.IconWirelessSignal1,
tomo.IconWirelessSignal2,
tomo.IconWirelessSignal3,
tomo.IconNetworkError,
tomo.IconNetworkIdle,
tomo.IconNetworkOffline,
tomo.IconNetworkReceive,
tomo.IconNetworkTransmit,
tomo.IconNetworkTransmitReceive,
tomo.IconPrintError,
tomo.IconPrintPrinting,
tomo.IconSecurityHigh,
tomo.IconSecurityMedium,
tomo.IconSecurityLow,
tomo.IconSoftwareUpdateAvailable,
tomo.IconSoftwareUpdateUrgent,
tomo.IconSoftwareInstalling,
tomo.IconSyncError,
tomo.IconSyncSynchronizing,
tomo.IconTaskDue,
tomo.IconTaskPastDue,
tomo.IconUserAvailable,
tomo.IconUserAway,
tomo.IconUserIdle,
tomo.IconUserOffline,
tomo.IconBattery0,
tomo.IconBattery1,
tomo.IconBattery2,
tomo.IconBattery3,
tomo.IconBrightness0,
tomo.IconBrightness1,
tomo.IconBrightness2,
tomo.IconBrightness3,
tomo.IconVolume0,
tomo.IconVolume1,
tomo.IconVolume2,
tomo.IconVolume3,
tomo.IconPlaylistRepeat,
tomo.IconPlaylistShuffle,
tomo.IconWeatherClear,
tomo.IconWeatherClearNight,
tomo.IconWeatherFewClouds,
tomo.IconWeatherFewCloudsNight,
tomo.IconWeatherFog,
tomo.IconWeatherOvercast,
tomo.IconWeatherSevereAlert,
tomo.IconWeatherShowers,
tomo.IconWeatherShowersScattered,
tomo.IconWeatherSnow,
tomo.IconWeatherStorm,
2024-05-06 23:30:12 -06:00
}
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)
})
2024-05-06 23:30:12 -06:00
}
}
2024-05-27 14:01:50 -06:00
func (this *Application) iconPopup (icon tomo.Icon) error {
popup, err := this.window.NewModal(image.Rectangle { })
if err != nil { return err }
2024-05-27 14:01:50 -06:00
if icon == "" {
icon = "<UNKNOWN>"
}
2024-05-28 19:57:34 -06:00
sizesRow := objects.NewSunkenContainer (
layouts.ContractHorizontal,
2024-05-27 14:01:50 -06:00
objects.NewIcon(icon, tomo.IconSizeSmall),
objects.NewIcon(icon, tomo.IconSizeMedium),
objects.NewIcon(icon, tomo.IconSizeLarge))
2024-05-28 19:57:34 -06:00
sizesRow.SetAlign(tomo.AlignMiddle, tomo.AlignMiddle)
okButton := objects.NewButton("OK")
2024-05-28 19:57:34 -06:00
okButton.SetFocused(true)
okButton.OnClick(popup.Close)
2024-05-27 14:01:50 -06:00
okButton.SetIcon(tomo.IconDialogOkay)
controlRow := objects.NewInnerContainer (
layouts.ContractHorizontal,
okButton)
controlRow.SetAlign(tomo.AlignEnd, tomo.AlignMiddle)
popup.SetRoot(objects.NewOuterContainer (
2024-05-28 19:57:34 -06:00
layouts.NewGrid([]bool { true }, []bool { false, false, true, false }),
objects.NewLabel("Icon ID: " + string(icon)),
2024-05-28 19:57:34 -06:00
objects.NewLabel("XDG Name: " + xdgIcons.XdgIconName(icon)),
sizesRow,
controlRow,
))
popup.SetTitle(string(icon) + ": Properties")
2024-05-27 14:01:50 -06:00
popup.SetVisible(true)
return nil
}
2024-05-06 23:30:12 -06:00
func main () {
nasin.RunApplication(&Application { })
}