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-04-14 23:45:11 -06:00
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/canvas"
|
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 {
|
2023-04-14 23:45:11 -06:00
|
|
|
entity tomo.Entity
|
|
|
|
|
2023-01-17 15:01:35 -07:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-04-18 11:14:10 -06:00
|
|
|
// NewSpacer creates a new spacer.
|
|
|
|
func NewSpacer () (element *Spacer) {
|
|
|
|
element = &Spacer { }
|
2023-04-14 23:45:11 -06:00
|
|
|
element.entity = tomo.NewEntity(element)
|
2023-03-30 23:06:29 -06:00
|
|
|
element.theme.Case = tomo.C("tomo", "spacer")
|
2023-02-27 22:17:05 -07:00
|
|
|
element.updateMinimumSize()
|
2023-01-17 15:01:35 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-04-18 11:14:10 -06:00
|
|
|
// NewLine creates a new line separator.
|
|
|
|
func NewLine () (element *Spacer) {
|
|
|
|
element = NewSpacer()
|
|
|
|
element.SetLine(true)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-04-14 23:45:11 -06:00
|
|
|
// Entity returns this element's entity.
|
|
|
|
func (element *Spacer) Entity () tomo.Entity {
|
|
|
|
return element.entity
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw causes the element to draw to the specified destination canvas.
|
|
|
|
func (element *Spacer) Draw (destination canvas.Canvas) {
|
|
|
|
bounds := element.entity.Bounds()
|
|
|
|
|
|
|
|
if element.line {
|
|
|
|
pattern := element.theme.Pattern (
|
|
|
|
tomo.PatternLine,
|
|
|
|
tomo.State { })
|
|
|
|
pattern.Draw(destination, bounds)
|
|
|
|
} else {
|
|
|
|
pattern := element.theme.Pattern (
|
|
|
|
tomo.PatternBackground,
|
|
|
|
tomo.State { })
|
|
|
|
pattern.Draw(destination, bounds)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-17 15:01:35 -07:00
|
|
|
/// 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
|
2023-02-27 22:17:05 -07:00
|
|
|
element.updateMinimumSize()
|
2023-04-14 23:45:11 -06:00
|
|
|
element.entity.Invalidate()
|
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-04-14 23:45:11 -06:00
|
|
|
element.entity.Invalidate()
|
2023-02-07 22:22:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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-04-14 23:45:11 -06:00
|
|
|
element.entity.Invalidate()
|
2023-02-07 22:22:40 -07:00
|
|
|
}
|
|
|
|
|
2023-02-27 22:17:05 -07:00
|
|
|
func (element *Spacer) updateMinimumSize () {
|
|
|
|
if element.line {
|
2023-03-30 23:06:29 -06:00
|
|
|
padding := element.theme.Padding(tomo.PatternLine)
|
2023-04-14 23:45:11 -06:00
|
|
|
element.entity.SetMinimumSize (
|
2023-02-27 22:17:05 -07:00
|
|
|
padding.Horizontal(),
|
|
|
|
padding.Vertical())
|
|
|
|
} else {
|
2023-04-14 23:45:11 -06:00
|
|
|
element.entity.SetMinimumSize(1, 1)
|
2023-01-17 15:01:35 -07:00
|
|
|
}
|
|
|
|
}
|