Well I think thats all of the examples

There are too many examples.
This commit is contained in:
Sasha Koshka 2023-04-10 02:58:52 -04:00
parent 6db5901247
commit aed448671b
29 changed files with 54 additions and 44 deletions

View File

@ -59,15 +59,17 @@ func (backend *Backend) newWindow (
output *window,
err error,
) {
// TODO: take position flag into account
if bounds.Dx() == 0 { bounds.Max.X = bounds.Min.X + 8 }
if bounds.Dy() == 0 { bounds.Max.Y = bounds.Min.Y + 8 }
window := &window { backend: backend }
window.xWindow, err = xwindow.Generate(backend.connection)
if err != nil { return }
window.xWindow.Create (
err = window.xWindow.CreateChecked (
backend.connection.RootWin(),
bounds.Min.X, bounds.Min.Y, bounds.Dx(), bounds.Dy(), 0)
if err != nil { return }
err = window.xWindow.Listen (
xproto.EventMaskExposure,
xproto.EventMaskStructureNotify,

View File

@ -11,7 +11,7 @@ func main () {
}
func run () {
window, _ := tomo.NewWindow(360, 360)
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
window.SetTitle("Text alignment")
container := containers.NewDocumentContainer()
@ -29,10 +29,10 @@ func run () {
right.SetAlign(textdraw.AlignRight)
justify.SetAlign(textdraw.AlignJustify)
container.Adopt(left)
container.Adopt(center)
container.Adopt(right)
container.Adopt(justify)
container.Adopt(left, true)
container.Adopt(center, true)
container.Adopt(right, true)
container.Adopt(justify, true)
window.OnClose(tomo.Stop)
window.Show()

View File

@ -10,7 +10,7 @@ func main () {
}
func run () {
window, _ := tomo.NewWindow(2, 2)
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
window.SetTitle("example button")
button := elements.NewButton("hello tomo!")
button.OnClick (func () {

View File

@ -12,7 +12,7 @@ func main () {
}
func run () {
window, _ := tomo.NewWindow(2, 2)
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
window.SetTitle("Checkboxes")
container := containers.NewContainer(layouts.Vertical { true, true })

View File

@ -24,7 +24,7 @@ var validImageTypes = []data.Mime {
}
func run () {
window, _ := tomo.NewWindow(256, 2)
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 256, 0))
window.SetTitle("Clipboard")
container := containers.NewContainer(layouts.Vertical { true, true })
@ -74,7 +74,7 @@ func run () {
"Cannot decode image:\n" + err.Error())
return
}
imageWindow(img)
imageWindow(window, img)
}
clipboardCallback := func (clipboard data.Data, err error) {
if err != nil {
@ -120,8 +120,8 @@ func run () {
window.Show()
}
func imageWindow (image image.Image) {
window, _ := tomo.NewWindow(2, 2)
func imageWindow (parent tomo.Window, image image.Image) {
window, _ := parent.NewModal(tomo.Bounds(0, 0, 0, 0))
window.SetTitle("Clipboard Image")
container := containers.NewContainer(layouts.Vertical { true, true })
closeButton := elements.NewButton("Ok")

View File

@ -11,7 +11,7 @@ func main () {
}
func run () {
window, _ := tomo.NewWindow(2, 2)
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
window.SetTitle("dialog")
container := containers.NewContainer(layouts.Dialog { true, true })

View File

@ -13,8 +13,8 @@ func main () {
}
func run () {
window, _ := tomo.NewWindow(383, 360)
window.SetTitle("Scroll")
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 383, 360))
window.SetTitle("Document Container")
file, err := os.Open("assets/banner.png")
if err != nil { panic(err.Error()); return }

View File

@ -10,7 +10,7 @@ func main () {
}
func run () {
window, _ := tomo.NewWindow(480, 360)
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 480, 360))
window.Adopt(testing.NewArtist())
window.OnClose(tomo.Stop)
window.Show()

View File

@ -14,7 +14,7 @@ func main () {
}
func run () {
window, _ := tomo.NewWindow(384, 384)
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 384, 384))
window.SetTitle("File browser")
container := containers.NewContainer(layouts.Vertical { true, true })
window.Adopt(container)

View File

@ -12,7 +12,7 @@ func main () {
}
func run () {
window, _ := tomo.NewWindow(192, 192)
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 192, 192))
window.SetTitle("adventure")
container := containers.NewContainer(layouts.Vertical { true, true })
window.Adopt(container)

View File

@ -15,7 +15,7 @@ func main () {
}
func run () {
window, _ := tomo.NewWindow(200, 216)
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 200, 216))
window.SetTitle("Clock")
container := containers.NewContainer(layouts.Vertical { true, true })
window.Adopt(container)

View File

@ -11,7 +11,7 @@ func main () {
}
func run () {
window, _ := tomo.NewWindow(360, 2)
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 360, 0))
window.SetTitle("horizontal stack")
container := containers.NewContainer(layouts.Horizontal { true, true })

View File

@ -11,7 +11,7 @@ func main () {
}
func run () {
window, _ := tomo.NewWindow(360, 2)
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 360, 0))
window.SetTitle("Icons")
container := containers.NewContainer(layouts.Vertical { true, true })

View File

@ -12,7 +12,7 @@ func main () {
}
func run () {
window, _ := tomo.NewWindow(2, 2)
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
window.SetTitle("Enter Details")
container := containers.NewContainer(layouts.Vertical { true, true })
window.Adopt(container)

View File

@ -9,7 +9,7 @@ func main () {
}
func run () {
window, _ := tomo.NewWindow(480, 360)
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 480, 360))
window.SetTitle("example label")
window.Adopt(elements.NewLabel(text, true))
window.OnClose(tomo.Stop)

View File

@ -13,7 +13,7 @@ func main () {
}
func run () {
window, _ := tomo.NewWindow(300, 2)
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 300, 0))
window.SetTitle("List Sidebar")
container := containers.NewContainer(layouts.Horizontal { true, true })

View File

@ -1,6 +1,7 @@
package main
import "fmt"
import "image"
import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/layouts"
import "git.tebibyte.media/sashakoshka/tomo/elements"
@ -12,7 +13,7 @@ func main () {
}
func run () {
window, _ := tomo.NewWindow(256, 256)
window, _ := tomo.NewWindow(tomo.Bounds(200, 200, 256, 256))
window.SetTitle("Main")
container := containers.NewContainer(layouts.Vertical { true, true })
@ -22,14 +23,14 @@ func run () {
window.OnClose(tomo.Stop)
window.Show()
createPanel(window, 0)
createPanel(window, 1)
createPanel(window, 2)
createPanel(window, 3)
createPanel(window, 0, tomo.Bounds(-64, 20, 0, 0))
createPanel(window, 1, tomo.Bounds(200, 20, 0, 0))
createPanel(window, 2, tomo.Bounds(-64, 180, 0, 0))
createPanel(window, 3, tomo.Bounds(200, 180, 0, 0))
}
func createPanel (parent tomo.MainWindow, id int) {
window, _ := parent.NewPanel(2, 2)
func createPanel (parent tomo.MainWindow, id int, bounds image.Rectangle) {
window, _ := parent.NewPanel(bounds)
title := fmt.Sprint("Panel #", id)
window.SetTitle(title)
container := containers.NewContainer(layouts.Vertical { true, true })

View File

@ -32,7 +32,7 @@ func main () {
}
func run () {
window, _ := tomo.NewWindow(2, 2)
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
window.SetTitle("Piano")
container := containers.NewContainer(layouts.Vertical { true, true })
controlBar := containers.NewContainer(layouts.Horizontal { true, false })

View File

@ -12,7 +12,8 @@ func main () {
}
func run () {
window, _ := tomo.NewWindow(2, 2)
window, err := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
if err != nil { panic(err.Error()) }
window.SetTitle("Dialog Boxes")
container := containers.NewContainer(layouts.Vertical { true, true })

View File

@ -13,7 +13,7 @@ func main () {
}
func run () {
window, _ := tomo.NewWindow(2, 2)
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
window.SetTitle("Approaching")
container := containers.NewContainer(layouts.Vertical { true, true })
window.Adopt(container)

View File

@ -18,7 +18,7 @@ func main () {
}
func run () {
window, _ := tomo.NewWindow(640, 480)
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 640, 480))
window.SetTitle("Raycaster")
container := containers.NewContainer(layouts.Vertical { false, false })

View File

@ -12,7 +12,7 @@ func main () {
}
func run () {
window, _ := tomo.NewWindow(360, 240)
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 360, 240))
window.SetTitle("Scroll")
container := containers.NewContainer(layouts.Vertical { true, true })
window.Adopt(container)

View File

@ -11,7 +11,7 @@ func main () {
}
func run () {
window, _ := tomo.NewWindow(2, 2)
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
window.SetTitle("Spaced Out")
container := containers.NewContainer(layouts.Vertical { true, true })

View File

@ -11,7 +11,7 @@ func main () {
}
func run () {
window, _ := tomo.NewWindow(2, 2)
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
window.SetTitle("Switches")
container := containers.NewContainer(layouts.Vertical { true, true })

View File

@ -13,7 +13,7 @@ func main () {
}
func run () {
window, _ := tomo.NewWindow(2, 2)
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
window.SetTitle("Table")
container := containers.NewContainer(layouts.Vertical { true, true })

View File

@ -9,7 +9,7 @@ func main () {
}
func run () {
window, _ := tomo.NewWindow(128, 128)
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 128, 128))
window.SetTitle("hellorld!")
window.Adopt(testing.NewMouse())
window.OnClose(tomo.Stop)

View File

@ -12,7 +12,7 @@ func main () {
}
func run () {
window, _ := tomo.NewWindow(128, 128)
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 128, 128))
window.SetTitle("vertical stack")
container := containers.NewContainer(layouts.Vertical { true, true })

View File

@ -1,5 +1,6 @@
package popups
import "image"
import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/layouts"
import "git.tebibyte.media/sashakoshka/tomo/elements"
@ -36,9 +37,9 @@ func NewDialog (
window tomo.Window,
) {
if parent == nil {
window, _ = tomo.NewWindow(2, 2)
window, _ = tomo.NewWindow(image.Rectangle { })
} else {
window, _ = parent.NewModal(2, 2)
window, _ = parent.NewModal(image.Rectangle { })
}
window.SetTitle(title)

View File

@ -47,6 +47,11 @@ func SetConfig (config Config) {
backend.SetConfig(config)
}
// Bounds creates a rectangle from an x, y, width, and height.
func Bounds (x, y, width, height int) image.Rectangle {
return image.Rect(x, y, x + width, y + height)
}
func assertBackend () {
if backend == nil { panic("no backend is running") }
}