I am going insane
This commit is contained in:
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user