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

82 lines
2.0 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-05-02 20:19:29 -06:00
import "git.tebibyte.media/sashakoshka/tomo/artist"
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
}
// NewSpacer creates a new spacer.
func NewSpacer () (element *Spacer) {
element = &Spacer { }
2023-05-02 20:19:29 -06:00
element.entity = tomo.NewEntity(element).(spacerEntity)
2023-03-30 23:06:29 -06:00
element.theme.Case = tomo.C("tomo", "spacer")
element.updateMinimumSize()
2023-01-17 15:01:35 -07:00
return
}
// 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.
2023-05-02 20:19:29 -06:00
func (element *Spacer) Draw (destination artist.Canvas) {
2023-04-14 23:45:11 -06:00
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
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
}
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 (
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
}
}