Update examples to use new API

This commit is contained in:
Sasha Koshka 2024-05-27 16:01:50 -04:00
parent a52a703ec1
commit 1142cb7ab6
4 changed files with 327 additions and 154 deletions

View File

@ -9,7 +9,6 @@ import "image/color"
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/theme"
import "git.tebibyte.media/tomo/tomo/canvas" import "git.tebibyte.media/tomo/tomo/canvas"
import "git.tebibyte.media/tomo/objects/layouts" import "git.tebibyte.media/tomo/objects/layouts"
@ -46,7 +45,7 @@ func (this *Application) Init () error {
} () } ()
window.OnClose(tomo.Stop) window.OnClose(tomo.Stop)
window.Show() window.SetVisible(true)
return nil return nil
} }
@ -69,7 +68,7 @@ func NewClockFace () *ClockFace {
box := &ClockFace { box := &ClockFace {
CanvasBox: tomo.NewCanvasBox(), CanvasBox: tomo.NewCanvasBox(),
} }
theme.Apply(box, theme.R("nasin", "ClockFace", "")) tomo.Apply(box, tomo.R("nasin", "ClockFace", ""))
box.SetDrawer(box) box.SetDrawer(box)
return box return box
} }
@ -89,7 +88,7 @@ func (this *ClockFace) Draw (destination canvas.Canvas) {
for hour := 0; hour < 12; hour ++ { for hour := 0; hour < 12; hour ++ {
radialLine ( radialLine (
destination, destination,
theme.ColorForeground, tomo.ColorForeground,
0.8, 0.9, float64(hour) / 6 * math.Pi) 0.8, 0.9, float64(hour) / 6 * math.Pi)
} }
@ -97,9 +96,9 @@ func (this *ClockFace) Draw (destination canvas.Canvas) {
minute := float64(this.time.Minute()) + second / 60 minute := float64(this.time.Minute()) + second / 60
hour := float64(this.time.Hour()) + minute / 60 hour := float64(this.time.Hour()) + minute / 60
radialLine(destination, theme.ColorForeground, 0, 0.5, (hour - 3) / 6 * math.Pi) radialLine(destination, tomo.ColorForeground, 0, 0.5, (hour - 3) / 6 * math.Pi)
radialLine(destination, theme.ColorForeground, 0, 0.7, (minute - 15) / 30 * math.Pi) radialLine(destination, tomo.ColorForeground, 0, 0.7, (minute - 15) / 30 * math.Pi)
radialLine(destination, theme.ColorAccent, 0, 0.7, (second - 15) / 30 * math.Pi) radialLine(destination, tomo.ColorAccent, 0, 0.7, (second - 15) / 30 * math.Pi)
} }
func radialLine ( func radialLine (

View File

@ -6,14 +6,13 @@ 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/input"
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 {
window tomo.Window window tomo.MainWindow
size theme.IconSize size tomo.IconSize
grid tomo.ContainerBox grid tomo.ContainerBox
} }
@ -30,23 +29,23 @@ func (this *Application) Init () error {
this.window = window this.window = window
this.grid = objects.NewSunkenContainer(layouts.FlowVertical) this.grid = objects.NewSunkenContainer(layouts.FlowVertical)
this.resizeIcons(theme.IconSizeSmall) this.resizeIcons(tomo.IconSizeSmall)
iconButtons := objects.NewInnerContainer(layouts.NewGrid([]bool { true, true, true}, []bool { false })) iconButtons := objects.NewInnerContainer(layouts.NewGrid([]bool { true, true, true}, []bool { false }))
button := objects.NewButton("small") button := objects.NewButton("small")
button.SetIcon(theme.IconActionZoomOut) button.SetIcon(tomo.IconZoomOut)
button.OnClick(func () { this.resizeIcons(theme.IconSizeSmall) }) button.OnClick(func () { this.resizeIcons(tomo.IconSizeSmall) })
iconButtons.Add(button) iconButtons.Add(button)
button = objects.NewButton("medium") button = objects.NewButton("medium")
button.SetIcon(theme.IconActionZoomReset) button.SetIcon(tomo.IconZoomOriginal)
button.OnClick(func () { this.resizeIcons(theme.IconSizeMedium) }) button.OnClick(func () { this.resizeIcons(tomo.IconSizeMedium) })
iconButtons.Add(button) iconButtons.Add(button)
button = objects.NewButton("large") button = objects.NewButton("large")
button.SetIcon(theme.IconActionZoomIn) button.SetIcon(tomo.IconZoomIn)
button.OnClick(func () { this.resizeIcons(theme.IconSizeLarge) }) button.OnClick(func () { this.resizeIcons(tomo.IconSizeLarge) })
iconButtons.Add(button) iconButtons.Add(button)
container := objects.NewOuterContainer ( container := objects.NewOuterContainer (
@ -64,128 +63,311 @@ func (this *Application) Init () error {
window.SetRoot(container) window.SetRoot(container)
window.OnClose(tomo.Stop) window.OnClose(tomo.Stop)
window.Show() window.SetVisible(true)
return nil return nil
} }
func (this *Application) resizeIcons (size theme.IconSize) { func (this *Application) resizeIcons (size tomo.IconSize) {
this.size = size this.size = size
this.grid.Clear() this.grid.Clear()
icons := []theme.Icon { icons := []tomo.Icon {
theme.IconUnknown, tomo.IconUnknown,
theme.IconFile, tomo.IconAddressBookNew,
theme.IconDirectory, tomo.IconApplicationExit,
theme.IconStorage, tomo.IconAppointmentNew,
theme.IconApplication, tomo.IconCallStart,
theme.IconNetwork, tomo.IconCallStop,
theme.IconDevice, tomo.IconContactNew,
theme.IconPeripheral, tomo.IconDialogOkay,
theme.IconPort, tomo.IconDialogCancel,
theme.IconActionOpen, tomo.IconEditClear,
theme.IconActionOpenIn, tomo.IconEditCopy,
theme.IconActionSave, tomo.IconEditCut,
theme.IconActionSaveAs, tomo.IconEditDelete,
theme.IconActionPrint, tomo.IconEditFind,
theme.IconActionNew, tomo.IconEditFindReplace,
theme.IconActionNewDirectory, tomo.IconEditPaste,
theme.IconActionDelete, tomo.IconEditRedo,
theme.IconActionRename, tomo.IconEditSelectAll,
theme.IconActionGetInformation, tomo.IconEditUndo,
theme.IconActionChangePermissions, tomo.IconFileNew,
theme.IconActionRevert, tomo.IconDirectoryNew,
theme.IconActionAdd, tomo.IconFileOpen,
theme.IconActionRemove, tomo.IconFileOpenRecent,
theme.IconActionAddBookmark, tomo.IconFilePageSetup,
theme.IconActionRemoveBookmark, tomo.IconFilePrint,
theme.IconActionAddFavorite, tomo.IconFilePrintPreview,
theme.IconActionRemoveFavorite, tomo.IconFilePermissions,
theme.IconActionPlay, tomo.IconFileProperties,
theme.IconActionPause, tomo.IconFileRename,
theme.IconActionStop, tomo.IconFileRevert,
theme.IconActionFastForward, tomo.IconFileSave,
theme.IconActionRewind, tomo.IconFileSaveAs,
theme.IconActionToBeginning, tomo.IconFileSend,
theme.IconActionToEnd, tomo.IconFormatIndentLess,
theme.IconActionRecord, tomo.IconFormatIndentMore,
theme.IconActionVolumeUp, tomo.IconFormatAlignCenter,
theme.IconActionVolumeDown, tomo.IconFormatAlignEven,
theme.IconActionMute, tomo.IconFormatAlignLeft,
theme.IconActionUndo, tomo.IconFormatAlignRight,
theme.IconActionRedo, tomo.IconFormatTextDirectionLtr,
theme.IconActionCut, tomo.IconFormatTextDirectionRtl,
theme.IconActionCopy, tomo.IconFormatTextBold,
theme.IconActionPaste, tomo.IconFormatTextItalic,
theme.IconActionFind, tomo.IconFormatTextUnderline,
theme.IconActionReplace, tomo.IconFormatTextStrikethrough,
theme.IconActionSelectAll, tomo.IconGoBottom,
theme.IconActionSelectNone, tomo.IconGoDown,
theme.IconActionIncrement, tomo.IconGoFirst,
theme.IconActionDecrement, tomo.IconGoHome,
theme.IconActionClose, tomo.IconGoJump,
theme.IconActionQuit, tomo.IconGoLast,
theme.IconActionIconify, tomo.IconGoNext,
theme.IconActionShade, tomo.IconGoPrevious,
theme.IconActionMaximize, tomo.IconGoTop,
theme.IconActionFullScreen, tomo.IconGoUp,
theme.IconActionRestore, tomo.IconHelpAbout,
theme.IconActionExpand, tomo.IconHelpContents,
theme.IconActionContract, tomo.IconHelpFaq,
theme.IconActionBack, tomo.IconInsertImage,
theme.IconActionForward, tomo.IconInsertLink,
theme.IconActionUp, tomo.IconInsertObject,
theme.IconActionDown, tomo.IconInsertText,
theme.IconActionReload, tomo.IconListAdd,
theme.IconActionZoomIn, tomo.IconListRemove,
theme.IconActionZoomOut, tomo.IconMailForward,
theme.IconActionZoomReset, tomo.IconMailMarkImportant,
theme.IconActionMove, tomo.IconMailMarkJunk,
theme.IconActionResize, tomo.IconMailMarkNotJunk,
theme.IconActionGoTo, tomo.IconMailMarkRead,
theme.IconActionTransform, tomo.IconMailMarkUnread,
theme.IconActionTranslate, tomo.IconMailMessageNew,
theme.IconActionRotate, tomo.IconMailReplyAll,
theme.IconActionScale, tomo.IconMailReplySender,
theme.IconActionWarp, tomo.IconMailSend,
theme.IconActionCornerPin, tomo.IconMailReceive,
theme.IconActionSelectRectangle, tomo.IconMediaEject,
theme.IconActionSelectEllipse, tomo.IconMediaPlaybackPause,
theme.IconActionSelectLasso, tomo.IconMediaPlaybackStart,
theme.IconActionSelectGeometric, tomo.IconMediaPlaybackStop,
theme.IconActionSelectAuto, tomo.IconMediaRecord,
theme.IconActionCrop, tomo.IconMediaSeekBackward,
theme.IconActionFill, tomo.IconMediaSeekForward,
theme.IconActionGradient, tomo.IconMediaSkipBackward,
theme.IconActionPencil, tomo.IconMediaSkipForward,
theme.IconActionBrush, tomo.IconObjectFlipHorizontal,
theme.IconActionEraser, tomo.IconObjectFlipVertical,
theme.IconActionText, tomo.IconObjectRotateLeft,
theme.IconActionEyedropper, tomo.IconObjectRotateRight,
theme.IconStatusInformation, tomo.IconProcessStop,
theme.IconStatusQuestion, tomo.IconSystemLockScreen,
theme.IconStatusWarning, tomo.IconSystemLogOut,
theme.IconStatusError, tomo.IconSystemRun,
theme.IconStatusCancel, tomo.IconSystemSearch,
theme.IconStatusOkay, tomo.IconSystemReboot,
theme.IconStatusCellSignal0, tomo.IconSystemShutdown,
theme.IconStatusCellSignal1, tomo.IconToolsCheckSpelling,
theme.IconStatusCellSignal2, tomo.IconValueIncrement,
theme.IconStatusCellSignal3, tomo.IconValueDecrement,
theme.IconStatusWirelessSignal0, tomo.IconValueReset,
theme.IconStatusWirelessSignal1, tomo.IconViewFullscreen,
theme.IconStatusWirelessSignal2, tomo.IconViewRefresh,
theme.IconStatusWirelessSignal3, tomo.IconViewRestore,
theme.IconStatusBattery0, tomo.IconViewSortAscending,
theme.IconStatusBattery1, tomo.IconViewSortDescending,
theme.IconStatusBattery2, tomo.IconWindowClose,
theme.IconStatusBattery3, tomo.IconWindowNew,
theme.IconStatusBrightness0, tomo.IconZoomFitBest,
theme.IconStatusBrightness1, tomo.IconZoomIn,
theme.IconStatusBrightness2, tomo.IconZoomOriginal,
theme.IconStatusBrightness3, tomo.IconZoomOut,
theme.IconStatusVolume0, tomo.IconApplication,
theme.IconStatusVolume1, tomo.IconApplicationWebBrowser,
theme.IconStatusVolume2, tomo.IconApplicationMesssanger,
theme.IconStatusVolume3, 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,
} }
for _, icon := range icons { for _, icon := range icons {
@ -199,29 +381,23 @@ func (this *Application) resizeIcons (size theme.IconSize) {
} }
} }
func (this *Application) iconPopup (icon theme.Icon) error { func (this *Application) iconPopup (icon tomo.Icon) error {
popup, err := this.window.NewModal(image.Rectangle { }) popup, err := this.window.NewModal(image.Rectangle { })
if err != nil { return err } if err != nil { return err }
// FIXME: remove this once https://git.tebibyte.media/tomo/tomo/issues/8 if icon == "" {
// is addressed and objects.Icon makes use of it icon = "<UNKNOWN>"
valign := func (child tomo.Object) tomo.Object {
container := objects.NewInnerContainer (
layouts.ContractVertical,
child)
container.SetAlign(tomo.AlignMiddle, tomo.AlignMiddle)
return container
} }
sizesRow := objects.NewInnerContainer ( sizesRow := objects.NewInnerContainer (
layouts.ContractHorizontal, layouts.ContractHorizontal,
valign(objects.NewIcon(icon, theme.IconSizeSmall)), objects.NewIcon(icon, tomo.IconSizeSmall),
valign(objects.NewIcon(icon, theme.IconSizeMedium)), objects.NewIcon(icon, tomo.IconSizeMedium),
valign(objects.NewIcon(icon, theme.IconSizeLarge))) objects.NewIcon(icon, tomo.IconSizeLarge))
okButton := objects.NewButton("OK") okButton := objects.NewButton("OK")
okButton.OnClick(popup.Close) okButton.OnClick(popup.Close)
okButton.SetIcon(theme.IconStatusOkay) okButton.SetIcon(tomo.IconDialogOkay)
controlRow := objects.NewInnerContainer ( controlRow := objects.NewInnerContainer (
layouts.ContractHorizontal, layouts.ContractHorizontal,
okButton) okButton)
@ -234,7 +410,7 @@ func (this *Application) iconPopup (icon theme.Icon) error {
controlRow, controlRow,
)) ))
popup.SetTitle(string(icon) + ": Properties") popup.SetTitle(string(icon) + ": Properties")
popup.Show() popup.SetVisible(true)
return nil return nil
} }

