I am going insane

This commit is contained in:
Sasha Koshka 2023-03-31 01:06:29 -04:00
parent 53bfc8df68
commit 7b300333cf
45 changed files with 527 additions and 508 deletions

View File

@ -1,8 +1,6 @@
package tomo package tomo
import "errors" import "errors"
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/config"
// Backend represents a connection to a display server, or something similar. // Backend represents a connection to a display server, or something similar.
// It is capable of managing an event loop, and creating windows. // It is capable of managing an event loop, and creating windows.
@ -24,10 +22,10 @@ type Backend interface {
NewWindow (width, height int) (window MainWindow, err error) NewWindow (width, height int) (window MainWindow, err error)
// SetTheme sets the theme of all open windows. // SetTheme sets the theme of all open windows.
SetTheme (theme.Theme) SetTheme (Theme)
// SetConfig sets the configuration of all open windows. // SetConfig sets the configuration of all open windows.
SetConfig (config.Config) SetConfig (Config)
} }
// BackendFactory represents a function capable of constructing a backend // BackendFactory represents a function capable of constructing a backend

View File

@ -12,8 +12,6 @@ import "github.com/jezek/xgbutil/xgraphics"
import "git.tebibyte.media/sashakoshka/tomo" import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/data" import "git.tebibyte.media/sashakoshka/tomo/data"
import "git.tebibyte.media/sashakoshka/tomo/input" import "git.tebibyte.media/sashakoshka/tomo/input"
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/config"
import "git.tebibyte.media/sashakoshka/tomo/canvas" import "git.tebibyte.media/sashakoshka/tomo/canvas"
// import "runtime/debug" // import "runtime/debug"
@ -30,8 +28,8 @@ type window struct {
modalParent *window modalParent *window
hasModal bool hasModal bool
theme theme.Theme theme tomo.Theme
config config.Config config tomo.Config
selectionRequest *selectionRequest selectionRequest *selectionRequest
selectionClaim *selectionClaim selectionClaim *selectionClaim
@ -334,14 +332,14 @@ func (window *window) OnClose (callback func ()) {
window.onClose = callback window.onClose = callback
} }
func (window *window) SetTheme (theme theme.Theme) { func (window *window) SetTheme (theme tomo.Theme) {
window.theme = theme window.theme = theme
if child, ok := window.child.(tomo.Themeable); ok { if child, ok := window.child.(tomo.Themeable); ok {
child.SetTheme(theme) child.SetTheme(theme)
} }
} }
func (window *window) SetConfig (config config.Config) { func (window *window) SetConfig (config tomo.Config) {
window.config = config window.config = config
if child, ok := window.child.(tomo.Configurable); ok { if child, ok := window.child.(tomo.Configurable); ok {
child.SetConfig(config) child.SetConfig(config)

View File

@ -1,8 +1,6 @@
package x package x
import "git.tebibyte.media/sashakoshka/tomo" import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/config"
import "github.com/jezek/xgbutil" import "github.com/jezek/xgbutil"
import "github.com/jezek/xgb/xproto" import "github.com/jezek/xgb/xproto"
@ -26,8 +24,8 @@ type Backend struct {
hyper uint16 hyper uint16
} }
theme theme.Theme theme tomo.Theme
config config.Config config tomo.Config
windows map[xproto.Window] *window windows map[xproto.Window] *window
@ -37,11 +35,9 @@ type Backend struct {
// NewBackend instantiates an X backend. // NewBackend instantiates an X backend.
func NewBackend () (output tomo.Backend, err error) { func NewBackend () (output tomo.Backend, err error) {
backend := &Backend { backend := &Backend {
windows: map[xproto.Window] *window { }, windows: map[xproto.Window] *window { },
doChannel: make(chan func (), 32), doChannel: make(chan func (), 32),
theme: theme.Default { }, open: true,
config: config.Default { },
open: true,
} }
// connect to X // connect to X
@ -97,7 +93,7 @@ func (backend *Backend) Do (callback func ()) {
} }
// SetTheme sets the theme of all open windows. // SetTheme sets the theme of all open windows.
func (backend *Backend) SetTheme (theme theme.Theme) { func (backend *Backend) SetTheme (theme tomo.Theme) {
backend.assert() backend.assert()
backend.theme = theme backend.theme = theme
for _, window := range backend.windows { for _, window := range backend.windows {
@ -106,7 +102,7 @@ func (backend *Backend) SetTheme (theme theme.Theme) {
} }
// SetConfig sets the configuration of all open windows. // SetConfig sets the configuration of all open windows.
func (backend *Backend) SetConfig (config config.Config) { func (backend *Backend) SetConfig (config tomo.Config) {
backend.assert() backend.assert()
backend.config = config backend.config = config
for _, window := range backend.windows { for _, window := range backend.windows {

15
config.go Normal file
View File

@ -0,0 +1,15 @@
package tomo
// Config can return global configuration parameters.
type Config interface {
// HandleWidth returns how large grab handles should typically be. This
// is important for accessibility reasons.
HandleWidth () int
// ScrollVelocity returns how many pixels should be scrolled every time
// a scroll button is pressed.
ScrollVelocity () int
// ThemePath returns the directory path to the theme.
ThemePath () string
}

View File

@ -1,9 +0,0 @@
package config
import "io"
// Parse parses one or more configuration files and returns them as a Config.
func Parse (sources ...io.Reader) (config Config) {
// TODO
return Default { }
}

View File

@ -1,18 +1,6 @@
package config package config
// Config can return global configuration parameters. import "git.tebibyte.media/sashakoshka/tomo"
type Config interface {
// HandleWidth returns how large grab handles should typically be. This
// is important for accessibility reasons.
HandleWidth () int
// ScrollVelocity returns how many pixels should be scrolled every time
// a scroll button is pressed.
ScrollVelocity () int
// ThemePath returns the directory path to the theme.
ThemePath () string
}
// Default specifies default configuration values. // Default specifies default configuration values.
type Default struct { } type Default struct { }
@ -35,7 +23,7 @@ func (Default) ThemePath () (string) {
// Wrapped wraps a configuration and uses Default if it is nil. // Wrapped wraps a configuration and uses Default if it is nil.
type Wrapped struct { type Wrapped struct {
Config tomo.Config
} }
// HandleWidth returns how large grab handles should typically be. This // HandleWidth returns how large grab handles should typically be. This
@ -55,7 +43,7 @@ func (wrapped Wrapped) ThemePath () string {
return wrapped.ensure().ThemePath() return wrapped.ensure().ThemePath()
} }
func (wrapped Wrapped) ensure () (real Config) { func (wrapped Wrapped) ensure () (real tomo.Config) {
real = wrapped.Config real = wrapped.Config
if real == nil { real = Default { } } if real == nil { real = Default { } }
return return

2
default/config/doc.go Normal file
View File

@ -0,0 +1,2 @@
// Package config implements a default configuration.
package config

9
default/config/parse.go Normal file
View File

@ -0,0 +1,9 @@
package config
// import "io"
// Parse parses one or more configuration files and returns them as a Config.
// func Parse (sources ...io.Reader) (config tomo.Config) {
// // TODO
// return Default { }
// }

View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -6,6 +6,7 @@ import _ "embed"
import _ "image/png" import _ "image/png"
import "image/color" import "image/color"
import "golang.org/x/image/font" import "golang.org/x/image/font"
import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/data" import "git.tebibyte.media/sashakoshka/tomo/data"
import "git.tebibyte.media/sashakoshka/tomo/artist" import "git.tebibyte.media/sashakoshka/tomo/artist"
import "git.tebibyte.media/sashakoshka/tomo/canvas" import "git.tebibyte.media/sashakoshka/tomo/canvas"
@ -155,13 +156,13 @@ func init () {
type Default struct { } type Default struct { }
// FontFace returns the default font face. // FontFace returns the default font face.
func (Default) FontFace (style FontStyle, size FontSize, c Case) font.Face { func (Default) FontFace (style tomo.FontStyle, size tomo.FontSize, c tomo.Case) font.Face {
switch style { switch style {
case FontStyleBold: case tomo.FontStyleBold:
return defaultfont.FaceBold return defaultfont.FaceBold
case FontStyleItalic: case tomo.FontStyleItalic:
return defaultfont.FaceItalic return defaultfont.FaceItalic
case FontStyleBoldItalic: case tomo.FontStyleBoldItalic:
return defaultfont.FaceBoldItalic return defaultfont.FaceBoldItalic
default: default:
return defaultfont.FaceRegular return defaultfont.FaceRegular
@ -169,8 +170,8 @@ func (Default) FontFace (style FontStyle, size FontSize, c Case) font.Face {
} }
// Icon returns an icon from the default set corresponding to the given name. // Icon returns an icon from the default set corresponding to the given name.
func (Default) Icon (id Icon, size IconSize, c Case) artist.Icon { func (Default) Icon (id tomo.Icon, size tomo.IconSize, c tomo.Case) artist.Icon {
if size == IconSizeLarge { if size == tomo.IconSizeLarge {
if id < 0 || int(id) >= len(defaultIconsLarge) { if id < 0 || int(id) >= len(defaultIconsLarge) {
return nil return nil
} else { } else {
@ -187,14 +188,14 @@ func (Default) Icon (id Icon, size IconSize, c Case) artist.Icon {
// MimeIcon returns an icon from the default set corresponding to the given mime. // MimeIcon returns an icon from the default set corresponding to the given mime.
// type. // type.
func (Default) MimeIcon (data.Mime, IconSize, Case) artist.Icon { func (Default) MimeIcon (data.Mime, tomo.IconSize, tomo.Case) artist.Icon {
// TODO // TODO
return nil return nil
} }
// Pattern returns a pattern from the default theme corresponding to the given // Pattern returns a pattern from the default theme corresponding to the given
// pattern ID. // pattern ID.
func (Default) Pattern (id Pattern, state State, c Case) artist.Pattern { func (Default) Pattern (id tomo.Pattern, state tomo.State, c tomo.Case) artist.Pattern {
offset := 0; switch { offset := 0; switch {
case state.Disabled: offset = 1 case state.Disabled: offset = 1
case state.Pressed && state.On: offset = 4 case state.Pressed && state.On: offset = 4
@ -207,17 +208,17 @@ func (Default) Pattern (id Pattern, state State, c Case) artist.Pattern {
} }
switch id { switch id {
case PatternBackground: return patterns.Uhex(0xaaaaaaFF) case tomo.PatternBackground: return patterns.Uhex(0xaaaaaaFF)
case PatternDead: return defaultTextures[0][offset] case tomo.PatternDead: return defaultTextures[0][offset]
case PatternRaised: case tomo.PatternRaised:
if c.Match("tomo", "listEntry", "") { if c.Match("tomo", "listEntry", "") {
return defaultTextures[10][offset] return defaultTextures[10][offset]
} else { } else {
return defaultTextures[1][offset] return defaultTextures[1][offset]
} }
case PatternSunken: return defaultTextures[2][offset] case tomo.PatternSunken: return defaultTextures[2][offset]
case PatternPinboard: return defaultTextures[3][offset] case tomo.PatternPinboard: return defaultTextures[3][offset]
case PatternButton: case tomo.PatternButton:
switch { switch {
case c.Match("tomo", "checkbox", ""): case c.Match("tomo", "checkbox", ""):
return defaultTextures[9][offset] return defaultTextures[9][offset]
@ -228,37 +229,37 @@ func (Default) Pattern (id Pattern, state State, c Case) artist.Pattern {
default: default:
return defaultTextures[4][offset] return defaultTextures[4][offset]
} }
case PatternInput: return defaultTextures[5][offset] case tomo.PatternInput: return defaultTextures[5][offset]
case PatternGutter: return defaultTextures[6][offset] case tomo.PatternGutter: return defaultTextures[6][offset]
case PatternHandle: return defaultTextures[7][offset] case tomo.PatternHandle: return defaultTextures[7][offset]
case PatternLine: return defaultTextures[8][offset] case tomo.PatternLine: return defaultTextures[8][offset]
case PatternMercury: return defaultTextures[13][offset] case tomo.PatternMercury: return defaultTextures[13][offset]
default: return patterns.Uhex(0xFF00FFFF) default: return patterns.Uhex(0xFF00FFFF)
} }
} }
func (Default) Color (id Color, state State, c Case) color.RGBA { func (Default) Color (id tomo.Color, state tomo.State, c tomo.Case) color.RGBA {
if state.Disabled { if state.Disabled {
return artist.Hex(0x444444FF) return artist.Hex(0x444444FF)
} else { } else {
switch id { switch id {
case ColorAccent: return artist.Hex(0x408090FF) case tomo.ColorAccent: return artist.Hex(0x408090FF)
case ColorForeground: return artist.Hex(0x000000FF) case tomo.ColorForeground: return artist.Hex(0x000000FF)
default: return artist.Hex(0x888888FF) default: return artist.Hex(0x888888FF)
} }
} }
} }
// Padding returns the default padding value for the given pattern. // Padding returns the default padding value for the given pattern.
func (Default) Padding (id Pattern, c Case) artist.Inset { func (Default) Padding (id tomo.Pattern, c tomo.Case) artist.Inset {
switch id { switch id {
case PatternRaised: case tomo.PatternRaised:
if c.Match("tomo", "listEntry", "") { if c.Match("tomo", "listEntry", "") {
return artist.I(4, 8) return artist.I(4, 8)
} else { } else {
return artist.I(8) return artist.I(8)
} }
case PatternSunken: case tomo.PatternSunken:
if c.Match("tomo", "list", "") { if c.Match("tomo", "list", "") {
return artist.I(4, 0, 3) return artist.I(4, 0, 3)
} else if c.Match("basic", "progressBar", "") { } else if c.Match("basic", "progressBar", "") {
@ -266,32 +267,32 @@ func (Default) Padding (id Pattern, c Case) artist.Inset {
} else { } else {
return artist.I(8) return artist.I(8)
} }
case PatternPinboard: case tomo.PatternPinboard:
if c.Match("tomo", "piano", "") { if c.Match("tomo", "piano", "") {
return artist.I(2) return artist.I(2)
} else { } else {
return artist.I(8) return artist.I(8)
} }
case PatternGutter: return artist.I(0) case tomo.PatternGutter: return artist.I(0)
case PatternLine: return artist.I(1) case tomo.PatternLine: return artist.I(1)
case PatternMercury: return artist.I(5) case tomo.PatternMercury: return artist.I(5)
default: return artist.I(8) default: return artist.I(8)
} }
} }
// Margin returns the default margin value for the given pattern. // Margin returns the default margin value for the given pattern.
func (Default) Margin (id Pattern, c Case) image.Point { func (Default) Margin (id tomo.Pattern, c tomo.Case) image.Point {
return image.Pt(8, 8) return image.Pt(8, 8)
} }
// Hints returns rendering optimization hints for a particular pattern. // Hints returns rendering optimization hints for a particular pattern.
// These are optional, but following them may result in improved // These are optional, but following them may result in improved
// performance. // performance.
func (Default) Hints (pattern Pattern, c Case) (hints Hints) { func (Default) Hints (pattern tomo.Pattern, c tomo.Case) (hints tomo.Hints) {
return return
} }
// Sink returns the default sink vector for the given pattern. // Sink returns the default sink vector for the given pattern.
func (Default) Sink (pattern Pattern, c Case) image.Point { func (Default) Sink (pattern tomo.Pattern, c tomo.Case) image.Point {
return image.Point { 1, 1 } return image.Point { 1, 1 }
} }

2
default/theme/doc.go Normal file
View File

@ -0,0 +1,2 @@
// Package theme implements a default theme.
package theme

9
default/theme/parse.go Normal file
View File

@ -0,0 +1,9 @@
package theme
// import "io"
// Parse parses one or more theme files and returns them as a Theme.
// func Parse (sources ...io.Reader) (Theme) {
// // TODO
// return Default { }
// }

View File

@ -3,6 +3,7 @@ package theme
import "image" import "image"
import "image/color" import "image/color"
import "golang.org/x/image/font" import "golang.org/x/image/font"
import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/data" import "git.tebibyte.media/sashakoshka/tomo/data"
import "git.tebibyte.media/sashakoshka/tomo/artist" import "git.tebibyte.media/sashakoshka/tomo/artist"
@ -10,43 +11,43 @@ import "git.tebibyte.media/sashakoshka/tomo/artist"
// doesn't need to be specified for each query. Additionally, if the underlying // doesn't need to be specified for each query. Additionally, if the underlying
// theme is nil, it just uses the default theme instead. // theme is nil, it just uses the default theme instead.
type Wrapped struct { type Wrapped struct {
Theme tomo.Theme
Case tomo.Case
} }
// FontFace returns the proper font for a given style and size. // FontFace returns the proper font for a given style and size.
func (wrapped Wrapped) FontFace (style FontStyle, size FontSize) font.Face { func (wrapped Wrapped) FontFace (style tomo.FontStyle, size tomo.FontSize) font.Face {
real := wrapped.ensure() real := wrapped.ensure()
return real.FontFace(style, size, wrapped.Case) return real.FontFace(style, size, wrapped.Case)
} }
// Icon returns an appropriate icon given an icon name. // Icon returns an appropriate icon given an icon name.
func (wrapped Wrapped) Icon (id Icon, size IconSize) artist.Icon { func (wrapped Wrapped) Icon (id tomo.Icon, size tomo.IconSize) artist.Icon {
real := wrapped.ensure() real := wrapped.ensure()
return real.Icon(id, size, wrapped.Case) return real.Icon(id, size, wrapped.Case)
} }
// MimeIcon returns an appropriate icon given file mime type. // MimeIcon returns an appropriate icon given file mime type.
func (wrapped Wrapped) MimeIcon (mime data.Mime, size IconSize) artist.Icon { func (wrapped Wrapped) MimeIcon (mime data.Mime, size tomo.IconSize) artist.Icon {
real := wrapped.ensure() real := wrapped.ensure()
return real.MimeIcon(mime, size, wrapped.Case) return real.MimeIcon(mime, size, wrapped.Case)
} }
// Pattern returns an appropriate pattern given a pattern name and state. // Pattern returns an appropriate pattern given a pattern name and state.
func (wrapped Wrapped) Pattern (id Pattern, state State) artist.Pattern { func (wrapped Wrapped) Pattern (id tomo.Pattern, state tomo.State) artist.Pattern {
real := wrapped.ensure() real := wrapped.ensure()
return real.Pattern(id, state, wrapped.Case) return real.Pattern(id, state, wrapped.Case)
} }
// Color returns an appropriate color given a color name and state. // Color returns an appropriate color given a color name and state.
func (wrapped Wrapped) Color (id Color, state State) color.RGBA { func (wrapped Wrapped) Color (id tomo.Color, state tomo.State) color.RGBA {
real := wrapped.ensure() real := wrapped.ensure()
return real.Color(id, state, wrapped.Case) return real.Color(id, state, wrapped.Case)
} }
// Padding returns how much space should be between the bounds of a // Padding returns how much space should be between the bounds of a
// pattern whatever an element draws inside of it. // pattern whatever an element draws inside of it.
func (wrapped Wrapped) Padding (id Pattern) artist.Inset { func (wrapped Wrapped) Padding (id tomo.Pattern) artist.Inset {
real := wrapped.ensure() real := wrapped.ensure()
return real.Padding(id, wrapped.Case) return real.Padding(id, wrapped.Case)
} }
@ -54,14 +55,14 @@ func (wrapped Wrapped) Padding (id Pattern) artist.Inset {
// Margin returns the left/right (x) and top/bottom (y) margins that // Margin returns the left/right (x) and top/bottom (y) margins that
// should be put between any self-contained objects drawn within this // should be put between any self-contained objects drawn within this
// pattern (if applicable). // pattern (if applicable).
func (wrapped Wrapped) Margin (id Pattern) image.Point { func (wrapped Wrapped) Margin (id tomo.Pattern) image.Point {
real := wrapped.ensure() real := wrapped.ensure()
return real.Margin(id, wrapped.Case) return real.Margin(id, wrapped.Case)
} }
// Sink returns a vector that should be added to an element's inner content when // Sink returns a vector that should be added to an element's inner content when
// it is pressed down (if applicable) to simulate a 3D sinking effect. // it is pressed down (if applicable) to simulate a 3D sinking effect.
func (wrapped Wrapped) Sink (id Pattern) image.Point { func (wrapped Wrapped) Sink (id tomo.Pattern) image.Point {
real := wrapped.ensure() real := wrapped.ensure()
return real.Sink(id, wrapped.Case) return real.Sink(id, wrapped.Case)
} }
@ -69,12 +70,12 @@ func (wrapped Wrapped) Sink (id Pattern) image.Point {
// Hints returns rendering optimization hints for a particular pattern. // Hints returns rendering optimization hints for a particular pattern.
// These are optional, but following them may result in improved // These are optional, but following them may result in improved
// performance. // performance.
func (wrapped Wrapped) Hints (id Pattern) Hints { func (wrapped Wrapped) Hints (id tomo.Pattern) tomo.Hints {
real := wrapped.ensure() real := wrapped.ensure()
return real.Hints(id, wrapped.Case) return real.Hints(id, wrapped.Case)
} }
func (wrapped Wrapped) ensure () (real Theme) { func (wrapped Wrapped) ensure () (real tomo.Theme) {
real = wrapped.Theme real = wrapped.Theme
if real == nil { real = Default { } } if real == nil { real = Default { } }
return return

View File

@ -2,9 +2,7 @@ package tomo
import "image" import "image"
import "git.tebibyte.media/sashakoshka/tomo/input" import "git.tebibyte.media/sashakoshka/tomo/input"
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/canvas" import "git.tebibyte.media/sashakoshka/tomo/canvas"
import "git.tebibyte.media/sashakoshka/tomo/config"
// Element represents a basic on-screen object. // Element represents a basic on-screen object.
type Element interface { type Element interface {
@ -164,7 +162,7 @@ type Themeable interface {
// SetTheme sets the element's theme to something fulfilling the // SetTheme sets the element's theme to something fulfilling the
// theme.Theme interface. // theme.Theme interface.
SetTheme (theme.Theme) SetTheme (Theme)
} }
// Configurable represents an element that can modify its behavior to fit within // Configurable represents an element that can modify its behavior to fit within
@ -174,5 +172,5 @@ type Configurable interface {
// SetConfig sets the element's configuration to something fulfilling // SetConfig sets the element's configuration to something fulfilling
// the config.Config interface. // the config.Config interface.
SetConfig (config.Config) SetConfig (Config)
} }

View File

@ -2,9 +2,10 @@ package elements
import "image" import "image"
// import "runtime/debug" // import "runtime/debug"
import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/input" import "git.tebibyte.media/sashakoshka/tomo/input"
import "git.tebibyte.media/sashakoshka/tomo/theme" import "git.tebibyte.media/sashakoshka/tomo/default/theme"
import "git.tebibyte.media/sashakoshka/tomo/config" import "git.tebibyte.media/sashakoshka/tomo/default/config"
// import "git.tebibyte.media/sashakoshka/tomo/artist" // import "git.tebibyte.media/sashakoshka/tomo/artist"
// import "git.tebibyte.media/sashakoshka/tomo/shatter" // import "git.tebibyte.media/sashakoshka/tomo/shatter"
import "git.tebibyte.media/sashakoshka/tomo/textdraw" import "git.tebibyte.media/sashakoshka/tomo/textdraw"
@ -26,7 +27,7 @@ type Button struct {
showText bool showText bool
hasIcon bool hasIcon bool
iconId theme.Icon iconId tomo.Icon
onClick func () onClick func ()
} }
@ -34,10 +35,13 @@ type Button struct {
// NewButton creates a new button with the specified label text. // NewButton creates a new button with the specified label text.
func NewButton (text string) (element *Button) { func NewButton (text string) (element *Button) {
element = &Button { showText: true } element = &Button { showText: true }
element.theme.Case = theme.C("tomo", "button") element.theme.Case = tomo.C("tomo", "button")
element.Core, element.core = core.NewCore(element, element.drawAll) element.Core, element.core = core.NewCore(element, element.drawAll)
element.FocusableCore, element.FocusableCore,
element.focusableControl = core.NewFocusableCore(element.core, element.drawAndPush) element.focusableControl = core.NewFocusableCore(element.core, element.drawAndPush)
element.drawer.SetFace (element.theme.FontFace (
tomo.FontStyleRegular,
tomo.FontSizeNormal))
element.SetText(text) element.SetText(text)
return return
} }
@ -102,8 +106,8 @@ func (element *Button) SetText (text string) {
// SetIcon sets the icon of the button. Passing theme.IconNone removes the // SetIcon sets the icon of the button. Passing theme.IconNone removes the
// current icon if it exists. // current icon if it exists.
func (element *Button) SetIcon (id theme.Icon) { func (element *Button) SetIcon (id tomo.Icon) {
if id == theme.IconNone { if id == tomo.IconNone {
element.hasIcon = false element.hasIcon = false
element.updateMinimumSize() element.updateMinimumSize()
element.drawAndPush() element.drawAndPush()
@ -125,18 +129,18 @@ func (element *Button) ShowText (showText bool) {
} }
// SetTheme sets the element's theme. // SetTheme sets the element's theme.
func (element *Button) SetTheme (new theme.Theme) { func (element *Button) SetTheme (new tomo.Theme) {
if new == element.theme.Theme { return } if new == element.theme.Theme { return }
element.theme.Theme = new element.theme.Theme = new
element.drawer.SetFace (element.theme.FontFace ( element.drawer.SetFace (element.theme.FontFace (
theme.FontStyleRegular, tomo.FontStyleRegular,
theme.FontSizeNormal)) tomo.FontSizeNormal))
element.updateMinimumSize() element.updateMinimumSize()
element.drawAndPush() element.drawAndPush()
} }
// SetConfig sets the element's configuration. // SetConfig sets the element's configuration.
func (element *Button) SetConfig (new config.Config) { func (element *Button) SetConfig (new tomo.Config) {
if new == element.config.Config { return } if new == element.config.Config { return }
element.config.Config = new element.config.Config = new
element.updateMinimumSize() element.updateMinimumSize()
@ -144,14 +148,14 @@ func (element *Button) SetConfig (new config.Config) {
} }
func (element *Button) updateMinimumSize () { func (element *Button) updateMinimumSize () {
padding := element.theme.Padding(theme.PatternButton) padding := element.theme.Padding(tomo.PatternButton)
margin := element.theme.Margin(theme.PatternButton) margin := element.theme.Margin(tomo.PatternButton)
textBounds := element.drawer.LayoutBounds() textBounds := element.drawer.LayoutBounds()
minimumSize := textBounds.Sub(textBounds.Min) minimumSize := textBounds.Sub(textBounds.Min)
if element.hasIcon { if element.hasIcon {
icon := element.theme.Icon(element.iconId, theme.IconSizeSmall) icon := element.theme.Icon(element.iconId, tomo.IconSizeSmall)
if icon != nil { if icon != nil {
bounds := icon.Bounds() bounds := icon.Bounds()
if element.showText { if element.showText {
@ -167,8 +171,8 @@ func (element *Button) updateMinimumSize () {
element.core.SetMinimumSize(minimumSize.Dx(), minimumSize.Dy()) element.core.SetMinimumSize(minimumSize.Dx(), minimumSize.Dy())
} }
func (element *Button) state () theme.State { func (element *Button) state () tomo.State {
return theme.State { return tomo.State {
Disabled: !element.Enabled(), Disabled: !element.Enabled(),
Focused: element.Focused(), Focused: element.Focused(),
Pressed: element.pressed, Pressed: element.pressed,
@ -190,7 +194,7 @@ func (element *Button) drawAll () {
func (element *Button) drawBackground () []image.Rectangle { func (element *Button) drawBackground () []image.Rectangle {
state := element.state() state := element.state()
bounds := element.Bounds() bounds := element.Bounds()
pattern := element.theme.Pattern(theme.PatternButton, state) pattern := element.theme.Pattern(tomo.PatternButton, state)
pattern.Draw(element.core, bounds) pattern.Draw(element.core, bounds)
return []image.Rectangle { bounds } return []image.Rectangle { bounds }
@ -199,9 +203,9 @@ func (element *Button) drawBackground () []image.Rectangle {
func (element *Button) drawText () { func (element *Button) drawText () {
state := element.state() state := element.state()
bounds := element.Bounds() bounds := element.Bounds()
foreground := element.theme.Color(theme.ColorForeground, state) foreground := element.theme.Color(tomo.ColorForeground, state)
sink := element.theme.Sink(theme.PatternButton) sink := element.theme.Sink(tomo.PatternButton)
margin := element.theme.Margin(theme.PatternButton) margin := element.theme.Margin(tomo.PatternButton)
offset := image.Pt ( offset := image.Pt (
bounds.Dx() / 2, bounds.Dx() / 2,
@ -216,7 +220,7 @@ func (element *Button) drawText () {
} }
if element.hasIcon { if element.hasIcon {
icon := element.theme.Icon(element.iconId, theme.IconSizeSmall) icon := element.theme.Icon(element.iconId, tomo.IconSizeSmall)
if icon != nil { if icon != nil {
iconBounds := icon.Bounds() iconBounds := icon.Bounds()
addedWidth := iconBounds.Dx() addedWidth := iconBounds.Dx()

View File

@ -1,11 +1,12 @@
package elements package elements
import "image" import "image"
import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/input" import "git.tebibyte.media/sashakoshka/tomo/input"
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/config"
import "git.tebibyte.media/sashakoshka/tomo/textdraw" import "git.tebibyte.media/sashakoshka/tomo/textdraw"
import "git.tebibyte.media/sashakoshka/tomo/elements/core" import "git.tebibyte.media/sashakoshka/tomo/elements/core"
import "git.tebibyte.media/sashakoshka/tomo/default/theme"
import "git.tebibyte.media/sashakoshka/tomo/default/config"
// Checkbox is a toggle-able checkbox with a label. // Checkbox is a toggle-able checkbox with a label.
type Checkbox struct { type Checkbox struct {
@ -28,10 +29,13 @@ type Checkbox struct {
// NewCheckbox creates a new cbeckbox with the specified label text. // NewCheckbox creates a new cbeckbox with the specified label text.
func NewCheckbox (text string, checked bool) (element *Checkbox) { func NewCheckbox (text string, checked bool) (element *Checkbox) {
element = &Checkbox { checked: checked } element = &Checkbox { checked: checked }
element.theme.Case = theme.C("tomo", "checkbox") element.theme.Case = tomo.C("tomo", "checkbox")
element.Core, element.core = core.NewCore(element, element.draw) element.Core, element.core = core.NewCore(element, element.draw)
element.FocusableCore, element.FocusableCore,
element.focusableControl = core.NewFocusableCore(element.core, element.redo) element.focusableControl = core.NewFocusableCore(element.core, element.redo)
element.drawer.SetFace (element.theme.FontFace (
tomo.FontStyleRegular,
tomo.FontSizeNormal))
element.SetText(text) element.SetText(text)
return return
} }
@ -119,18 +123,18 @@ func (element *Checkbox) SetText (text string) {
} }
// SetTheme sets the element's theme. // SetTheme sets the element's theme.
func (element *Checkbox) SetTheme (new theme.Theme) { func (element *Checkbox) SetTheme (new tomo.Theme) {
if new == element.theme.Theme { return } if new == element.theme.Theme { return }
element.theme.Theme = new element.theme.Theme = new
element.drawer.SetFace (element.theme.FontFace ( element.drawer.SetFace (element.theme.FontFace (
theme.FontStyleRegular, tomo.FontStyleRegular,
theme.FontSizeNormal)) tomo.FontSizeNormal))
element.updateMinimumSize() element.updateMinimumSize()
element.redo() element.redo()
} }
// SetConfig sets the element's configuration. // SetConfig sets the element's configuration.
func (element *Checkbox) SetConfig (new config.Config) { func (element *Checkbox) SetConfig (new tomo.Config) {
if new == element.config.Config { return } if new == element.config.Config { return }
element.config.Config = new element.config.Config = new
element.updateMinimumSize() element.updateMinimumSize()
@ -142,7 +146,7 @@ func (element *Checkbox) updateMinimumSize () {
if element.text == "" { if element.text == "" {
element.core.SetMinimumSize(textBounds.Dy(), textBounds.Dy()) element.core.SetMinimumSize(textBounds.Dy(), textBounds.Dy())
} else { } else {
margin := element.theme.Margin(theme.PatternBackground) margin := element.theme.Margin(tomo.PatternBackground)
element.core.SetMinimumSize ( element.core.SetMinimumSize (
textBounds.Dy() + margin.X + textBounds.Dx(), textBounds.Dy() + margin.X + textBounds.Dx(),
textBounds.Dy()) textBounds.Dy())
@ -160,7 +164,7 @@ func (element *Checkbox) draw () {
bounds := element.Bounds() bounds := element.Bounds()
boxBounds := image.Rect(0, 0, bounds.Dy(), bounds.Dy()).Add(bounds.Min) boxBounds := image.Rect(0, 0, bounds.Dy(), bounds.Dy()).Add(bounds.Min)
state := theme.State { state := tomo.State {
Disabled: !element.Enabled(), Disabled: !element.Enabled(),
Focused: element.Focused(), Focused: element.Focused(),
Pressed: element.pressed, Pressed: element.pressed,
@ -168,14 +172,14 @@ func (element *Checkbox) draw () {
} }
backgroundPattern := element.theme.Pattern ( backgroundPattern := element.theme.Pattern (
theme.PatternBackground, state) tomo.PatternBackground, state)
backgroundPattern.Draw(element.core, bounds) backgroundPattern.Draw(element.core, bounds)
pattern := element.theme.Pattern(theme.PatternButton, state) pattern := element.theme.Pattern(tomo.PatternButton, state)
pattern.Draw(element.core, boxBounds) pattern.Draw(element.core, boxBounds)
textBounds := element.drawer.LayoutBounds() textBounds := element.drawer.LayoutBounds()
margin := element.theme.Margin(theme.PatternBackground) margin := element.theme.Margin(tomo.PatternBackground)
offset := bounds.Min.Add(image.Point { offset := bounds.Min.Add(image.Point {
X: bounds.Dy() + margin.X, X: bounds.Dy() + margin.X,
}) })
@ -183,6 +187,6 @@ func (element *Checkbox) draw () {
offset.Y -= textBounds.Min.Y offset.Y -= textBounds.Min.Y
offset.X -= textBounds.Min.X offset.X -= textBounds.Min.X
foreground := element.theme.Color(theme.ColorForeground, state) foreground := element.theme.Color(tomo.ColorForeground, state)
element.drawer.Draw(element.core, foreground, offset) element.drawer.Draw(element.core, foreground, offset)
} }

View File

@ -3,11 +3,11 @@ package containers
import "image" import "image"
import "git.tebibyte.media/sashakoshka/tomo" import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/input" import "git.tebibyte.media/sashakoshka/tomo/input"
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/config"
import "git.tebibyte.media/sashakoshka/tomo/canvas" import "git.tebibyte.media/sashakoshka/tomo/canvas"
import "git.tebibyte.media/sashakoshka/tomo/artist" import "git.tebibyte.media/sashakoshka/tomo/artist"
import "git.tebibyte.media/sashakoshka/tomo/elements/core" import "git.tebibyte.media/sashakoshka/tomo/elements/core"
import "git.tebibyte.media/sashakoshka/tomo/default/theme"
import "git.tebibyte.media/sashakoshka/tomo/default/config"
// Container is an element capable of containg other elements, and arranging // Container is an element capable of containg other elements, and arranging
// them in a layout. // them in a layout.
@ -30,7 +30,7 @@ type Container struct {
// NewContainer creates a new container. // NewContainer creates a new container.
func NewContainer (layout tomo.Layout) (element *Container) { func NewContainer (layout tomo.Layout) (element *Container) {
element = &Container { } element = &Container { }
element.theme.Case = theme.C("tomo", "container") element.theme.Case = tomo.C("tomo", "container")
element.Core, element.core = core.NewCore(element, element.redoAll) element.Core, element.core = core.NewCore(element, element.redoAll)
element.Propagator = core.NewPropagator(element, element.core) element.Propagator = core.NewPropagator(element, element.core)
element.SetLayout(layout) element.SetLayout(layout)
@ -190,8 +190,8 @@ func (element *Container) redoAll () {
rocks[index] = entry.Bounds rocks[index] = entry.Bounds
} }
pattern := element.theme.Pattern ( pattern := element.theme.Pattern (
theme.PatternBackground, tomo.PatternBackground,
theme.State { }) tomo.State { })
artist.DrawShatter(element.core, pattern, element.Bounds(), rocks...) artist.DrawShatter(element.core, pattern, element.Bounds(), rocks...)
// cut our canvas up and give peices to child elements // cut our canvas up and give peices to child elements
@ -213,7 +213,7 @@ func (element *Container) NotifyMinimumSizeChange (child tomo.Element) {
} }
// SetTheme sets the element's theme. // SetTheme sets the element's theme.
func (element *Container) SetTheme (new theme.Theme) { func (element *Container) SetTheme (new tomo.Theme) {
if new == element.theme.Theme { return } if new == element.theme.Theme { return }
element.theme.Theme = new element.theme.Theme = new
element.Propagator.SetTheme(new) element.Propagator.SetTheme(new)
@ -222,7 +222,7 @@ func (element *Container) SetTheme (new theme.Theme) {
} }
// SetConfig sets the element's configuration. // SetConfig sets the element's configuration.
func (element *Container) SetConfig (new config.Config) { func (element *Container) SetConfig (new tomo.Config) {
if new == element.config.Config { return } if new == element.config.Config { return }
element.Propagator.SetConfig(new) element.Propagator.SetConfig(new)
element.updateMinimumSize() element.updateMinimumSize()
@ -230,16 +230,16 @@ func (element *Container) SetConfig (new config.Config) {
} }
func (element *Container) updateMinimumSize () { func (element *Container) updateMinimumSize () {
margin := element.theme.Margin(theme.PatternBackground) margin := element.theme.Margin(tomo.PatternBackground)
padding := element.theme.Padding(theme.PatternBackground) padding := element.theme.Padding(tomo.PatternBackground)
width, height := element.layout.MinimumSize ( width, height := element.layout.MinimumSize (
element.children, margin, padding) element.children, margin, padding)
element.core.SetMinimumSize(width, height) element.core.SetMinimumSize(width, height)
} }
func (element *Container) doLayout () { func (element *Container) doLayout () {
margin := element.theme.Margin(theme.PatternBackground) margin := element.theme.Margin(tomo.PatternBackground)
padding := element.theme.Padding(theme.PatternBackground) padding := element.theme.Padding(tomo.PatternBackground)
element.layout.Arrange ( element.layout.Arrange (
element.children, margin, element.children, margin,
padding, element.Bounds()) padding, element.Bounds())

View File

@ -2,11 +2,11 @@ package containers
import "image" import "image"
import "git.tebibyte.media/sashakoshka/tomo" import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/config"
import "git.tebibyte.media/sashakoshka/tomo/canvas" import "git.tebibyte.media/sashakoshka/tomo/canvas"
import "git.tebibyte.media/sashakoshka/tomo/artist" import "git.tebibyte.media/sashakoshka/tomo/artist"
import "git.tebibyte.media/sashakoshka/tomo/elements/core" import "git.tebibyte.media/sashakoshka/tomo/elements/core"
import "git.tebibyte.media/sashakoshka/tomo/default/theme"
import "git.tebibyte.media/sashakoshka/tomo/default/config"
type DocumentContainer struct { type DocumentContainer struct {
*core.Core *core.Core
@ -27,7 +27,7 @@ type DocumentContainer struct {
// NewDocumentContainer creates a new document container. // NewDocumentContainer creates a new document container.
func NewDocumentContainer () (element *DocumentContainer) { func NewDocumentContainer () (element *DocumentContainer) {
element = &DocumentContainer { } element = &DocumentContainer { }
element.theme.Case = theme.C("tomo", "documentContainer") element.theme.Case = tomo.C("tomo", "documentContainer")
element.Core, element.core = core.NewCore(element, element.redoAll) element.Core, element.core = core.NewCore(element, element.redoAll)
element.Propagator = core.NewPropagator(element, element.core) element.Propagator = core.NewPropagator(element, element.core)
return return
@ -172,8 +172,8 @@ func (element *DocumentContainer) redoAll () {
rocks[index] = entry.Bounds rocks[index] = entry.Bounds
} }
pattern := element.theme.Pattern ( pattern := element.theme.Pattern (
theme.PatternBackground, tomo.PatternBackground,
theme.State { }) tomo.State { })
artist.DrawShatter(element.core, pattern, element.Bounds(), rocks...) artist.DrawShatter(element.core, pattern, element.Bounds(), rocks...)
element.partition() element.partition()
@ -219,7 +219,7 @@ func (element *DocumentContainer) NotifyFlexibleHeightChange (child tomo.Flexibl
} }
// SetTheme sets the element's theme. // SetTheme sets the element's theme.
func (element *DocumentContainer) SetTheme (new theme.Theme) { func (element *DocumentContainer) SetTheme (new tomo.Theme) {
if new == element.theme.Theme { return } if new == element.theme.Theme { return }
element.theme.Theme = new element.theme.Theme = new
element.Propagator.SetTheme(new) element.Propagator.SetTheme(new)
@ -227,7 +227,7 @@ func (element *DocumentContainer) SetTheme (new theme.Theme) {
} }
// SetConfig sets the element's configuration. // SetConfig sets the element's configuration.
func (element *DocumentContainer) SetConfig (new config.Config) { func (element *DocumentContainer) SetConfig (new tomo.Config) {
if new == element.config.Config { return } if new == element.config.Config { return }
element.Propagator.SetConfig(new) element.Propagator.SetConfig(new)
element.redoAll() element.redoAll()
@ -241,7 +241,7 @@ func (element *DocumentContainer) ScrollContentBounds () image.Rectangle {
// ScrollViewportBounds returns the size and position of the element's // ScrollViewportBounds returns the size and position of the element's
// viewport relative to ScrollBounds. // viewport relative to ScrollBounds.
func (element *DocumentContainer) ScrollViewportBounds () image.Rectangle { func (element *DocumentContainer) ScrollViewportBounds () image.Rectangle {
padding := element.theme.Padding(theme.PatternBackground) padding := element.theme.Padding(tomo.PatternBackground)
bounds := padding.Apply(element.Bounds()) bounds := padding.Apply(element.Bounds())
bounds = bounds.Sub(bounds.Min).Add(element.scroll) bounds = bounds.Sub(bounds.Min).Add(element.scroll)
return bounds return bounds
@ -271,7 +271,7 @@ func (element *DocumentContainer) OnScrollBoundsChange (callback func ()) {
} }
func (element *DocumentContainer) maxScrollHeight () (height int) { func (element *DocumentContainer) maxScrollHeight () (height int) {
padding := element.theme.Padding(theme.PatternSunken) padding := element.theme.Padding(tomo.PatternSunken)
viewportHeight := element.Bounds().Dy() - padding.Vertical() viewportHeight := element.Bounds().Dy() - padding.Vertical()
height = element.contentBounds.Dy() - viewportHeight height = element.contentBounds.Dy() - viewportHeight
if height < 0 { height = 0 } if height < 0 { height = 0 }
@ -284,8 +284,8 @@ func (element *DocumentContainer) ScrollAxes () (horizontal, vertical bool) {
} }
func (element *DocumentContainer) doLayout () { func (element *DocumentContainer) doLayout () {
margin := element.theme.Margin(theme.PatternBackground) margin := element.theme.Margin(tomo.PatternBackground)
padding := element.theme.Padding(theme.PatternBackground) padding := element.theme.Padding(tomo.PatternBackground)
bounds := padding.Apply(element.Bounds()) bounds := padding.Apply(element.Bounds())
element.contentBounds = image.Rectangle { } element.contentBounds = image.Rectangle { }
@ -315,7 +315,7 @@ func (element *DocumentContainer) doLayout () {
} }
func (element *DocumentContainer) updateMinimumSize () { func (element *DocumentContainer) updateMinimumSize () {
padding := element.theme.Padding(theme.PatternBackground) padding := element.theme.Padding(tomo.PatternBackground)
minimumWidth := 0 minimumWidth := 0
for _, entry := range element.children { for _, entry := range element.children {
width, _ := entry.MinimumSize() width, _ := entry.MinimumSize()

View File

@ -3,11 +3,11 @@ package containers
import "image" import "image"
import "git.tebibyte.media/sashakoshka/tomo" import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/input" import "git.tebibyte.media/sashakoshka/tomo/input"
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/config"
import "git.tebibyte.media/sashakoshka/tomo/canvas" import "git.tebibyte.media/sashakoshka/tomo/canvas"
import "git.tebibyte.media/sashakoshka/tomo/elements" import "git.tebibyte.media/sashakoshka/tomo/elements"
import "git.tebibyte.media/sashakoshka/tomo/elements/core" import "git.tebibyte.media/sashakoshka/tomo/elements/core"
import "git.tebibyte.media/sashakoshka/tomo/default/theme"
import "git.tebibyte.media/sashakoshka/tomo/default/config"
// ScrollContainer is a container that is capable of holding a scrollable // ScrollContainer is a container that is capable of holding a scrollable
// element. // element.
@ -31,7 +31,7 @@ type ScrollContainer struct {
// bars. // bars.
func NewScrollContainer (horizontal, vertical bool) (element *ScrollContainer) { func NewScrollContainer (horizontal, vertical bool) (element *ScrollContainer) {
element = &ScrollContainer { } element = &ScrollContainer { }
element.theme.Case = theme.C("tomo", "scrollContainer") element.theme.Case = tomo.C("tomo", "scrollContainer")
element.Core, element.core = core.NewCore(element, element.redoAll) element.Core, element.core = core.NewCore(element, element.redoAll)
element.Propagator = core.NewPropagator(element, element.core) element.Propagator = core.NewPropagator(element, element.core)
@ -132,7 +132,7 @@ func (element *ScrollContainer) NotifyScrollBoundsChange (child tomo.Scrollable)
} }
// SetTheme sets the element's theme. // SetTheme sets the element's theme.
func (element *ScrollContainer) SetTheme (new theme.Theme) { func (element *ScrollContainer) SetTheme (new tomo.Theme) {
if new == element.theme.Theme { return } if new == element.theme.Theme { return }
element.theme.Theme = new element.theme.Theme = new
element.Propagator.SetTheme(new) element.Propagator.SetTheme(new)
@ -141,7 +141,7 @@ func (element *ScrollContainer) SetTheme (new theme.Theme) {
} }
// SetConfig sets the element's configuration. // SetConfig sets the element's configuration.
func (element *ScrollContainer) SetConfig (new config.Config) { func (element *ScrollContainer) SetConfig (new tomo.Config) {
if new == element.config.Config { return } if new == element.config.Config { return }
element.Propagator.SetConfig(new) element.Propagator.SetConfig(new)
element.updateMinimumSize() element.updateMinimumSize()
@ -258,8 +258,8 @@ func (element *ScrollContainer) draw () {
bounds.Min = image.Pt ( bounds.Min = image.Pt (
bounds.Max.X - element.vertical.Bounds().Dx(), bounds.Max.X - element.vertical.Bounds().Dx(),
bounds.Max.Y - element.horizontal.Bounds().Dy()) bounds.Max.Y - element.horizontal.Bounds().Dy())
state := theme.State { } state := tomo.State { }
deadArea := element.theme.Pattern(theme.PatternDead, state) deadArea := element.theme.Pattern(tomo.PatternDead, state)
deadArea.Draw(canvas.Cut(element.core, bounds), bounds) deadArea.Draw(canvas.Cut(element.core, bounds), bounds)
} }
} }

View File

@ -3,8 +3,6 @@ package core
import "image" import "image"
import "git.tebibyte.media/sashakoshka/tomo" import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/input" import "git.tebibyte.media/sashakoshka/tomo/input"
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/config"
// Container represents an object that can provide access to a list of child // Container represents an object that can provide access to a list of child
// elements. // elements.
@ -242,7 +240,7 @@ func (propagator *Propagator) HandleScroll (x, y int, deltaX, deltaY float64) {
} }
// SetTheme sets the theme of all children to the specified theme. // SetTheme sets the theme of all children to the specified theme.
func (propagator *Propagator) SetTheme (theme theme.Theme) { func (propagator *Propagator) SetTheme (theme tomo.Theme) {
propagator.forChildren (func (child tomo.Element) bool { propagator.forChildren (func (child tomo.Element) bool {
typedChild, themeable := child.(tomo.Themeable) typedChild, themeable := child.(tomo.Themeable)
if themeable { if themeable {
@ -253,7 +251,7 @@ func (propagator *Propagator) SetTheme (theme theme.Theme) {
} }
// SetConfig sets the theme of all children to the specified config. // SetConfig sets the theme of all children to the specified config.
func (propagator *Propagator) SetConfig (config config.Config) { func (propagator *Propagator) SetConfig (config tomo.Config) {
propagator.forChildren (func (child tomo.Element) bool { propagator.forChildren (func (child tomo.Element) bool {
typedChild, configurable := child.(tomo.Configurable) typedChild, configurable := child.(tomo.Configurable)
if configurable { if configurable {

View File

@ -3,14 +3,14 @@ package fileElements
import "io/fs" import "io/fs"
import "image" import "image"
import "path/filepath" import "path/filepath"
import "git.tebibyte.media/sashakoshka/tomo/theme" import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/input" import "git.tebibyte.media/sashakoshka/tomo/input"
import "git.tebibyte.media/sashakoshka/tomo/artist" import "git.tebibyte.media/sashakoshka/tomo/artist"
import "git.tebibyte.media/sashakoshka/tomo/canvas" import "git.tebibyte.media/sashakoshka/tomo/canvas"
import "git.tebibyte.media/sashakoshka/tomo/config"
import "git.tebibyte.media/sashakoshka/tomo/textdraw" import "git.tebibyte.media/sashakoshka/tomo/textdraw"
import "git.tebibyte.media/sashakoshka/tomo/elements"
import "git.tebibyte.media/sashakoshka/tomo/elements/core" import "git.tebibyte.media/sashakoshka/tomo/elements/core"
import "git.tebibyte.media/sashakoshka/tomo/default/theme"
import "git.tebibyte.media/sashakoshka/tomo/default/config"
type fileLayoutEntry struct { type fileLayoutEntry struct {
*File *File
@ -56,7 +56,7 @@ func NewDirectory (
err error, err error,
) { ) {
element = &Directory { } element = &Directory { }
element.theme.Case = theme.C("files", "directory") element.theme.Case = tomo.C("files", "directory")
element.Core, element.core = core.NewCore(element, element.redoAll) element.Core, element.core = core.NewCore(element, element.redoAll)
element.Propagator = core.NewPropagator(element, element.core) element.Propagator = core.NewPropagator(element, element.core)
err = element.SetLocation(location, within) err = element.SetLocation(location, within)
@ -138,8 +138,8 @@ func (element *Directory) Update () error {
element.children[index].File = file element.children[index].File = file
element.children[index].DirEntry = entry element.children[index].DirEntry = entry
element.children[index].Drawer.SetFace (element.theme.FontFace( element.children[index].Drawer.SetFace (element.theme.FontFace(
theme.FontStyleRegular, tomo.FontStyleRegular,
theme.FontSizeNormal)) tomo.FontSizeNormal))
element.children[index].Drawer.SetText([]rune(entry.Name())) element.children[index].Drawer.SetText([]rune(entry.Name()))
element.children[index].Drawer.SetAlign(textdraw.AlignCenter) element.children[index].Drawer.SetAlign(textdraw.AlignCenter)
} }
@ -164,7 +164,7 @@ func (element *Directory) CountChildren () (count int) {
// Child returns the child at the specified index. If the index is out of // Child returns the child at the specified index. If the index is out of
// bounds, this method will return nil. // bounds, this method will return nil.
func (element *Directory) Child (index int) (child elements.Element) { func (element *Directory) Child (index int) (child tomo.Element) {
if index < 0 || index > len(element.children) { return } if index < 0 || index > len(element.children) { return }
return element.children[index].File return element.children[index].File
} }
@ -202,12 +202,12 @@ func (element *Directory) redoAll () {
rocks[index] = entry.Bounds rocks[index] = entry.Bounds
} }
pattern := element.theme.Pattern ( pattern := element.theme.Pattern (
theme.PatternPinboard, tomo.PatternPinboard,
theme.State { }) tomo.State { })
artist.DrawShatter(element.core, pattern, element.Bounds(), rocks...) artist.DrawShatter(element.core, pattern, element.Bounds(), rocks...)
element.partition() element.partition()
if parent, ok := element.core.Parent().(elements.ScrollableParent); ok { if parent, ok := element.core.Parent().(tomo.ScrollableParent); ok {
parent.NotifyScrollBoundsChange(element) parent.NotifyScrollBoundsChange(element)
} }
if element.onScrollBoundsChange != nil { if element.onScrollBoundsChange != nil {
@ -215,7 +215,7 @@ func (element *Directory) redoAll () {
} }
// draw labels // draw labels
foreground := element.theme.Color(theme.ColorForeground, theme.State { }) foreground := element.theme.Color(tomo.ColorForeground, tomo.State { })
for _, entry := range element.children { for _, entry := range element.children {
entry.Drawer.Draw(element.core, foreground, entry.TextPoint) entry.Drawer.Draw(element.core, foreground, entry.TextPoint)
} }
@ -240,13 +240,13 @@ func (element *Directory) partition () {
// NotifyMinimumSizeChange notifies the container that the minimum size of a // NotifyMinimumSizeChange notifies the container that the minimum size of a
// child element has changed. // child element has changed.
func (element *Directory) NotifyMinimumSizeChange (child elements.Element) { func (element *Directory) NotifyMinimumSizeChange (child tomo.Element) {
element.redoAll() element.redoAll()
element.core.DamageAll() element.core.DamageAll()
} }
// SetTheme sets the element's theme. // SetTheme sets the element's theme.
func (element *Directory) SetTheme (new theme.Theme) { func (element *Directory) SetTheme (new tomo.Theme) {
if new == element.theme.Theme { return } if new == element.theme.Theme { return }
element.theme.Theme = new element.theme.Theme = new
element.Propagator.SetTheme(new) element.Propagator.SetTheme(new)
@ -254,7 +254,7 @@ func (element *Directory) SetTheme (new theme.Theme) {
} }
// SetConfig sets the element's configuration. // SetConfig sets the element's configuration.
func (element *Directory) SetConfig (new config.Config) { func (element *Directory) SetConfig (new tomo.Config) {
if new == element.config.Config { return } if new == element.config.Config { return }
element.Propagator.SetConfig(new) element.Propagator.SetConfig(new)
element.redoAll() element.redoAll()
@ -267,7 +267,7 @@ func (element *Directory) ScrollContentBounds () image.Rectangle {
// ScrollViewportBounds returns the size and position of the element's // ScrollViewportBounds returns the size and position of the element's
// viewport relative to ScrollBounds. // viewport relative to ScrollBounds.
func (element *Directory) ScrollViewportBounds () image.Rectangle { func (element *Directory) ScrollViewportBounds () image.Rectangle {
padding := element.theme.Padding(theme.PatternPinboard) padding := element.theme.Padding(tomo.PatternPinboard)
bounds := padding.Apply(element.Bounds()) bounds := padding.Apply(element.Bounds())
bounds = bounds.Sub(bounds.Min).Add(element.scroll) bounds = bounds.Sub(bounds.Min).Add(element.scroll)
return bounds return bounds
@ -302,7 +302,7 @@ func (element *Directory) ScrollAxes () (horizontal, vertical bool) {
} }
func (element *Directory) maxScrollHeight () (height int) { func (element *Directory) maxScrollHeight () (height int) {
padding := element.theme.Padding(theme.PatternSunken) padding := element.theme.Padding(tomo.PatternSunken)
viewportHeight := element.Bounds().Dy() - padding.Vertical() viewportHeight := element.Bounds().Dy() - padding.Vertical()
height = element.contentBounds.Dy() - viewportHeight height = element.contentBounds.Dy() - viewportHeight
if height < 0 { height = 0 } if height < 0 { height = 0 }
@ -310,8 +310,8 @@ func (element *Directory) maxScrollHeight () (height int) {
} }
func (element *Directory) doLayout () { func (element *Directory) doLayout () {
margin := element.theme.Margin(theme.PatternPinboard) margin := element.theme.Margin(tomo.PatternPinboard)
padding := element.theme.Padding(theme.PatternPinboard) padding := element.theme.Padding(tomo.PatternPinboard)
bounds := padding.Apply(element.Bounds()) bounds := padding.Apply(element.Bounds())
element.contentBounds = image.Rectangle { } element.contentBounds = image.Rectangle { }
@ -360,7 +360,7 @@ func (element *Directory) doLayout () {
} }
func (element *Directory) updateMinimumSize () { func (element *Directory) updateMinimumSize () {
padding := element.theme.Padding(theme.PatternPinboard) padding := element.theme.Padding(tomo.PatternPinboard)
minimumWidth := 0 minimumWidth := 0
for _, entry := range element.children { for _, entry := range element.children {
width, _ := entry.MinimumSize() width, _ := entry.MinimumSize()

View File

@ -3,11 +3,12 @@ package fileElements
import "time" import "time"
import "io/fs" import "io/fs"
import "image" import "image"
import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/input" import "git.tebibyte.media/sashakoshka/tomo/input"
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/artist" import "git.tebibyte.media/sashakoshka/tomo/artist"
import "git.tebibyte.media/sashakoshka/tomo/config"
import "git.tebibyte.media/sashakoshka/tomo/elements/core" import "git.tebibyte.media/sashakoshka/tomo/elements/core"
import "git.tebibyte.media/sashakoshka/tomo/default/theme"
import "git.tebibyte.media/sashakoshka/tomo/default/config"
// File displays an interactive visual representation of a file within any // File displays an interactive visual representation of a file within any
// file system. // file system.
@ -22,7 +23,7 @@ type File struct {
lastClick time.Time lastClick time.Time
pressed bool pressed bool
iconID theme.Icon iconID tomo.Icon
filesystem fs.StatFS filesystem fs.StatFS
location string location string
selected bool selected bool
@ -40,7 +41,7 @@ func NewFile (
err error, err error,
) { ) {
element = &File { } element = &File { }
element.theme.Case = theme.C("files", "file") element.theme.Case = tomo.C("files", "file")
element.Core, element.core = core.NewCore(element, element.drawAll) element.Core, element.core = core.NewCore(element, element.drawAll)
element.FocusableCore, element.FocusableCore,
element.focusableControl = core.NewFocusableCore(element.core, element.drawAndPush) element.focusableControl = core.NewFocusableCore(element.core, element.drawAndPush)
@ -72,12 +73,12 @@ func (element *File) Update () error {
info, err := element.filesystem.Stat(element.location) info, err := element.filesystem.Stat(element.location)
if err != nil { if err != nil {
element.iconID = theme.IconError element.iconID = tomo.IconError
} else if info.IsDir() { } else if info.IsDir() {
element.iconID = theme.IconDirectory element.iconID = tomo.IconDirectory
} else { } else {
// TODO: choose icon based on file mime type // TODO: choose icon based on file mime type
element.iconID = theme.IconFile element.iconID = tomo.IconFile
} }
element.updateMinimumSize() element.updateMinimumSize()
@ -142,21 +143,21 @@ func (element *File) HandleMouseUp (x, y int, button input.Button) {
} }
// SetTheme sets the element's theme. // SetTheme sets the element's theme.
func (element *File) SetTheme (new theme.Theme) { func (element *File) SetTheme (new tomo.Theme) {
if new == element.theme.Theme { return } if new == element.theme.Theme { return }
element.theme.Theme = new element.theme.Theme = new
element.drawAndPush() element.drawAndPush()
} }
// SetConfig sets the element's configuration. // SetConfig sets the element's configuration.
func (element *File) SetConfig (new config.Config) { func (element *File) SetConfig (new tomo.Config) {
if new == element.config.Config { return } if new == element.config.Config { return }
element.config.Config = new element.config.Config = new
element.drawAndPush() element.drawAndPush()
} }
func (element *File) state () theme.State { func (element *File) state () tomo.State {
return theme.State { return tomo.State {
Disabled: !element.Enabled(), Disabled: !element.Enabled(),
Focused: element.Focused(), Focused: element.Focused(),
Pressed: element.pressed, Pressed: element.pressed,
@ -165,11 +166,11 @@ func (element *File) state () theme.State {
} }
func (element *File) icon () artist.Icon { func (element *File) icon () artist.Icon {
return element.theme.Icon(element.iconID, theme.IconSizeLarge) return element.theme.Icon(element.iconID, tomo.IconSizeLarge)
} }
func (element *File) updateMinimumSize () { func (element *File) updateMinimumSize () {
padding := element.theme.Padding(theme.PatternButton) padding := element.theme.Padding(tomo.PatternButton)
icon := element.icon() icon := element.icon()
if icon == nil { if icon == nil {
element.core.SetMinimumSize ( element.core.SetMinimumSize (
@ -192,9 +193,9 @@ func (element *File) drawAll () {
// background // background
state := element.state() state := element.state()
bounds := element.Bounds() bounds := element.Bounds()
sink := element.theme.Sink(theme.PatternButton) sink := element.theme.Sink(tomo.PatternButton)
element.theme. element.theme.
Pattern(theme.PatternButton, state). Pattern(tomo.PatternButton, state).
Draw(element.core, bounds) Draw(element.core, bounds)
// icon // icon
@ -209,8 +210,7 @@ func (element *File) drawAll () {
} }
icon.Draw ( icon.Draw (
element.core, element.core,
element.theme.Color ( element.theme.Color(tomo.ColorForeground, state),
theme.ColorForeground, state),
bounds.Min.Add(offset)) bounds.Min.Add(offset))
} }
} }

View File

@ -4,10 +4,11 @@ import "time"
import "math" import "math"
import "image" import "image"
import "image/color" import "image/color"
import "git.tebibyte.media/sashakoshka/tomo/theme" import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/config"
import "git.tebibyte.media/sashakoshka/tomo/artist/shapes" import "git.tebibyte.media/sashakoshka/tomo/artist/shapes"
import "git.tebibyte.media/sashakoshka/tomo/elements/core" import "git.tebibyte.media/sashakoshka/tomo/elements/core"
import "git.tebibyte.media/sashakoshka/tomo/default/theme"
import "git.tebibyte.media/sashakoshka/tomo/default/config"
// AnalogClock can display the time of day in an analog format. // AnalogClock can display the time of day in an analog format.
type AnalogClock struct { type AnalogClock struct {
@ -22,7 +23,7 @@ type AnalogClock struct {
// NewAnalogClock creates a new analog clock that displays the specified time. // NewAnalogClock creates a new analog clock that displays the specified time.
func NewAnalogClock (newTime time.Time) (element *AnalogClock) { func NewAnalogClock (newTime time.Time) (element *AnalogClock) {
element = &AnalogClock { } element = &AnalogClock { }
element.theme.Case = theme.C("tomo", "clock") element.theme.Case = tomo.C("tomo", "clock")
element.Core, element.core = core.NewCore(element, element.draw) element.Core, element.core = core.NewCore(element, element.draw)
element.core.SetMinimumSize(64, 64) element.core.SetMinimumSize(64, 64)
return return
@ -36,14 +37,14 @@ func (element *AnalogClock) SetTime (newTime time.Time) {
} }
// SetTheme sets the element's theme. // SetTheme sets the element's theme.
func (element *AnalogClock) SetTheme (new theme.Theme) { func (element *AnalogClock) SetTheme (new tomo.Theme) {
if new == element.theme.Theme { return } if new == element.theme.Theme { return }
element.theme.Theme = new element.theme.Theme = new
element.redo() element.redo()
} }
// SetConfig sets the element's configuration. // SetConfig sets the element's configuration.
func (element *AnalogClock) SetConfig (new config.Config) { func (element *AnalogClock) SetConfig (new tomo.Config) {
if new == element.config.Config { return } if new == element.config.Config { return }
element.config.Config = new element.config.Config = new
element.redo() element.redo()
@ -59,15 +60,15 @@ func (element *AnalogClock) redo () {
func (element *AnalogClock) draw () { func (element *AnalogClock) draw () {
bounds := element.Bounds() bounds := element.Bounds()
state := theme.State { } state := tomo.State { }
pattern := element.theme.Pattern(theme.PatternSunken, state) pattern := element.theme.Pattern(tomo.PatternSunken, state)
padding := element.theme.Padding(theme.PatternSunken) padding := element.theme.Padding(tomo.PatternSunken)
pattern.Draw(element.core, bounds) pattern.Draw(element.core, bounds)
bounds = padding.Apply(bounds) bounds = padding.Apply(bounds)
foreground := element.theme.Color(theme.ColorForeground, state) foreground := element.theme.Color(tomo.ColorForeground, state)
accent := element.theme.Color(theme.ColorAccent, state) accent := element.theme.Color(tomo.ColorAccent, state)
for hour := 0; hour < 12; hour ++ { for hour := 0; hour < 12; hour ++ {
element.radialLine ( element.radialLine (

View File

@ -1,11 +1,12 @@
package fun package fun
import "image" import "image"
import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/input" import "git.tebibyte.media/sashakoshka/tomo/input"
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/config"
import "git.tebibyte.media/sashakoshka/tomo/artist" import "git.tebibyte.media/sashakoshka/tomo/artist"
import "git.tebibyte.media/sashakoshka/tomo/elements/core" import "git.tebibyte.media/sashakoshka/tomo/elements/core"
import "git.tebibyte.media/sashakoshka/tomo/default/theme"
import "git.tebibyte.media/sashakoshka/tomo/default/config"
import "git.tebibyte.media/sashakoshka/tomo/elements/fun/music" import "git.tebibyte.media/sashakoshka/tomo/elements/fun/music"
const pianoKeyWidth = 18 const pianoKeyWidth = 18
@ -52,7 +53,7 @@ func NewPiano (low, high music.Octave) (element *Piano) {
keynavPressed: make(map[music.Note] bool), keynavPressed: make(map[music.Note] bool),
} }
element.theme.Case = theme.C("tomo", "piano") element.theme.Case = tomo.C("tomo", "piano")
element.Core, element.core = core.NewCore (element, func () { element.Core, element.core = core.NewCore (element, func () {
element.recalculate() element.recalculate()
element.draw() element.draw()
@ -198,7 +199,7 @@ func (element *Piano) HandleKeyUp (key input.Key, modifiers input.Modifiers) {
} }
// SetTheme sets the element's theme. // SetTheme sets the element's theme.
func (element *Piano) SetTheme (new theme.Theme) { func (element *Piano) SetTheme (new tomo.Theme) {
if new == element.theme.Theme { return } if new == element.theme.Theme { return }
element.theme.Theme = new element.theme.Theme = new
element.updateMinimumSize() element.updateMinimumSize()
@ -207,7 +208,7 @@ func (element *Piano) SetTheme (new theme.Theme) {
} }
// SetConfig sets the element's configuration. // SetConfig sets the element's configuration.
func (element *Piano) SetConfig (new config.Config) { func (element *Piano) SetConfig (new tomo.Config) {
if new == element.config.Config { return } if new == element.config.Config { return }
element.config.Config = new element.config.Config = new
element.updateMinimumSize() element.updateMinimumSize()
@ -216,7 +217,7 @@ func (element *Piano) SetConfig (new config.Config) {
} }
func (element *Piano) updateMinimumSize () { func (element *Piano) updateMinimumSize () {
padding := element.theme.Padding(theme.PatternPinboard) padding := element.theme.Padding(tomo.PatternPinboard)
element.core.SetMinimumSize ( element.core.SetMinimumSize (
pianoKeyWidth * 7 * element.countOctaves() + pianoKeyWidth * 7 * element.countOctaves() +
padding.Horizontal(), padding.Horizontal(),
@ -246,7 +247,7 @@ func (element *Piano) recalculate () {
element.flatKeys = make([]pianoKey, element.countFlats()) element.flatKeys = make([]pianoKey, element.countFlats())
element.sharpKeys = make([]pianoKey, element.countSharps()) element.sharpKeys = make([]pianoKey, element.countSharps())
padding := element.theme.Padding(theme.PatternPinboard) padding := element.theme.Padding(tomo.PatternPinboard)
bounds := padding.Apply(element.Bounds()) bounds := padding.Apply(element.Bounds())
dot := bounds.Min dot := bounds.Min
@ -279,7 +280,7 @@ func (element *Piano) recalculate () {
} }
func (element *Piano) draw () { func (element *Piano) draw () {
state := theme.State { state := tomo.State {
Focused: element.Focused(), Focused: element.Focused(),
Disabled: !element.Enabled(), Disabled: !element.Enabled(),
} }
@ -301,7 +302,7 @@ func (element *Piano) draw () {
state) state)
} }
pattern := element.theme.Pattern(theme.PatternPinboard, state) pattern := element.theme.Pattern(tomo.PatternPinboard, state)
artist.DrawShatter ( artist.DrawShatter (
element.core, pattern, element.Bounds(), element.contentBounds) element.core, pattern, element.Bounds(), element.contentBounds)
} }
@ -309,21 +310,21 @@ func (element *Piano) draw () {
func (element *Piano) drawFlat ( func (element *Piano) drawFlat (
bounds image.Rectangle, bounds image.Rectangle,
pressed bool, pressed bool,
state theme.State, state tomo.State,
) { ) {
state.Pressed = pressed state.Pressed = pressed
pattern := element.theme.Theme.Pattern ( pattern := element.theme.Theme.Pattern (
theme.PatternButton, state, theme.C("fun", "piano", "flatKey")) tomo.PatternButton, state, tomo.C("fun", "piano", "flatKey"))
pattern.Draw(element.core, bounds) pattern.Draw(element.core, bounds)
} }
func (element *Piano) drawSharp ( func (element *Piano) drawSharp (
bounds image.Rectangle, bounds image.Rectangle,
pressed bool, pressed bool,
state theme.State, state tomo.State,
) { ) {
state.Pressed = pressed state.Pressed = pressed
pattern := element.theme.Theme.Pattern ( pattern := element.theme.Theme.Pattern (
theme.PatternButton, state, theme.C("fun", "piano", "sharpKey")) tomo.PatternButton, state, tomo.C("fun", "piano", "sharpKey"))
pattern.Draw(element.core, bounds) pattern.Draw(element.core, bounds)
} }

View File

@ -1,30 +1,31 @@
package elements package elements
import "image" import "image"
import "git.tebibyte.media/sashakoshka/tomo/theme" import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/artist" import "git.tebibyte.media/sashakoshka/tomo/artist"
import "git.tebibyte.media/sashakoshka/tomo/default/theme"
import "git.tebibyte.media/sashakoshka/tomo/elements/core" import "git.tebibyte.media/sashakoshka/tomo/elements/core"
type Icon struct { type Icon struct {
*core.Core *core.Core
core core.CoreControl core core.CoreControl
theme theme.Wrapped theme theme.Wrapped
id theme.Icon id tomo.Icon
size theme.IconSize size tomo.IconSize
} }
func NewIcon (id theme.Icon, size theme.IconSize) (element *Icon) { func NewIcon (id tomo.Icon, size tomo.IconSize) (element *Icon) {
element = &Icon { element = &Icon {
id: id, id: id,
size: size, size: size,
} }
element.theme.Case = theme.C("tomo", "icon") element.theme.Case = tomo.C("tomo", "icon")
element.Core, element.core = core.NewCore(element, element.draw) element.Core, element.core = core.NewCore(element, element.draw)
element.updateMinimumSize() element.updateMinimumSize()
return return
} }
func (element *Icon) SetIcon (id theme.Icon, size theme.IconSize) { func (element *Icon) SetIcon (id tomo.Icon, size tomo.IconSize) {
element.id = id element.id = id
element.size = size element.size = size
element.updateMinimumSize() element.updateMinimumSize()
@ -35,7 +36,7 @@ func (element *Icon) SetIcon (id theme.Icon, size theme.IconSize) {
} }
// SetTheme sets the element's theme. // SetTheme sets the element's theme.
func (element *Icon) SetTheme (new theme.Theme) { func (element *Icon) SetTheme (new tomo.Theme) {
if new == element.theme.Theme { return } if new == element.theme.Theme { return }
element.theme.Theme = new element.theme.Theme = new
element.updateMinimumSize() element.updateMinimumSize()
@ -61,9 +62,9 @@ func (element *Icon) updateMinimumSize () {
func (element *Icon) draw () { func (element *Icon) draw () {
bounds := element.Bounds() bounds := element.Bounds()
state := theme.State { } state := tomo.State { }
element.theme. element.theme.
Pattern(theme.PatternBackground, state). Pattern(tomo.PatternBackground, state).
Draw(element.core, bounds) Draw(element.core, bounds)
icon := element.icon() icon := element.icon()
if icon != nil { if icon != nil {
@ -73,8 +74,7 @@ func (element *Icon) draw () {
(bounds.Dy() - iconBounds.Dy()) / 2) (bounds.Dy() - iconBounds.Dy()) / 2)
icon.Draw ( icon.Draw (
element.core, element.core,
element.theme.Color ( element.theme.Color(tomo.ColorForeground, state),
theme.ColorForeground, state),
bounds.Min.Add(offset)) bounds.Min.Add(offset))
} }
} }

View File

@ -1,10 +1,11 @@
package elements package elements
import "golang.org/x/image/math/fixed" import "golang.org/x/image/math/fixed"
import "git.tebibyte.media/sashakoshka/tomo/theme" import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/config"
import "git.tebibyte.media/sashakoshka/tomo/textdraw" import "git.tebibyte.media/sashakoshka/tomo/textdraw"
import "git.tebibyte.media/sashakoshka/tomo/elements/core" import "git.tebibyte.media/sashakoshka/tomo/elements/core"
import "git.tebibyte.media/sashakoshka/tomo/default/theme"
import "git.tebibyte.media/sashakoshka/tomo/default/config"
// Label is a simple text box. // Label is a simple text box.
type Label struct { type Label struct {
@ -29,8 +30,11 @@ type Label struct {
// wrapped. // wrapped.
func NewLabel (text string, wrap bool) (element *Label) { func NewLabel (text string, wrap bool) (element *Label) {
element = &Label { } element = &Label { }
element.theme.Case = theme.C("tomo", "label") element.theme.Case = tomo.C("tomo", "label")
element.Core, element.core = core.NewCore(element, element.handleResize) element.Core, element.core = core.NewCore(element, element.handleResize)
element.drawer.SetFace (element.theme.FontFace (
tomo.FontStyleRegular,
tomo.FontSizeNormal))
element.SetWrap(wrap) element.SetWrap(wrap)
element.SetText(text) element.SetText(text)
return return
@ -38,8 +42,8 @@ func NewLabel (text string, wrap bool) (element *Label) {
func (element *Label) redo () { func (element *Label) redo () {
face := element.theme.FontFace ( face := element.theme.FontFace (
theme.FontStyleRegular, tomo.FontStyleRegular,
theme.FontSizeNormal) tomo.FontSizeNormal)
element.drawer.SetFace(face) element.drawer.SetFace(face)
element.updateMinimumSize() element.updateMinimumSize()
bounds := element.Bounds() bounds := element.Bounds()
@ -137,12 +141,12 @@ func (element *Label) SetAlign (align textdraw.Align) {
} }
// SetTheme sets the element's theme. // SetTheme sets the element's theme.
func (element *Label) SetTheme (new theme.Theme) { func (element *Label) SetTheme (new tomo.Theme) {
if new == element.theme.Theme { return } if new == element.theme.Theme { return }
element.theme.Theme = new element.theme.Theme = new
element.drawer.SetFace (element.theme.FontFace ( element.drawer.SetFace (element.theme.FontFace (
theme.FontStyleRegular, tomo.FontStyleRegular,
theme.FontSizeNormal)) tomo.FontSizeNormal))
element.updateMinimumSize() element.updateMinimumSize()
if element.core.HasImage () { if element.core.HasImage () {
@ -152,7 +156,7 @@ func (element *Label) SetTheme (new theme.Theme) {
} }
// SetConfig sets the element's configuration. // SetConfig sets the element's configuration.
func (element *Label) SetConfig (new config.Config) { func (element *Label) SetConfig (new tomo.Config) {
if new == element.config.Config { return } if new == element.config.Config { return }
element.config.Config = new element.config.Config = new
element.updateMinimumSize() element.updateMinimumSize()
@ -169,7 +173,7 @@ func (element *Label) updateMinimumSize () {
if element.wrap { if element.wrap {
em := element.drawer.Em().Round() em := element.drawer.Em().Round()
if em < 1 { if em < 1 {
em = element.theme.Padding(theme.PatternBackground)[0] em = element.theme.Padding(tomo.PatternBackground)[0]
} }
width, height = em, element.drawer.LineHeight().Round() width, height = em, element.drawer.LineHeight().Round()
if element.onFlexibleHeightChange != nil { if element.onFlexibleHeightChange != nil {
@ -199,14 +203,14 @@ func (element *Label) draw () {
bounds := element.Bounds() bounds := element.Bounds()
pattern := element.theme.Pattern ( pattern := element.theme.Pattern (
theme.PatternBackground, tomo.PatternBackground,
theme.State { }) tomo.State { })
pattern.Draw(element.core, bounds) pattern.Draw(element.core, bounds)
textBounds := element.drawer.LayoutBounds() textBounds := element.drawer.LayoutBounds()
foreground := element.theme.Color ( foreground := element.theme.Color (
theme.ColorForeground, tomo.ColorForeground,
theme.State { }) tomo.State { })
element.drawer.Draw(element.core, foreground, bounds.Min.Sub(textBounds.Min)) element.drawer.Draw(element.core, foreground, bounds.Min.Sub(textBounds.Min))
} }

View File

@ -4,11 +4,11 @@ import "fmt"
import "image" import "image"
import "git.tebibyte.media/sashakoshka/tomo" import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/input" import "git.tebibyte.media/sashakoshka/tomo/input"
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/config"
import "git.tebibyte.media/sashakoshka/tomo/canvas" import "git.tebibyte.media/sashakoshka/tomo/canvas"
import "git.tebibyte.media/sashakoshka/tomo/artist" import "git.tebibyte.media/sashakoshka/tomo/artist"
import "git.tebibyte.media/sashakoshka/tomo/elements/core" import "git.tebibyte.media/sashakoshka/tomo/elements/core"
import "git.tebibyte.media/sashakoshka/tomo/default/theme"
import "git.tebibyte.media/sashakoshka/tomo/default/config"
// List is an element that contains several objects that a user can select. // List is an element that contains several objects that a user can select.
type List struct { type List struct {
@ -37,7 +37,7 @@ type List struct {
// NewList creates a new list element with the specified entries. // NewList creates a new list element with the specified entries.
func NewList (entries ...ListEntry) (element *List) { func NewList (entries ...ListEntry) (element *List) {
element = &List { selectedEntry: -1 } element = &List { selectedEntry: -1 }
element.theme.Case = theme.C("tomo", "list") element.theme.Case = tomo.C("tomo", "list")
element.Core, element.core = core.NewCore(element, element.handleResize) element.Core, element.core = core.NewCore(element, element.handleResize)
element.FocusableCore, element.FocusableCore,
element.focusableControl = core.NewFocusableCore (element.core, func () { element.focusableControl = core.NewFocusableCore (element.core, func () {
@ -69,7 +69,7 @@ func (element *List) handleResize () {
} }
// SetTheme sets the element's theme. // SetTheme sets the element's theme.
func (element *List) SetTheme (new theme.Theme) { func (element *List) SetTheme (new tomo.Theme) {
if new == element.theme.Theme { return } if new == element.theme.Theme { return }
element.theme.Theme = new element.theme.Theme = new
for index, entry := range element.entries { for index, entry := range element.entries {
@ -81,7 +81,7 @@ func (element *List) SetTheme (new theme.Theme) {
} }
// SetConfig sets the element's configuration. // SetConfig sets the element's configuration.
func (element *List) SetConfig (new config.Config) { func (element *List) SetConfig (new tomo.Config) {
if new == element.config.Config { return } if new == element.config.Config { return }
element.config.Config = new element.config.Config = new
for index, entry := range element.entries { for index, entry := range element.entries {
@ -214,7 +214,7 @@ func (element *List) ScrollAxes () (horizontal, vertical bool) {
} }
func (element *List) scrollViewportHeight () (height int) { func (element *List) scrollViewportHeight () (height int) {
padding := element.theme.Padding(theme.PatternSunken) padding := element.theme.Padding(tomo.PatternSunken)
return element.Bounds().Dy() - padding[0] - padding[2] return element.Bounds().Dy() - padding[0] - padding[2]
} }
@ -358,7 +358,7 @@ func (element *List) Select (index int) {
} }
func (element *List) selectUnderMouse (x, y int) (updated bool) { func (element *List) selectUnderMouse (x, y int) (updated bool) {
padding := element.theme.Padding(theme.PatternSunken) padding := element.theme.Padding(tomo.PatternSunken)
bounds := padding.Apply(element.Bounds()) bounds := padding.Apply(element.Bounds())
mousePoint := image.Pt(x, y) mousePoint := image.Pt(x, y)
dot := image.Pt ( dot := image.Pt (
@ -401,7 +401,7 @@ func (element *List) changeSelectionBy (delta int) (updated bool) {
func (element *List) resizeEntryToFit (entry ListEntry) (resized ListEntry) { func (element *List) resizeEntryToFit (entry ListEntry) (resized ListEntry) {
bounds := element.Bounds() bounds := element.Bounds()
padding := element.theme.Padding(theme.PatternSunken) padding := element.theme.Padding(tomo.PatternSunken)
entry.Resize(padding.Apply(bounds).Dx()) entry.Resize(padding.Apply(bounds).Dx())
return entry return entry
} }
@ -428,7 +428,7 @@ func (element *List) updateMinimumSize () {
minimumHeight = element.contentHeight minimumHeight = element.contentHeight
} }
padding := element.theme.Padding(theme.PatternSunken) padding := element.theme.Padding(tomo.PatternSunken)
minimumHeight += padding[0] + padding[2] minimumHeight += padding[0] + padding[2]
element.core.SetMinimumSize(minimumWidth, minimumHeight) element.core.SetMinimumSize(minimumWidth, minimumHeight)
@ -445,9 +445,9 @@ func (element *List) scrollBoundsChange () {
func (element *List) draw () { func (element *List) draw () {
bounds := element.Bounds() bounds := element.Bounds()
padding := element.theme.Padding(theme.PatternSunken) padding := element.theme.Padding(tomo.PatternSunken)
innerBounds := padding.Apply(bounds) innerBounds := padding.Apply(bounds)
state := theme.State { state := tomo.State {
Disabled: !element.Enabled(), Disabled: !element.Enabled(),
Focused: element.Focused(), Focused: element.Focused(),
} }
@ -471,7 +471,7 @@ func (element *List) draw () {
0, 0, 0, 0,
innerBounds.Dx(), element.contentHeight, innerBounds.Dx(), element.contentHeight,
).Add(innerBounds.Min).Intersect(innerBounds) ).Add(innerBounds.Min).Intersect(innerBounds)
pattern := element.theme.Pattern(theme.PatternSunken, state) pattern := element.theme.Pattern(tomo.PatternSunken, state)
artist.DrawShatter ( artist.DrawShatter (
element.core, pattern, bounds, covered) element.core, pattern, bounds, covered)
} }

View File

@ -1,11 +1,12 @@
package elements package elements
import "image" import "image"
import "git.tebibyte.media/sashakoshka/tomo/theme" import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/config"
import "git.tebibyte.media/sashakoshka/tomo/canvas" import "git.tebibyte.media/sashakoshka/tomo/canvas"
import "git.tebibyte.media/sashakoshka/tomo/artist" import "git.tebibyte.media/sashakoshka/tomo/artist"
import "git.tebibyte.media/sashakoshka/tomo/textdraw" import "git.tebibyte.media/sashakoshka/tomo/textdraw"
import "git.tebibyte.media/sashakoshka/tomo/default/theme"
import "git.tebibyte.media/sashakoshka/tomo/default/config"
// ListEntry is an item that can be added to a list. // ListEntry is an item that can be added to a list.
type ListEntry struct { type ListEntry struct {
@ -26,28 +27,31 @@ func NewListEntry (text string, onSelect func ()) (entry ListEntry) {
text: text, text: text,
onSelect: onSelect, onSelect: onSelect,
} }
entry.theme.Case = theme.C("tomo", "listEntry") entry.theme.Case = tomo.C("tomo", "listEntry")
entry.drawer.SetFace (entry.theme.FontFace (
tomo.FontStyleRegular,
tomo.FontSizeNormal))
entry.drawer.SetText([]rune(text)) entry.drawer.SetText([]rune(text))
entry.updateBounds() entry.updateBounds()
return return
} }
func (entry *ListEntry) SetTheme (new theme.Theme) { func (entry *ListEntry) SetTheme (new tomo.Theme) {
if new == entry.theme.Theme { return } if new == entry.theme.Theme { return }
entry.theme.Theme = new entry.theme.Theme = new
entry.drawer.SetFace (entry.theme.FontFace ( entry.drawer.SetFace (entry.theme.FontFace (
theme.FontStyleRegular, tomo.FontStyleRegular,
theme.FontSizeNormal)) tomo.FontSizeNormal))
entry.updateBounds() entry.updateBounds()
} }
func (entry *ListEntry) SetConfig (new config.Config) { func (entry *ListEntry) SetConfig (new tomo.Config) {
if new == entry.config.Config { return } if new == entry.config.Config { return }
entry.config.Config = new entry.config.Config = new
} }
func (entry *ListEntry) updateBounds () { func (entry *ListEntry) updateBounds () {
padding := entry.theme.Padding(theme.PatternRaised) padding := entry.theme.Padding(tomo.PatternRaised)
entry.bounds = padding.Inverse().Apply(entry.drawer.LayoutBounds()) entry.bounds = padding.Inverse().Apply(entry.drawer.LayoutBounds())
entry.bounds = entry.bounds.Sub(entry.bounds.Min) entry.bounds = entry.bounds.Sub(entry.bounds.Min)
entry.minimumWidth = entry.bounds.Dx() entry.minimumWidth = entry.bounds.Dx()
@ -62,17 +66,17 @@ func (entry *ListEntry) Draw (
) ( ) (
updatedRegion image.Rectangle, updatedRegion image.Rectangle,
) { ) {
state := theme.State { state := tomo.State {
Focused: focused, Focused: focused,
On: on, On: on,
} }
pattern := entry.theme.Pattern(theme.PatternRaised, state) pattern := entry.theme.Pattern(tomo.PatternRaised, state)
padding := entry.theme.Padding(theme.PatternRaised) padding := entry.theme.Padding(tomo.PatternRaised)
bounds := entry.Bounds().Add(offset) bounds := entry.Bounds().Add(offset)
pattern.Draw(destination, bounds) pattern.Draw(destination, bounds)
foreground := entry.theme.Color (theme.ColorForeground, state) foreground := entry.theme.Color (tomo.ColorForeground, state)
return entry.drawer.Draw ( return entry.drawer.Draw (
destination, destination,
foreground, foreground,

View File

@ -1,9 +1,10 @@
package elements package elements
import "image" import "image"
import "git.tebibyte.media/sashakoshka/tomo/theme" import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/config"
import "git.tebibyte.media/sashakoshka/tomo/elements/core" import "git.tebibyte.media/sashakoshka/tomo/elements/core"
import "git.tebibyte.media/sashakoshka/tomo/default/theme"
import "git.tebibyte.media/sashakoshka/tomo/default/config"
// ProgressBar displays a visual indication of how far along a task is. // ProgressBar displays a visual indication of how far along a task is.
type ProgressBar struct { type ProgressBar struct {
@ -19,7 +20,7 @@ type ProgressBar struct {
// level. // level.
func NewProgressBar (progress float64) (element *ProgressBar) { func NewProgressBar (progress float64) (element *ProgressBar) {
element = &ProgressBar { progress: progress } element = &ProgressBar { progress: progress }
element.theme.Case = theme.C("tomo", "progressBar") element.theme.Case = tomo.C("tomo", "progressBar")
element.Core, element.core = core.NewCore(element, element.draw) element.Core, element.core = core.NewCore(element, element.draw)
return return
} }
@ -35,7 +36,7 @@ func (element *ProgressBar) SetProgress (progress float64) {
} }
// SetTheme sets the element's theme. // SetTheme sets the element's theme.
func (element *ProgressBar) SetTheme (new theme.Theme) { func (element *ProgressBar) SetTheme (new tomo.Theme) {
if new == element.theme.Theme { return } if new == element.theme.Theme { return }
element.theme.Theme = new element.theme.Theme = new
element.updateMinimumSize() element.updateMinimumSize()
@ -43,7 +44,7 @@ func (element *ProgressBar) SetTheme (new theme.Theme) {
} }
// SetConfig sets the element's configuration. // SetConfig sets the element's configuration.
func (element *ProgressBar) SetConfig (new config.Config) { func (element *ProgressBar) SetConfig (new tomo.Config) {
if new == nil || new == element.config.Config { return } if new == nil || new == element.config.Config { return }
element.config.Config = new element.config.Config = new
element.updateMinimumSize() element.updateMinimumSize()
@ -51,8 +52,8 @@ func (element *ProgressBar) SetConfig (new config.Config) {
} }
func (element (ProgressBar)) updateMinimumSize() { func (element (ProgressBar)) updateMinimumSize() {
padding := element.theme.Padding(theme.PatternSunken) padding := element.theme.Padding(tomo.PatternSunken)
innerPadding := element.theme.Padding(theme.PatternMercury) innerPadding := element.theme.Padding(tomo.PatternMercury)
element.core.SetMinimumSize ( element.core.SetMinimumSize (
padding.Horizontal() + innerPadding.Horizontal(), padding.Horizontal() + innerPadding.Horizontal(),
padding.Vertical() + innerPadding.Vertical()) padding.Vertical() + innerPadding.Vertical())
@ -68,14 +69,14 @@ func (element *ProgressBar) redo () {
func (element *ProgressBar) draw () { func (element *ProgressBar) draw () {
bounds := element.Bounds() bounds := element.Bounds()
pattern := element.theme.Pattern(theme.PatternSunken, theme.State { }) pattern := element.theme.Pattern(tomo.PatternSunken, tomo.State { })
padding := element.theme.Padding(theme.PatternSunken) padding := element.theme.Padding(tomo.PatternSunken)
pattern.Draw(element.core, bounds) pattern.Draw(element.core, bounds)
bounds = padding.Apply(bounds) bounds = padding.Apply(bounds)
meterBounds := image.Rect ( meterBounds := image.Rect (
bounds.Min.X, bounds.Min.Y, bounds.Min.X, bounds.Min.Y,
bounds.Min.X + int(float64(bounds.Dx()) * element.progress), bounds.Min.X + int(float64(bounds.Dx()) * element.progress),
bounds.Max.Y) bounds.Max.Y)
mercury := element.theme.Pattern(theme.PatternMercury, theme.State { }) mercury := element.theme.Pattern(tomo.PatternMercury, tomo.State { })
mercury.Draw(element.core, meterBounds) mercury.Draw(element.core, meterBounds)
} }

View File

@ -1,10 +1,11 @@
package elements package elements
import "image" import "image"
import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/input" import "git.tebibyte.media/sashakoshka/tomo/input"
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/config"
import "git.tebibyte.media/sashakoshka/tomo/elements/core" import "git.tebibyte.media/sashakoshka/tomo/elements/core"
import "git.tebibyte.media/sashakoshka/tomo/default/theme"
import "git.tebibyte.media/sashakoshka/tomo/default/config"
// ScrollBar is an element similar to Slider, but it has special behavior that // ScrollBar is an element similar to Slider, but it has special behavior that
// makes it well suited for controlling the viewport position on one axis of a // makes it well suited for controlling the viewport position on one axis of a
@ -45,9 +46,9 @@ func NewScrollBar (vertical bool) (element *ScrollBar) {
enabled: true, enabled: true,
} }
if vertical { if vertical {
element.theme.Case = theme.C("tomo", "scrollBarHorizontal") element.theme.Case = tomo.C("tomo", "scrollBarHorizontal")
} else { } else {
element.theme.Case = theme.C("tomo", "scrollBarVertical") element.theme.Case = tomo.C("tomo", "scrollBarVertical")
} }
element.Core, element.core = core.NewCore(element, element.handleResize) element.Core, element.core = core.NewCore(element, element.handleResize)
element.updateMinimumSize() element.updateMinimumSize()
@ -159,14 +160,14 @@ func (element *ScrollBar) OnScroll (callback func (viewport image.Point)) {
} }
// SetTheme sets the element's theme. // SetTheme sets the element's theme.
func (element *ScrollBar) SetTheme (new theme.Theme) { func (element *ScrollBar) SetTheme (new tomo.Theme) {
if new == element.theme.Theme { return } if new == element.theme.Theme { return }
element.theme.Theme = new element.theme.Theme = new
element.drawAndPush() element.drawAndPush()
} }
// SetConfig sets the element's configuration. // SetConfig sets the element's configuration.
func (element *ScrollBar) SetConfig (new config.Config) { func (element *ScrollBar) SetConfig (new tomo.Config) {
if new == element.config.Config { return } if new == element.config.Config { return }
element.config.Config = new element.config.Config = new
element.updateMinimumSize() element.updateMinimumSize()
@ -236,7 +237,7 @@ func (element *ScrollBar) recalculate () {
func (element *ScrollBar) recalculateVertical () { func (element *ScrollBar) recalculateVertical () {
bounds := element.Bounds() bounds := element.Bounds()
padding := element.theme.Padding(theme.PatternGutter) padding := element.theme.Padding(tomo.PatternGutter)
element.track = padding.Apply(bounds) element.track = padding.Apply(bounds)
contentBounds := element.contentBounds contentBounds := element.contentBounds
@ -263,7 +264,7 @@ func (element *ScrollBar) recalculateVertical () {
func (element *ScrollBar) recalculateHorizontal () { func (element *ScrollBar) recalculateHorizontal () {
bounds := element.Bounds() bounds := element.Bounds()
padding := element.theme.Padding(theme.PatternGutter) padding := element.theme.Padding(tomo.PatternGutter)
element.track = padding.Apply(bounds) element.track = padding.Apply(bounds)
contentBounds := element.contentBounds contentBounds := element.contentBounds
@ -289,7 +290,7 @@ func (element *ScrollBar) recalculateHorizontal () {
} }
func (element *ScrollBar) updateMinimumSize () { func (element *ScrollBar) updateMinimumSize () {
padding := element.theme.Padding(theme.PatternGutter) padding := element.theme.Padding(tomo.PatternGutter)
if element.vertical { if element.vertical {
element.core.SetMinimumSize ( element.core.SetMinimumSize (
padding.Horizontal() + element.config.HandleWidth(), padding.Horizontal() + element.config.HandleWidth(),
@ -310,14 +311,14 @@ func (element *ScrollBar) drawAndPush () {
func (element *ScrollBar) draw () { func (element *ScrollBar) draw () {
bounds := element.Bounds() bounds := element.Bounds()
state := theme.State { state := tomo.State {
Disabled: !element.Enabled(), Disabled: !element.Enabled(),
Pressed: element.dragging, Pressed: element.dragging,
} }
element.theme.Pattern(theme.PatternGutter, state).Draw ( element.theme.Pattern(tomo.PatternGutter, state).Draw (
element.core, element.core,
bounds) bounds)
element.theme.Pattern(theme.PatternHandle, state).Draw ( element.theme.Pattern(tomo.PatternHandle, state).Draw (
element.core, element.core,
element.bar) element.bar)
} }

View File

@ -1,10 +1,11 @@
package elements package elements
import "image" import "image"
import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/input" import "git.tebibyte.media/sashakoshka/tomo/input"
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/config"
import "git.tebibyte.media/sashakoshka/tomo/elements/core" import "git.tebibyte.media/sashakoshka/tomo/elements/core"
import "git.tebibyte.media/sashakoshka/tomo/default/theme"
import "git.tebibyte.media/sashakoshka/tomo/default/config"
// Slider is a slider control with a floating point value between zero and one. // Slider is a slider control with a floating point value between zero and one.
type Slider struct { type Slider struct {
@ -35,9 +36,9 @@ func NewSlider (value float64, vertical bool) (element *Slider) {
vertical: vertical, vertical: vertical,
} }
if vertical { if vertical {
element.theme.Case = theme.C("tomo", "sliderVertical") element.theme.Case = tomo.C("tomo", "sliderVertical")
} else { } else {
element.theme.Case = theme.C("tomo", "sliderHorizontal") element.theme.Case = tomo.C("tomo", "sliderHorizontal")
} }
element.Core, element.core = core.NewCore(element, element.draw) element.Core, element.core = core.NewCore(element, element.draw)
element.FocusableCore, element.FocusableCore,
@ -140,14 +141,14 @@ func (element *Slider) OnRelease (callback func ()) {
} }
// SetTheme sets the element's theme. // SetTheme sets the element's theme.
func (element *Slider) SetTheme (new theme.Theme) { func (element *Slider) SetTheme (new tomo.Theme) {
if new == element.theme.Theme { return } if new == element.theme.Theme { return }
element.theme.Theme = new element.theme.Theme = new
element.redo() element.redo()
} }
// SetConfig sets the element's configuration. // SetConfig sets the element's configuration.
func (element *Slider) SetConfig (new config.Config) { func (element *Slider) SetConfig (new tomo.Config) {
if new == element.config.Config { return } if new == element.config.Config { return }
element.config.Config = new element.config.Config = new
element.updateMinimumSize() element.updateMinimumSize()
@ -206,7 +207,7 @@ func (element *Slider) redo () {
func (element *Slider) draw () { func (element *Slider) draw () {
bounds := element.Bounds() bounds := element.Bounds()
element.track = element.theme.Padding(theme.PatternGutter).Apply(bounds) element.track = element.theme.Padding(tomo.PatternGutter).Apply(bounds)
if element.vertical { if element.vertical {
barSize := element.track.Dx() barSize := element.track.Dx()
element.bar = image.Rect(0, 0, barSize, barSize).Add(bounds.Min) element.bar = image.Rect(0, 0, barSize, barSize).Add(bounds.Min)
@ -223,15 +224,15 @@ func (element *Slider) draw () {
element.bar = element.bar.Add(image.Pt(int(barOffset), 0)) element.bar = element.bar.Add(image.Pt(int(barOffset), 0))
} }
state := theme.State { state := tomo.State {
Focused: element.Focused(), Focused: element.Focused(),
Disabled: !element.Enabled(), Disabled: !element.Enabled(),
Pressed: element.dragging, Pressed: element.dragging,
} }
element.theme.Pattern(theme.PatternGutter, state).Draw ( element.theme.Pattern(tomo.PatternGutter, state).Draw (
element.core, element.core,
bounds) bounds)
element.theme.Pattern(theme.PatternHandle, state).Draw ( element.theme.Pattern(tomo.PatternHandle, state).Draw (
element.core, element.core,
element.bar) element.bar)
} }

View File

@ -1,8 +1,9 @@
package elements package elements
import "git.tebibyte.media/sashakoshka/tomo/theme" import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/config"
import "git.tebibyte.media/sashakoshka/tomo/elements/core" import "git.tebibyte.media/sashakoshka/tomo/elements/core"
import "git.tebibyte.media/sashakoshka/tomo/default/theme"
import "git.tebibyte.media/sashakoshka/tomo/default/config"
// Spacer can be used to put space between two elements.. // Spacer can be used to put space between two elements..
type Spacer struct { type Spacer struct {
@ -19,7 +20,7 @@ type Spacer struct {
// will appear as a line. // will appear as a line.
func NewSpacer (line bool) (element *Spacer) { func NewSpacer (line bool) (element *Spacer) {
element = &Spacer { line: line } element = &Spacer { line: line }
element.theme.Case = theme.C("tomo", "spacer") element.theme.Case = tomo.C("tomo", "spacer")
element.Core, element.core = core.NewCore(element, element.draw) element.Core, element.core = core.NewCore(element, element.draw)
element.updateMinimumSize() element.updateMinimumSize()
return return
@ -37,14 +38,14 @@ func (element *Spacer) SetLine (line bool) {
} }
// SetTheme sets the element's theme. // SetTheme sets the element's theme.
func (element *Spacer) SetTheme (new theme.Theme) { func (element *Spacer) SetTheme (new tomo.Theme) {
if new == element.theme.Theme { return } if new == element.theme.Theme { return }
element.theme.Theme = new element.theme.Theme = new
element.redo() element.redo()
} }
// SetConfig sets the element's configuration. // SetConfig sets the element's configuration.
func (element *Spacer) SetConfig (new config.Config) { func (element *Spacer) SetConfig (new tomo.Config) {
if new == element.config.Config { return } if new == element.config.Config { return }
element.config.Config = new element.config.Config = new
element.redo() element.redo()
@ -52,7 +53,7 @@ func (element *Spacer) SetConfig (new config.Config) {
func (element *Spacer) updateMinimumSize () { func (element *Spacer) updateMinimumSize () {
if element.line { if element.line {
padding := element.theme.Padding(theme.PatternLine) padding := element.theme.Padding(tomo.PatternLine)
element.core.SetMinimumSize ( element.core.SetMinimumSize (
padding.Horizontal(), padding.Horizontal(),
padding.Vertical()) padding.Vertical())
@ -73,13 +74,13 @@ func (element *Spacer) draw () {
if element.line { if element.line {
pattern := element.theme.Pattern ( pattern := element.theme.Pattern (
theme.PatternLine, tomo.PatternLine,
theme.State { }) tomo.State { })
pattern.Draw(element.core, bounds) pattern.Draw(element.core, bounds)
} else { } else {
pattern := element.theme.Pattern ( pattern := element.theme.Pattern (
theme.PatternBackground, tomo.PatternBackground,
theme.State { }) tomo.State { })
pattern.Draw(element.core, bounds) pattern.Draw(element.core, bounds)
} }
} }

View File

@ -1,11 +1,12 @@
package elements package elements
import "image" import "image"
import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/input" import "git.tebibyte.media/sashakoshka/tomo/input"
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/config"
import "git.tebibyte.media/sashakoshka/tomo/textdraw" import "git.tebibyte.media/sashakoshka/tomo/textdraw"
import "git.tebibyte.media/sashakoshka/tomo/elements/core" import "git.tebibyte.media/sashakoshka/tomo/elements/core"
import "git.tebibyte.media/sashakoshka/tomo/default/theme"
import "git.tebibyte.media/sashakoshka/tomo/default/config"
// Switch is a toggle-able on/off switch with an optional label. It is // Switch is a toggle-able on/off switch with an optional label. It is
// functionally identical to Checkbox, but plays a different semantic role. // functionally identical to Checkbox, but plays a different semantic role.
@ -32,10 +33,13 @@ func NewSwitch (text string, on bool) (element *Switch) {
checked: on, checked: on,
text: text, text: text,
} }
element.theme.Case = theme.C("tomo", "switch") element.theme.Case = tomo.C("tomo", "switch")
element.Core, element.core = core.NewCore(element, element.draw) element.Core, element.core = core.NewCore(element, element.draw)
element.FocusableCore, element.FocusableCore,
element.focusableControl = core.NewFocusableCore(element.core, element.redo) element.focusableControl = core.NewFocusableCore(element.core, element.redo)
element.drawer.SetFace (element.theme.FontFace (
tomo.FontStyleRegular,
tomo.FontSizeNormal))
element.drawer.SetText([]rune(text)) element.drawer.SetText([]rune(text))
element.updateMinimumSize() element.updateMinimumSize()
return return
@ -111,18 +115,18 @@ func (element *Switch) SetText (text string) {
} }
// SetTheme sets the element's theme. // SetTheme sets the element's theme.
func (element *Switch) SetTheme (new theme.Theme) { func (element *Switch) SetTheme (new tomo.Theme) {
if new == element.theme.Theme { return } if new == element.theme.Theme { return }
element.theme.Theme = new element.theme.Theme = new
element.drawer.SetFace (element.theme.FontFace ( element.drawer.SetFace (element.theme.FontFace (
theme.FontStyleRegular, tomo.FontStyleRegular,
theme.FontSizeNormal)) tomo.FontSizeNormal))
element.updateMinimumSize() element.updateMinimumSize()
element.redo() element.redo()
} }
// SetConfig sets the element's configuration. // SetConfig sets the element's configuration.
func (element *Switch) SetConfig (new config.Config) { func (element *Switch) SetConfig (new tomo.Config) {
if new == element.config.Config { return } if new == element.config.Config { return }
element.config.Config = new element.config.Config = new
element.updateMinimumSize() element.updateMinimumSize()
@ -145,7 +149,7 @@ func (element *Switch) updateMinimumSize () {
} else { } else {
element.core.SetMinimumSize ( element.core.SetMinimumSize (
lineHeight * 2 + lineHeight * 2 +
element.theme.Margin(theme.PatternBackground).X + element.theme.Margin(tomo.PatternBackground).X +
textBounds.Dx(), textBounds.Dx(),
lineHeight) lineHeight)
} }
@ -156,13 +160,13 @@ func (element *Switch) draw () {
handleBounds := image.Rect(0, 0, bounds.Dy(), bounds.Dy()).Add(bounds.Min) handleBounds := image.Rect(0, 0, bounds.Dy(), bounds.Dy()).Add(bounds.Min)
gutterBounds := image.Rect(0, 0, bounds.Dy() * 2, bounds.Dy()).Add(bounds.Min) gutterBounds := image.Rect(0, 0, bounds.Dy() * 2, bounds.Dy()).Add(bounds.Min)
state := theme.State { state := tomo.State {
Disabled: !element.Enabled(), Disabled: !element.Enabled(),
Focused: element.Focused(), Focused: element.Focused(),
Pressed: element.pressed, Pressed: element.pressed,
} }
backgroundPattern := element.theme.Pattern ( backgroundPattern := element.theme.Pattern (
theme.PatternBackground, state) tomo.PatternBackground, state)
backgroundPattern.Draw(element.core, bounds) backgroundPattern.Draw(element.core, bounds)
if element.checked { if element.checked {
@ -180,23 +184,22 @@ func (element *Switch) draw () {
} }
gutterPattern := element.theme.Pattern ( gutterPattern := element.theme.Pattern (
theme.PatternGutter, state) tomo.PatternGutter, state)
gutterPattern.Draw(element.core, gutterBounds) gutterPattern.Draw(element.core, gutterBounds)
handlePattern := element.theme.Pattern ( handlePattern := element.theme.Pattern (
theme.PatternHandle, state) tomo.PatternHandle, state)
handlePattern.Draw(element.core, handleBounds) handlePattern.Draw(element.core, handleBounds)
textBounds := element.drawer.LayoutBounds() textBounds := element.drawer.LayoutBounds()
offset := bounds.Min.Add(image.Point { offset := bounds.Min.Add(image.Point {
X: bounds.Dy() * 2 + X: bounds.Dy() * 2 +
element.theme.Margin(theme.PatternBackground).X, element.theme.Margin(tomo.PatternBackground).X,
}) })
offset.Y -= textBounds.Min.Y offset.Y -= textBounds.Min.Y
offset.X -= textBounds.Min.X offset.X -= textBounds.Min.X
foreground := element.theme.Color ( foreground := element.theme.Color(tomo.ColorForeground, state)
theme.ColorForeground, state)
element.drawer.Draw(element.core, foreground, offset) element.drawer.Draw(element.core, foreground, offset)
} }

View File

@ -1,12 +1,13 @@
package testing package testing
import "image" import "image"
import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/input" import "git.tebibyte.media/sashakoshka/tomo/input"
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/config"
import "git.tebibyte.media/sashakoshka/tomo/artist" import "git.tebibyte.media/sashakoshka/tomo/artist"
import "git.tebibyte.media/sashakoshka/tomo/artist/shapes" import "git.tebibyte.media/sashakoshka/tomo/artist/shapes"
import "git.tebibyte.media/sashakoshka/tomo/elements/core" import "git.tebibyte.media/sashakoshka/tomo/elements/core"
import "git.tebibyte.media/sashakoshka/tomo/default/theme"
import "git.tebibyte.media/sashakoshka/tomo/default/config"
// Mouse is an element capable of testing mouse input. When the mouse is clicked // Mouse is an element capable of testing mouse input. When the mouse is clicked
// and dragged on it, it draws a trail. // and dragged on it, it draws a trail.
@ -16,28 +17,28 @@ type Mouse struct {
drawing bool drawing bool
lastMousePos image.Point lastMousePos image.Point
config config.Config config config.Wrapped
theme theme.Theme theme theme.Wrapped
c theme.Case
} }
// NewMouse creates a new mouse test element. // NewMouse creates a new mouse test element.
func NewMouse () (element *Mouse) { func NewMouse () (element *Mouse) {
element = &Mouse { c: theme.C("tomo", "mouse") } element = &Mouse { }
element.theme.Case = tomo.C("tomo", "piano")
element.Core, element.core = core.NewCore(element, element.draw) element.Core, element.core = core.NewCore(element, element.draw)
element.core.SetMinimumSize(32, 32) element.core.SetMinimumSize(32, 32)
return return
} }
// SetTheme sets the element's theme. // SetTheme sets the element's theme.
func (element *Mouse) SetTheme (new theme.Theme) { func (element *Mouse) SetTheme (new tomo.Theme) {
element.theme = new element.theme.Theme = new
element.redo() element.redo()
} }
// SetConfig sets the element's configuration. // SetConfig sets the element's configuration.
func (element *Mouse) SetConfig (new config.Config) { func (element *Mouse) SetConfig (new tomo.Config) {
element.config = new element.config.Config = new
element.redo() element.redo()
} }
@ -50,9 +51,8 @@ func (element *Mouse) redo () {
func (element *Mouse) draw () { func (element *Mouse) draw () {
bounds := element.Bounds() bounds := element.Bounds()
accent := element.theme.Color ( accent := element.theme.Color (
theme.ColorAccent, tomo.ColorAccent,
theme.State { }, tomo.State { })
element.c)
shapes.FillColorRectangle(element.core, accent, bounds) shapes.FillColorRectangle(element.core, accent, bounds)
shapes.StrokeColorRectangle ( shapes.StrokeColorRectangle (
element.core, element.core,

View File

@ -3,8 +3,6 @@ package elements
import "image" import "image"
import "git.tebibyte.media/sashakoshka/tomo" import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/input" import "git.tebibyte.media/sashakoshka/tomo/input"
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/config"
import "git.tebibyte.media/sashakoshka/tomo/artist" import "git.tebibyte.media/sashakoshka/tomo/artist"
import "git.tebibyte.media/sashakoshka/tomo/canvas" import "git.tebibyte.media/sashakoshka/tomo/canvas"
import "git.tebibyte.media/sashakoshka/tomo/textdraw" import "git.tebibyte.media/sashakoshka/tomo/textdraw"
@ -12,6 +10,8 @@ import "git.tebibyte.media/sashakoshka/tomo/textmanip"
import "git.tebibyte.media/sashakoshka/tomo/fixedutil" import "git.tebibyte.media/sashakoshka/tomo/fixedutil"
import "git.tebibyte.media/sashakoshka/tomo/artist/shapes" import "git.tebibyte.media/sashakoshka/tomo/artist/shapes"
import "git.tebibyte.media/sashakoshka/tomo/elements/core" import "git.tebibyte.media/sashakoshka/tomo/elements/core"
import "git.tebibyte.media/sashakoshka/tomo/default/theme"
import "git.tebibyte.media/sashakoshka/tomo/default/config"
// TextBox is a single-line text input. // TextBox is a single-line text input.
type TextBox struct { type TextBox struct {
@ -43,7 +43,7 @@ type TextBox struct {
// text. // text.
func NewTextBox (placeholder, value string) (element *TextBox) { func NewTextBox (placeholder, value string) (element *TextBox) {
element = &TextBox { } element = &TextBox { }
element.theme.Case = theme.C("tomo", "textBox") element.theme.Case = tomo.C("tomo", "textBox")
element.Core, element.core = core.NewCore(element, element.handleResize) element.Core, element.core = core.NewCore(element, element.handleResize)
element.FocusableCore, element.FocusableCore,
element.focusableControl = core.NewFocusableCore (element.core, func () { element.focusableControl = core.NewFocusableCore (element.core, func () {
@ -53,6 +53,12 @@ func NewTextBox (placeholder, value string) (element *TextBox) {
} }
}) })
element.placeholder = placeholder element.placeholder = placeholder
element.placeholderDrawer.SetFace (element.theme.FontFace (
tomo.FontStyleRegular,
tomo.FontSizeNormal))
element.valueDrawer.SetFace (element.theme.FontFace (
tomo.FontStyleRegular,
tomo.FontSizeNormal))
element.placeholderDrawer.SetText([]rune(placeholder)) element.placeholderDrawer.SetText([]rune(placeholder))
element.updateMinimumSize() element.updateMinimumSize()
element.SetValue(value) element.SetValue(value)
@ -94,7 +100,7 @@ func (element *TextBox) HandleMotion (x, y int) {
} }
func (element *TextBox) textOffset () image.Point { func (element *TextBox) textOffset () image.Point {
padding := element.theme.Padding(theme.PatternInput) padding := element.theme.Padding(tomo.PatternInput)
bounds := element.Bounds() bounds := element.Bounds()
innerBounds := padding.Apply(bounds) innerBounds := padding.Apply(bounds)
textHeight := element.valueDrawer.LineHeight().Round() textHeight := element.valueDrawer.LineHeight().Round()
@ -277,7 +283,7 @@ func (element *TextBox) ScrollViewportBounds () (bounds image.Rectangle) {
} }
func (element *TextBox) scrollViewportWidth () (width int) { func (element *TextBox) scrollViewportWidth () (width int) {
padding := element.theme.Padding(theme.PatternInput) padding := element.theme.Padding(tomo.PatternInput)
return padding.Apply(element.Bounds()).Dx() return padding.Apply(element.Bounds()).Dx()
} }
@ -313,7 +319,7 @@ func (element *TextBox) runOnChange () {
func (element *TextBox) scrollToCursor () { func (element *TextBox) scrollToCursor () {
if !element.core.HasImage() { return } if !element.core.HasImage() { return }
padding := element.theme.Padding(theme.PatternInput) padding := element.theme.Padding(tomo.PatternInput)
bounds := padding.Apply(element.Bounds()) bounds := padding.Apply(element.Bounds())
bounds = bounds.Sub(bounds.Min) bounds = bounds.Sub(bounds.Min)
bounds.Max.X -= element.valueDrawer.Em().Round() bounds.Max.X -= element.valueDrawer.Em().Round()
@ -331,12 +337,12 @@ func (element *TextBox) scrollToCursor () {
} }
// SetTheme sets the element's theme. // SetTheme sets the element's theme.
func (element *TextBox) SetTheme (new theme.Theme) { func (element *TextBox) SetTheme (new tomo.Theme) {
if new == element.theme.Theme { return } if new == element.theme.Theme { return }
element.theme.Theme = new element.theme.Theme = new
face := element.theme.FontFace ( face := element.theme.FontFace (
theme.FontStyleRegular, tomo.FontStyleRegular,
theme.FontSizeNormal) tomo.FontSizeNormal)
element.placeholderDrawer.SetFace(face) element.placeholderDrawer.SetFace(face)
element.valueDrawer.SetFace(face) element.valueDrawer.SetFace(face)
element.updateMinimumSize() element.updateMinimumSize()
@ -344,7 +350,7 @@ func (element *TextBox) SetTheme (new theme.Theme) {
} }
// SetConfig sets the element's configuration. // SetConfig sets the element's configuration.
func (element *TextBox) SetConfig (new config.Config) { func (element *TextBox) SetConfig (new tomo.Config) {
if new == element.config.Config { return } if new == element.config.Config { return }
element.config.Config = new element.config.Config = new
element.updateMinimumSize() element.updateMinimumSize()
@ -353,7 +359,7 @@ func (element *TextBox) SetConfig (new config.Config) {
func (element *TextBox) updateMinimumSize () { func (element *TextBox) updateMinimumSize () {
textBounds := element.placeholderDrawer.LayoutBounds() textBounds := element.placeholderDrawer.LayoutBounds()
padding := element.theme.Padding(theme.PatternInput) padding := element.theme.Padding(tomo.PatternInput)
element.core.SetMinimumSize ( element.core.SetMinimumSize (
padding.Horizontal() + textBounds.Dx(), padding.Horizontal() + textBounds.Dx(),
padding.Vertical() + padding.Vertical() +
@ -370,19 +376,19 @@ func (element *TextBox) redo () {
func (element *TextBox) draw () { func (element *TextBox) draw () {
bounds := element.Bounds() bounds := element.Bounds()
state := theme.State { state := tomo.State {
Disabled: !element.Enabled(), Disabled: !element.Enabled(),
Focused: element.Focused(), Focused: element.Focused(),
} }
pattern := element.theme.Pattern(theme.PatternInput, state) pattern := element.theme.Pattern(tomo.PatternInput, state)
padding := element.theme.Padding(theme.PatternInput) padding := element.theme.Padding(tomo.PatternInput)
innerCanvas := canvas.Cut(element.core, padding.Apply(bounds)) innerCanvas := canvas.Cut(element.core, padding.Apply(bounds))
pattern.Draw(element.core, bounds) pattern.Draw(element.core, bounds)
offset := element.textOffset() offset := element.textOffset()
if element.Focused() && !element.dot.Empty() { if element.Focused() && !element.dot.Empty() {
// draw selection bounds // draw selection bounds
accent := element.theme.Color(theme.ColorAccent, state) accent := element.theme.Color(tomo.ColorAccent, state)
canon := element.dot.Canon() canon := element.dot.Canon()
foff := fixedutil.Pt(offset) foff := fixedutil.Pt(offset)
start := element.valueDrawer.PositionAt(canon.Start).Add(foff) start := element.valueDrawer.PositionAt(canon.Start).Add(foff)
@ -401,8 +407,8 @@ func (element *TextBox) draw () {
// draw placeholder // draw placeholder
textBounds := element.placeholderDrawer.LayoutBounds() textBounds := element.placeholderDrawer.LayoutBounds()
foreground := element.theme.Color ( foreground := element.theme.Color (
theme.ColorForeground, tomo.ColorForeground,
theme.State { Disabled: true }) tomo.State { Disabled: true })
element.placeholderDrawer.Draw ( element.placeholderDrawer.Draw (
innerCanvas, innerCanvas,
foreground, foreground,
@ -410,7 +416,7 @@ func (element *TextBox) draw () {
} else { } else {
// draw input value // draw input value
textBounds := element.valueDrawer.LayoutBounds() textBounds := element.valueDrawer.LayoutBounds()
foreground := element.theme.Color(theme.ColorForeground, state) foreground := element.theme.Color(tomo.ColorForeground, state)
element.valueDrawer.Draw ( element.valueDrawer.Draw (
innerCanvas, innerCanvas,
foreground, foreground,
@ -419,7 +425,7 @@ func (element *TextBox) draw () {
if element.Focused() && element.dot.Empty() { if element.Focused() && element.dot.Empty() {
// draw cursor // draw cursor
foreground := element.theme.Color(theme.ColorForeground, state) foreground := element.theme.Color(tomo.ColorForeground, state)
cursorPosition := fixedutil.RoundPt ( cursorPosition := fixedutil.RoundPt (
element.valueDrawer.PositionAt(element.dot.End)) element.valueDrawer.PositionAt(element.dot.End))
shapes.ColorLine ( shapes.ColorLine (

View File

@ -7,7 +7,6 @@ import _ "image/gif"
import _ "image/jpeg" import _ "image/jpeg"
import "git.tebibyte.media/sashakoshka/tomo" import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/data" import "git.tebibyte.media/sashakoshka/tomo/data"
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/popups" import "git.tebibyte.media/sashakoshka/tomo/popups"
import "git.tebibyte.media/sashakoshka/tomo/layouts" import "git.tebibyte.media/sashakoshka/tomo/layouts"
import "git.tebibyte.media/sashakoshka/tomo/elements" import "git.tebibyte.media/sashakoshka/tomo/elements"
@ -32,11 +31,11 @@ func run () {
textInput := elements.NewTextBox("", "") textInput := elements.NewTextBox("", "")
controlRow := containers.NewContainer(layouts.Horizontal { true, false }) controlRow := containers.NewContainer(layouts.Horizontal { true, false })
copyButton := elements.NewButton("Copy") copyButton := elements.NewButton("Copy")
copyButton.SetIcon(theme.IconCopy) copyButton.SetIcon(tomo.IconCopy)
pasteButton := elements.NewButton("Paste") pasteButton := elements.NewButton("Paste")
pasteButton.SetIcon(theme.IconPaste) pasteButton.SetIcon(tomo.IconPaste)
pasteImageButton := elements.NewButton("Image") pasteImageButton := elements.NewButton("Image")
pasteImageButton.SetIcon(theme.IconPictures) pasteImageButton.SetIcon(tomo.IconPictures)
imageClipboardCallback := func (clipboard data.Data, err error) { imageClipboardCallback := func (clipboard data.Data, err error) {
if err != nil { if err != nil {
@ -126,7 +125,7 @@ func imageWindow (image image.Image) {
window.SetTitle("Clipboard Image") window.SetTitle("Clipboard Image")
container := containers.NewContainer(layouts.Vertical { true, true }) container := containers.NewContainer(layouts.Vertical { true, true })
closeButton := elements.NewButton("Ok") closeButton := elements.NewButton("Ok")
closeButton.SetIcon(theme.IconYes) closeButton.SetIcon(tomo.IconYes)
closeButton.OnClick(window.Close) closeButton.OnClick(window.Close)
container.Adopt(elements.NewImage(image), true) container.Adopt(elements.NewImage(image), true)

View File

@ -3,7 +3,6 @@ package main
import "os" import "os"
import "path/filepath" import "path/filepath"
import "git.tebibyte.media/sashakoshka/tomo" import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/layouts" import "git.tebibyte.media/sashakoshka/tomo/layouts"
import "git.tebibyte.media/sashakoshka/tomo/elements" import "git.tebibyte.media/sashakoshka/tomo/elements"
import "git.tebibyte.media/sashakoshka/tomo/elements/file" import "git.tebibyte.media/sashakoshka/tomo/elements/file"
@ -17,28 +16,28 @@ func main () {
func run () { func run () {
window, _ := tomo.NewWindow(384, 384) window, _ := tomo.NewWindow(384, 384)
window.SetTitle("File browser") window.SetTitle("File browser")
container := containers.NewContainer(basicLayouts.Vertical { true, true }) container := containers.NewContainer(layouts.Vertical { true, true })
window.Adopt(container) window.Adopt(container)
homeDir, _ := os.UserHomeDir() homeDir, _ := os.UserHomeDir()
controlBar := containers.NewContainer(basicLayouts.Horizontal { }) controlBar := containers.NewContainer(layouts.Horizontal { })
backButton := basicElements.NewButton("Back") backButton := elements.NewButton("Back")
backButton.SetIcon(theme.IconBackward) backButton.SetIcon(tomo.IconBackward)
backButton.ShowText(false) backButton.ShowText(false)
forwardButton := basicElements.NewButton("Forward") forwardButton := elements.NewButton("Forward")
forwardButton.SetIcon(theme.IconForward) forwardButton.SetIcon(tomo.IconForward)
forwardButton.ShowText(false) forwardButton.ShowText(false)
refreshButton := basicElements.NewButton("Refresh") refreshButton := elements.NewButton("Refresh")
refreshButton.SetIcon(theme.IconRefresh) refreshButton.SetIcon(tomo.IconRefresh)
refreshButton.ShowText(false) refreshButton.ShowText(false)
upwardButton := basicElements.NewButton("Go Up") upwardButton := elements.NewButton("Go Up")
upwardButton.SetIcon(theme.IconUpward) upwardButton.SetIcon(tomo.IconUpward)
upwardButton.ShowText(false) upwardButton.ShowText(false)
locationInput := basicElements.NewTextBox("Location", "") locationInput := elements.NewTextBox("Location", "")
statusBar := containers.NewContainer(basicLayouts.Horizontal { true, false }) statusBar := containers.NewContainer(layouts.Horizontal { true, false })
directory, _ := fileElements.NewFile(homeDir, nil) directory, _ := fileElements.NewFile(homeDir, nil)
baseName := basicElements.NewLabel(filepath.Base(homeDir), false) baseName := elements.NewLabel(filepath.Base(homeDir), false)
scrollContainer := containers.NewScrollContainer(false, true) scrollContainer := containers.NewScrollContainer(false, true)
directoryView, _ := fileElements.NewDirectory(homeDir, nil) directoryView, _ := fileElements.NewDirectory(homeDir, nil)

View File

@ -1,7 +1,6 @@
package popups package popups
import "git.tebibyte.media/sashakoshka/tomo" import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/layouts" import "git.tebibyte.media/sashakoshka/tomo/layouts"
import "git.tebibyte.media/sashakoshka/tomo/elements" import "git.tebibyte.media/sashakoshka/tomo/elements"
import "git.tebibyte.media/sashakoshka/tomo/elements/containers" import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
@ -47,21 +46,21 @@ func NewDialog (
window.Adopt(container) window.Adopt(container)
messageContainer := containers.NewContainer(layouts.Horizontal { true, false }) messageContainer := containers.NewContainer(layouts.Horizontal { true, false })
iconId := theme.IconInformation iconId := tomo.IconInformation
switch kind { switch kind {
case DialogKindInfo: iconId = theme.IconInformation case DialogKindInfo: iconId = tomo.IconInformation
case DialogKindQuestion: iconId = theme.IconQuestion case DialogKindQuestion: iconId = tomo.IconQuestion
case DialogKindWarning: iconId = theme.IconWarning case DialogKindWarning: iconId = tomo.IconWarning
case DialogKindError: iconId = theme.IconError case DialogKindError: iconId = tomo.IconError
} }
messageContainer.Adopt(elements.NewIcon(iconId, theme.IconSizeLarge), false) messageContainer.Adopt(elements.NewIcon(iconId, tomo.IconSizeLarge), false)
messageContainer.Adopt(elements.NewLabel(message, false), true) messageContainer.Adopt(elements.NewLabel(message, false), true)
container.Adopt(messageContainer, true) container.Adopt(messageContainer, true)
if len(buttons) == 0 { if len(buttons) == 0 {
button := elements.NewButton("OK") button := elements.NewButton("OK")
button.SetIcon(theme.IconYes) button.SetIcon(tomo.IconYes)
button.OnClick(window.Close) button.OnClick(window.Close)
container.Adopt(button, false) container.Adopt(button, false)
button.Focus() button.Focus()

View File

@ -1,4 +1,4 @@
package theme package tomo
import "image" import "image"
import "image/color" import "image/color"
@ -240,3 +240,110 @@ type Theme interface {
// performance. // performance.
Hints (Pattern, Case) Hints Hints (Pattern, Case) Hints
} }
// Case sepecifies what kind of element is using a pattern. It contains a
// namespace parameter, an element parameter, and an optional component trail.
// All parameter values should be written in camel case. Themes can change their
// styling based on the case for fine-grained control over the look and feel of
// specific elements.
type Case struct {
// Namespace refers to the package that the element comes from. This is
// so different element packages can have elements with the same name
// while still allowing themes to differentiate between them.
Namespace string
// Element refers to the name of the element. This should (generally) be
// the type name of the element. For example: Button, Input, Container,
// etc.
Element string
// Component specifies the specific part of the element that is being
// referred to. This parameter is entirely optional.
Component string
}
// C can be used as shorthand to generate a case struct. The component parameter
// may be left out of this argument list for brevity. Arguments passed after
// component will be ignored.
func C (namespace, element string, component ...string) Case {
if component == nil { component = []string { "" } }
return Case {
Namespace: namespace,
Element: element,
Component: component[0],
}
}
// Match determines if a case matches the specified parameters. A blank string
// will act as a wildcard.
func (c Case) Match (namespace, element, component string) bool {
if namespace == "" { namespace = c.Namespace }
if element == "" { element = c.Element }
if component == "" { component = c.Component }
return namespace == c.Namespace &&
element == c.Element &&
component == c.Component
}
// State lists parameters which can change the appearance of some patterns and
// colors. For example, passing a State with Selected set to true may result in
// a pattern that has a colored border within it.
type State struct {
// On should be set to true if the element that is using this pattern is
// in some sort of selected or "on" state, such as if a checkbox is
// checked, a file is selected, or a switch is toggled on. This is only
// necessary if the element in question is capable of being toggled or
// selected.
On bool
// Focused should be set to true if the element that is using this
// pattern is currently focused.
Focused bool
// Pressed should be set to true if the element that is using this
// pattern is being pressed down by the mouse. This is only necessary if
// the element in question processes mouse button events.
Pressed bool
// Disabled should be set to true if the element that is using this
// pattern is locked and cannot be interacted with. Disabled variations
// of patterns are typically flattened and greyed-out.
Disabled bool
// Invalid should be set to true if th element that is using this
// pattern wants to warn the user of an invalid interaction or data
// entry. Invalid variations typically have some sort of reddish tint
// or outline.
Invalid bool
}
// FontStyle specifies stylistic alterations to a font face.
type FontStyle int; const (
FontStyleRegular FontStyle = 0
FontStyleBold FontStyle = 1
FontStyleItalic FontStyle = 2
FontStyleBoldItalic FontStyle = 1 | 2
)
// FontSize specifies the general size of a font face in a semantic way.
type FontSize int; const (
// FontSizeNormal is the default font size that should be used for most
// things.
FontSizeNormal FontSize = iota
// FontSizeLarge is a larger font size suitable for things like section
// headings.
FontSizeLarge
// FontSizeHuge is a very large font size suitable for things like
// titles, wizard step names, digital clocks, etc.
FontSizeHuge
// FontSizeSmall is a smaller font size. Try not to use this unless it
// makes a lot of sense to do so, because it can negatively impact
// accessibility. It is useful for things like copyright notices at the
// bottom of some window that the average user doesn't actually care
// about.
FontSizeSmall
)

View File

@ -1,2 +0,0 @@
// Package theme implements a theming system for tomo.
package theme

View File

@ -1,9 +0,0 @@
package theme
import "io"
// Parse parses one or more theme files and returns them as a Theme.
func Parse (sources ...io.Reader) (Theme) {
// TODO
return Default { }
}

View File

@ -1,108 +0,0 @@
package theme
// Case sepecifies what kind of element is using a pattern. It contains a
// namespace parameter, an element parameter, and an optional component trail.
// All parameter values should be written in camel case. Themes can change their
// styling based on the case for fine-grained control over the look and feel of
// specific elements.
type Case struct {
// Namespace refers to the package that the element comes from. This is
// so different element packages can have elements with the same name
// while still allowing themes to differentiate between them.
Namespace string
// Element refers to the name of the element. This should (generally) be
// the type name of the element. For example: Button, Input, Container,
// etc.
Element string
// Component specifies the specific part of the element that is being
// referred to. This parameter is entirely optional.
Component string
}
// C can be used as shorthand to generate a case struct. The component parameter
// may be left out of this argument list for brevity. Arguments passed after
// component will be ignored.
func C (namespace, element string, component ...string) Case {
if component == nil { component = []string { "" } }
return Case {
Namespace: namespace,
Element: element,
Component: component[0],
}
}
// Match determines if a case matches the specified parameters. A blank string
// will act as a wildcard.
func (c Case) Match (namespace, element, component string) bool {
if namespace == "" { namespace = c.Namespace }
if element == "" { element = c.Element }
if component == "" { component = c.Component }
return namespace == c.Namespace &&
element == c.Element &&
component == c.Component
}
// State lists parameters which can change the appearance of some patterns and
// colors. For example, passing a State with Selected set to true may result in
// a pattern that has a colored border within it.
type State struct {
// On should be set to true if the element that is using this pattern is
// in some sort of selected or "on" state, such as if a checkbox is
// checked, a file is selected, or a switch is toggled on. This is only
// necessary if the element in question is capable of being toggled or
// selected.
On bool
// Focused should be set to true if the element that is using this
// pattern is currently focused.
Focused bool
// Pressed should be set to true if the element that is using this
// pattern is being pressed down by the mouse. This is only necessary if
// the element in question processes mouse button events.
Pressed bool
// Disabled should be set to true if the element that is using this
// pattern is locked and cannot be interacted with. Disabled variations
// of patterns are typically flattened and greyed-out.
Disabled bool
// Invalid should be set to true if th element that is using this
// pattern wants to warn the user of an invalid interaction or data
// entry. Invalid variations typically have some sort of reddish tint
// or outline.
Invalid bool
}
// FontStyle specifies stylistic alterations to a font face.
type FontStyle int; const (
FontStyleRegular FontStyle = 0
FontStyleBold FontStyle = 1
FontStyleItalic FontStyle = 2
FontStyleBoldItalic FontStyle = 1 | 2
)
// FontSize specifies the general size of a font face in a semantic way.
type FontSize int; const (
// FontSizeNormal is the default font size that should be used for most
// things.
FontSizeNormal FontSize = iota
// FontSizeLarge is a larger font size suitable for things like section
// headings.
FontSizeLarge
// FontSizeHuge is a very large font size suitable for things like
// titles, wizard step names, digital clocks, etc.
FontSizeHuge
// FontSizeSmall is a smaller font size. Try not to use this unless it
// makes a lot of sense to do so, because it can negatively impact
// accessibility. It is useful for things like copyright notices at the
// bottom of some window that the average user doesn't actually care
// about.
FontSizeSmall
)

View File

@ -1,8 +1,5 @@
package tomo package tomo
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/config"
var backend Backend var backend Backend
// Run initializes a backend, calls the callback function, and begins the event // Run initializes a backend, calls the callback function, and begins the event
@ -39,12 +36,12 @@ func NewWindow (width, height int) (window MainWindow, err error) {
} }
// SetTheme sets the theme of all open windows. // SetTheme sets the theme of all open windows.
func SetTheme (theme theme.Theme) { func SetTheme (theme Theme) {
backend.SetTheme(theme) backend.SetTheme(theme)
} }
// SetConfig sets the configuration of all open windows. // SetConfig sets the configuration of all open windows.
func SetConfig (config config.Config) { func SetConfig (config Config) {
backend.SetConfig(config) backend.SetConfig(config)
} }