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/basic/spacer.go
Sasha Koshka 174beba79f Added a case specifier to the theme API
This will allow themes to pull off some cool dirty tricks without
screwing anything up
2023-01-30 01:30:13 -05:00

60 lines
1.5 KiB
Go

package basic
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/artist"
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
var spacerCase = theme.C("basic", "spacer")
// 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()
element.core.DamageAll()
}
}
func (element *Spacer) draw () {
bounds := element.core.Bounds()
if element.line {
pattern, _ := theme.ForegroundPattern(theme.PatternState {
Case: spacerCase,
Disabled: true,
})
artist.FillRectangle(element.core, pattern, bounds)
} else {
pattern, _ := theme.BackgroundPattern(theme.PatternState {
Case: spacerCase,
Disabled: true,
})
artist.FillRectangle(element.core, pattern, bounds)
}
}