Compare commits
2 Commits
2cde2cc6d5
...
d90fb327db
Author | SHA1 | Date | |
---|---|---|---|
d90fb327db | |||
2b9f17b612 |
126
examples/clock/main.go
Normal file
126
examples/clock/main.go
Normal file
@ -0,0 +1,126 @@
|
||||
// Example clock demonstrates the use of goroutines and tomo.Do() to provide
|
||||
// live-updating information.
|
||||
package main
|
||||
|
||||
import "time"
|
||||
import "math"
|
||||
import "image"
|
||||
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"
|
||||
|
||||
type Application struct {
|
||||
clockFace *ClockFace
|
||||
timeLabel *objects.Label
|
||||
}
|
||||
|
||||
func (this *Application) Describe () nasin.ApplicationDescription {
|
||||
return nasin.ApplicationDescription {
|
||||
Name: "Clock",
|
||||
ID: "xyz.holanet.TomoClockExample",
|
||||
}
|
||||
}
|
||||
|
||||
func (this *Application) Init () error {
|
||||
window, err := nasin.NewApplicationWindow(this, image.Rect(0, 0, 128, 160))
|
||||
if err != nil { return err }
|
||||
|
||||
this.clockFace = NewClockFace()
|
||||
this.timeLabel = objects.NewLabel("")
|
||||
this.timeLabel.SetAlign(tomo.AlignMiddle, tomo.AlignMiddle)
|
||||
container := objects.NewOuterContainer (
|
||||
layouts.NewGrid([]bool { true }, []bool { true, false }),
|
||||
this.clockFace,
|
||||
this.timeLabel)
|
||||
window.SetRoot(container)
|
||||
|
||||
go func () {
|
||||
for {
|
||||
tomo.Do(this.updateTime)
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
} ()
|
||||
|
||||
window.OnClose(tomo.Stop)
|
||||
window.Show()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *Application) updateTime () {
|
||||
now := time.Now()
|
||||
this.clockFace.SetTime(now)
|
||||
this.timeLabel.SetText(now.Format(time.DateTime))
|
||||
}
|
||||
|
||||
func main () {
|
||||
nasin.RunApplication(&Application { })
|
||||
}
|
||||
|
||||
type ClockFace struct {
|
||||
tomo.CanvasBox
|
||||
time time.Time
|
||||
}
|
||||
|
||||
func NewClockFace () *ClockFace {
|
||||
box := &ClockFace {
|
||||
CanvasBox: tomo.NewCanvasBox(),
|
||||
}
|
||||
theme.Apply(box, theme.R("nasin", "ClockFace", ""))
|
||||
box.SetDrawer(box)
|
||||
return box
|
||||
}
|
||||
|
||||
// TODO move ClockFace to objects
|
||||
|
||||
func (this *ClockFace) SetTime (when time.Time) {
|
||||
this.time = when
|
||||
this.Invalidate()
|
||||
}
|
||||
|
||||
func (this *ClockFace) Draw (destination canvas.Canvas) {
|
||||
pen := destination.Pen()
|
||||
pen.Fill(color.Transparent)
|
||||
pen.Rectangle(destination.Bounds())
|
||||
|
||||
for hour := 0; hour < 12; hour ++ {
|
||||
radialLine (
|
||||
destination,
|
||||
theme.ColorForeground,
|
||||
0.8, 0.9, float64(hour) / 6 * math.Pi)
|
||||
}
|
||||
|
||||
second := float64(this.time.Second())
|
||||
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)
|
||||
}
|
||||
|
||||
func radialLine (
|
||||
destination canvas.Canvas,
|
||||
source color.Color,
|
||||
inner float64,
|
||||
outer float64,
|
||||
theta float64,
|
||||
) {
|
||||
pen := destination.Pen()
|
||||
bounds := destination.Bounds()
|
||||
width := float64(bounds.Dx()) / 2
|
||||
height := float64(bounds.Dy()) / 2
|
||||
min := bounds.Min.Add(image.Pt (
|
||||
int(math.Cos(theta) * inner * width + width),
|
||||
int(math.Sin(theta) * inner * height + height)))
|
||||
max := bounds.Min.Add(image.Pt (
|
||||
int(math.Cos(theta) * outer * width + width),
|
||||
int(math.Sin(theta) * outer * height + height)))
|
||||
|
||||
pen.Stroke(source)
|
||||
pen.StrokeWeight(1)
|
||||
pen.Path(min, max)
|
||||
}
|
190
examples/icons/main.go
Normal file
190
examples/icons/main.go
Normal file
@ -0,0 +1,190 @@
|
||||
// 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/theme"
|
||||
import "git.tebibyte.media/tomo/objects/layouts"
|
||||
|
||||
type Application struct {
|
||||
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, 128))
|
||||
if err != nil { return err }
|
||||
|
||||
this.grid = objects.NewInnerContainer (
|
||||
layouts.NewGrid([]bool {
|
||||
false, false, false, false, false, false, false, false, false, false, false, false,
|
||||
}, []bool { }),
|
||||
)
|
||||
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:"),
|
||||
this.grid,
|
||||
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 {
|
||||
this.grid.Add(objects.NewIcon(icon, size))
|
||||
}
|
||||
}
|
||||
|
||||
func main () {
|
||||
nasin.RunApplication(&Application { })
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user