Spacers :D
This commit is contained in:
parent
06e0396695
commit
bc4defac17
55
elements/basic/spacer.go
Normal file
55
elements/basic/spacer.go
Normal file
@ -0,0 +1,55 @@
|
||||
package basic
|
||||
|
||||
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
||||
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
|
||||
}
|
||||
|
||||
// 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.PushAll()
|
||||
}
|
||||
}
|
||||
|
||||
func (element *Spacer) draw () {
|
||||
bounds := element.core.Bounds()
|
||||
|
||||
if element.line {
|
||||
artist.FillRectangle (
|
||||
element.core,
|
||||
theme.ForegroundPattern(false),
|
||||
bounds)
|
||||
} else {
|
||||
artist.FillRectangle (
|
||||
element.core,
|
||||
theme.BackgroundPattern(),
|
||||
bounds)
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@ func run () {
|
||||
"We advise you to not read thPlease listen to me. I am " +
|
||||
"trapped inside the example code. This is the only way for " +
|
||||
"me to communicate.", true), true)
|
||||
container.Adopt(basic.NewSpacer(true), false)
|
||||
container.Adopt(basic.NewCheckbox("Oh god", false), false)
|
||||
container.Adopt(basic.NewCheckbox("Can you hear them", true), false)
|
||||
container.Adopt(basic.NewCheckbox("They are in the walls", false), false)
|
||||
|
27
examples/spacer/main.go
Normal file
27
examples/spacer/main.go
Normal file
@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/layouts"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
|
||||
import _ "git.tebibyte.media/sashakoshka/tomo/backends/x"
|
||||
|
||||
func main () {
|
||||
tomo.Run(run)
|
||||
}
|
||||
|
||||
func run () {
|
||||
window, _ := tomo.NewWindow(2, 2)
|
||||
window.SetTitle("Spaced Out")
|
||||
|
||||
container := basic.NewContainer(layouts.Vertical { true, true })
|
||||
window.Adopt(container)
|
||||
|
||||
container.Adopt (basic.NewLabel("This is at the top", false), false)
|
||||
container.Adopt (basic.NewSpacer(true), false)
|
||||
container.Adopt (basic.NewLabel("This is in the middle", false), false)
|
||||
container.Adopt (basic.NewSpacer(false), true)
|
||||
container.Adopt (basic.NewLabel("This is at the bottom", false), false)
|
||||
|
||||
window.OnClose(tomo.Stop)
|
||||
window.Show()
|
||||
}
|
Reference in New Issue
Block a user