10 Commits

Author SHA1 Message Date
ac51d3dc9f Upgrade objects, x 2024-05-13 19:56:07 -04:00
573ab6bcdc Update Wintergreen theme 2024-05-13 19:55:57 -04:00
c1686e336b Upgrade X version 2024-05-07 20:25:15 -04:00
dfd566b23d Include new objects in Wintergreen theme 2024-05-07 20:22:53 -04:00
da4af8d240 Add examples 2024-05-07 20:22:39 -04:00
d90fb327db Add icons example 2024-05-07 01:30:12 -04:00
2b9f17b612 Add clock example 2024-05-07 01:30:06 -04:00
2cde2cc6d5 Update X backend 2024-05-07 00:46:52 -04:00
69576c7aca Add basic icons to wintergreen theme 2024-05-06 23:25:53 -04:00
a11cc2cb89 Rename registry to registrar 2024-05-06 23:25:44 -04:00
16 changed files with 858 additions and 223 deletions

View File

@@ -3,7 +3,7 @@ package nasin
import "log"
import "image"
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/nasin/internal/registry"
import "git.tebibyte.media/tomo/nasin/internal/registrar"
// Application represents an application object.
type Application interface {
@@ -79,7 +79,7 @@ type ApplicationRole string; const (
// RunApplication is like tomo.Run, but runs an application. If something fails
// to initialize, an error is written to the standard logger.
func RunApplication (application Application) {
err := registry.Init()
err := registrar.Init()
if err != nil { log.Fatal("nasin: could not init registry:", err) }
err = tomo.Run(func () {
err := application.Init()

126
examples/clock/main.go Normal file
View 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)
}

199
examples/icons/main.go Normal file
View File

@@ -0,0 +1,199 @@
// 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"
const scrollIcons = false
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:"))
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 {
this.grid.Add(objects.NewIcon(icon, size))
}
}
func main () {
nasin.RunApplication(&Application { })
}

38
examples/inputs/main.go Normal file
View File

@@ -0,0 +1,38 @@
// Example inputs demonstrates the use of various user input methods.
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 { }
func (this *Application) Describe () nasin.ApplicationDescription {
return nasin.ApplicationDescription {
Name: "Tomo Input Example",
ID: "xyz.holanet.TomoInputExample",
}
}
func (this *Application) Init () error {
window, err := nasin.NewApplicationWindow(this, image.Rect(0, 0, 128, 128))
if err != nil { return err }
window.SetRoot(objects.NewOuterContainer(layouts.Column { },
objects.NewTextInput(""),
objects.NewHorizontalSlider(0.5),
objects.NewLabelCheckbox(false, "checkbox"),
objects.NewNumberInput(5),
))
window.OnClose(tomo.Stop)
window.Show()
return nil
}
func main () {
nasin.RunApplication(&Application { })
}

7
go.mod
View File

@@ -3,17 +3,18 @@ module git.tebibyte.media/tomo/nasin
go 1.20
require (
git.tebibyte.media/tomo/objects v0.11.0
git.tebibyte.media/tomo/tomo v0.31.0
git.tebibyte.media/tomo/x v0.7.0
git.tebibyte.media/tomo/x v0.7.3
git.tebibyte.media/tomo/xdg v0.1.0
golang.org/x/image v0.11.0
)
require (
git.tebibyte.media/tomo/typeset v0.7.0 // indirect
git.tebibyte.media/tomo/typeset v0.7.1 // indirect
git.tebibyte.media/tomo/xgbkb v1.0.1 // indirect
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298 // indirect
github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966 // indirect
github.com/jezek/xgb v1.1.0 // indirect
github.com/jezek/xgbutil v0.0.0-20230603163917-04188eb39cf0 // indirect
golang.org/x/image v0.11.0 // indirect
)

10
go.sum
View File

@@ -1,10 +1,12 @@
git.tebibyte.media/sashakoshka/xgbkb v1.0.0/go.mod h1:pNcE6TRO93vHd6q42SdwLSTTj25L0Yzggz7yLe0JV6Q=
git.tebibyte.media/tomo/objects v0.11.0 h1:ESv6/9UtLOX2lJKopQhPNuxd6U6jWOrU1XnHaH+dgv8=
git.tebibyte.media/tomo/objects v0.11.0/go.mod h1:34UDkPEHxBgIsAYWyqqE4u1KvVtwzwdpCO6AdkgsrKo=
git.tebibyte.media/tomo/tomo v0.31.0 h1:LHPpj3AWycochnC8F441aaRNS6Tq6w6WnBrp/LGjyhM=
git.tebibyte.media/tomo/tomo v0.31.0/go.mod h1:C9EzepS9wjkTJjnZaPBh22YvVPyA4hbBAJVU20Rdmps=
git.tebibyte.media/tomo/typeset v0.7.0 h1:JFpEuGmN6R2XSCvkINYxpH0AyYUqqs+dZYr6OSd91y0=
git.tebibyte.media/tomo/typeset v0.7.0/go.mod h1:PwDpSdBF3l/EzoIsa2ME7QffVVajnTHZN6l3MHEGe1g=
git.tebibyte.media/tomo/x v0.7.0 h1:HiLbKRWwwR+D1lYruhK3Z63JPiMlcISBe9TtCkZTeBI=
git.tebibyte.media/tomo/x v0.7.0/go.mod h1:h4vXFU+ZQETr7hxr/ydHqM1xFzHKvV2uKnmGzagWgnY=
git.tebibyte.media/tomo/typeset v0.7.1 h1:aZrsHwCG5ZB4f5CruRFsxLv5ezJUCFUFsQJJso2sXQ8=
git.tebibyte.media/tomo/typeset v0.7.1/go.mod h1:PwDpSdBF3l/EzoIsa2ME7QffVVajnTHZN6l3MHEGe1g=
git.tebibyte.media/tomo/x v0.7.3 h1:9sjjYC7UMsrce6GsWdP/Jb2U6UEE3st4WiUvz9RhycI=
git.tebibyte.media/tomo/x v0.7.3/go.mod h1:8BLhXlFSTmn/y2FM+yrc6yLmMzqMhFQYYrN9SXMbmZM=
git.tebibyte.media/tomo/xdg v0.1.0 h1:6G2WYPPiM2IXleCpKKHuJA34BxumwNWuLsUoX3yu5zA=
git.tebibyte.media/tomo/xdg v0.1.0/go.mod h1:tuaRwRkyYW7mqlxA7P2+V+e10KzcamNoUzcOgaIYKAY=
git.tebibyte.media/tomo/xgbkb v1.0.1 h1:b3HDUopjdQp1MZrb5Vpil4bOtk3NnNXtfQW27Blw2kE=

View File

@@ -0,0 +1,2 @@
// Package registrar provides platform-dependent components at compile time.
package registrar

View File

@@ -1,5 +1,5 @@
//go:build unix && (!darwin)
package registry
package registrar
import "git.tebibyte.media/tomo/x"
import "git.tebibyte.media/tomo/tomo"

View File

@@ -1,2 +0,0 @@
// Package registry provides platform-dependent components at compile time.
package registry

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

View File

@@ -1,220 +1,9 @@
package defaultTheme
import "image/color"
import "git.tebibyte.media/tomo/tomo"
import "golang.org/x/image/font/basicfont"
import "git.tebibyte.media/tomo/tomo/theme"
import dataTheme "git.tebibyte.media/tomo/nasin/internal/theme"
var colorFocus = color.RGBA { R: 61, G: 128, B: 143, A: 255 }
var colorInput = color.RGBA { R: 208, G: 203, B: 150, A: 255 }
var colorCarved = color.RGBA { R: 151, G: 160, B: 150, A: 255 }
var colorShadow = color.RGBA { R: 57, G: 59, B: 57, A: 255 }
var colorInputShadow = color.RGBA { R: 143, G: 146, B: 91, A: 255 }
var colorHighlight = color.RGBA { R: 207, G: 215, B: 210, A: 255 }
var colorBackground = color.RGBA { R: 169, G: 171, B: 168, A: 255 }
var colorCarvedPressed = color.RGBA { R: 129, G: 142, B: 137, A: 255 }
var colorForeground = color.Black
var colorOutline = color.Black
var outline = tomo.Border {
Width: tomo.I(1),
Color: [4]color.Color {
colorOutline,
colorOutline,
colorOutline,
colorOutline,
},
}
var borderColorEngraved = [4]color.Color { colorShadow, colorHighlight, colorHighlight, colorShadow }
var borderColorLifted = [4]color.Color { colorHighlight, colorShadow, colorShadow, colorHighlight }
var borderColorInput = [4]color.Color { colorInputShadow, colorInput, colorInput, colorInputShadow }
var borderColorFocused = [4]color.Color { colorFocus, colorFocus, colorFocus, colorFocus }
var rules = []dataTheme.Rule {
// *.*[*]
dataTheme.Rule {
Default: dataTheme.AS (
dataTheme.AttrFace { Face: basicfont.Face7x13 },
dataTheme.AttrTextColor { Color: theme.ColorForeground },
dataTheme.AttrDotColor { Color: theme.ColorAccent },
dataTheme.AttrGap { X: 8, Y: 8 },
),
},
// *.Button[*]
dataTheme.Rule {
Role: theme.R("", "Button", ""),
Default: dataTheme.AS (
dataTheme.AttrBorder {
outline,
tomo.Border {
Width: tomo.I(1),
Color: borderColorLifted,
},
},
dataTheme.AttrPadding(tomo.I(4, 8)),
dataTheme.AttrColor { Color: theme.ColorRaised },
),
Pressed: dataTheme.AS (
dataTheme.AttrBorder {
outline,
tomo.Border {
Width: tomo.I(1, 0, 0, 1),
Color: borderColorEngraved,
},
},
dataTheme.AttrPadding(tomo.I(5, 8, 4, 9)),
dataTheme.AttrColor { Color: colorCarvedPressed },
),
Focused: dataTheme.AS (
dataTheme.AttrBorder {
outline,
tomo.Border {
Width: tomo.I(1),
Color: borderColorFocused,
},
},
dataTheme.AttrPadding(tomo.I(4, 8)),
),
},
// *.TextInput[*]
dataTheme.Rule {
Role: theme.R("", "TextInput", ""),
Default: dataTheme.AS (
dataTheme.AttrBorder {
outline,
tomo.Border {
Width: tomo.I(1),
Color: borderColorInput,
},
},
dataTheme.AttrColor { Color: colorInput },
dataTheme.AttrPadding(tomo.I(5, 4, 4, 5)),
),
Focused: dataTheme.AS (
dataTheme.AttrBorder {
outline,
tomo.Border {
Width: tomo.I(1),
Color: borderColorFocused,
},
},
),
},
// *.NumberInput[*]
dataTheme.Rule {
Role: theme.R("", "NumberInput", ""),
Default: dataTheme.AS (
dataTheme.AttrBorder {
outline,
tomo.Border {
Width: tomo.I(1),
Color: borderColorInput,
},
},
dataTheme.AttrColor { Color: colorInput },
dataTheme.AttrPadding(tomo.I(5, 4, 4, 5)),
),
Focused: dataTheme.AS (
dataTheme.AttrBorder {
outline,
tomo.Border {
Width: tomo.I(1),
Color: borderColorFocused,
},
},
),
},
// *.Container[outer]
dataTheme.Rule {
Role: theme.R("", "Container", "outer"),
Default: dataTheme.AS (
dataTheme.AttrColor { Color: theme.ColorBackground },
dataTheme.AttrPadding(tomo.I(8)),
),
},
// *.Heading[*]
dataTheme.Rule {
Role: theme.R("", "Heading", ""),
Default: dataTheme.AS (
dataTheme.AttrAlign { X: tomo.AlignMiddle, Y: tomo.AlignMiddle },
),
},
// *.Separator[*]
dataTheme.Rule {
Role: theme.R("", "Separator", ""),
Default: dataTheme.AS (
dataTheme.AttrBorder {
tomo.Border {
Width: tomo.I(1),
Color: borderColorEngraved,
},
},
),
},
// *.Slider[*]
dataTheme.Rule {
Role: theme.R("", "Slider", ""),
Default: dataTheme.AS (
dataTheme.AttrBorder {
outline,
tomo.Border {
Width: tomo.I(1, 0, 0, 1),
Color: borderColorEngraved,
},
},
dataTheme.AttrColor { Color: theme.ColorSunken },
dataTheme.AttrPadding(tomo.I(0, 1, 1, 0)),
),
Focused: dataTheme.AS (
dataTheme.AttrBorder {
outline,
tomo.Border {
Width: tomo.I(1),
Color: borderColorFocused,
},
},
dataTheme.AttrPadding(tomo.I(0)),
),
},
// *.Slider[horizontal]
dataTheme.Rule {
Role: theme.R("", "Slider", "horizontal"),
Default: dataTheme.AS(dataTheme.AttrMinimumSize { X: 48 }),
},
// *.Slider[vertical]
dataTheme.Rule {
Role: theme.R("", "Slider", "vertical"),
Default: dataTheme.AS(dataTheme.AttrMinimumSize { Y: 48 }),
},
// *.SliderHandle[*]
dataTheme.Rule {
Role: theme.R("", "SliderHandle", ""),
Default: dataTheme.AS (
dataTheme.AttrBorder {
outline,
tomo.Border {
Width: tomo.I(1),
Color: borderColorLifted,
},
},
dataTheme.AttrColor { Color: theme.ColorRaised },
dataTheme.AttrMinimumSize { X: 12, Y: 12, },
),
},
}
// Theme returns Wintergreen, the default Tomo theme. It is neutral-gray with
// green and turquoise accents.
func Theme () theme.Theme {
@@ -227,5 +16,6 @@ func Theme () theme.Theme {
theme.ColorAccent: colorFocus,
},
Rules: rules,
IconTheme: &iconTheme { },
}
}

View File

@@ -0,0 +1,228 @@
package defaultTheme
import "bytes"
import "image"
import _ "embed"
import _ "image/png"
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/data"
import "git.tebibyte.media/tomo/tomo/theme"
import "git.tebibyte.media/tomo/tomo/canvas"
//go:embed assets/icons-small.png
var atlasSmallBytes []byte
//go:embed assets/icons-large.png
var atlasLargeBytes []byte
func generateSource (data []byte, width int) map[theme.Icon] canvas.Texture {
atlasImage, _, err := image.Decode(bytes.NewReader(data))
if err != nil { panic(err) }
atlasTexture := tomo.NewTexture(atlasImage)
source := make(map[theme.Icon] canvas.Texture)
x := 0
y := 0
row := func () {
x = 0
y ++
}
col := func (id theme.Icon) {
source[id] = atlasTexture.Clip(image.Rect (
x * width,
y * width,
(x + 1) * width,
(y + 1) * width))
x++
}
// objects
col(theme.IconUnknown)
col(theme.IconFile)
col(theme.IconDirectory)
col(theme.IconStorage)
col(theme.IconApplication)
col(theme.IconNetwork)
col(theme.IconDevice)
col(theme.IconPeripheral)
col(theme.IconPort)
// actions: files
row()
col(theme.IconActionOpen)
col(theme.IconActionOpenIn)
col(theme.IconActionSave)
col(theme.IconActionSaveAs)
col(theme.IconActionPrint)
col(theme.IconActionNew)
col(theme.IconActionNewDirectory)
col(theme.IconActionDelete)
col(theme.IconActionRename)
col(theme.IconActionGetInformation)
col(theme.IconActionChangePermissions)
col(theme.IconActionRevert)
// actions: list management
row()
col(theme.IconActionAdd)
col(theme.IconActionRemove)
col(theme.IconActionAddBookmark)
col(theme.IconActionRemoveBookmark)
col(theme.IconActionAddFavorite)
col(theme.IconActionRemoveFavorite)
// actions: media
row()
col(theme.IconActionPlay)
col(theme.IconActionPause)
col(theme.IconActionStop)
col(theme.IconActionFastForward)
col(theme.IconActionRewind)
col(theme.IconActionToBeginning)
col(theme.IconActionToEnd)
col(theme.IconActionRecord)
col(theme.IconActionVolumeUp)
col(theme.IconActionVolumeDown)
col(theme.IconActionMute)
// actions: editing
row()
col(theme.IconActionUndo)
col(theme.IconActionRedo)
col(theme.IconActionCut)
col(theme.IconActionCopy)
col(theme.IconActionPaste)
col(theme.IconActionFind)
col(theme.IconActionReplace)
col(theme.IconActionSelectAll)
col(theme.IconActionSelectNone)
col(theme.IconActionIncrement)
col(theme.IconActionDecrement)
// actions: window management
row()
col(theme.IconActionClose)
col(theme.IconActionQuit)
col(theme.IconActionIconify)
col(theme.IconActionShade)
col(theme.IconActionMaximize)
col(theme.IconActionFullScreen)
col(theme.IconActionRestore)
// actions: view
row()
col(theme.IconActionExpand)
col(theme.IconActionContract)
col(theme.IconActionBack)
col(theme.IconActionForward)
col(theme.IconActionUp)
col(theme.IconActionDown)
col(theme.IconActionReload)
col(theme.IconActionZoomIn)
col(theme.IconActionZoomOut)
col(theme.IconActionZoomReset)
col(theme.IconActionMove)
col(theme.IconActionResize)
col(theme.IconActionGoTo)
// actions: tools
row()
col(theme.IconActionTransform)
col(theme.IconActionTranslate)
col(theme.IconActionRotate)
col(theme.IconActionScale)
col(theme.IconActionWarp)
col(theme.IconActionCornerPin)
col(theme.IconActionSelectRectangle)
col(theme.IconActionSelectEllipse)
col(theme.IconActionSelectLasso)
col(theme.IconActionSelectGeometric)
col(theme.IconActionSelectAuto)
col(theme.IconActionCrop)
col(theme.IconActionFill)
row()
col(theme.IconActionGradient)
col(theme.IconActionPencil)
col(theme.IconActionBrush)
col(theme.IconActionEraser)
col(theme.IconActionText)
col(theme.IconActionEyedropper)
// status: dialog
row()
col(theme.IconStatusInformation)
col(theme.IconStatusQuestion)
col(theme.IconStatusWarning)
col(theme.IconStatusError)
col(theme.IconStatusCancel)
col(theme.IconStatusOkay)
// status: network
row()
col(theme.IconStatusCellSignal0)
col(theme.IconStatusCellSignal1)
col(theme.IconStatusCellSignal2)
col(theme.IconStatusCellSignal3)
col(theme.IconStatusWirelessSignal0)
col(theme.IconStatusWirelessSignal1)
col(theme.IconStatusWirelessSignal2)
col(theme.IconStatusWirelessSignal3)
// status: power
row()
col(theme.IconStatusBattery0)
col(theme.IconStatusBattery1)
col(theme.IconStatusBattery2)
col(theme.IconStatusBattery3)
col(theme.IconStatusBrightness0)
col(theme.IconStatusBrightness1)
col(theme.IconStatusBrightness2)
col(theme.IconStatusBrightness3)
// status: media
row()
col(theme.IconStatusVolume0)
col(theme.IconStatusVolume1)
col(theme.IconStatusVolume2)
col(theme.IconStatusVolume3)
return source
}
type iconTheme struct {
texturesSmall map[theme.Icon] canvas.Texture
texturesLarge map[theme.Icon] canvas.Texture
}
func (this *iconTheme) ensure () {
if this.texturesSmall != nil { return }
this.texturesSmall = generateSource(atlasSmallBytes, 16)
this.texturesLarge = generateSource(atlasLargeBytes, 32)
}
func (this *iconTheme) selectSource (size theme.IconSize) map[theme.Icon] canvas.Texture {
if size == theme.IconSizeSmall {
return this.texturesSmall
} else {
return this.texturesLarge
}
}
func (this *iconTheme) Icon (icon theme.Icon, size theme.IconSize) canvas.Texture {
this.ensure()
source := this.selectSource(size)
if texture, ok := source[icon]; ok {
return texture
}
return source[theme.IconUnknown]
}
func (this *iconTheme) MimeIcon (mime data.Mime, size theme.IconSize) canvas.Texture {
this.ensure()
source := this.selectSource(size)
if mime == data.M("inode", "directory") {
return source[theme.IconDirectory]
} else {
return source[theme.IconFile]
}
}

View File

@@ -0,0 +1,251 @@
package defaultTheme
import "image/color"
import "git.tebibyte.media/tomo/tomo"
import "golang.org/x/image/font/basicfont"
import "git.tebibyte.media/tomo/tomo/theme"
import dataTheme "git.tebibyte.media/tomo/nasin/internal/theme"
var colorFocus = color.RGBA { R: 61, G: 128, B: 143, A: 255 }
var colorInput = color.RGBA { R: 208, G: 203, B: 150, A: 255 }
var colorCarved = color.RGBA { R: 151, G: 160, B: 150, A: 255 }
var colorGutter = color.RGBA { R: 116, G: 132, B: 126, A: 255 }
var colorShadow = color.RGBA { R: 57, G: 59, B: 57, A: 255 }
var colorInputShadow = color.RGBA { R: 143, G: 146, B: 91, A: 255 }
var colorHighlight = color.RGBA { R: 207, G: 215, B: 210, A: 255 }
var colorBackground = color.RGBA { R: 169, G: 171, B: 168, A: 255 }
var colorCarvedPressed = color.RGBA { R: 129, G: 142, B: 137, A: 255 }
var colorForeground = color.Black
var colorOutline = color.Black
var outline = tomo.Border {
Width: tomo.I(1),
Color: [4]color.Color {
colorOutline,
colorOutline,
colorOutline,
colorOutline,
},
}
var borderColorEngraved = [4]color.Color { colorShadow, colorHighlight, colorHighlight, colorShadow }
var borderColorLifted = [4]color.Color { colorHighlight, colorShadow, colorShadow, colorHighlight }
var borderColorInput = [4]color.Color { colorInputShadow, colorInput, colorInput, colorInputShadow }
var borderColorFocused = [4]color.Color { colorFocus, colorFocus, colorFocus, colorFocus }
var rules = []dataTheme.Rule {
// *.*[*]
dataTheme.Rule {
Default: dataTheme.AS (
dataTheme.AttrFace { Face: basicfont.Face7x13 },
dataTheme.AttrTextColor { Color: theme.ColorForeground },
dataTheme.AttrDotColor { Color: theme.ColorAccent },
dataTheme.AttrGap { X: 8, Y: 8 },
),
},
// *.Button[*]
dataTheme.Rule {
Role: theme.R("", "Button", ""),
Default: dataTheme.AS (
dataTheme.AttrBorder {
outline,
tomo.Border {
Width: tomo.I(1),
Color: borderColorLifted,
},
},
dataTheme.AttrPadding(tomo.I(4, 8)),
dataTheme.AttrColor { Color: theme.ColorRaised },
),
Pressed: dataTheme.AS (
dataTheme.AttrBorder {
outline,
tomo.Border {
Width: tomo.I(1, 0, 0, 1),
Color: borderColorEngraved,
},
},
dataTheme.AttrPadding(tomo.I(5, 8, 4, 9)),
dataTheme.AttrColor { Color: colorCarvedPressed },
),
Focused: dataTheme.AS (
dataTheme.AttrBorder {
outline,
tomo.Border {
Width: tomo.I(1),
Color: borderColorFocused,
},
},
dataTheme.AttrPadding(tomo.I(4, 8)),
),
},
// *.TextInput[*]
dataTheme.Rule {
Role: theme.R("", "TextInput", ""),
Default: dataTheme.AS (
dataTheme.AttrBorder {
outline,
tomo.Border {
Width: tomo.I(1),
Color: borderColorInput,
},
},
dataTheme.AttrColor { Color: colorInput },
dataTheme.AttrPadding(tomo.I(5, 4, 4, 5)),
),
Focused: dataTheme.AS (
dataTheme.AttrBorder {
outline,
tomo.Border {
Width: tomo.I(1),
Color: borderColorFocused,
},
},
),
},
// *.NumberInput[*]
dataTheme.Rule {
Role: theme.R("", "NumberInput", ""),
Default: dataTheme.AS (
dataTheme.AttrGap { },
),
},
// *.Container[sunken]
dataTheme.Rule {
Role: theme.R("", "Container", "sunken"),
Default: dataTheme.AS (
dataTheme.AttrBorder {
outline,
tomo.Border {
Width: tomo.I(1, 0, 0, 1),
Color: borderColorEngraved,
},
},
dataTheme.AttrColor { Color: theme.ColorSunken },
dataTheme.AttrPadding(tomo.I(8)),
),
},
// *.Container[outer]
dataTheme.Rule {
Role: theme.R("", "Container", "outer"),
Default: dataTheme.AS (
dataTheme.AttrColor { Color: theme.ColorBackground },
dataTheme.AttrPadding(tomo.I(8)),
),
},
// *.Heading[*]
dataTheme.Rule {
Role: theme.R("", "Heading", ""),
Default: dataTheme.AS (
dataTheme.AttrAlign { X: tomo.AlignMiddle, Y: tomo.AlignMiddle },
),
},
// *.Separator[*]
dataTheme.Rule {
Role: theme.R("", "Separator", ""),
Default: dataTheme.AS (
dataTheme.AttrBorder {
tomo.Border {
Width: tomo.I(1),
Color: borderColorEngraved,
},
},
),
},
// *.Slider[*]
dataTheme.Rule {
Role: theme.R("", "Slider", ""),
Default: dataTheme.AS (
dataTheme.AttrBorder {
outline,
tomo.Border {
Width: tomo.I(1, 0, 0, 1),
Color: borderColorEngraved,
},
},
dataTheme.AttrColor { Color: colorGutter },
dataTheme.AttrPadding(tomo.I(0, 1, 1, 0)),
),
Focused: dataTheme.AS (
dataTheme.AttrBorder {
outline,
tomo.Border {
Width: tomo.I(1),
Color: borderColorFocused,
},
},
dataTheme.AttrPadding(tomo.I(0)),
),
},
// *.Slider[horizontal]
dataTheme.Rule {
Role: theme.R("", "Slider", "horizontal"),
Default: dataTheme.AS(dataTheme.AttrMinimumSize { X: 48 }),
},
// *.Slider[vertical]
dataTheme.Rule {
Role: theme.R("", "Slider", "vertical"),
Default: dataTheme.AS(dataTheme.AttrMinimumSize { Y: 48 }),
},
// *.SliderHandle[*]
dataTheme.Rule {
Role: theme.R("", "SliderHandle", ""),
Default: dataTheme.AS (
dataTheme.AttrBorder {
outline,
tomo.Border {
Width: tomo.I(1),
Color: borderColorLifted,
},
},
dataTheme.AttrColor { Color: theme.ColorRaised },
dataTheme.AttrMinimumSize { X: 12, Y: 12, },
),
},
// *.Checkbox[*]
dataTheme.Rule {
Role: theme.R("", "Checkbox", ""),
Default: dataTheme.AS (
dataTheme.AttrBorder {
outline,
tomo.Border {
Width: tomo.I(1, 0, 0, 1),
Color: borderColorEngraved,
},
},
dataTheme.AttrColor { Color: theme.ColorSunken },
dataTheme.AttrPadding(tomo.I(0, 1, 1, 0)),
dataTheme.AttrMinimumSize { X: 19, Y: 19 },
),
Focused: dataTheme.AS (
dataTheme.AttrBorder {
outline,
tomo.Border {
Width: tomo.I(1),
Color: borderColorFocused,
},
},
dataTheme.AttrPadding(tomo.I(0)),
),
},
// *.LabelCheckbox[*]
dataTheme.Rule {
Role: theme.R("", "LabelCheckbox", ""),
Default: dataTheme.AS (
dataTheme.AttrGap { X: 8, Y: 8 },
),
},
}