main.go raw
1 package main
2
3 import (
4 "github.com/p9c/qu"
5
6 l "github.com/p9c/gio/layout"
7
8 "github.com/p9c/gel"
9 "github.com/p9c/gel/clipboard"
10 )
11
12 type State struct {
13 *gel.Window
14 evKey int
15 showClicker *gel.Clickable
16 showPrimaryClicker *gel.Clickable
17 showText *string
18 editor *gel.Input
19 }
20
21 func NewState(quit qu.C) (s *State) {
22 s = &State{
23 Window: gel.NewWindowP9(quit),
24 }
25 txt := ""
26 s.showText = &txt
27 s.showClicker = s.WidgetPool.GetClickable()
28 s.showPrimaryClicker = s.WidgetPool.GetClickable()
29 s.editor = s.Input(
30 "",
31 "type something to test editor things",
32 "DocText",
33 "PanelBg",
34 "DocBg",
35 func(amt string) {},
36 func(string) {},
37 )
38 return
39 }
40
41 func main() {
42 quit := qu.T()
43 state := NewState(quit)
44 *state.showText = "clipboard demo/test"
45 var e error
46 if e = state.Window.
47 Size(48, 32).
48 Title("hello world").
49 Open().
50 Run(state.rootWidget, quit.Q, quit); E.Chk(e) {
51 }
52 }
53
54 func (s *State) rootWidget(gtx l.Context) l.Dimensions {
55 return s.Direction().Center().
56 Embed(
57 s.Inset(0.5,
58 s.Border().Color("DocText").Embed(
59 s.VFlex().
60 Flexed(0.5,
61 s.Inset(0.5,
62 s.Border().Color("DocText").Embed(
63 s.VFlex().
64 Rigid(
65 s.Direction().Center().Embed(
66 s.Flex().
67 Rigid(
68 s.Inset(0.5,
69 s.ButtonLayout(
70 s.showClicker.
71 SetClick(func() {
72 I.Ln("user clicked show clipboard button")
73 s.ClipboardReadReqs <- func(cs string) {
74 *s.showText = cs
75 I.Ln("clipboard contents:", cs)
76 }
77 }),
78 ).CornerRadius(0.25).Corners(^0).
79 Embed(
80 s.Border().CornerRadius(0.25).Color("DocText").Embed(
81 s.Inset(0.5,
82 s.H6("show clipboard").
83 Fn,
84 ).Fn,
85 ).Fn,
86 ).Fn,
87 ).Fn,
88 ).
89 Rigid(
90 s.Inset(0.5,
91 s.ButtonLayout(
92 s.showPrimaryClicker.
93 SetClick(func() {
94 *s.showText = clipboard.GetPrimary()
95 I.Ln("clipboard contents:", *s.showText)
96 }),
97 ).CornerRadius(0.25).Corners(^0).
98 Embed(
99 s.Border().CornerRadius(0.25).Color("DocText").Embed(
100 s.Inset(0.5,
101 s.H6("show primary").
102 Fn,
103 ).Fn,
104 ).Fn,
105 ).Fn,
106 ).Fn,
107 ).Fn,
108 ).Fn,
109 ).
110 Rigid(
111 s.Inset(0.5,
112 s.editor.Fn,
113 ).Fn,
114 ).Fn,
115 ).Fn,
116 ).Fn,
117 ).
118 Flexed(0.5,
119 s.Inset(0.5,
120 s.Border().Color("DocText").Embed(
121 s.Flex().Flexed(1,
122 s.Direction().NW().Embed(
123 s.Inset(0.5,
124 s.Body1(*s.showText).
125 Fn,
126 ).Fn,
127 ).Fn,
128 ).
129 Fn,
130 ).Fn,
131 ).Fn,
132 ).Fn,
133 ).Fn,
134 ).Fn,
135 ).
136 Fn(gtx)
137 }
138