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/nasin"
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/objects/layouts"
@ -46,7 +45,7 @@ func (this *Application) Init () error {
} ()
window.OnClose(tomo.Stop)
window.Show()
window.SetVisible(true)
return nil
}
@ -69,7 +68,7 @@ func NewClockFace () *ClockFace {
box := &ClockFace {
CanvasBox: tomo.NewCanvasBox(),
}
theme.Apply(box, theme.R("nasin", "ClockFace", ""))
tomo.Apply(box, tomo.R("nasin", "ClockFace", ""))
box.SetDrawer(box)
return box
}
@ -89,7 +88,7 @@ func (this *ClockFace) Draw (destination canvas.Canvas) {
for hour := 0; hour < 12; hour ++ {
radialLine (
destination,
theme.ColorForeground,
tomo.ColorForeground,
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
hour := float64(this.time.Hour()) + minute / 60
radialLine(destination, theme.ColorForeground, 0, 0.5, (hour - 3) / 6 * math.Pi)
radialLine(destination, theme.ColorForeground, 0, 0.7, (minute - 15) / 30 * math.Pi)
radialLine(destination, theme.ColorAccent, 0, 0.7, (second - 15) / 30 * math.Pi)
radialLine(destination, tomo.ColorForeground, 0, 0.5, (hour - 3) / 6 * math.Pi)
radialLine(destination, tomo.ColorForeground, 0, 0.7, (minute - 15) / 30 * math.Pi)
radialLine(destination, tomo.ColorAccent, 0, 0.7, (second - 15) / 30 * math.Pi)
}
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/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
window tomo.MainWindow
size tomo.IconSize
grid tomo.ContainerBox
}
@ -30,23 +29,23 @@ func (this *Application) Init () error {
this.window = window
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 }))
button := objects.NewButton("small")
button.SetIcon(theme.IconActionZoomOut)
button.OnClick(func () { this.resizeIcons(theme.IconSizeSmall) })
button.SetIcon(tomo.IconZoomOut)
button.OnClick(func () { this.resizeIcons(tomo.IconSizeSmall) })
iconButtons.Add(button)
button = objects.NewButton("medium")
button.SetIcon(theme.IconActionZoomReset)
button.OnClick(func () { this.resizeIcons(theme.IconSizeMedium) })
button.SetIcon(tomo.IconZoomOriginal)
button.OnClick(func () { this.resizeIcons(tomo.IconSizeMedium) })
iconButtons.Add(button)
button = objects.NewButton("large")
button.SetIcon(theme.IconActionZoomIn)
button.OnClick(func () { this.resizeIcons(theme.IconSizeLarge) })
button.SetIcon(tomo.IconZoomIn)
button.OnClick(func () { this.resizeIcons(tomo.IconSizeLarge) })
iconButtons.Add(button)
container := objects.NewOuterContainer (
@ -64,128 +63,311 @@ func (this *Application) Init () error {
window.SetRoot(container)
window.OnClose(tomo.Stop)
window.Show()
window.SetVisible(true)
return nil
}
func (this *Application) resizeIcons (size theme.IconSize) {
func (this *Application) resizeIcons (size tomo.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,
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,
}
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 { })
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
if icon == "" {
icon = "<UNKNOWN>"
}
sizesRow := objects.NewInnerContainer (
layouts.ContractHorizontal,
valign(objects.NewIcon(icon, theme.IconSizeSmall)),
valign(objects.NewIcon(icon, theme.IconSizeMedium)),
valign(objects.NewIcon(icon, theme.IconSizeLarge)))
objects.NewIcon(icon, tomo.IconSizeSmall),
objects.NewIcon(icon, tomo.IconSizeMedium),
objects.NewIcon(icon, tomo.IconSizeLarge))
okButton := objects.NewButton("OK")
okButton.OnClick(popup.Close)
okButton.SetIcon(theme.IconStatusOkay)
okButton.SetIcon(tomo.IconDialogOkay)
controlRow := objects.NewInnerContainer (
layouts.ContractHorizontal,
okButton)
@ -234,7 +410,7 @@ func (this *Application) iconPopup (icon theme.Icon) error {
controlRow,
))
popup.SetTitle(string(icon) + ": Properties")
popup.Show()
popup.SetVisible(true)
return nil
}

View File

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

View File

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