Moved containers into a separate package

This commit is contained in:
Sasha Koshka 2023-03-16 14:22:56 -04:00
parent c55925d152
commit a4ef28cdd0
22 changed files with 65 additions and 45 deletions

View File

@ -1,4 +1,4 @@
package basicElements
package containers
import "image"
import "git.tebibyte.media/sashakoshka/tomo/input"
@ -31,7 +31,7 @@ type Container struct {
// NewContainer creates a new container.
func NewContainer (layout layouts.Layout) (element *Container) {
element = &Container { }
element.theme.Case = theme.C("basic", "container")
element.theme.Case = theme.C("containers", "container")
element.Core, element.core = core.NewCore(element, element.redoAll)
element.Propagator = core.NewPropagator(element, element.core)
element.SetLayout(layout)

View File

@ -1,4 +1,4 @@
package basicElements
package containers
import "image"
import "git.tebibyte.media/sashakoshka/tomo/theme"
@ -28,7 +28,7 @@ type DocumentContainer struct {
// NewDocumentContainer creates a new document container.
func NewDocumentContainer () (element *DocumentContainer) {
element = &DocumentContainer { }
element.theme.Case = theme.C("basic", "documentContainer")
element.theme.Case = theme.C("containers", "documentContainer")
element.Core, element.core = core.NewCore(element, element.redoAll)
element.Propagator = core.NewPropagator(element, element.core)
return

View File

@ -1,4 +1,4 @@
package basicElements
package containers
import "image"
import "git.tebibyte.media/sashakoshka/tomo/input"
@ -7,6 +7,7 @@ import "git.tebibyte.media/sashakoshka/tomo/config"
import "git.tebibyte.media/sashakoshka/tomo/canvas"
import "git.tebibyte.media/sashakoshka/tomo/elements"
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
// ScrollContainer is a container that is capable of holding a scrollable
// element.
@ -16,8 +17,8 @@ type ScrollContainer struct {
core core.CoreControl
child elements.Scrollable
horizontal *ScrollBar
vertical *ScrollBar
horizontal *basicElements.ScrollBar
vertical *basicElements.ScrollBar
config config.Wrapped
theme theme.Wrapped
@ -30,12 +31,12 @@ type ScrollContainer struct {
// bars.
func NewScrollContainer (horizontal, vertical bool) (element *ScrollContainer) {
element = &ScrollContainer { }
element.theme.Case = theme.C("basic", "scrollContainer")
element.theme.Case = theme.C("containers", "scrollContainer")
element.Core, element.core = core.NewCore(element, element.redoAll)
element.Propagator = core.NewPropagator(element, element.core)
if horizontal {
element.horizontal = NewScrollBar(false)
element.horizontal = basicElements.NewScrollBar(false)
element.setUpChild(element.horizontal)
element.horizontal.OnScroll (func (viewport image.Point) {
if element.child != nil {
@ -49,7 +50,7 @@ func NewScrollContainer (horizontal, vertical bool) (element *ScrollContainer) {
})
}
if vertical {
element.vertical = NewScrollBar(true)
element.vertical = basicElements.NewScrollBar(true)
element.setUpChild(element.vertical)
element.vertical.OnScroll (func (viewport image.Point) {
if element.child != nil {

View File

@ -4,6 +4,7 @@ import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/popups"
import "git.tebibyte.media/sashakoshka/tomo/layouts/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
func main () {
@ -14,7 +15,7 @@ func run () {
window, _ := tomo.NewWindow(2, 2)
window.SetTitle("Checkboxes")
container := basicElements.NewContainer(basicLayouts.Vertical { true, true })
container := containers.NewContainer(basicLayouts.Vertical { true, true })
window.Adopt(container)
container.Adopt (basicElements.NewLabel (

View File

@ -4,6 +4,7 @@ import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/layouts/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
func main () {
tomo.Run(run)
@ -13,7 +14,7 @@ func run () {
window, _ := tomo.NewWindow(2, 2)
window.SetTitle("dialog")
container := basicElements.NewContainer(basicLayouts.Dialog { true, true })
container := containers.NewContainer(basicLayouts.Dialog { true, true })
window.Adopt(container)
container.Adopt(basicElements.NewLabel("you will explode", true), true)

View File

@ -7,6 +7,7 @@ import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/layouts/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
func main () {
tomo.Run(run)
@ -22,8 +23,8 @@ func run () {
file.Close()
if err != nil { panic(err.Error()); return }
scrollContainer := basicElements.NewScrollContainer(false, true)
document := basicElements.NewDocumentContainer()
scrollContainer := containers.NewScrollContainer(false, true)
document := containers.NewDocumentContainer()
document.Adopt (basicElements.NewLabel (
"A document container is a vertically stacked container " +
@ -48,7 +49,7 @@ func run () {
document.Adopt (basicElements.NewLabel (
"Oh, you're a switch? Then name all of these switches:", true))
for i := 0; i < 3; i ++ {
switchContainer := basicElements.NewContainer (basicLayouts.Horizontal {
switchContainer := containers.NewContainer (basicLayouts.Horizontal {
Gap: true,
})
for i := 0; i < 10; i ++ {

View File

@ -5,6 +5,7 @@ import "git.tebibyte.media/sashakoshka/tomo/flow"
import "git.tebibyte.media/sashakoshka/tomo/layouts/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
func main () {
tomo.Run(run)
@ -13,7 +14,7 @@ func main () {
func run () {
window, _ := tomo.NewWindow(2, 2)
window.SetTitle("adventure")
container := basicElements.NewContainer(basicLayouts.Vertical { true, true })
container := containers.NewContainer(basicLayouts.Vertical { true, true })
window.Adopt(container)
var world flow.Flow

View File

@ -3,10 +3,11 @@ package main
import "os"
import "time"
import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/layouts/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/fun"
import "git.tebibyte.media/sashakoshka/tomo/layouts/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
func main () {
tomo.Run(run)
@ -16,7 +17,7 @@ func main () {
func run () {
window, _ := tomo.NewWindow(200, 216)
window.SetTitle("Clock")
container := basicElements.NewContainer(basicLayouts.Vertical { true, true })
container := containers.NewContainer(basicLayouts.Vertical { true, true })
window.Adopt(container)
clock := fun.NewAnalogClock(time.Now())

View File

@ -4,6 +4,7 @@ import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/layouts/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
func main () {
tomo.Run(run)
@ -13,7 +14,7 @@ func run () {
window, _ := tomo.NewWindow(360, 2)
window.SetTitle("horizontal stack")
container := basicElements.NewContainer(basicLayouts.Horizontal { true, true })
container := containers.NewContainer(basicLayouts.Horizontal { true, true })
window.Adopt(container)
container.Adopt(basicElements.NewLabel("this is sample text", true), true)

View File

@ -5,6 +5,7 @@ import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/layouts/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
func main () {
tomo.Run(run)
@ -14,7 +15,7 @@ func run () {
window, _ := tomo.NewWindow(360, 2)
window.SetTitle("Icons")
container := basicElements.NewContainer(basicLayouts.Vertical { true, true })
container := containers.NewContainer(basicLayouts.Vertical { true, true })
window.Adopt(container)
container.Adopt(basicElements.NewLabel("Just some of the wonderful icons we have:", false), false)
@ -33,8 +34,8 @@ func run () {
window.Show()
}
func icons (min, max theme.Icon) (container *basicElements.Container) {
container = basicElements.NewContainer(basicLayouts.Horizontal { true, false })
func icons (min, max theme.Icon) (container *containers.Container) {
container = containers.NewContainer(basicLayouts.Horizontal { true, false })
for index := min; index <= max; index ++ {
container.Adopt(basicElements.NewIcon(index, theme.IconSizeSmall), true)
}

View File

@ -10,6 +10,7 @@ import "git.tebibyte.media/sashakoshka/tomo/popups"
import "git.tebibyte.media/sashakoshka/tomo/layouts/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
func main () {
tomo.Run(run)
@ -25,7 +26,7 @@ func run () {
file.Close()
if err != nil { fatalError(err); return }
container := basicElements.NewContainer(basicLayouts.Vertical { true, true })
container := containers.NewContainer(basicLayouts.Vertical { true, true })
logoImage := basicElements.NewImage(logo)
button := basicElements.NewButton("Show me a gopher instead")
button.OnClick (func () { container.Warp (func () {

View File

@ -5,6 +5,7 @@ import "git.tebibyte.media/sashakoshka/tomo/popups"
import "git.tebibyte.media/sashakoshka/tomo/layouts/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
func main () {
tomo.Run(run)
@ -13,7 +14,7 @@ func main () {
func run () {
window, _ := tomo.NewWindow(2, 2)
window.SetTitle("Enter Details")
container := basicElements.NewContainer(basicLayouts.Vertical { true, true })
container := containers.NewContainer(basicLayouts.Vertical { true, true })
window.Adopt(container)
// create inputs

View File

@ -6,6 +6,7 @@ import "git.tebibyte.media/sashakoshka/tomo/elements"
import "git.tebibyte.media/sashakoshka/tomo/layouts/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/testing"
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
func main () {
@ -16,7 +17,7 @@ func run () {
window, _ := tomo.NewWindow(300, 2)
window.SetTitle("List Sidebar")
container := basicElements.NewContainer(basicLayouts.Horizontal { true, true })
container := containers.NewContainer(basicLayouts.Horizontal { true, true })
window.Adopt(container)
var currentPage elements.Element
@ -39,7 +40,7 @@ func run () {
})
mouse := testing.NewMouse()
input := basicElements.NewTextBox("Write some text", "")
form := basicElements.NewContainer(basicLayouts.Vertical { true, false})
form := containers.NewContainer(basicLayouts.Vertical { true, false})
form.Adopt(basicElements.NewLabel("I have:", false), false)
form.Adopt(basicElements.NewSpacer(true), false)
form.Adopt(basicElements.NewCheckbox("Skin", true), false)

View File

@ -10,6 +10,7 @@ import "git.tebibyte.media/sashakoshka/tomo/elements/fun"
import "git.tebibyte.media/sashakoshka/tomo/layouts/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/fun/music"
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
const sampleRate = 44100
@ -33,10 +34,10 @@ func main () {
func run () {
window, _ := tomo.NewWindow(2, 2)
window.SetTitle("Piano")
container := basicElements.NewContainer(basicLayouts.Vertical { true, true })
controlBar := basicElements.NewContainer(basicLayouts.Horizontal { true, false })
container := containers.NewContainer(basicLayouts.Vertical { true, true })
controlBar := containers.NewContainer(basicLayouts.Horizontal { true, false })
waveformColumn := basicElements.NewContainer(basicLayouts.Vertical { true, false })
waveformColumn := containers.NewContainer(basicLayouts.Vertical { true, false })
waveformList := basicElements.NewList (
basicElements.NewListEntry("Sine", func(){ waveform = 0 }),
basicElements.NewListEntry("Triangle", func(){ waveform = 3 }),
@ -47,8 +48,8 @@ func run () {
waveformList.OnNoEntrySelected (func(){waveformList.Select(0)})
waveformList.Select(0)
adsrColumn := basicElements.NewContainer(basicLayouts.Vertical { true, false })
adsrGroup := basicElements.NewContainer(basicLayouts.Horizontal { true, false })
adsrColumn := containers.NewContainer(basicLayouts.Vertical { true, false })
adsrGroup := containers.NewContainer(basicLayouts.Horizontal { true, false })
attackSlider := basicElements.NewLerpSlider(0, 3 * time.Second, adsr.Attack, true)
decaySlider := basicElements.NewLerpSlider(0, 3 * time.Second, adsr.Decay, true)
sustainSlider := basicElements.NewSlider(adsr.Sustain, true)
@ -71,7 +72,7 @@ func run () {
gain = math.Pow(gainSlider.Value(), 2)
})
patchColumn := basicElements.NewContainer(basicLayouts.Vertical { true, false })
patchColumn := containers.NewContainer(basicLayouts.Vertical { true, false })
patch := func (w int, a, d time.Duration, s float64, r time.Duration) func () {
return func () {
waveform = w
@ -107,7 +108,7 @@ func run () {
2, 3000, 60, 0, 0)),
)
patchList.Collapse(0, 32)
patchScrollBox := basicElements.NewScrollContainer(false, true)
patchScrollBox := containers.NewScrollContainer(false, true)
piano := fun.NewPiano(2, 5)
piano.OnPress(playNote)

View File

@ -5,6 +5,7 @@ import "git.tebibyte.media/sashakoshka/tomo/popups"
import "git.tebibyte.media/sashakoshka/tomo/layouts/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
func main () {
tomo.Run(run)
@ -14,7 +15,7 @@ func run () {
window, _ := tomo.NewWindow(2, 2)
window.SetTitle("Dialog Boxes")
container := basicElements.NewContainer(basicLayouts.Vertical { true, true })
container := containers.NewContainer(basicLayouts.Vertical { true, true })
window.Adopt(container)
container.Adopt(basicElements.NewLabel("Try out different dialogs:", false), true)

View File

@ -5,6 +5,7 @@ import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/popups"
import "git.tebibyte.media/sashakoshka/tomo/layouts/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
func main () {
@ -14,7 +15,7 @@ func main () {
func run () {
window, _ := tomo.NewWindow(2, 2)
window.SetTitle("Approaching")
container := basicElements.NewContainer(basicLayouts.Vertical { true, true })
container := containers.NewContainer(basicLayouts.Vertical { true, true })
window.Adopt(container)
container.Adopt (basicElements.NewLabel (

View File

@ -8,6 +8,7 @@ import "git.tebibyte.media/sashakoshka/tomo/popups"
import "git.tebibyte.media/sashakoshka/tomo/layouts/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
//go:embed wall.png
var wallTextureBytes []uint8
@ -20,7 +21,7 @@ func run () {
window, _ := tomo.NewWindow(640, 480)
window.SetTitle("Raycaster")
container := basicElements.NewContainer(basicLayouts.Vertical { false, false })
container := containers.NewContainer(basicLayouts.Vertical { false, false })
window.Adopt(container)
wallTexture, _ := TextureFrom(bytes.NewReader(wallTextureBytes))
@ -47,7 +48,7 @@ func run () {
wallTexture,
})
topBar := basicElements.NewContainer(basicLayouts.Horizontal { true, true })
topBar := containers.NewContainer(basicLayouts.Horizontal { true, true })
staminaBar := basicElements.NewProgressBar(game.Stamina())
healthBar := basicElements.NewProgressBar(game.Health())

View File

@ -5,6 +5,7 @@ import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/layouts/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
func main () {
tomo.Run(run)
@ -13,13 +14,13 @@ func main () {
func run () {
window, _ := tomo.NewWindow(480, 360)
window.SetTitle("Scroll")
container := basicElements.NewContainer(basicLayouts.Vertical { true, true })
container := containers.NewContainer(basicLayouts.Vertical { true, true })
window.Adopt(container)
textBox := basicElements.NewTextBox("", copypasta)
scrollContainer := basicElements.NewScrollContainer(true, false)
scrollContainer := containers.NewScrollContainer(true, false)
disconnectedContainer := basicElements.NewContainer (basicLayouts.Horizontal {
disconnectedContainer := containers.NewContainer (basicLayouts.Horizontal {
Gap: true,
})
list := basicElements.NewList (

View File

@ -4,6 +4,7 @@ import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/layouts/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
func main () {
tomo.Run(run)
@ -13,7 +14,7 @@ func run () {
window, _ := tomo.NewWindow(2, 2)
window.SetTitle("Spaced Out")
container := basicElements.NewContainer(basicLayouts.Vertical { true, true })
container := containers.NewContainer(basicLayouts.Vertical { true, true })
window.Adopt(container)
container.Adopt (basicElements.NewLabel("This is at the top", false), false)

View File

@ -4,6 +4,7 @@ import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/layouts/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
func main () {
tomo.Run(run)
@ -13,7 +14,7 @@ func run () {
window, _ := tomo.NewWindow(2, 2)
window.SetTitle("Switches")
container := basicElements.NewContainer(basicLayouts.Vertical { true, true })
container := containers.NewContainer(basicLayouts.Vertical { true, true })
window.Adopt(container)
container.Adopt(basicElements.NewSwitch("hahahah", false), false)

View File

@ -4,6 +4,7 @@ import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/layouts/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/testing"
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
func main () {
@ -14,7 +15,7 @@ func run () {
window, _ := tomo.NewWindow(2, 2)
window.SetTitle("vertical stack")
container := basicElements.NewContainer(basicLayouts.Vertical { true, true })
container := containers.NewContainer(basicLayouts.Vertical { true, true })
window.Adopt(container)
label := basicElements.NewLabel("it is a label hehe", true)

View File

@ -5,6 +5,7 @@ import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/elements"
import "git.tebibyte.media/sashakoshka/tomo/layouts/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
// DialogKind defines the semantic role of a dialog window.
type DialogKind int
@ -37,10 +38,10 @@ func NewDialog (
window, _ = tomo.NewWindow(2, 2)
window.SetTitle(title)
container := basicElements.NewContainer(basicLayouts.Dialog { true, true })
container := containers.NewContainer(basicLayouts.Dialog { true, true })
window.Adopt(container)
messageContainer := basicElements.NewContainer(basicLayouts.Horizontal { true, false })
messageContainer := containers.NewContainer(basicLayouts.Horizontal { true, false })
iconId := theme.IconInformation
switch kind {
case DialogKindInfo: iconId = theme.IconInformation