This repository has been archived on 2023-08-08. You can view files and clone it, but cannot push or open issues or pull requests.
tomo-old/elements/spacer.go

87 lines
2.1 KiB
Go
Raw Normal View History

2023-03-30 21:19:04 -06:00
package elements
2023-01-17 15:01:35 -07:00
2023-03-30 23:06:29 -06:00
import "git.tebibyte.media/sashakoshka/tomo"
2023-01-17 15:01:35 -07:00
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
2023-03-30 23:06:29 -06:00
import "git.tebibyte.media/sashakoshka/tomo/default/theme"
import "git.tebibyte.media/sashakoshka/tomo/default/config"
2023-01-17 15:01:35 -07:00
// Spacer can be used to put space between two elements..
type Spacer struct {
*core.Core
core core.CoreControl
line bool
2023-02-07 22:22:40 -07:00
2023-02-08 12:36:14 -07:00
config config.Wrapped
theme theme.Wrapped
2023-01-17 15:01:35 -07:00
}
// NewSpacer creates a new spacer. If line is set to true, the spacer will be
// filled with a line color, and if compressed to its minimum width or height,
// will appear as a line.
func NewSpacer (line bool) (element *Spacer) {
2023-02-08 12:36:14 -07:00
element = &Spacer { line: line }
2023-03-30 23:06:29 -06:00
element.theme.Case = tomo.C("tomo", "spacer")
2023-03-14 23:41:23 -06:00
element.Core, element.core = core.NewCore(element, element.draw)
element.updateMinimumSize()
2023-01-17 15:01:35 -07:00
return
}
/// SetLine sets whether or not the spacer will appear as a colored line.
func (element *Spacer) SetLine (line bool) {
if element.line == line { return }
element.line = line
element.updateMinimumSize()
2023-01-17 15:01:35 -07:00
if element.core.HasImage() {
element.draw()
element.core.DamageAll()
2023-01-17 15:01:35 -07:00
}
}
2023-02-07 22:22:40 -07:00
// SetTheme sets the element's theme.
2023-03-30 23:06:29 -06:00
func (element *Spacer) SetTheme (new tomo.Theme) {
2023-02-08 12:36:14 -07:00
if new == element.theme.Theme { return }
element.theme.Theme = new
2023-02-07 22:22:40 -07:00
element.redo()
}
// SetConfig sets the element's configuration.
2023-03-30 23:06:29 -06:00
func (element *Spacer) SetConfig (new tomo.Config) {
2023-02-08 12:36:14 -07:00
if new == element.config.Config { return }
element.config.Config = new
2023-02-07 22:22:40 -07:00
element.redo()
}
func (element *Spacer) updateMinimumSize () {
if element.line {
2023-03-30 23:06:29 -06:00
padding := element.theme.Padding(tomo.PatternLine)
element.core.SetMinimumSize (
padding.Horizontal(),
padding.Vertical())
} else {
element.core.SetMinimumSize(1, 1)
}
}
2023-02-07 22:22:40 -07:00
func (element *Spacer) redo () {
if !element.core.HasImage() {
element.draw()
element.core.DamageAll()
}
}
2023-01-17 15:01:35 -07:00
func (element *Spacer) draw () {
bounds := element.Bounds()
2023-01-17 15:01:35 -07:00
if element.line {
pattern := element.theme.Pattern (
2023-03-30 23:06:29 -06:00
tomo.PatternLine,
tomo.State { })
pattern.Draw(element.core, bounds)
2023-01-17 15:01:35 -07:00
} else {
2023-02-07 22:22:40 -07:00
pattern := element.theme.Pattern (
2023-03-30 23:06:29 -06:00
tomo.PatternBackground,
tomo.State { })
2023-02-26 20:20:17 -07:00
pattern.Draw(element.core, bounds)
2023-01-17 15:01:35 -07:00
}
}