diff --git a/backends/x/window.go b/backends/x/window.go index 315d33f..7fb2e93 100644 --- a/backends/x/window.go +++ b/backends/x/window.go @@ -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, diff --git a/examples/align/main.go b/examples/align/main.go index 9cba3cb..1d0c77d 100644 --- a/examples/align/main.go +++ b/examples/align/main.go @@ -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() diff --git a/examples/button/main.go b/examples/button/main.go index 86666e5..d5d7cc3 100644 --- a/examples/button/main.go +++ b/examples/button/main.go @@ -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 () { diff --git a/examples/checkbox/main.go b/examples/checkbox/main.go index 42acb7d..a0dfbf4 100644 --- a/examples/checkbox/main.go +++ b/examples/checkbox/main.go @@ -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 }) diff --git a/examples/clipboard/main.go b/examples/clipboard/main.go index edf1bae..40eb0df 100644 --- a/examples/clipboard/main.go +++ b/examples/clipboard/main.go @@ -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") diff --git a/examples/dialogLayout/main.go b/examples/dialogLayout/main.go index 3ce6663..519ae4a 100644 --- a/examples/dialogLayout/main.go +++ b/examples/dialogLayout/main.go @@ -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 }) diff --git a/examples/documentContainer/main.go b/examples/documentContainer/main.go index d9cf402..37a2a3f 100644 --- a/examples/documentContainer/main.go +++ b/examples/documentContainer/main.go @@ -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 } diff --git a/examples/drawing/main.go b/examples/drawing/main.go index e917a1a..4c8db43 100644 --- a/examples/drawing/main.go +++ b/examples/drawing/main.go @@ -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() diff --git a/examples/fileBrowser/main.go b/examples/fileBrowser/main.go index 2174ec5..156aab1 100644 --- a/examples/fileBrowser/main.go +++ b/examples/fileBrowser/main.go @@ -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) diff --git a/examples/flow/main.go b/examples/flow/main.go index 146e5ee..565f614 100644 --- a/examples/flow/main.go +++ b/examples/flow/main.go @@ -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) diff --git a/examples/goroutines/main.go b/examples/goroutines/main.go index 0b3b8b4..caa41bb 100644 --- a/examples/goroutines/main.go +++ b/examples/goroutines/main.go @@ -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) diff --git a/examples/horizontalLayout/main.go b/examples/horizontalLayout/main.go index 9364d39..c55a424 100644 --- a/examples/horizontalLayout/main.go +++ b/examples/horizontalLayout/main.go @@ -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 }) diff --git a/examples/icons/main.go b/examples/icons/main.go index 85ee36e..52c45cf 100644 --- a/examples/icons/main.go +++ b/examples/icons/main.go @@ -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 }) diff --git a/examples/input/main.go b/examples/input/main.go index 1d19a37..1016493 100644 --- a/examples/input/main.go +++ b/examples/input/main.go @@ -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) diff --git a/examples/label/main.go b/examples/label/main.go index 68c53f4..0429587 100644 --- a/examples/label/main.go +++ b/examples/label/main.go @@ -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) diff --git a/examples/list/main.go b/examples/list/main.go index 3264da6..0aeeec8 100644 --- a/examples/list/main.go +++ b/examples/list/main.go @@ -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 }) diff --git a/examples/panels/main.go b/examples/panels/main.go index f725b68..4997c8f 100644 --- a/examples/panels/main.go +++ b/examples/panels/main.go @@ -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 }) diff --git a/examples/piano/main.go b/examples/piano/main.go index 8aa291b..2783bc9 100644 --- a/examples/piano/main.go +++ b/examples/piano/main.go @@ -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 }) diff --git a/examples/popups/main.go b/examples/popups/main.go index 1140df6..7ce287f 100644 --- a/examples/popups/main.go +++ b/examples/popups/main.go @@ -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 }) diff --git a/examples/progress/main.go b/examples/progress/main.go index c76f2d5..8e0a630 100644 --- a/examples/progress/main.go +++ b/examples/progress/main.go @@ -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) diff --git a/examples/raycaster/main.go b/examples/raycaster/main.go index 567e704..69256d7 100644 --- a/examples/raycaster/main.go +++ b/examples/raycaster/main.go @@ -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 }) diff --git a/examples/scroll/main.go b/examples/scroll/main.go index bf59682..2436bd9 100644 --- a/examples/scroll/main.go +++ b/examples/scroll/main.go @@ -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) diff --git a/examples/spacer/main.go b/examples/spacer/main.go index 0a1a447..92d6855 100644 --- a/examples/spacer/main.go +++ b/examples/spacer/main.go @@ -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 }) diff --git a/examples/switch/main.go b/examples/switch/main.go index 0750631..2c7ccda 100644 --- a/examples/switch/main.go +++ b/examples/switch/main.go @@ -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 }) diff --git a/examples/table/main.go b/examples/table/main.go index 1cb9d04..23592f6 100644 --- a/examples/table/main.go +++ b/examples/table/main.go @@ -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 }) diff --git a/examples/test/main.go b/examples/test/main.go index 5bdab16..d4c352f 100644 --- a/examples/test/main.go +++ b/examples/test/main.go @@ -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) diff --git a/examples/verticalLayout/main.go b/examples/verticalLayout/main.go index c48a381..ddced0a 100644 --- a/examples/verticalLayout/main.go +++ b/examples/verticalLayout/main.go @@ -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 }) diff --git a/popups/dialog.go b/popups/dialog.go index 8a0b522..8339c2c 100644 --- a/popups/dialog.go +++ b/popups/dialog.go @@ -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) diff --git a/tomo.go b/tomo.go index 7273c5c..28a57a3 100644 --- a/tomo.go +++ b/tomo.go @@ -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") } }