aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorClement Benard <contact@clementbenard.com>2019-07-09 10:59:38 +0200
committerClement Benard <contact@clementbenard.com>2019-07-09 10:59:38 +0200
commit1223e277009005337243ca991cb54dd75bf723a7 (patch)
treeaa4863dc2a08649c825fd28843940ef5d60beba1 /examples
parent3a216b96b6a7c80275a2516e7de82d9b2ffc96df (diff)
downloadgui-1223e277009005337243ca991cb54dd75bf723a7.zip
Layout system remaking
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/layout/layoutbin0 -> 5570192 bytes
-rw-r--r--examples/layout/main.go122
2 files changed, 94 insertions, 28 deletions
diff --git a/examples/layout/layout b/examples/layout/layout
new file mode 100755
index 0000000..050fbdf
--- /dev/null
+++ b/examples/layout/layout
Binary files differ
diff --git a/examples/layout/main.go b/examples/layout/main.go
index 47364a9..20d82c2 100644
--- a/examples/layout/main.go
+++ b/examples/layout/main.go
@@ -7,7 +7,7 @@ import (
"time"
"github.com/faiface/gui"
- "github.com/faiface/gui/fixedgrid"
+ "github.com/faiface/gui/layout"
"github.com/faiface/gui/win"
"github.com/faiface/mainthread"
"golang.org/x/image/colornames"
@@ -81,39 +81,105 @@ func run() {
ButtonUp: colornames.Lightgrey,
ButtonDown: colornames.Grey,
}
- w, err := win.New(win.Title("gui test"),
- win.Resizable(),
- )
+ w, err := win.New(win.Title("gui test")) // win.Resizable(),
+
if err != nil {
panic(err)
}
mux, env := gui.NewMux(w)
- gr := fixedgrid.New(mux.MakeEnv(),
- fixedgrid.Rows(5),
- fixedgrid.Columns(2),
- fixedgrid.Gap(10),
+ var (
+ top gui.Env
+ left, right gui.Env
+ bottomLeft, bottom, bottomRight gui.Env
+ )
+ layout.NewGrid(
+ mux.MakeEnv(),
+ [][]*gui.Env{
+ {&top},
+ {&left, &right},
+ {&bottomLeft, &bottom, &bottomRight},
+ },
+ layout.GridGap(10),
+ layout.GridBackground(colornames.Sandybrown),
+ layout.GridSplitY(func(els int, width int) []int {
+ ret := make([]int, els)
+ total := 0
+ for i := 0; i < els; i++ {
+ if i == els-1 {
+ ret[i] = width - total
+ } else {
+ v := (width - total) / 2
+ ret[i] = v
+ total += v
+ }
+ }
+ return ret
+ }),
+ )
+ go Blinker(right, false)
+ go Blinker(left, false)
+ go Blinker(bottomRight, false)
+
+ var (
+ b1, b2, b3, b4, b5, b6 gui.Env
)
- log.Print(gr)
- go Blinker(gr.GetEnv("0;0"), false)
- go Blinker(gr.GetEnv("0;1"), true)
- go Blinker(gr.GetEnv("1;1"), false)
- go Blinker(gr.GetEnv("0;2"), false)
- go Blinker(gr.GetEnv("0;3"), false)
- go Blinker(gr.GetEnv("0;4"), false)
- sgr := fixedgrid.New(gr.GetEnv("1;0"),
- fixedgrid.Columns(3),
- fixedgrid.Gap(4),
- fixedgrid.Background(colornames.Darkgrey),
+ layout.NewBox(
+ top,
+ []*gui.Env{
+ &b1, &b2, &b3,
+ },
+ layout.BoxGap(10),
+ layout.BoxBackground(colornames.Lightblue),
)
- go Button(sgr.GetEnv("0;0"), theme, "Hey", func() {
- log.Print("hey")
- })
- go Button(sgr.GetEnv("1;0"), theme, "Ho", func() {
- log.Print("ho")
- })
- go Button(sgr.GetEnv("2;0"), theme, "Hu", func() {
- log.Print("hu")
- })
+ go Blinker(b1, false)
+ go Blinker(b2, false)
+ layout.NewBox(
+ b3,
+ []*gui.Env{
+ &b4, &b5, &b6,
+ },
+ layout.BoxVertical,
+ layout.BoxBackground(colornames.Pink),
+ layout.BoxGap(4),
+ layout.BoxSplit(func(els int, width int) []int {
+ ret := make([]int, els)
+ total := 0
+ for i := 0; i < els; i++ {
+ if i == els-1 {
+ ret[i] = width - total
+ } else {
+ v := (width - total) / 2
+ ret[i] = v
+ total += v
+ }
+ }
+ return ret
+ }),
+ )
+ go Blinker(b4, false)
+ go Blinker(b5, false)
+ go Blinker(b6, false)
+
+ var (
+ btn1, btn2, btn3 gui.Env
+ )
+ layout.NewGrid(
+ bottom,
+ [][]*gui.Env{
+ {&btn1, &btn2, &btn3},
+ },
+ layout.GridGap(4),
+ layout.GridBackground(colornames.Darkgrey),
+ )
+ btn := func(env gui.Env, name string) {
+ Button(env, theme, name, func() {
+ log.Print(name)
+ })
+ }
+ go btn(btn1, "Hey")
+ go btn(btn2, "Ho")
+ go btn(btn3, "Hu")
+
// we use the master env now, w is used by the mux
for event := range env.Events() {
switch event.(type) {