View File

@ -5,7 +5,6 @@ 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/theme"
import "git.tebibyte.media/tomo/objects/layouts" import "git.tebibyte.media/tomo/objects/layouts"
type Application struct { } type Application struct { }
@ -29,7 +28,7 @@ func (this *Application) Init () error {
)) ))
window.OnClose(tomo.Stop) window.OnClose(tomo.Stop)
window.Show() window.SetVisible(true)
return nil return nil
} }

View File

@ -7,7 +7,6 @@ import _ "embed"
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/theme"
import "git.tebibyte.media/tomo/objects/layouts" import "git.tebibyte.media/tomo/objects/layouts"
//go:embed LICENSE //go:embed LICENSE
@ -30,7 +29,7 @@ func (this *Application) Init () error {
checkbox.SetFocused(true) checkbox.SetFocused(true)
okButtok := objects.NewButton("OK") okButtok := objects.NewButton("OK")
okButtok.SetIcon(theme.IconStatusOkay) okButtok.SetIcon(tomo.IconDialogOkay)
okButtok.OnClick(func () { okButtok.OnClick(func () {
if checkbox.Value() { if checkbox.Value() {
window.Close() window.Close()
@ -38,7 +37,7 @@ func (this *Application) Init () error {
dialog, _ := objects.NewDialogOk ( dialog, _ := objects.NewDialogOk (
objects.DialogInformation, window, objects.DialogInformation, window,
"", "You must read and agree to the license terms", nil) "", "You must read and agree to the license terms", nil)
dialog.Show() dialog.SetVisible(true)
} }
}) })
@ -54,7 +53,7 @@ func (this *Application) Init () error {
okButtok))) okButtok)))
window.OnClose(tomo.Stop) window.OnClose(tomo.Stop)
window.Show() window.SetVisible(true)
return nil return nil
} }