2023-01-17 15:01:35 -07:00
|
|
|
package basic
|
|
|
|
|
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
|
|
|
|
2023-01-29 23:30:13 -07:00
|
|
|
var spacerCase = theme.C("basic", "spacer")
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
element = &Spacer { line: line }
|
|
|
|
element.Core, element.core = core.NewCore(element)
|
|
|
|
element.core.SetMinimumSize(1, 1)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resize resizes the label and re-wraps the text if wrapping is enabled.
|
|
|
|
func (element *Spacer) Resize (width, height int) {
|
|
|
|
element.core.AllocateCanvas(width, height)
|
|
|
|
element.draw()
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (element *Spacer) draw () {
|
|
|
|
bounds := element.core.Bounds()
|
|
|
|
|
|
|
|
if element.line {
|
2023-01-28 23:49:01 -07:00
|
|
|
pattern, _ := theme.ForegroundPattern(theme.PatternState {
|
2023-01-29 23:30:13 -07:00
|
|
|
Case: spacerCase,
|
2023-01-28 23:49:01 -07:00
|
|
|
Disabled: true,
|
|
|
|
})
|
|
|
|
artist.FillRectangle(element.core, pattern, bounds)
|
2023-01-17 15:01:35 -07:00
|
|
|
} else {
|
2023-01-28 23:49:01 -07:00
|
|
|
pattern, _ := theme.BackgroundPattern(theme.PatternState {
|
2023-01-29 23:30:13 -07:00
|
|
|
Case: spacerCase,
|
2023-01-28 23:49:01 -07:00
|
|
|
Disabled: true,
|
|
|
|
})
|
|
|
|
artist.FillRectangle(element.core, pattern, bounds)
|
2023-01-17 15:01:35 -07:00
|
|
|
}
|
|
|
|
}
|