I am going insane
This commit is contained in:
parent
53bfc8df68
commit
7b300333cf
|
@ -1,8 +1,6 @@
|
|||
package tomo
|
||||
|
||||
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.
|
||||
// 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)
|
||||
|
||||
// SetTheme sets the theme of all open windows.
|
||||
SetTheme (theme.Theme)
|
||||
SetTheme (Theme)
|
||||
|
||||
// SetConfig sets the configuration of all open windows.
|
||||
SetConfig (config.Config)
|
||||
SetConfig (Config)
|
||||
}
|
||||
|
||||
// BackendFactory represents a function capable of constructing a backend
|
||||
|
|
|
@ -12,8 +12,6 @@ import "github.com/jezek/xgbutil/xgraphics"
|
|||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/data"
|
||||
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 "runtime/debug"
|
||||
|
||||
|
@ -30,8 +28,8 @@ type window struct {
|
|||
modalParent *window
|
||||
hasModal bool
|
||||
|
||||
theme theme.Theme
|
||||
config config.Config
|
||||
theme tomo.Theme
|
||||
config tomo.Config
|
||||
|
||||
selectionRequest *selectionRequest
|
||||
selectionClaim *selectionClaim
|
||||
|
@ -334,14 +332,14 @@ func (window *window) OnClose (callback func ()) {
|
|||
window.onClose = callback
|
||||
}
|
||||
|
||||
func (window *window) SetTheme (theme theme.Theme) {
|
||||
func (window *window) SetTheme (theme tomo.Theme) {
|
||||
window.theme = theme
|
||||
if child, ok := window.child.(tomo.Themeable); ok {
|
||||
child.SetTheme(theme)
|
||||
}
|
||||
}
|
||||
|
||||
func (window *window) SetConfig (config config.Config) {
|
||||
func (window *window) SetConfig (config tomo.Config) {
|
||||
window.config = config
|
||||
if child, ok := window.child.(tomo.Configurable); ok {
|
||||
child.SetConfig(config)
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package x
|
||||
|
||||
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/xgb/xproto"
|
||||
|
@ -26,8 +24,8 @@ type Backend struct {
|
|||
hyper uint16
|
||||
}
|
||||
|
||||
theme theme.Theme
|
||||
config config.Config
|
||||
theme tomo.Theme
|
||||
config tomo.Config
|
||||
|
||||
windows map[xproto.Window] *window
|
||||
|
||||
|
@ -37,11 +35,9 @@ type Backend struct {
|
|||
// NewBackend instantiates an X backend.
|
||||
func NewBackend () (output tomo.Backend, err error) {
|
||||
backend := &Backend {
|
||||
windows: map[xproto.Window] *window { },
|
||||
windows: map[xproto.Window] *window { },
|
||||
doChannel: make(chan func (), 32),
|
||||
theme: theme.Default { },
|
||||
config: config.Default { },
|
||||
open: true,
|
||||
open: true,
|
||||
}
|
||||
|
||||
// connect to X
|
||||
|
@ -97,7 +93,7 @@ func (backend *Backend) Do (callback func ()) {
|
|||
}
|
||||
|
||||
// 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.theme = theme
|
||||
for _, window := range backend.windows {
|
||||
|
@ -106,7 +102,7 @@ func (backend *Backend) SetTheme (theme theme.Theme) {
|
|||
}
|
||||
|
||||
// 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.config = config
|
||||
for _, window := range backend.windows {
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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 { }
|
||||
}
|
|
@ -1,18 +1,6 @@
|
|||
package config
|
||||
|
||||
// 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
|
||||
}
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
|
||||
// Default specifies default configuration values.
|
||||
type Default struct { }
|
||||
|
@ -35,7 +23,7 @@ func (Default) ThemePath () (string) {
|
|||
|
||||
// Wrapped wraps a configuration and uses Default if it is nil.
|
||||
type Wrapped struct {
|
||||
Config
|
||||
tomo.Config
|
||||
}
|
||||
|
||||
// HandleWidth returns how large grab handles should typically be. This
|
||||
|
@ -55,7 +43,7 @@ func (wrapped Wrapped) ThemePath () string {
|
|||
return wrapped.ensure().ThemePath()
|
||||
}
|
||||
|
||||
func (wrapped Wrapped) ensure () (real Config) {
|
||||
func (wrapped Wrapped) ensure () (real tomo.Config) {
|
||||
real = wrapped.Config
|
||||
if real == nil { real = Default { } }
|
||||
return
|
|
@ -0,0 +1,2 @@
|
|||
// Package config implements a default configuration.
|
||||
package config
|
|
@ -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 { }
|
||||
// }
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
|
@ -6,6 +6,7 @@ import _ "embed"
|
|||
import _ "image/png"
|
||||
import "image/color"
|
||||
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/artist"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/canvas"
|
||||
|
@ -155,13 +156,13 @@ func init () {
|
|||
type Default struct { }
|
||||
|
||||
// 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 {
|
||||
case FontStyleBold:
|
||||
case tomo.FontStyleBold:
|
||||
return defaultfont.FaceBold
|
||||
case FontStyleItalic:
|
||||
case tomo.FontStyleItalic:
|
||||
return defaultfont.FaceItalic
|
||||
case FontStyleBoldItalic:
|
||||
case tomo.FontStyleBoldItalic:
|
||||
return defaultfont.FaceBoldItalic
|
||||
default:
|
||||
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.
|
||||
func (Default) Icon (id Icon, size IconSize, c Case) artist.Icon {
|
||||
if size == IconSizeLarge {
|
||||
func (Default) Icon (id tomo.Icon, size tomo.IconSize, c tomo.Case) artist.Icon {
|
||||
if size == tomo.IconSizeLarge {
|
||||
if id < 0 || int(id) >= len(defaultIconsLarge) {
|
||||
return nil
|
||||
} 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.
|
||||
// type.
|
||||
func (Default) MimeIcon (data.Mime, IconSize, Case) artist.Icon {
|
||||
func (Default) MimeIcon (data.Mime, tomo.IconSize, tomo.Case) artist.Icon {
|
||||
// TODO
|
||||
return nil
|
||||
}
|
||||
|
||||
// Pattern returns a pattern from the default theme corresponding to the given
|
||||
// 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 {
|
||||
case state.Disabled: offset = 1
|
||||
case state.Pressed && state.On: offset = 4
|
||||
|
@ -207,17 +208,17 @@ func (Default) Pattern (id Pattern, state State, c Case) artist.Pattern {
|
|||
}
|
||||
|
||||
switch id {
|
||||
case PatternBackground: return patterns.Uhex(0xaaaaaaFF)
|
||||
case PatternDead: return defaultTextures[0][offset]
|
||||
case PatternRaised:
|
||||
case tomo.PatternBackground: return patterns.Uhex(0xaaaaaaFF)
|
||||
case tomo.PatternDead: return defaultTextures[0][offset]
|
||||
case tomo.PatternRaised:
|
||||
if c.Match("tomo", "listEntry", "") {
|
||||
return defaultTextures[10][offset]
|
||||
} else {
|
||||
return defaultTextures[1][offset]
|
||||
}
|
||||
case PatternSunken: return defaultTextures[2][offset]
|
||||
case PatternPinboard: return defaultTextures[3][offset]
|
||||
case PatternButton:
|
||||
case tomo.PatternSunken: return defaultTextures[2][offset]
|
||||
case tomo.PatternPinboard: return defaultTextures[3][offset]
|
||||
case tomo.PatternButton:
|
||||
switch {
|
||||
case c.Match("tomo", "checkbox", ""):
|
||||
return defaultTextures[9][offset]
|
||||
|
@ -228,37 +229,37 @@ func (Default) Pattern (id Pattern, state State, c Case) artist.Pattern {
|
|||
default:
|
||||
return defaultTextures[4][offset]
|
||||
}
|
||||
case PatternInput: return defaultTextures[5][offset]
|
||||
case PatternGutter: return defaultTextures[6][offset]
|
||||
case PatternHandle: return defaultTextures[7][offset]
|
||||
case PatternLine: return defaultTextures[8][offset]
|
||||
case PatternMercury: return defaultTextures[13][offset]
|
||||
case tomo.PatternInput: return defaultTextures[5][offset]
|
||||
case tomo.PatternGutter: return defaultTextures[6][offset]
|
||||
case tomo.PatternHandle: return defaultTextures[7][offset]
|
||||
case tomo.PatternLine: return defaultTextures[8][offset]
|
||||
case tomo.PatternMercury: return defaultTextures[13][offset]
|
||||
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 {
|
||||
return artist.Hex(0x444444FF)
|
||||
} else {
|
||||
switch id {
|
||||
case ColorAccent: return artist.Hex(0x408090FF)
|
||||
case ColorForeground: return artist.Hex(0x000000FF)
|
||||
case tomo.ColorAccent: return artist.Hex(0x408090FF)
|
||||
case tomo.ColorForeground: return artist.Hex(0x000000FF)
|
||||
default: return artist.Hex(0x888888FF)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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 {
|
||||
case PatternRaised:
|
||||
case tomo.PatternRaised:
|
||||
if c.Match("tomo", "listEntry", "") {
|
||||
return artist.I(4, 8)
|
||||
} else {
|
||||
return artist.I(8)
|
||||
}
|
||||
case PatternSunken:
|
||||
case tomo.PatternSunken:
|
||||
if c.Match("tomo", "list", "") {
|
||||
return artist.I(4, 0, 3)
|
||||
} else if c.Match("basic", "progressBar", "") {
|
||||
|
@ -266,32 +267,32 @@ func (Default) Padding (id Pattern, c Case) artist.Inset {
|
|||
} else {
|
||||
return artist.I(8)
|
||||
}
|
||||
case PatternPinboard:
|
||||
case tomo.PatternPinboard:
|
||||
if c.Match("tomo", "piano", "") {
|
||||
return artist.I(2)
|
||||
} else {
|
||||
return artist.I(8)
|
||||
}
|
||||
case PatternGutter: return artist.I(0)
|
||||
case PatternLine: return artist.I(1)
|
||||
case PatternMercury: return artist.I(5)
|
||||
case tomo.PatternGutter: return artist.I(0)
|
||||
case tomo.PatternLine: return artist.I(1)
|
||||
case tomo.PatternMercury: return artist.I(5)
|
||||
default: return artist.I(8)
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
// Hints returns rendering optimization hints for a particular pattern.
|
||||
// These are optional, but following them may result in improved
|
||||
// performance.
|
||||
func (Default) Hints (pattern Pattern, c Case) (hints Hints) {
|
||||
func (Default) Hints (pattern tomo.Pattern, c tomo.Case) (hints tomo.Hints) {
|
||||
return
|
||||
}
|
||||
|
||||
// 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 }
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
// Package theme implements a default theme.
|
||||
package theme
|
|
@ -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 { }
|
||||
// }
|
|
@ -3,6 +3,7 @@ package theme
|
|||
import "image"
|
||||
import "image/color"
|
||||
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/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
|
||||
// theme is nil, it just uses the default theme instead.
|
||||
type Wrapped struct {
|
||||
Theme
|
||||
Case
|
||||
tomo.Theme
|
||||
tomo.Case
|
||||
}
|
||||
|
||||
// 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()
|
||||
return real.FontFace(style, size, wrapped.Case)
|
||||
}
|
||||
|
||||
// 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()
|
||||
return real.Icon(id, size, wrapped.Case)
|
||||
}
|
||||
|
||||
// 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()
|
||||
return real.MimeIcon(mime, size, wrapped.Case)
|
||||
}
|
||||
|
||||
// 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()
|
||||
return real.Pattern(id, state, wrapped.Case)
|
||||
}
|
||||
|
||||
// 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()
|
||||
return real.Color(id, state, wrapped.Case)
|
||||
}
|
||||
|
||||
// Padding returns how much space should be between the bounds of a
|
||||
// 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()
|
||||
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
|
||||
// should be put between any self-contained objects drawn within this
|
||||
// pattern (if applicable).
|
||||
func (wrapped Wrapped) Margin (id Pattern) image.Point {
|
||||
func (wrapped Wrapped) Margin (id tomo.Pattern) image.Point {
|
||||
real := wrapped.ensure()
|
||||
return real.Margin(id, wrapped.Case)
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (wrapped Wrapped) Sink (id Pattern) image.Point {
|
||||
func (wrapped Wrapped) Sink (id tomo.Pattern) image.Point {
|
||||
real := wrapped.ensure()
|
||||
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.
|
||||
// These are optional, but following them may result in improved
|
||||
// performance.
|
||||
func (wrapped Wrapped) Hints (id Pattern) Hints {
|
||||
func (wrapped Wrapped) Hints (id tomo.Pattern) tomo.Hints {
|
||||
real := wrapped.ensure()
|
||||
return real.Hints(id, wrapped.Case)
|
||||
}
|
||||
|
||||
func (wrapped Wrapped) ensure () (real Theme) {
|
||||
func (wrapped Wrapped) ensure () (real tomo.Theme) {
|
||||
real = wrapped.Theme
|
||||
if real == nil { real = Default { } }
|
||||
return
|
|
@ -2,9 +2,7 @@ package tomo
|
|||
|
||||
import "image"
|
||||
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/config"
|
||||
|
||||
// Element represents a basic on-screen object.
|
||||
type Element interface {
|
||||
|
@ -164,7 +162,7 @@ type Themeable interface {
|
|||
|
||||
// SetTheme sets the element's theme to something fulfilling the
|
||||
// theme.Theme interface.
|
||||
SetTheme (theme.Theme)
|
||||
SetTheme (Theme)
|
||||
}
|
||||
|
||||
// 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
|
||||
// the config.Config interface.
|
||||
SetConfig (config.Config)
|
||||
SetConfig (Config)
|
||||
}
|
||||
|
|
|
@ -2,9 +2,10 @@ package elements
|
|||
|
||||
import "image"
|
||||
// import "runtime/debug"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
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/default/theme"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/default/config"
|
||||
// import "git.tebibyte.media/sashakoshka/tomo/artist"
|
||||
// import "git.tebibyte.media/sashakoshka/tomo/shatter"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/textdraw"
|
||||
|
@ -26,7 +27,7 @@ type Button struct {
|
|||
|
||||
showText bool
|
||||
hasIcon bool
|
||||
iconId theme.Icon
|
||||
iconId tomo.Icon
|
||||
|
||||
onClick func ()
|
||||
}
|
||||
|
@ -34,10 +35,13 @@ type Button struct {
|
|||
// NewButton creates a new button with the specified label text.
|
||||
func NewButton (text string) (element *Button) {
|
||||
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.FocusableCore,
|
||||
element.focusableControl = core.NewFocusableCore(element.core, element.drawAndPush)
|
||||
element.drawer.SetFace (element.theme.FontFace (
|
||||
tomo.FontStyleRegular,
|
||||
tomo.FontSizeNormal))
|
||||
element.SetText(text)
|
||||
return
|
||||
}
|
||||
|
@ -102,8 +106,8 @@ func (element *Button) SetText (text string) {
|
|||
|
||||
// SetIcon sets the icon of the button. Passing theme.IconNone removes the
|
||||
// current icon if it exists.
|
||||
func (element *Button) SetIcon (id theme.Icon) {
|
||||
if id == theme.IconNone {
|
||||
func (element *Button) SetIcon (id tomo.Icon) {
|
||||
if id == tomo.IconNone {
|
||||
element.hasIcon = false
|
||||
element.updateMinimumSize()
|
||||
element.drawAndPush()
|
||||
|
@ -125,18 +129,18 @@ func (element *Button) ShowText (showText bool) {
|
|||
}
|
||||
|
||||
// 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 }
|
||||
element.theme.Theme = new
|
||||
element.drawer.SetFace (element.theme.FontFace (
|
||||
theme.FontStyleRegular,
|
||||
theme.FontSizeNormal))
|
||||
tomo.FontStyleRegular,
|
||||
tomo.FontSizeNormal))
|
||||
element.updateMinimumSize()
|
||||
element.drawAndPush()
|
||||
}
|
||||
|
||||
// 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 }
|
||||
element.config.Config = new
|
||||
element.updateMinimumSize()
|
||||
|
@ -144,14 +148,14 @@ func (element *Button) SetConfig (new config.Config) {
|
|||
}
|
||||
|
||||
func (element *Button) updateMinimumSize () {
|
||||
padding := element.theme.Padding(theme.PatternButton)
|
||||
margin := element.theme.Margin(theme.PatternButton)
|
||||
padding := element.theme.Padding(tomo.PatternButton)
|
||||
margin := element.theme.Margin(tomo.PatternButton)
|
||||
|
||||
textBounds := element.drawer.LayoutBounds()
|
||||
minimumSize := textBounds.Sub(textBounds.Min)
|
||||
|
||||
if element.hasIcon {
|
||||
icon := element.theme.Icon(element.iconId, theme.IconSizeSmall)
|
||||
icon := element.theme.Icon(element.iconId, tomo.IconSizeSmall)
|
||||
if icon != nil {
|
||||
bounds := icon.Bounds()
|
||||
if element.showText {
|
||||
|
@ -167,8 +171,8 @@ func (element *Button) updateMinimumSize () {
|
|||
element.core.SetMinimumSize(minimumSize.Dx(), minimumSize.Dy())
|
||||
}
|
||||
|
||||
func (element *Button) state () theme.State {
|
||||
return theme.State {
|
||||
func (element *Button) state () tomo.State {
|
||||
return tomo.State {
|
||||
Disabled: !element.Enabled(),
|
||||
Focused: element.Focused(),
|
||||
Pressed: element.pressed,
|
||||
|
@ -190,7 +194,7 @@ func (element *Button) drawAll () {
|
|||
func (element *Button) drawBackground () []image.Rectangle {
|
||||
state := element.state()
|
||||
bounds := element.Bounds()
|
||||
pattern := element.theme.Pattern(theme.PatternButton, state)
|
||||
pattern := element.theme.Pattern(tomo.PatternButton, state)
|
||||
|
||||
pattern.Draw(element.core, bounds)
|
||||
return []image.Rectangle { bounds }
|
||||
|
@ -199,9 +203,9 @@ func (element *Button) drawBackground () []image.Rectangle {
|
|||
func (element *Button) drawText () {
|
||||
state := element.state()
|
||||
bounds := element.Bounds()
|
||||
foreground := element.theme.Color(theme.ColorForeground, state)
|
||||
sink := element.theme.Sink(theme.PatternButton)
|
||||
margin := element.theme.Margin(theme.PatternButton)
|
||||
foreground := element.theme.Color(tomo.ColorForeground, state)
|
||||
sink := element.theme.Sink(tomo.PatternButton)
|
||||
margin := element.theme.Margin(tomo.PatternButton)
|
||||
|
||||
offset := image.Pt (
|
||||
bounds.Dx() / 2,
|
||||
|
@ -216,7 +220,7 @@ func (element *Button) drawText () {
|
|||
}
|
||||
|
||||
if element.hasIcon {
|
||||
icon := element.theme.Icon(element.iconId, theme.IconSizeSmall)
|
||||
icon := element.theme.Icon(element.iconId, tomo.IconSizeSmall)
|
||||
if icon != nil {
|
||||
iconBounds := icon.Bounds()
|
||||
addedWidth := iconBounds.Dx()
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package elements
|
||||
|
||||
import "image"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
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/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.
|
||||
type Checkbox struct {
|
||||
|
@ -28,10 +29,13 @@ type Checkbox struct {
|
|||
// NewCheckbox creates a new cbeckbox with the specified label text.
|
||||
func NewCheckbox (text string, checked bool) (element *Checkbox) {
|
||||
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.FocusableCore,
|
||||
element.focusableControl = core.NewFocusableCore(element.core, element.redo)
|
||||
element.drawer.SetFace (element.theme.FontFace (
|
||||
tomo.FontStyleRegular,
|
||||
tomo.FontSizeNormal))
|
||||
element.SetText(text)
|
||||
return
|
||||
}
|
||||
|
@ -119,18 +123,18 @@ func (element *Checkbox) SetText (text string) {
|
|||
}
|
||||
|
||||
// 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 }
|
||||
element.theme.Theme = new
|
||||
element.drawer.SetFace (element.theme.FontFace (
|
||||
theme.FontStyleRegular,
|
||||
theme.FontSizeNormal))
|
||||
tomo.FontStyleRegular,
|
||||
tomo.FontSizeNormal))
|
||||
element.updateMinimumSize()
|
||||
element.redo()
|
||||
}
|
||||
|
||||
// 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 }
|
||||
element.config.Config = new
|
||||
element.updateMinimumSize()
|
||||
|
@ -142,7 +146,7 @@ func (element *Checkbox) updateMinimumSize () {
|
|||
if element.text == "" {
|
||||
element.core.SetMinimumSize(textBounds.Dy(), textBounds.Dy())
|
||||
} else {
|
||||
margin := element.theme.Margin(theme.PatternBackground)
|
||||
margin := element.theme.Margin(tomo.PatternBackground)
|
||||
element.core.SetMinimumSize (
|
||||
textBounds.Dy() + margin.X + textBounds.Dx(),
|
||||
textBounds.Dy())
|
||||
|
@ -160,7 +164,7 @@ func (element *Checkbox) draw () {
|
|||
bounds := element.Bounds()
|
||||
boxBounds := image.Rect(0, 0, bounds.Dy(), bounds.Dy()).Add(bounds.Min)
|
||||
|
||||
state := theme.State {
|
||||
state := tomo.State {
|
||||
Disabled: !element.Enabled(),
|
||||
Focused: element.Focused(),
|
||||
Pressed: element.pressed,
|
||||
|
@ -168,14 +172,14 @@ func (element *Checkbox) draw () {
|
|||
}
|
||||
|
||||
backgroundPattern := element.theme.Pattern (
|
||||
theme.PatternBackground, state)
|
||||
tomo.PatternBackground, state)
|
||||
backgroundPattern.Draw(element.core, bounds)
|
||||
|
||||
pattern := element.theme.Pattern(theme.PatternButton, state)
|
||||
pattern := element.theme.Pattern(tomo.PatternButton, state)
|
||||
pattern.Draw(element.core, boxBounds)
|
||||
|
||||
textBounds := element.drawer.LayoutBounds()
|
||||
margin := element.theme.Margin(theme.PatternBackground)
|
||||
margin := element.theme.Margin(tomo.PatternBackground)
|
||||
offset := bounds.Min.Add(image.Point {
|
||||
X: bounds.Dy() + margin.X,
|
||||
})
|
||||
|
@ -183,6 +187,6 @@ func (element *Checkbox) draw () {
|
|||
offset.Y -= textBounds.Min.Y
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -3,11 +3,11 @@ package containers
|
|||
import "image"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
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/artist"
|
||||
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
|
||||
// them in a layout.
|
||||
|
@ -30,7 +30,7 @@ type Container struct {
|
|||
// NewContainer creates a new container.
|
||||
func NewContainer (layout tomo.Layout) (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.Propagator = core.NewPropagator(element, element.core)
|
||||
element.SetLayout(layout)
|
||||
|
@ -190,8 +190,8 @@ func (element *Container) redoAll () {
|
|||
rocks[index] = entry.Bounds
|
||||
}
|
||||
pattern := element.theme.Pattern (
|
||||
theme.PatternBackground,
|
||||
theme.State { })
|
||||
tomo.PatternBackground,
|
||||
tomo.State { })
|
||||
artist.DrawShatter(element.core, pattern, element.Bounds(), rocks...)
|
||||
|
||||
// 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.
|
||||
func (element *Container) SetTheme (new theme.Theme) {
|
||||
func (element *Container) SetTheme (new tomo.Theme) {
|
||||
if new == element.theme.Theme { return }
|
||||
element.theme.Theme = new
|
||||
element.Propagator.SetTheme(new)
|
||||
|
@ -222,7 +222,7 @@ func (element *Container) SetTheme (new theme.Theme) {
|
|||
}
|
||||
|
||||
// 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 }
|
||||
element.Propagator.SetConfig(new)
|
||||
element.updateMinimumSize()
|
||||
|
@ -230,16 +230,16 @@ func (element *Container) SetConfig (new config.Config) {
|
|||
}
|
||||
|
||||
func (element *Container) updateMinimumSize () {
|
||||
margin := element.theme.Margin(theme.PatternBackground)
|
||||
padding := element.theme.Padding(theme.PatternBackground)
|
||||
margin := element.theme.Margin(tomo.PatternBackground)
|
||||
padding := element.theme.Padding(tomo.PatternBackground)
|
||||
width, height := element.layout.MinimumSize (
|
||||
element.children, margin, padding)
|
||||
element.core.SetMinimumSize(width, height)
|
||||
}
|
||||
|
||||
func (element *Container) doLayout () {
|
||||
margin := element.theme.Margin(theme.PatternBackground)
|
||||
padding := element.theme.Padding(theme.PatternBackground)
|
||||
margin := element.theme.Margin(tomo.PatternBackground)
|
||||
padding := element.theme.Padding(tomo.PatternBackground)
|
||||
element.layout.Arrange (
|
||||
element.children, margin,
|
||||
padding, element.Bounds())
|
||||
|
|
|
@ -2,11 +2,11 @@ package containers
|
|||
|
||||
import "image"
|
||||
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/artist"
|
||||
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 {
|
||||
*core.Core
|
||||
|
@ -27,7 +27,7 @@ type DocumentContainer struct {
|
|||
// NewDocumentContainer creates a new document container.
|
||||
func NewDocumentContainer () (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.Propagator = core.NewPropagator(element, element.core)
|
||||
return
|
||||
|
@ -172,8 +172,8 @@ func (element *DocumentContainer) redoAll () {
|
|||
rocks[index] = entry.Bounds
|
||||
}
|
||||
pattern := element.theme.Pattern (
|
||||
theme.PatternBackground,
|
||||
theme.State { })
|
||||
tomo.PatternBackground,
|
||||
tomo.State { })
|
||||
artist.DrawShatter(element.core, pattern, element.Bounds(), rocks...)
|
||||
|
||||
element.partition()
|
||||
|
@ -219,7 +219,7 @@ func (element *DocumentContainer) NotifyFlexibleHeightChange (child tomo.Flexibl
|
|||
}
|
||||
|
||||
// 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 }
|
||||
element.theme.Theme = new
|
||||
element.Propagator.SetTheme(new)
|
||||
|
@ -227,7 +227,7 @@ func (element *DocumentContainer) SetTheme (new theme.Theme) {
|
|||
}
|
||||
|
||||
// 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 }
|
||||
element.Propagator.SetConfig(new)
|
||||
element.redoAll()
|
||||
|
@ -241,7 +241,7 @@ func (element *DocumentContainer) ScrollContentBounds () image.Rectangle {
|
|||
// ScrollViewportBounds returns the size and position of the element's
|
||||
// viewport relative to ScrollBounds.
|
||||
func (element *DocumentContainer) ScrollViewportBounds () image.Rectangle {
|
||||
padding := element.theme.Padding(theme.PatternBackground)
|
||||
padding := element.theme.Padding(tomo.PatternBackground)
|
||||
bounds := padding.Apply(element.Bounds())
|
||||
bounds = bounds.Sub(bounds.Min).Add(element.scroll)
|
||||
return bounds
|
||||
|
@ -271,7 +271,7 @@ func (element *DocumentContainer) OnScrollBoundsChange (callback func ()) {
|
|||
}
|
||||
|
||||
func (element *DocumentContainer) maxScrollHeight () (height int) {
|
||||
padding := element.theme.Padding(theme.PatternSunken)
|
||||
padding := element.theme.Padding(tomo.PatternSunken)
|
||||
viewportHeight := element.Bounds().Dy() - padding.Vertical()
|
||||
height = element.contentBounds.Dy() - viewportHeight
|
||||
if height < 0 { height = 0 }
|
||||
|
@ -284,8 +284,8 @@ func (element *DocumentContainer) ScrollAxes () (horizontal, vertical bool) {
|
|||
}
|
||||
|
||||
func (element *DocumentContainer) doLayout () {
|
||||
margin := element.theme.Margin(theme.PatternBackground)
|
||||
padding := element.theme.Padding(theme.PatternBackground)
|
||||
margin := element.theme.Margin(tomo.PatternBackground)
|
||||
padding := element.theme.Padding(tomo.PatternBackground)
|
||||
bounds := padding.Apply(element.Bounds())
|
||||
element.contentBounds = image.Rectangle { }
|
||||
|
||||
|
@ -315,7 +315,7 @@ func (element *DocumentContainer) doLayout () {
|
|||
}
|
||||
|
||||
func (element *DocumentContainer) updateMinimumSize () {
|
||||
padding := element.theme.Padding(theme.PatternBackground)
|
||||
padding := element.theme.Padding(tomo.PatternBackground)
|
||||
minimumWidth := 0
|
||||
for _, entry := range element.children {
|
||||
width, _ := entry.MinimumSize()
|
||||
|
|
|
@ -3,11 +3,11 @@ package containers
|
|||
import "image"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
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/elements"
|
||||
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
|
||||
// element.
|
||||
|
@ -31,7 +31,7 @@ type ScrollContainer struct {
|
|||
// bars.
|
||||
func NewScrollContainer (horizontal, vertical bool) (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.Propagator = core.NewPropagator(element, element.core)
|
||||
|
||||
|
@ -132,7 +132,7 @@ func (element *ScrollContainer) NotifyScrollBoundsChange (child tomo.Scrollable)
|
|||
}
|
||||
|
||||
// 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 }
|
||||
element.theme.Theme = new
|
||||
element.Propagator.SetTheme(new)
|
||||
|
@ -141,7 +141,7 @@ func (element *ScrollContainer) SetTheme (new theme.Theme) {
|
|||
}
|
||||
|
||||
// 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 }
|
||||
element.Propagator.SetConfig(new)
|
||||
element.updateMinimumSize()
|
||||
|
@ -258,8 +258,8 @@ func (element *ScrollContainer) draw () {
|
|||
bounds.Min = image.Pt (
|
||||
bounds.Max.X - element.vertical.Bounds().Dx(),
|
||||
bounds.Max.Y - element.horizontal.Bounds().Dy())
|
||||
state := theme.State { }
|
||||
deadArea := element.theme.Pattern(theme.PatternDead, state)
|
||||
state := tomo.State { }
|
||||
deadArea := element.theme.Pattern(tomo.PatternDead, state)
|
||||
deadArea.Draw(canvas.Cut(element.core, bounds), bounds)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,6 @@ package core
|
|||
import "image"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
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
|
||||
// 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.
|
||||
func (propagator *Propagator) SetTheme (theme theme.Theme) {
|
||||
func (propagator *Propagator) SetTheme (theme tomo.Theme) {
|
||||
propagator.forChildren (func (child tomo.Element) bool {
|
||||
typedChild, themeable := child.(tomo.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.
|
||||
func (propagator *Propagator) SetConfig (config config.Config) {
|
||||
func (propagator *Propagator) SetConfig (config tomo.Config) {
|
||||
propagator.forChildren (func (child tomo.Element) bool {
|
||||
typedChild, configurable := child.(tomo.Configurable)
|
||||
if configurable {
|
||||
|
|
|
@ -3,14 +3,14 @@ package fileElements
|
|||
import "io/fs"
|
||||
import "image"
|
||||
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/artist"
|
||||
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/elements"
|
||||
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 {
|
||||
*File
|
||||
|
@ -56,7 +56,7 @@ func NewDirectory (
|
|||
err error,
|
||||
) {
|
||||
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.Propagator = core.NewPropagator(element, element.core)
|
||||
err = element.SetLocation(location, within)
|
||||
|
@ -138,8 +138,8 @@ func (element *Directory) Update () error {
|
|||
element.children[index].File = file
|
||||
element.children[index].DirEntry = entry
|
||||
element.children[index].Drawer.SetFace (element.theme.FontFace(
|
||||
theme.FontStyleRegular,
|
||||
theme.FontSizeNormal))
|
||||
tomo.FontStyleRegular,
|
||||
tomo.FontSizeNormal))
|
||||
element.children[index].Drawer.SetText([]rune(entry.Name()))
|
||||
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
|
||||
// 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 }
|
||||
return element.children[index].File
|
||||
}
|
||||
|
@ -202,12 +202,12 @@ func (element *Directory) redoAll () {
|
|||
rocks[index] = entry.Bounds
|
||||
}
|
||||
pattern := element.theme.Pattern (
|
||||
theme.PatternPinboard,
|
||||
theme.State { })
|
||||
tomo.PatternPinboard,
|
||||
tomo.State { })
|
||||
artist.DrawShatter(element.core, pattern, element.Bounds(), rocks...)
|
||||
|
||||
element.partition()
|
||||
if parent, ok := element.core.Parent().(elements.ScrollableParent); ok {
|
||||
if parent, ok := element.core.Parent().(tomo.ScrollableParent); ok {
|
||||
parent.NotifyScrollBoundsChange(element)
|
||||
}
|
||||
if element.onScrollBoundsChange != nil {
|
||||
|
@ -215,7 +215,7 @@ func (element *Directory) redoAll () {
|
|||
}
|
||||
|
||||
// draw labels
|
||||
foreground := element.theme.Color(theme.ColorForeground, theme.State { })
|
||||
foreground := element.theme.Color(tomo.ColorForeground, tomo.State { })
|
||||
for _, entry := range element.children {
|
||||
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
|
||||
// child element has changed.
|
||||
func (element *Directory) NotifyMinimumSizeChange (child elements.Element) {
|
||||
func (element *Directory) NotifyMinimumSizeChange (child tomo.Element) {
|
||||
element.redoAll()
|
||||
element.core.DamageAll()
|
||||
}
|
||||
|
||||
// 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 }
|
||||
element.theme.Theme = new
|
||||
element.Propagator.SetTheme(new)
|
||||
|
@ -254,7 +254,7 @@ func (element *Directory) SetTheme (new theme.Theme) {
|
|||
}
|
||||
|
||||
// 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 }
|
||||
element.Propagator.SetConfig(new)
|
||||
element.redoAll()
|
||||
|
@ -267,7 +267,7 @@ func (element *Directory) ScrollContentBounds () image.Rectangle {
|
|||
// ScrollViewportBounds returns the size and position of the element's
|
||||
// viewport relative to ScrollBounds.
|
||||
func (element *Directory) ScrollViewportBounds () image.Rectangle {
|
||||
padding := element.theme.Padding(theme.PatternPinboard)
|
||||
padding := element.theme.Padding(tomo.PatternPinboard)
|
||||
bounds := padding.Apply(element.Bounds())
|
||||
bounds = bounds.Sub(bounds.Min).Add(element.scroll)
|
||||
return bounds
|
||||
|
@ -302,7 +302,7 @@ func (element *Directory) ScrollAxes () (horizontal, vertical bool) {
|
|||
}
|
||||
|
||||
func (element *Directory) maxScrollHeight () (height int) {
|
||||
padding := element.theme.Padding(theme.PatternSunken)
|
||||
padding := element.theme.Padding(tomo.PatternSunken)
|
||||
viewportHeight := element.Bounds().Dy() - padding.Vertical()
|
||||
height = element.contentBounds.Dy() - viewportHeight
|
||||
if height < 0 { height = 0 }
|
||||
|
@ -310,8 +310,8 @@ func (element *Directory) maxScrollHeight () (height int) {
|
|||
}
|
||||
|
||||
func (element *Directory) doLayout () {
|
||||
margin := element.theme.Margin(theme.PatternPinboard)
|
||||
padding := element.theme.Padding(theme.PatternPinboard)
|
||||
margin := element.theme.Margin(tomo.PatternPinboard)
|
||||
padding := element.theme.Padding(tomo.PatternPinboard)
|
||||
bounds := padding.Apply(element.Bounds())
|
||||
element.contentBounds = image.Rectangle { }
|
||||
|
||||
|
@ -360,7 +360,7 @@ func (element *Directory) doLayout () {
|
|||
}
|
||||
|
||||
func (element *Directory) updateMinimumSize () {
|
||||
padding := element.theme.Padding(theme.PatternPinboard)
|
||||
padding := element.theme.Padding(tomo.PatternPinboard)
|
||||
minimumWidth := 0
|
||||
for _, entry := range element.children {
|
||||
width, _ := entry.MinimumSize()
|
||||
|
|
|
@ -3,11 +3,12 @@ package fileElements
|
|||
import "time"
|
||||
import "io/fs"
|
||||
import "image"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
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/config"
|
||||
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 system.
|
||||
|
@ -22,7 +23,7 @@ type File struct {
|
|||
|
||||
lastClick time.Time
|
||||
pressed bool
|
||||
iconID theme.Icon
|
||||
iconID tomo.Icon
|
||||
filesystem fs.StatFS
|
||||
location string
|
||||
selected bool
|
||||
|
@ -40,7 +41,7 @@ func NewFile (
|
|||
err error,
|
||||
) {
|
||||
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.FocusableCore,
|
||||
element.focusableControl = core.NewFocusableCore(element.core, element.drawAndPush)
|
||||
|
@ -72,12 +73,12 @@ func (element *File) Update () error {
|
|||
info, err := element.filesystem.Stat(element.location)
|
||||
|
||||
if err != nil {
|
||||
element.iconID = theme.IconError
|
||||
element.iconID = tomo.IconError
|
||||
} else if info.IsDir() {
|
||||
element.iconID = theme.IconDirectory
|
||||
element.iconID = tomo.IconDirectory
|
||||
} else {
|
||||
// TODO: choose icon based on file mime type
|
||||
element.iconID = theme.IconFile
|
||||
element.iconID = tomo.IconFile
|
||||
}
|
||||
|
||||
element.updateMinimumSize()
|
||||
|
@ -142,21 +143,21 @@ func (element *File) HandleMouseUp (x, y int, button input.Button) {
|
|||
}
|
||||
|
||||
// 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 }
|
||||
element.theme.Theme = new
|
||||
element.drawAndPush()
|
||||
}
|
||||
|
||||
// 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 }
|
||||
element.config.Config = new
|
||||
element.drawAndPush()
|
||||
}
|
||||
|
||||
func (element *File) state () theme.State {
|
||||
return theme.State {
|
||||
func (element *File) state () tomo.State {
|
||||
return tomo.State {
|
||||
Disabled: !element.Enabled(),
|
||||
Focused: element.Focused(),
|
||||
Pressed: element.pressed,
|
||||
|
@ -165,11 +166,11 @@ func (element *File) state () theme.State {
|
|||
}
|
||||
|
||||
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 () {
|
||||
padding := element.theme.Padding(theme.PatternButton)
|
||||
padding := element.theme.Padding(tomo.PatternButton)
|
||||
icon := element.icon()
|
||||
if icon == nil {
|
||||
element.core.SetMinimumSize (
|
||||
|
@ -192,9 +193,9 @@ func (element *File) drawAll () {
|
|||
// background
|
||||
state := element.state()
|
||||
bounds := element.Bounds()
|
||||
sink := element.theme.Sink(theme.PatternButton)
|
||||
sink := element.theme.Sink(tomo.PatternButton)
|
||||
element.theme.
|
||||
Pattern(theme.PatternButton, state).
|
||||
Pattern(tomo.PatternButton, state).
|
||||
Draw(element.core, bounds)
|
||||
|
||||
// icon
|
||||
|
@ -209,8 +210,7 @@ func (element *File) drawAll () {
|
|||
}
|
||||
icon.Draw (
|
||||
element.core,
|
||||
element.theme.Color (
|
||||
theme.ColorForeground, state),
|
||||
element.theme.Color(tomo.ColorForeground, state),
|
||||
bounds.Min.Add(offset))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,10 +4,11 @@ import "time"
|
|||
import "math"
|
||||
import "image"
|
||||
import "image/color"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/config"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/artist/shapes"
|
||||
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.
|
||||
type AnalogClock struct {
|
||||
|
@ -22,7 +23,7 @@ type AnalogClock struct {
|
|||
// NewAnalogClock creates a new analog clock that displays the specified time.
|
||||
func NewAnalogClock (newTime time.Time) (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.SetMinimumSize(64, 64)
|
||||
return
|
||||
|
@ -36,14 +37,14 @@ func (element *AnalogClock) SetTime (newTime time.Time) {
|
|||
}
|
||||
|
||||
// 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 }
|
||||
element.theme.Theme = new
|
||||
element.redo()
|
||||
}
|
||||
|
||||
// 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 }
|
||||
element.config.Config = new
|
||||
element.redo()
|
||||
|
@ -59,15 +60,15 @@ func (element *AnalogClock) redo () {
|
|||
func (element *AnalogClock) draw () {
|
||||
bounds := element.Bounds()
|
||||
|
||||
state := theme.State { }
|
||||
pattern := element.theme.Pattern(theme.PatternSunken, state)
|
||||
padding := element.theme.Padding(theme.PatternSunken)
|
||||
state := tomo.State { }
|
||||
pattern := element.theme.Pattern(tomo.PatternSunken, state)
|
||||
padding := element.theme.Padding(tomo.PatternSunken)
|
||||
pattern.Draw(element.core, bounds)
|
||||
|
||||
bounds = padding.Apply(bounds)
|
||||
|
||||
foreground := element.theme.Color(theme.ColorForeground, state)
|
||||
accent := element.theme.Color(theme.ColorAccent, state)
|
||||
foreground := element.theme.Color(tomo.ColorForeground, state)
|
||||
accent := element.theme.Color(tomo.ColorAccent, state)
|
||||
|
||||
for hour := 0; hour < 12; hour ++ {
|
||||
element.radialLine (
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package fun
|
||||
|
||||
import "image"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
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/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"
|
||||
|
||||
const pianoKeyWidth = 18
|
||||
|
@ -52,7 +53,7 @@ func NewPiano (low, high music.Octave) (element *Piano) {
|
|||
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.recalculate()
|
||||
element.draw()
|
||||
|
@ -198,7 +199,7 @@ func (element *Piano) HandleKeyUp (key input.Key, modifiers input.Modifiers) {
|
|||
}
|
||||
|
||||
// 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 }
|
||||
element.theme.Theme = new
|
||||
element.updateMinimumSize()
|
||||
|
@ -207,7 +208,7 @@ func (element *Piano) SetTheme (new theme.Theme) {
|
|||
}
|
||||
|
||||
// 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 }
|
||||
element.config.Config = new
|
||||
element.updateMinimumSize()
|
||||
|
@ -216,7 +217,7 @@ func (element *Piano) SetConfig (new config.Config) {
|
|||
}
|
||||
|
||||
func (element *Piano) updateMinimumSize () {
|
||||
padding := element.theme.Padding(theme.PatternPinboard)
|
||||
padding := element.theme.Padding(tomo.PatternPinboard)
|
||||
element.core.SetMinimumSize (
|
||||
pianoKeyWidth * 7 * element.countOctaves() +
|
||||
padding.Horizontal(),
|
||||
|
@ -246,7 +247,7 @@ func (element *Piano) recalculate () {
|
|||
element.flatKeys = make([]pianoKey, element.countFlats())
|
||||
element.sharpKeys = make([]pianoKey, element.countSharps())
|
||||
|
||||
padding := element.theme.Padding(theme.PatternPinboard)
|
||||
padding := element.theme.Padding(tomo.PatternPinboard)
|
||||
bounds := padding.Apply(element.Bounds())
|
||||
|
||||
dot := bounds.Min
|
||||
|
@ -279,7 +280,7 @@ func (element *Piano) recalculate () {
|
|||
}
|
||||
|
||||
func (element *Piano) draw () {
|
||||
state := theme.State {
|
||||
state := tomo.State {
|
||||
Focused: element.Focused(),
|
||||
Disabled: !element.Enabled(),
|
||||
}
|
||||
|
@ -301,7 +302,7 @@ func (element *Piano) draw () {
|
|||
state)
|
||||
}
|
||||
|
||||
pattern := element.theme.Pattern(theme.PatternPinboard, state)
|
||||
pattern := element.theme.Pattern(tomo.PatternPinboard, state)
|
||||
artist.DrawShatter (
|
||||
element.core, pattern, element.Bounds(), element.contentBounds)
|
||||
}
|
||||
|
@ -309,21 +310,21 @@ func (element *Piano) draw () {
|
|||
func (element *Piano) drawFlat (
|
||||
bounds image.Rectangle,
|
||||
pressed bool,
|
||||
state theme.State,
|
||||
state tomo.State,
|
||||
) {
|
||||
state.Pressed = pressed
|
||||
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)
|
||||
}
|
||||
|
||||
func (element *Piano) drawSharp (
|
||||
bounds image.Rectangle,
|
||||
pressed bool,
|
||||
state theme.State,
|
||||
state tomo.State,
|
||||
) {
|
||||
state.Pressed = pressed
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -1,30 +1,31 @@
|
|||
package elements
|
||||
|
||||
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/default/theme"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
||||
|
||||
type Icon struct {
|
||||
*core.Core
|
||||
core core.CoreControl
|
||||
theme theme.Wrapped
|
||||
id theme.Icon
|
||||
size theme.IconSize
|
||||
id tomo.Icon
|
||||
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 {
|
||||
id: id,
|
||||
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.updateMinimumSize()
|
||||
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.size = size
|
||||
element.updateMinimumSize()
|
||||
|
@ -35,7 +36,7 @@ func (element *Icon) SetIcon (id theme.Icon, size theme.IconSize) {
|
|||
}
|
||||
|
||||
// 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 }
|
||||
element.theme.Theme = new
|
||||
element.updateMinimumSize()
|
||||
|
@ -61,9 +62,9 @@ func (element *Icon) updateMinimumSize () {
|
|||
|
||||
func (element *Icon) draw () {
|
||||
bounds := element.Bounds()
|
||||
state := theme.State { }
|
||||
state := tomo.State { }
|
||||
element.theme.
|
||||
Pattern(theme.PatternBackground, state).
|
||||
Pattern(tomo.PatternBackground, state).
|
||||
Draw(element.core, bounds)
|
||||
icon := element.icon()
|
||||
if icon != nil {
|
||||
|
@ -73,8 +74,7 @@ func (element *Icon) draw () {
|
|||
(bounds.Dy() - iconBounds.Dy()) / 2)
|
||||
icon.Draw (
|
||||
element.core,
|
||||
element.theme.Color (
|
||||
theme.ColorForeground, state),
|
||||
element.theme.Color(tomo.ColorForeground, state),
|
||||
bounds.Min.Add(offset))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
package elements
|
||||
|
||||
import "golang.org/x/image/math/fixed"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/config"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/textdraw"
|
||||
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.
|
||||
type Label struct {
|
||||
|
@ -29,8 +30,11 @@ type Label struct {
|
|||
// wrapped.
|
||||
func NewLabel (text string, wrap bool) (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.drawer.SetFace (element.theme.FontFace (
|
||||
tomo.FontStyleRegular,
|
||||
tomo.FontSizeNormal))
|
||||
element.SetWrap(wrap)
|
||||
element.SetText(text)
|
||||
return
|
||||
|
@ -38,8 +42,8 @@ func NewLabel (text string, wrap bool) (element *Label) {
|
|||
|
||||
func (element *Label) redo () {
|
||||
face := element.theme.FontFace (
|
||||
theme.FontStyleRegular,
|
||||
theme.FontSizeNormal)
|
||||
tomo.FontStyleRegular,
|
||||
tomo.FontSizeNormal)
|
||||
element.drawer.SetFace(face)
|
||||
element.updateMinimumSize()
|
||||
bounds := element.Bounds()
|
||||
|
@ -137,12 +141,12 @@ func (element *Label) SetAlign (align textdraw.Align) {
|
|||
}
|
||||
|
||||
// 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 }
|
||||
element.theme.Theme = new
|
||||
element.drawer.SetFace (element.theme.FontFace (
|
||||
theme.FontStyleRegular,
|
||||
theme.FontSizeNormal))
|
||||
tomo.FontStyleRegular,
|
||||
tomo.FontSizeNormal))
|
||||
element.updateMinimumSize()
|
||||
|
||||
if element.core.HasImage () {
|
||||
|
@ -152,7 +156,7 @@ func (element *Label) SetTheme (new theme.Theme) {
|
|||
}
|
||||
|
||||
// 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 }
|
||||
element.config.Config = new
|
||||
element.updateMinimumSize()
|
||||
|
@ -169,7 +173,7 @@ func (element *Label) updateMinimumSize () {
|
|||
if element.wrap {
|
||||
em := element.drawer.Em().Round()
|
||||
if em < 1 {
|
||||
em = element.theme.Padding(theme.PatternBackground)[0]
|
||||
em = element.theme.Padding(tomo.PatternBackground)[0]
|
||||
}
|
||||
width, height = em, element.drawer.LineHeight().Round()
|
||||
if element.onFlexibleHeightChange != nil {
|
||||
|
@ -199,14 +203,14 @@ func (element *Label) draw () {
|
|||
bounds := element.Bounds()
|
||||
|
||||
pattern := element.theme.Pattern (
|
||||
theme.PatternBackground,
|
||||
theme.State { })
|
||||
tomo.PatternBackground,
|
||||
tomo.State { })
|
||||
pattern.Draw(element.core, bounds)
|
||||
|
||||
textBounds := element.drawer.LayoutBounds()
|
||||
|
||||
foreground := element.theme.Color (
|
||||
theme.ColorForeground,
|
||||
theme.State { })
|
||||
tomo.ColorForeground,
|
||||
tomo.State { })
|
||||
element.drawer.Draw(element.core, foreground, bounds.Min.Sub(textBounds.Min))
|
||||
}
|
||||
|
|
|
@ -4,11 +4,11 @@ import "fmt"
|
|||
import "image"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
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/artist"
|
||||
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.
|
||||
type List struct {
|
||||
|
@ -37,7 +37,7 @@ type List struct {
|
|||
// NewList creates a new list element with the specified entries.
|
||||
func NewList (entries ...ListEntry) (element *List) {
|
||||
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.FocusableCore,
|
||||
element.focusableControl = core.NewFocusableCore (element.core, func () {
|
||||
|
@ -69,7 +69,7 @@ func (element *List) handleResize () {
|
|||
}
|
||||
|
||||
// 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 }
|
||||
element.theme.Theme = new
|
||||
for index, entry := range element.entries {
|
||||
|
@ -81,7 +81,7 @@ func (element *List) SetTheme (new theme.Theme) {
|
|||
}
|
||||
|
||||
// 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 }
|
||||
element.config.Config = new
|
||||
for index, entry := range element.entries {
|
||||
|
@ -214,7 +214,7 @@ func (element *List) ScrollAxes () (horizontal, vertical bool) {
|
|||
}
|
||||
|
||||
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]
|
||||
}
|
||||
|
||||
|
@ -358,7 +358,7 @@ func (element *List) Select (index int) {
|
|||
}
|
||||
|
||||
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())
|
||||
mousePoint := image.Pt(x, y)
|
||||
dot := image.Pt (
|
||||
|
@ -401,7 +401,7 @@ func (element *List) changeSelectionBy (delta int) (updated bool) {
|
|||
|
||||
func (element *List) resizeEntryToFit (entry ListEntry) (resized ListEntry) {
|
||||
bounds := element.Bounds()
|
||||
padding := element.theme.Padding(theme.PatternSunken)
|
||||
padding := element.theme.Padding(tomo.PatternSunken)
|
||||
entry.Resize(padding.Apply(bounds).Dx())
|
||||
return entry
|
||||
}
|
||||
|
@ -428,7 +428,7 @@ func (element *List) updateMinimumSize () {
|
|||
minimumHeight = element.contentHeight
|
||||
}
|
||||
|
||||
padding := element.theme.Padding(theme.PatternSunken)
|
||||
padding := element.theme.Padding(tomo.PatternSunken)
|
||||
minimumHeight += padding[0] + padding[2]
|
||||
|
||||
element.core.SetMinimumSize(minimumWidth, minimumHeight)
|
||||
|
@ -445,9 +445,9 @@ func (element *List) scrollBoundsChange () {
|
|||
|
||||
func (element *List) draw () {
|
||||
bounds := element.Bounds()
|
||||
padding := element.theme.Padding(theme.PatternSunken)
|
||||
padding := element.theme.Padding(tomo.PatternSunken)
|
||||
innerBounds := padding.Apply(bounds)
|
||||
state := theme.State {
|
||||
state := tomo.State {
|
||||
Disabled: !element.Enabled(),
|
||||
Focused: element.Focused(),
|
||||
}
|
||||
|
@ -471,7 +471,7 @@ func (element *List) draw () {
|
|||
0, 0,
|
||||
innerBounds.Dx(), element.contentHeight,
|
||||
).Add(innerBounds.Min).Intersect(innerBounds)
|
||||
pattern := element.theme.Pattern(theme.PatternSunken, state)
|
||||
pattern := element.theme.Pattern(tomo.PatternSunken, state)
|
||||
artist.DrawShatter (
|
||||
element.core, pattern, bounds, covered)
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package elements
|
||||
|
||||
import "image"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/config"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/canvas"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
||||
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.
|
||||
type ListEntry struct {
|
||||
|
@ -26,28 +27,31 @@ func NewListEntry (text string, onSelect func ()) (entry ListEntry) {
|
|||
text: text,
|
||||
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.updateBounds()
|
||||
return
|
||||
}
|
||||
|
||||
func (entry *ListEntry) SetTheme (new theme.Theme) {
|
||||
func (entry *ListEntry) SetTheme (new tomo.Theme) {
|
||||
if new == entry.theme.Theme { return }
|
||||
entry.theme.Theme = new
|
||||
entry.drawer.SetFace (entry.theme.FontFace (
|
||||
theme.FontStyleRegular,
|
||||
theme.FontSizeNormal))
|
||||
tomo.FontStyleRegular,
|
||||
tomo.FontSizeNormal))
|
||||
entry.updateBounds()
|
||||
}
|
||||
|
||||
func (entry *ListEntry) SetConfig (new config.Config) {
|
||||
func (entry *ListEntry) SetConfig (new tomo.Config) {
|
||||
if new == entry.config.Config { return }
|
||||
entry.config.Config = new
|
||||
}
|
||||
|
||||
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 = entry.bounds.Sub(entry.bounds.Min)
|
||||
entry.minimumWidth = entry.bounds.Dx()
|
||||
|
@ -62,17 +66,17 @@ func (entry *ListEntry) Draw (
|
|||
) (
|
||||
updatedRegion image.Rectangle,
|
||||
) {
|
||||
state := theme.State {
|
||||
state := tomo.State {
|
||||
Focused: focused,
|
||||
On: on,
|
||||
}
|
||||
|
||||
pattern := entry.theme.Pattern(theme.PatternRaised, state)
|
||||
padding := entry.theme.Padding(theme.PatternRaised)
|
||||
pattern := entry.theme.Pattern(tomo.PatternRaised, state)
|
||||
padding := entry.theme.Padding(tomo.PatternRaised)
|
||||
bounds := entry.Bounds().Add(offset)
|
||||
pattern.Draw(destination, bounds)
|
||||
|
||||
foreground := entry.theme.Color (theme.ColorForeground, state)
|
||||
foreground := entry.theme.Color (tomo.ColorForeground, state)
|
||||
return entry.drawer.Draw (
|
||||
destination,
|
||||
foreground,
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
package elements
|
||||
|
||||
import "image"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/config"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
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.
|
||||
type ProgressBar struct {
|
||||
|
@ -19,7 +20,7 @@ type ProgressBar struct {
|
|||
// level.
|
||||
func NewProgressBar (progress float64) (element *ProgressBar) {
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
@ -35,7 +36,7 @@ func (element *ProgressBar) SetProgress (progress float64) {
|
|||
}
|
||||
|
||||
// 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 }
|
||||
element.theme.Theme = new
|
||||
element.updateMinimumSize()
|
||||
|
@ -43,7 +44,7 @@ func (element *ProgressBar) SetTheme (new theme.Theme) {
|
|||
}
|
||||
|
||||
// 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 }
|
||||
element.config.Config = new
|
||||
element.updateMinimumSize()
|
||||
|
@ -51,8 +52,8 @@ func (element *ProgressBar) SetConfig (new config.Config) {
|
|||
}
|
||||
|
||||
func (element (ProgressBar)) updateMinimumSize() {
|
||||
padding := element.theme.Padding(theme.PatternSunken)
|
||||
innerPadding := element.theme.Padding(theme.PatternMercury)
|
||||
padding := element.theme.Padding(tomo.PatternSunken)
|
||||
innerPadding := element.theme.Padding(tomo.PatternMercury)
|
||||
element.core.SetMinimumSize (
|
||||
padding.Horizontal() + innerPadding.Horizontal(),
|
||||
padding.Vertical() + innerPadding.Vertical())
|
||||
|
@ -68,14 +69,14 @@ func (element *ProgressBar) redo () {
|
|||
func (element *ProgressBar) draw () {
|
||||
bounds := element.Bounds()
|
||||
|
||||
pattern := element.theme.Pattern(theme.PatternSunken, theme.State { })
|
||||
padding := element.theme.Padding(theme.PatternSunken)
|
||||
pattern := element.theme.Pattern(tomo.PatternSunken, tomo.State { })
|
||||
padding := element.theme.Padding(tomo.PatternSunken)
|
||||
pattern.Draw(element.core, bounds)
|
||||
bounds = padding.Apply(bounds)
|
||||
meterBounds := image.Rect (
|
||||
bounds.Min.X, bounds.Min.Y,
|
||||
bounds.Min.X + int(float64(bounds.Dx()) * element.progress),
|
||||
bounds.Max.Y)
|
||||
mercury := element.theme.Pattern(theme.PatternMercury, theme.State { })
|
||||
mercury := element.theme.Pattern(tomo.PatternMercury, tomo.State { })
|
||||
mercury.Draw(element.core, meterBounds)
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
package elements
|
||||
|
||||
import "image"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
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/default/theme"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/default/config"
|
||||
|
||||
// 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
|
||||
|
@ -45,9 +46,9 @@ func NewScrollBar (vertical bool) (element *ScrollBar) {
|
|||
enabled: true,
|
||||
}
|
||||
if vertical {
|
||||
element.theme.Case = theme.C("tomo", "scrollBarHorizontal")
|
||||
element.theme.Case = tomo.C("tomo", "scrollBarHorizontal")
|
||||
} 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.updateMinimumSize()
|
||||
|
@ -159,14 +160,14 @@ func (element *ScrollBar) OnScroll (callback func (viewport image.Point)) {
|
|||
}
|
||||
|
||||
// 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 }
|
||||
element.theme.Theme = new
|
||||
element.drawAndPush()
|
||||
}
|
||||
|
||||
// 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 }
|
||||
element.config.Config = new
|
||||
element.updateMinimumSize()
|
||||
|
@ -236,7 +237,7 @@ func (element *ScrollBar) recalculate () {
|
|||
|
||||
func (element *ScrollBar) recalculateVertical () {
|
||||
bounds := element.Bounds()
|
||||
padding := element.theme.Padding(theme.PatternGutter)
|
||||
padding := element.theme.Padding(tomo.PatternGutter)
|
||||
element.track = padding.Apply(bounds)
|
||||
|
||||
contentBounds := element.contentBounds
|
||||
|
@ -263,7 +264,7 @@ func (element *ScrollBar) recalculateVertical () {
|
|||
|
||||
func (element *ScrollBar) recalculateHorizontal () {
|
||||
bounds := element.Bounds()
|
||||
padding := element.theme.Padding(theme.PatternGutter)
|
||||
padding := element.theme.Padding(tomo.PatternGutter)
|
||||
element.track = padding.Apply(bounds)
|
||||
|
||||
contentBounds := element.contentBounds
|
||||
|
@ -289,7 +290,7 @@ func (element *ScrollBar) recalculateHorizontal () {
|
|||
}
|
||||
|
||||
func (element *ScrollBar) updateMinimumSize () {
|
||||
padding := element.theme.Padding(theme.PatternGutter)
|
||||
padding := element.theme.Padding(tomo.PatternGutter)
|
||||
if element.vertical {
|
||||
element.core.SetMinimumSize (
|
||||
padding.Horizontal() + element.config.HandleWidth(),
|
||||
|
@ -310,14 +311,14 @@ func (element *ScrollBar) drawAndPush () {
|
|||
|
||||
func (element *ScrollBar) draw () {
|
||||
bounds := element.Bounds()
|
||||
state := theme.State {
|
||||
state := tomo.State {
|
||||
Disabled: !element.Enabled(),
|
||||
Pressed: element.dragging,
|
||||
}
|
||||
element.theme.Pattern(theme.PatternGutter, state).Draw (
|
||||
element.theme.Pattern(tomo.PatternGutter, state).Draw (
|
||||
element.core,
|
||||
bounds)
|
||||
element.theme.Pattern(theme.PatternHandle, state).Draw (
|
||||
element.theme.Pattern(tomo.PatternHandle, state).Draw (
|
||||
element.core,
|
||||
element.bar)
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
package elements
|
||||
|
||||
import "image"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
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/default/theme"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/default/config"
|
||||
|
||||
// Slider is a slider control with a floating point value between zero and one.
|
||||
type Slider struct {
|
||||
|
@ -35,9 +36,9 @@ func NewSlider (value float64, vertical bool) (element *Slider) {
|
|||
vertical: vertical,
|
||||
}
|
||||
if vertical {
|
||||
element.theme.Case = theme.C("tomo", "sliderVertical")
|
||||
element.theme.Case = tomo.C("tomo", "sliderVertical")
|
||||
} 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.FocusableCore,
|
||||
|
@ -140,14 +141,14 @@ func (element *Slider) OnRelease (callback func ()) {
|
|||
}
|
||||
|
||||
// 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 }
|
||||
element.theme.Theme = new
|
||||
element.redo()
|
||||
}
|
||||
|
||||
// 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 }
|
||||
element.config.Config = new
|
||||
element.updateMinimumSize()
|
||||
|
@ -206,7 +207,7 @@ func (element *Slider) redo () {
|
|||
|
||||
func (element *Slider) draw () {
|
||||
bounds := element.Bounds()
|
||||
element.track = element.theme.Padding(theme.PatternGutter).Apply(bounds)
|
||||
element.track = element.theme.Padding(tomo.PatternGutter).Apply(bounds)
|
||||
if element.vertical {
|
||||
barSize := element.track.Dx()
|
||||
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))
|
||||
}
|
||||
|
||||
state := theme.State {
|
||||
state := tomo.State {
|
||||
Focused: element.Focused(),
|
||||
Disabled: !element.Enabled(),
|
||||
Pressed: element.dragging,
|
||||
}
|
||||
element.theme.Pattern(theme.PatternGutter, state).Draw (
|
||||
element.theme.Pattern(tomo.PatternGutter, state).Draw (
|
||||
element.core,
|
||||
bounds)
|
||||
element.theme.Pattern(theme.PatternHandle, state).Draw (
|
||||
element.theme.Pattern(tomo.PatternHandle, state).Draw (
|
||||
element.core,
|
||||
element.bar)
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package elements
|
||||
|
||||
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/config"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
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..
|
||||
type Spacer struct {
|
||||
|
@ -19,7 +20,7 @@ type Spacer struct {
|
|||
// will appear as a line.
|
||||
func NewSpacer (line bool) (element *Spacer) {
|
||||
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.updateMinimumSize()
|
||||
return
|
||||
|
@ -37,14 +38,14 @@ func (element *Spacer) SetLine (line bool) {
|
|||
}
|
||||
|
||||
// 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 }
|
||||
element.theme.Theme = new
|
||||
element.redo()
|
||||
}
|
||||
|
||||
// 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 }
|
||||
element.config.Config = new
|
||||
element.redo()
|
||||
|
@ -52,7 +53,7 @@ func (element *Spacer) SetConfig (new config.Config) {
|
|||
|
||||
func (element *Spacer) updateMinimumSize () {
|
||||
if element.line {
|
||||
padding := element.theme.Padding(theme.PatternLine)
|
||||
padding := element.theme.Padding(tomo.PatternLine)
|
||||
element.core.SetMinimumSize (
|
||||
padding.Horizontal(),
|
||||
padding.Vertical())
|
||||
|
@ -73,13 +74,13 @@ func (element *Spacer) draw () {
|
|||
|
||||
if element.line {
|
||||
pattern := element.theme.Pattern (
|
||||
theme.PatternLine,
|
||||
theme.State { })
|
||||
tomo.PatternLine,
|
||||
tomo.State { })
|
||||
pattern.Draw(element.core, bounds)
|
||||
} else {
|
||||
pattern := element.theme.Pattern (
|
||||
theme.PatternBackground,
|
||||
theme.State { })
|
||||
tomo.PatternBackground,
|
||||
tomo.State { })
|
||||
pattern.Draw(element.core, bounds)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package elements
|
||||
|
||||
import "image"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
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/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
|
||||
// functionally identical to Checkbox, but plays a different semantic role.
|
||||
|
@ -32,10 +33,13 @@ func NewSwitch (text string, on bool) (element *Switch) {
|
|||
checked: on,
|
||||
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.FocusableCore,
|
||||
element.focusableControl = core.NewFocusableCore(element.core, element.redo)
|
||||
element.drawer.SetFace (element.theme.FontFace (
|
||||
tomo.FontStyleRegular,
|
||||
tomo.FontSizeNormal))
|
||||
element.drawer.SetText([]rune(text))
|
||||
element.updateMinimumSize()
|
||||
return
|
||||
|
@ -111,18 +115,18 @@ func (element *Switch) SetText (text string) {
|
|||
}
|
||||
|
||||
// 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 }
|
||||
element.theme.Theme = new
|
||||
element.drawer.SetFace (element.theme.FontFace (
|
||||
theme.FontStyleRegular,
|
||||
theme.FontSizeNormal))
|
||||
tomo.FontStyleRegular,
|
||||
tomo.FontSizeNormal))
|
||||
element.updateMinimumSize()
|
||||
element.redo()
|
||||
}
|
||||
|
||||
// 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 }
|
||||
element.config.Config = new
|
||||
element.updateMinimumSize()
|
||||
|
@ -145,7 +149,7 @@ func (element *Switch) updateMinimumSize () {
|
|||
} else {
|
||||
element.core.SetMinimumSize (
|
||||
lineHeight * 2 +
|
||||
element.theme.Margin(theme.PatternBackground).X +
|
||||
element.theme.Margin(tomo.PatternBackground).X +
|
||||
textBounds.Dx(),
|
||||
lineHeight)
|
||||
}
|
||||
|
@ -156,13 +160,13 @@ func (element *Switch) draw () {
|
|||
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)
|
||||
|
||||
state := theme.State {
|
||||
state := tomo.State {
|
||||
Disabled: !element.Enabled(),
|
||||
Focused: element.Focused(),
|
||||
Pressed: element.pressed,
|
||||
}
|
||||
backgroundPattern := element.theme.Pattern (
|
||||
theme.PatternBackground, state)
|
||||
tomo.PatternBackground, state)
|
||||
backgroundPattern.Draw(element.core, bounds)
|
||||
|
||||
if element.checked {
|
||||
|
@ -180,23 +184,22 @@ func (element *Switch) draw () {
|
|||
}
|
||||
|
||||
gutterPattern := element.theme.Pattern (
|
||||
theme.PatternGutter, state)
|
||||
tomo.PatternGutter, state)
|
||||
gutterPattern.Draw(element.core, gutterBounds)
|
||||
|
||||
handlePattern := element.theme.Pattern (
|
||||
theme.PatternHandle, state)
|
||||
tomo.PatternHandle, state)
|
||||
handlePattern.Draw(element.core, handleBounds)
|
||||
|
||||
textBounds := element.drawer.LayoutBounds()
|
||||
offset := bounds.Min.Add(image.Point {
|
||||
X: bounds.Dy() * 2 +
|
||||
element.theme.Margin(theme.PatternBackground).X,
|
||||
element.theme.Margin(tomo.PatternBackground).X,
|
||||
})
|
||||
|
||||
offset.Y -= textBounds.Min.Y
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package testing
|
||||
|
||||
import "image"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
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/shapes"
|
||||
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
|
||||
// and dragged on it, it draws a trail.
|
||||
|
@ -16,28 +17,28 @@ type Mouse struct {
|
|||
drawing bool
|
||||
lastMousePos image.Point
|
||||
|
||||
config config.Config
|
||||
theme theme.Theme
|
||||
c theme.Case
|
||||
config config.Wrapped
|
||||
theme theme.Wrapped
|
||||
}
|
||||
|
||||
// NewMouse creates a new mouse test element.
|
||||
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.SetMinimumSize(32, 32)
|
||||
return
|
||||
}
|
||||
|
||||
// SetTheme sets the element's theme.
|
||||
func (element *Mouse) SetTheme (new theme.Theme) {
|
||||
element.theme = new
|
||||
func (element *Mouse) SetTheme (new tomo.Theme) {
|
||||
element.theme.Theme = new
|
||||
element.redo()
|
||||
}
|
||||
|
||||
// SetConfig sets the element's configuration.
|
||||
func (element *Mouse) SetConfig (new config.Config) {
|
||||
element.config = new
|
||||
func (element *Mouse) SetConfig (new tomo.Config) {
|
||||
element.config.Config = new
|
||||
element.redo()
|
||||
}
|
||||
|
||||
|
@ -50,9 +51,8 @@ func (element *Mouse) redo () {
|
|||
func (element *Mouse) draw () {
|
||||
bounds := element.Bounds()
|
||||
accent := element.theme.Color (
|
||||
theme.ColorAccent,
|
||||
theme.State { },
|
||||
element.c)
|
||||
tomo.ColorAccent,
|
||||
tomo.State { })
|
||||
shapes.FillColorRectangle(element.core, accent, bounds)
|
||||
shapes.StrokeColorRectangle (
|
||||
element.core,
|
||||
|
|
|
@ -3,8 +3,6 @@ package elements
|
|||
import "image"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
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/canvas"
|
||||
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/artist/shapes"
|
||||
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.
|
||||
type TextBox struct {
|
||||
|
@ -43,7 +43,7 @@ type TextBox struct {
|
|||
// text.
|
||||
func NewTextBox (placeholder, value string) (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.FocusableCore,
|
||||
element.focusableControl = core.NewFocusableCore (element.core, func () {
|
||||
|
@ -53,6 +53,12 @@ func NewTextBox (placeholder, value string) (element *TextBox) {
|
|||
}
|
||||
})
|
||||
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.updateMinimumSize()
|
||||
element.SetValue(value)
|
||||
|
@ -94,7 +100,7 @@ func (element *TextBox) HandleMotion (x, y int) {
|
|||
}
|
||||
|
||||
func (element *TextBox) textOffset () image.Point {
|
||||
padding := element.theme.Padding(theme.PatternInput)
|
||||
padding := element.theme.Padding(tomo.PatternInput)
|
||||
bounds := element.Bounds()
|
||||
innerBounds := padding.Apply(bounds)
|
||||
textHeight := element.valueDrawer.LineHeight().Round()
|
||||
|
@ -277,7 +283,7 @@ func (element *TextBox) ScrollViewportBounds () (bounds image.Rectangle) {
|
|||
}
|
||||
|
||||
func (element *TextBox) scrollViewportWidth () (width int) {
|
||||
padding := element.theme.Padding(theme.PatternInput)
|
||||
padding := element.theme.Padding(tomo.PatternInput)
|
||||
return padding.Apply(element.Bounds()).Dx()
|
||||
}
|
||||
|
||||
|
@ -313,7 +319,7 @@ func (element *TextBox) runOnChange () {
|
|||
func (element *TextBox) scrollToCursor () {
|
||||
if !element.core.HasImage() { return }
|
||||
|
||||
padding := element.theme.Padding(theme.PatternInput)
|
||||
padding := element.theme.Padding(tomo.PatternInput)
|
||||
bounds := padding.Apply(element.Bounds())
|
||||
bounds = bounds.Sub(bounds.Min)
|
||||
bounds.Max.X -= element.valueDrawer.Em().Round()
|
||||
|
@ -331,12 +337,12 @@ func (element *TextBox) scrollToCursor () {
|
|||
}
|
||||
|
||||
// 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 }
|
||||
element.theme.Theme = new
|
||||
face := element.theme.FontFace (
|
||||
theme.FontStyleRegular,
|
||||
theme.FontSizeNormal)
|
||||
tomo.FontStyleRegular,
|
||||
tomo.FontSizeNormal)
|
||||
element.placeholderDrawer.SetFace(face)
|
||||
element.valueDrawer.SetFace(face)
|
||||
element.updateMinimumSize()
|
||||
|
@ -344,7 +350,7 @@ func (element *TextBox) SetTheme (new theme.Theme) {
|
|||
}
|
||||
|
||||
// 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 }
|
||||
element.config.Config = new
|
||||
element.updateMinimumSize()
|
||||
|
@ -353,7 +359,7 @@ func (element *TextBox) SetConfig (new config.Config) {
|
|||
|
||||
func (element *TextBox) updateMinimumSize () {
|
||||
textBounds := element.placeholderDrawer.LayoutBounds()
|
||||
padding := element.theme.Padding(theme.PatternInput)
|
||||
padding := element.theme.Padding(tomo.PatternInput)
|
||||
element.core.SetMinimumSize (
|
||||
padding.Horizontal() + textBounds.Dx(),
|
||||
padding.Vertical() +
|
||||
|
@ -370,19 +376,19 @@ func (element *TextBox) redo () {
|
|||
func (element *TextBox) draw () {
|
||||
bounds := element.Bounds()
|
||||
|
||||
state := theme.State {
|
||||
state := tomo.State {
|
||||
Disabled: !element.Enabled(),
|
||||
Focused: element.Focused(),
|
||||
}
|
||||
pattern := element.theme.Pattern(theme.PatternInput, state)
|
||||
padding := element.theme.Padding(theme.PatternInput)
|
||||
pattern := element.theme.Pattern(tomo.PatternInput, state)
|
||||
padding := element.theme.Padding(tomo.PatternInput)
|
||||
innerCanvas := canvas.Cut(element.core, padding.Apply(bounds))
|
||||
pattern.Draw(element.core, bounds)
|
||||
offset := element.textOffset()
|
||||
|
||||
if element.Focused() && !element.dot.Empty() {
|
||||
// draw selection bounds
|
||||
accent := element.theme.Color(theme.ColorAccent, state)
|
||||
accent := element.theme.Color(tomo.ColorAccent, state)
|
||||
canon := element.dot.Canon()
|
||||
foff := fixedutil.Pt(offset)
|
||||
start := element.valueDrawer.PositionAt(canon.Start).Add(foff)
|
||||
|
@ -401,8 +407,8 @@ func (element *TextBox) draw () {
|
|||
// draw placeholder
|
||||
textBounds := element.placeholderDrawer.LayoutBounds()
|
||||
foreground := element.theme.Color (
|
||||
theme.ColorForeground,
|
||||
theme.State { Disabled: true })
|
||||
tomo.ColorForeground,
|
||||
tomo.State { Disabled: true })
|
||||
element.placeholderDrawer.Draw (
|
||||
innerCanvas,
|
||||
foreground,
|
||||
|
@ -410,7 +416,7 @@ func (element *TextBox) draw () {
|
|||
} else {
|
||||
// draw input value
|
||||
textBounds := element.valueDrawer.LayoutBounds()
|
||||
foreground := element.theme.Color(theme.ColorForeground, state)
|
||||
foreground := element.theme.Color(tomo.ColorForeground, state)
|
||||
element.valueDrawer.Draw (
|
||||
innerCanvas,
|
||||
foreground,
|
||||
|
@ -419,7 +425,7 @@ func (element *TextBox) draw () {
|
|||
|
||||
if element.Focused() && element.dot.Empty() {
|
||||
// draw cursor
|
||||
foreground := element.theme.Color(theme.ColorForeground, state)
|
||||
foreground := element.theme.Color(tomo.ColorForeground, state)
|
||||
cursorPosition := fixedutil.RoundPt (
|
||||
element.valueDrawer.PositionAt(element.dot.End))
|
||||
shapes.ColorLine (
|
||||
|
|
|
@ -7,7 +7,6 @@ import _ "image/gif"
|
|||
import _ "image/jpeg"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
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/layouts"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/elements"
|
||||
|
@ -32,11 +31,11 @@ func run () {
|
|||
textInput := elements.NewTextBox("", "")
|
||||
controlRow := containers.NewContainer(layouts.Horizontal { true, false })
|
||||
copyButton := elements.NewButton("Copy")
|
||||
copyButton.SetIcon(theme.IconCopy)
|
||||
copyButton.SetIcon(tomo.IconCopy)
|
||||
pasteButton := elements.NewButton("Paste")
|
||||
pasteButton.SetIcon(theme.IconPaste)
|
||||
pasteButton.SetIcon(tomo.IconPaste)
|
||||
pasteImageButton := elements.NewButton("Image")
|
||||
pasteImageButton.SetIcon(theme.IconPictures)
|
||||
pasteImageButton.SetIcon(tomo.IconPictures)
|
||||
|
||||
imageClipboardCallback := func (clipboard data.Data, err error) {
|
||||
if err != nil {
|
||||
|
@ -126,7 +125,7 @@ func imageWindow (image image.Image) {
|
|||
window.SetTitle("Clipboard Image")
|
||||
container := containers.NewContainer(layouts.Vertical { true, true })
|
||||
closeButton := elements.NewButton("Ok")
|
||||
closeButton.SetIcon(theme.IconYes)
|
||||
closeButton.SetIcon(tomo.IconYes)
|
||||
closeButton.OnClick(window.Close)
|
||||
|
||||
container.Adopt(elements.NewImage(image), true)
|
||||
|
|
|
@ -3,7 +3,6 @@ package main
|
|||
import "os"
|
||||
import "path/filepath"
|
||||
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/elements"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/elements/file"
|
||||
|
@ -17,28 +16,28 @@ func main () {
|
|||
func run () {
|
||||
window, _ := tomo.NewWindow(384, 384)
|
||||
window.SetTitle("File browser")
|
||||
container := containers.NewContainer(basicLayouts.Vertical { true, true })
|
||||
container := containers.NewContainer(layouts.Vertical { true, true })
|
||||
window.Adopt(container)
|
||||
homeDir, _ := os.UserHomeDir()
|
||||
|
||||
controlBar := containers.NewContainer(basicLayouts.Horizontal { })
|
||||
backButton := basicElements.NewButton("Back")
|
||||
backButton.SetIcon(theme.IconBackward)
|
||||
controlBar := containers.NewContainer(layouts.Horizontal { })
|
||||
backButton := elements.NewButton("Back")
|
||||
backButton.SetIcon(tomo.IconBackward)
|
||||
backButton.ShowText(false)
|
||||
forwardButton := basicElements.NewButton("Forward")
|
||||
forwardButton.SetIcon(theme.IconForward)
|
||||
forwardButton := elements.NewButton("Forward")
|
||||
forwardButton.SetIcon(tomo.IconForward)
|
||||
forwardButton.ShowText(false)
|
||||
refreshButton := basicElements.NewButton("Refresh")
|
||||
refreshButton.SetIcon(theme.IconRefresh)
|
||||
refreshButton := elements.NewButton("Refresh")
|
||||
refreshButton.SetIcon(tomo.IconRefresh)
|
||||
refreshButton.ShowText(false)
|
||||
upwardButton := basicElements.NewButton("Go Up")
|
||||
upwardButton.SetIcon(theme.IconUpward)
|
||||
upwardButton := elements.NewButton("Go Up")
|
||||
upwardButton.SetIcon(tomo.IconUpward)
|
||||
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)
|
||||
baseName := basicElements.NewLabel(filepath.Base(homeDir), false)
|
||||
baseName := elements.NewLabel(filepath.Base(homeDir), false)
|
||||
|
||||
scrollContainer := containers.NewScrollContainer(false, true)
|
||||
directoryView, _ := fileElements.NewDirectory(homeDir, nil)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package popups
|
||||
|
||||
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/elements"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
|
||||
|
@ -47,21 +46,21 @@ func NewDialog (
|
|||
window.Adopt(container)
|
||||
|
||||
messageContainer := containers.NewContainer(layouts.Horizontal { true, false })
|
||||
iconId := theme.IconInformation
|
||||
iconId := tomo.IconInformation
|
||||
switch kind {
|
||||
case DialogKindInfo: iconId = theme.IconInformation
|
||||
case DialogKindQuestion: iconId = theme.IconQuestion
|
||||
case DialogKindWarning: iconId = theme.IconWarning
|
||||
case DialogKindError: iconId = theme.IconError
|
||||
case DialogKindInfo: iconId = tomo.IconInformation
|
||||
case DialogKindQuestion: iconId = tomo.IconQuestion
|
||||
case DialogKindWarning: iconId = tomo.IconWarning
|
||||
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)
|
||||
container.Adopt(messageContainer, true)
|
||||
|
||||
if len(buttons) == 0 {
|
||||
button := elements.NewButton("OK")
|
||||
button.SetIcon(theme.IconYes)
|
||||
button.SetIcon(tomo.IconYes)
|
||||
button.OnClick(window.Close)
|
||||
container.Adopt(button, false)
|
||||
button.Focus()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package theme
|
||||
package tomo
|
||||
|
||||
import "image"
|
||||
import "image/color"
|
||||
|
@ -240,3 +240,110 @@ type Theme interface {
|
|||
// performance.
|
||||
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
|
||||
)
|
|
@ -1,2 +0,0 @@
|
|||
// Package theme implements a theming system for tomo.
|
||||
package theme
|
|
@ -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 { }
|
||||
}
|
108
theme/state.go
108
theme/state.go
|
@ -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
|
||||
)
|
7
tomo.go
7
tomo.go
|
@ -1,8 +1,5 @@
|
|||
package tomo
|
||||
|
||||
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/config"
|
||||
|
||||
var backend Backend
|
||||
|
||||
// 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.
|
||||
func SetTheme (theme theme.Theme) {
|
||||
func SetTheme (theme Theme) {
|
||||
backend.SetTheme(theme)
|
||||
}
|
||||
|
||||
// SetConfig sets the configuration of all open windows.
|
||||
func SetConfig (config config.Config) {
|
||||
func SetConfig (config Config) {
|
||||
backend.SetConfig(config)
|
||||
}
|
||||
|
||||
|
|
Reference in New Issue