pathtree.go raw
1 package pathtree
2
3 import (
4 l "github.com/p9c/p9/pkg/gel/gio/layout"
5 "github.com/p9c/p9/pkg/gel/gio/text"
6 uberatomic "go.uber.org/atomic"
7 "golang.org/x/exp/shiny/materialdesign/icons"
8
9 "github.com/p9c/p9/pkg/opts/binary"
10 "github.com/p9c/p9/pkg/opts/meta"
11
12 "github.com/p9c/p9/pkg/gel"
13 )
14
15 type Widget struct {
16 *gel.Window
17 *gel.App
18 activePage *uberatomic.String
19 sidebarButtons []*gel.Clickable
20 statusBarButtons []*gel.Clickable
21 buttonBarButtons []*gel.Clickable
22 Size *uberatomic.Int32
23 }
24
25 func New(w *gel.Window) (wg *Widget) {
26 activePage := uberatomic.NewString("home")
27 w.Dark = binary.New(meta.Data{}, false, func(b bool) error { return nil })
28 w.Colors.SetDarkTheme(false)
29 // I.S(w.Colors)
30 app := w.App(w.Width, activePage, 48)
31 wg = &Widget{
32 Window: w,
33 App: app,
34 activePage: uberatomic.NewString("home"),
35 Size: w.Width,
36 }
37 wg.GetButtons()
38 app.Pages(
39 map[string]l.Widget{
40 "home": wg.Page(
41 "home", gel.Widgets{
42 // p9.WidgetSize{Widget: p9.EmptyMaxHeight()},
43 gel.WidgetSize{
44 Widget: wg.Flex().Flexed(1, wg.H3("glom").Fn).Fn,
45 },
46 },
47 ),
48 },
49 )
50 app.SideBar(
51 []l.Widget{
52 // wg.SideBarButton(" ", " ", 11),
53 wg.SideBarButton("home", "home", 0),
54 },
55 )
56 app.ButtonBar(
57 []l.Widget{
58 wg.PageTopBarButton(
59 "help", 0, &icons.ActionHelp, func(name string) {
60 }, app, "",
61 ),
62 wg.PageTopBarButton(
63 "home", 1, &icons.ActionLockOpen, func(name string) {
64 wg.App.ActivePage(name)
65 }, app, "green",
66 ),
67 // wg.Flex().Rigid(wg.Inset(0.5, gel.EmptySpace(0, 0)).Fn).Fn,
68 // wg.PageTopBarButton(
69 // "quit", 3, &icons.ActionExitToApp, func(name string) {
70 // wg.MainApp.ActivePage(name)
71 // }, a, "",
72 // ),
73 },
74 )
75 app.StatusBar(
76 []l.Widget{
77 wg.StatusBarButton(
78 "log", 0, &icons.ActionList, func(name string) {
79 D.Ln("click on button", name)
80 }, app,
81 ),
82 },
83 []l.Widget{
84 wg.StatusBarButton(
85 "settings", 1, &icons.ActionSettings, func(name string) {
86 D.Ln("click on button", name)
87 }, app,
88 ),
89 },
90 )
91 return
92 }
93
94 func (w *Widget) Fn(gtx l.Context) l.Dimensions {
95 return w.App.Fn()(gtx)
96 }
97
98 func (w *Widget) Page(title string, widget gel.Widgets) func(gtx l.Context) l.Dimensions {
99 return func(gtx l.Context) l.Dimensions {
100 return w.VFlex().
101 // SpaceEvenly().
102 Rigid(
103 w.Responsive(
104 w.Size.Load(), gel.Widgets{
105 // p9.WidgetSize{
106 // Widget: a.ButtonInset(0.25, a.H5(title).Color(wg.App.BodyColorGet()).Fn).Fn,
107 // },
108 gel.WidgetSize{
109 // Size: 800,
110 Widget: gel.EmptySpace(0, 0),
111 // a.ButtonInset(0.25, a.Caption(title).Color(wg.BodyColorGet()).Fn).Fn,
112 },
113 },
114 ).Fn,
115 ).
116 Flexed(
117 1,
118 w.Inset(
119 0.25,
120 w.Responsive(w.Size.Load(), widget).Fn,
121 ).Fn,
122 ).Fn(gtx)
123 }
124 }
125
126 func (wg *Widget) GetButtons() {
127 wg.sidebarButtons = make([]*gel.Clickable, 2)
128 // wg.walletLocked.Store(true)
129 for i := range wg.sidebarButtons {
130 wg.sidebarButtons[i] = wg.Clickable()
131 }
132 wg.buttonBarButtons = make([]*gel.Clickable, 2)
133 for i := range wg.buttonBarButtons {
134 wg.buttonBarButtons[i] = wg.Clickable()
135 }
136 wg.statusBarButtons = make([]*gel.Clickable, 2)
137 for i := range wg.statusBarButtons {
138 wg.statusBarButtons[i] = wg.Clickable()
139 }
140 }
141
142 func (w *Widget) SideBarButton(title, page string, index int) func(gtx l.Context) l.Dimensions {
143 return func(gtx l.Context) l.Dimensions {
144 var scale float32
145 scale = gel.Scales["H6"]
146 var color string
147 background := "Transparent"
148 color = "DocText"
149 var ins float32 = 0.5
150 // var hl = false
151 if w.App.ActivePageGet() == page || w.App.PreRendering {
152 background = "PanelBg"
153 scale = gel.Scales["H6"]
154 color = "DocText"
155 // ins = 0.5
156 // hl = true
157 }
158 if title == " " {
159 scale = gel.Scales["H6"] / 2
160 }
161 max := int(w.App.SideBarSize.V)
162 if max > 0 {
163 gtx.Constraints.Max.X = max
164 gtx.Constraints.Min.X = max
165 }
166 // D.Ln("sideMAXXXXXX!!", max)
167 return w.Direction().E().Embed(
168 w.ButtonLayout(w.sidebarButtons[index]).
169 CornerRadius(scale).Corners(0).
170 Background(background).
171 Embed(
172 w.Inset(
173 ins,
174 func(gtx l.Context) l.Dimensions {
175 return w.H5(title).
176 Color(color).
177 Alignment(text.End).
178 Fn(gtx)
179 },
180 ).Fn,
181 ).
182 SetClick(
183 func() {
184 if w.App.MenuOpen {
185 w.App.MenuOpen = false
186 }
187 w.App.ActivePage(page)
188 },
189 ).
190 Fn,
191 ).
192 Fn(gtx)
193 }
194 }
195
196 func (w *Widget) PageTopBarButton(
197 name string, index int, ico *[]byte, onClick func(string), app *gel.App,
198 highlightColor string,
199 ) func(gtx l.Context) l.Dimensions {
200 return func(gtx l.Context) l.Dimensions {
201 background := "Transparent"
202 // background := node.TitleBarBackgroundGet()
203 color := app.MenuColorGet()
204
205 if app.ActivePageGet() == name {
206 color = "PanelText"
207 // background = "scrim"
208 background = "PanelBg"
209 }
210 // if name == "home" {
211 // background = "scrim"
212 // }
213 if highlightColor != "" {
214 color = highlightColor
215 }
216 ic := w.Icon().
217 Scale(gel.Scales["H5"]).
218 Color(color).
219 Src(ico).
220 Fn
221 return w.Flex().Rigid(
222 // wg.ButtonInset(0.25,
223 w.ButtonLayout(w.buttonBarButtons[index]).
224 CornerRadius(0).
225 Embed(
226 w.Inset(
227 0.375,
228 ic,
229 ).Fn,
230 ).
231 Background(background).
232 SetClick(func() { onClick(name) }).
233 Fn,
234 // ).Fn,
235 ).Fn(gtx)
236 }
237 }
238
239 func (w *Widget) StatusBarButton(
240 name string,
241 index int,
242 ico *[]byte,
243 onClick func(string),
244 app *gel.App,
245 ) func(gtx l.Context) l.Dimensions {
246 return func(gtx l.Context) l.Dimensions {
247 background := app.StatusBarBackgroundGet()
248 color := app.StatusBarColorGet()
249 if app.ActivePageGet() == name {
250 // background, color = color, background
251 background = "PanelBg"
252 // color = "Danger"
253 }
254 ic := w.Icon().
255 Scale(gel.Scales["H5"]).
256 Color(color).
257 Src(ico).
258 Fn
259 return w.Flex().
260 Rigid(
261 w.ButtonLayout(w.statusBarButtons[index]).
262 CornerRadius(0).
263 Embed(
264 w.Inset(0.25, ic).Fn,
265 ).
266 Background(background).
267 SetClick(func() { onClick(name) }).
268 Fn,
269 ).Fn(gtx)
270 }
271 }
272