2023-02-01 23:48:16 -07:00
|
|
|
package basicElements
|
2023-01-17 15:01:35 -07:00
|
|
|
|
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
2023-02-07 22:22:40 -07:00
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/config"
|
2023-01-17 15:01:35 -07:00
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
theme theme.Theme
|
|
|
|
config config.Config
|
|
|
|
c theme.Case
|
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-07 22:22:40 -07:00
|
|
|
element = &Spacer { line: line, c: theme.C("basic", "spacer") }
|
2023-01-31 12:54:43 -07:00
|
|
|
element.Core, element.core = core.NewCore(element.draw)
|
2023-01-17 15:01:35 -07:00
|
|
|
element.core.SetMinimumSize(1, 1)
|
|
|
|
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
|
|
|
|
if element.core.HasImage() {
|
|
|
|
element.draw()
|
2023-01-19 14:49:34 -07:00
|
|
|
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.
|
|
|
|
func (element *Spacer) SetTheme (new theme.Theme) {
|
|
|
|
element.theme = new
|
|
|
|
element.redo()
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetConfig sets the element's configuration.
|
|
|
|
func (element *Spacer) SetConfig (new config.Config) {
|
|
|
|
element.config = new
|
|
|
|
element.redo()
|
|
|
|
}
|
|
|
|
|
|
|
|
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 () {
|
2023-01-31 14:18:10 -07:00
|
|
|
bounds := element.Bounds()
|
2023-01-17 15:01:35 -07:00
|
|
|
|
|
|
|
if element.line {
|
2023-02-07 22:22:40 -07:00
|
|
|
pattern := element.theme.Pattern (
|
|
|
|
theme.PatternForeground,
|
|
|
|
element.c,
|
|
|
|
theme.PatternState { })
|
2023-01-31 14:18:10 -07:00
|
|
|
artist.FillRectangle(element, pattern, bounds)
|
2023-01-17 15:01:35 -07:00
|
|
|
} else {
|
2023-02-07 22:22:40 -07:00
|
|
|
pattern := element.theme.Pattern (
|
|
|
|
theme.PatternBackground,
|
|
|
|
element.c,
|
|
|
|
theme.PatternState { })
|
2023-01-31 14:18:10 -07:00
|
|
|
artist.FillRectangle(element, pattern, bounds)
|
2023-01-17 15:01:35 -07:00
|
|
|
}
|
|
|
|
}
|