Skip to content

Commit ecbf066

Browse files
authored
remove gg.Context from UI and add ClippingWidget interface (#500)
1 parent 92f043f commit ecbf066

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1397
-745
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ fmt_verify_all
1919
*.code-workspace
2020
.lite_workspace.lua
2121
ui.iml
22+
*~
23+
*#
2224

2325
# Other files
2426
fns.txt

component/accordion.v

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub fn accordion_component_from_id(w ui.Window, id string) &AccordionComponent {
8383
return accordion_component(w.get_or_panic[ui.Stack](ui.component_id(id, 'layout')))
8484
}
8585

86-
fn accordion_draw(d ui.DrawDevice, c &ui.CanvasLayout) {
86+
fn accordion_draw(mut d ui.DrawDevice, c &ui.CanvasLayout) {
8787
acc := accordion_component(c)
8888
if acc.selected[c.id] {
8989
c.draw_device_triangle_filled(d, 5, 8, 12, 8, 8, 14, gx.black)

component/colorbox.v

+3-3
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ fn cv_h_mouse_move(c &ui.CanvasLayout, e ui.MouseMoveEvent) {
207207
}
208208
}
209209

210-
fn cv_h_draw(d ui.DrawDevice, c &ui.CanvasLayout) {
210+
fn cv_h_draw(mut d ui.DrawDevice, c &ui.CanvasLayout) {
211211
cb := colorbox_component(c)
212212
for j in 0 .. 255 {
213213
c.draw_device_rect_empty(d, 0, j, 30, 1, cb.hsv_to_rgb(f64(j) / 256.0, .75, .75))
@@ -240,7 +240,7 @@ fn cv_sv_mouse_move(c &ui.CanvasLayout, e ui.MouseMoveEvent) {
240240
}
241241
}
242242

243-
fn cv_sv_draw(d ui.DrawDevice, mut c ui.CanvasLayout) {
243+
fn cv_sv_draw(mut d ui.DrawDevice, mut c ui.CanvasLayout) {
244244
mut cb := colorbox_component(c)
245245

246246
// TODO: check extra_draw c.draw_device_texture
@@ -281,7 +281,7 @@ fn cv_sel_click(c &ui.CanvasLayout, e ui.MouseEvent) {
281281
cb.update_cur_color(true)
282282
}
283283

284-
fn cv_sel_draw(d ui.DrawDevice, mut c ui.CanvasLayout) {
284+
fn cv_sel_draw(mut d ui.DrawDevice, mut c ui.CanvasLayout) {
285285
cb := colorbox_component(c)
286286
mut hsv := HSVColor{}
287287
mut h, mut s, mut v := 0.0, 0.0, 0.0

component/grid.v

+19-19
Original file line numberDiff line numberDiff line change
@@ -494,14 +494,14 @@ fn grid_cb_clicked(mut cb ui.CheckBox) {
494494

495495
// main actions
496496

497-
fn grid_draw(d ui.DrawDevice, c &ui.CanvasLayout) {
497+
fn grid_draw(mut d ui.DrawDevice, c &ui.CanvasLayout) {
498498
// println("draw begin")
499499
mut g := grid_component(c)
500500
g.pos_x = g.from_x + c.x + c.offset_x
501501
// println("$g.rowbar_width == $g.pos_x")
502502

503503
for j in g.from_j .. g.to_j {
504-
g.vars[j].draw_device(d, j, mut g)
504+
g.vars[j].draw_device(mut d, j, mut g)
505505
g.pos_x += g.widths[j]
506506
// println("draw $j")
507507
}
@@ -516,14 +516,14 @@ fn grid_draw(d ui.DrawDevice, c &ui.CanvasLayout) {
516516
// println("draw end")
517517
}
518518

519-
fn grid_post_draw(d ui.DrawDevice, c &ui.CanvasLayout) {
519+
fn grid_post_draw(mut d ui.DrawDevice, c &ui.CanvasLayout) {
520520
// println("post draw begin")
521521
mut g := grid_component(c)
522522

523-
g.draw_device_current(d)
523+
g.draw_device_current(mut d)
524524

525-
g.draw_device_rowbar(d)
526-
g.draw_device_colbar(d)
525+
g.draw_device_rowbar(mut d)
526+
g.draw_device_colbar(mut d)
527527

528528
ui.scrollview_update(c)
529529
// println("post draw end")
@@ -548,14 +548,14 @@ fn (g &GridComponent) nrow() int {
548548
return if g.index.len > 0 { g.index.len } else { g.nrow }
549549
}
550550

551-
fn (mut g GridComponent) draw_device_current(d ui.DrawDevice) {
551+
fn (mut g GridComponent) draw_device_current(mut d ui.DrawDevice) {
552552
pos_x, pos_y := g.get_pos(g.cur_i, g.cur_j)
553553
w, h := g.widths[g.cur_j], g.height(g.cur_i)
554554
sel_color := gx.red
555555
g.layout.draw_device_rect_surrounded(d, pos_x, pos_y, w, h, 3, sel_color)
556556
}
557557

558-
fn (mut g GridComponent) draw_device_colbar(d ui.DrawDevice) {
558+
fn (mut g GridComponent) draw_device_colbar(mut d ui.DrawDevice) {
559559
mut tb := g.tb_colbar
560560
tb.is_focused = false
561561
tb.read_only = true
@@ -578,18 +578,18 @@ fn (mut g GridComponent) draw_device_colbar(d ui.DrawDevice) {
578578
unsafe {
579579
*tb.text = var
580580
}
581-
tb.draw_device(d)
581+
tb.draw_device(mut d)
582582
pos_x += g.widths[j]
583583
}
584584
tb.set_pos(g.pos_x, g.pos_y)
585585
tb.propose_size(g.rowbar_width, g.colbar_height)
586586
unsafe {
587587
*tb.text = ''
588588
}
589-
tb.draw_device(d)
589+
tb.draw_device(mut d)
590590
}
591591

592-
fn (mut g GridComponent) draw_device_rowbar(d ui.DrawDevice) {
592+
fn (mut g GridComponent) draw_device_rowbar(mut d ui.DrawDevice) {
593593
mut tb := g.tb_rowbar
594594
tb.is_focused = false
595595
tb.read_only = true
@@ -604,7 +604,7 @@ fn (mut g GridComponent) draw_device_rowbar(d ui.DrawDevice) {
604604
unsafe {
605605
*tb.text = '${g.ind(i) + 1}'
606606
}
607-
tb.draw_device(d)
607+
tb.draw_device(mut d)
608608
g.pos_y += g.height(i)
609609
}
610610
}
@@ -908,7 +908,7 @@ interface GridVar {
908908
id string
909909
grid &GridComponent
910910
compare(a int, b int) int
911-
draw_device(d ui.DrawDevice, j int, mut g GridComponent)
911+
draw_device(mut d ui.DrawDevice, j int, mut g GridComponent)
912912
value(i int) (string, GridType)
913913
mut:
914914
set_value(i int, v string)
@@ -954,7 +954,7 @@ fn (mut gtb GridTextBox) set_value(i int, v string) {
954954
gtb.var[i] = v
955955
}
956956

957-
fn (gtb &GridTextBox) draw_device(d ui.DrawDevice, j int, mut g GridComponent) {
957+
fn (gtb &GridTextBox) draw_device(mut d ui.DrawDevice, j int, mut g GridComponent) {
958958
mut tb := g.tb_string
959959
tb.is_focused = false
960960
tb.read_only = true
@@ -974,7 +974,7 @@ fn (gtb &GridTextBox) draw_device(d ui.DrawDevice, j int, mut g GridComponent) {
974974
}
975975
// g.layout.update_layout()
976976
// println("draw var tb $j: ${g.layout.get_children().map(it.id)}")
977-
tb.draw_device(d)
977+
tb.draw_device(mut d)
978978
g.pos_y += g.height(i)
979979
}
980980
}
@@ -1027,7 +1027,7 @@ fn (mut gdd GridDropdown) set_value(i int, v string) {
10271027
}
10281028
}
10291029

1030-
fn (gdd &GridDropdown) draw_device(d ui.DrawDevice, j int, mut g GridComponent) {
1030+
fn (gdd &GridDropdown) draw_device(mut d ui.DrawDevice, j int, mut g GridComponent) {
10311031
mut dd := g.dd_factor[gdd.name] or { return }
10321032
dd.set_visible(false)
10331033
g.pos_y = g.from_y + g.layout.y + g.layout.offset_y
@@ -1038,7 +1038,7 @@ fn (gdd &GridDropdown) draw_device(d ui.DrawDevice, j int, mut g GridComponent)
10381038
// println("$i) ${g.widths[j]}, ${g.height(i)}")
10391039
dd.propose_size(g.widths[j], g.height(i))
10401040
dd.selected_index = gdd.var.values[g.ind(i)]
1041-
dd.draw_device(d)
1041+
dd.draw_device(mut d)
10421042
g.pos_y += g.height(i)
10431043
}
10441044
}
@@ -1086,7 +1086,7 @@ fn (mut gcb GridCheckBox) set_value(i int, v string) {
10861086
}
10871087
}
10881088

1089-
fn (gcb &GridCheckBox) draw_device(d ui.DrawDevice, j int, mut g GridComponent) {
1089+
fn (gcb &GridCheckBox) draw_device(mut d ui.DrawDevice, j int, mut g GridComponent) {
10901090
mut cb := g.cb_bool
10911091
cb.is_focused = false
10921092
cb.set_visible(false)
@@ -1103,7 +1103,7 @@ fn (gcb &GridCheckBox) draw_device(d ui.DrawDevice, j int, mut g GridComponent)
11031103
// *cb.text = gtb.var[g.ind(i)].clone()
11041104
// }
11051105
cb.checked = gcb.var[g.ind(i)]
1106-
cb.draw_device(d)
1106+
cb.draw_device(mut d)
11071107
g.pos_y += g.height(i)
11081108
}
11091109
}

component/rasterview.v

+4-3
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ pub fn rasterview_canvaslayout(p RasterViewParams) &ui.CanvasLayout {
7575
full_size_fn: rv_full_size
7676
on_scroll_change: rv_scroll_change
7777
)
78-
layout.point_inside_visible = true
7978
rv := &RasterViewComponent{
8079
id: p.id
8180
layout: layout
@@ -127,7 +126,7 @@ fn rv_scroll_change(sw ui.ScrollableWidget) {
127126
}
128127
}
129128

130-
fn rv_draw(d ui.DrawDevice, c &ui.CanvasLayout) {
129+
fn rv_draw(mut d ui.DrawDevice, c &ui.CanvasLayout) {
131130
// Calculate the color of each pixel
132131
mut rv := rasterview_component(c)
133132
// N.B.: rv.size = rv.pixel_size + rv.inter
@@ -384,7 +383,9 @@ pub fn (mut rv RasterViewComponent) new_image() {
384383
}
385384

386385
pub fn (mut rv RasterViewComponent) load_image(path string) {
387-
rv.r.load_image(mut rv.layout.ui.gg, path)
386+
if mut rv.layout.ui.dd is ui.DrawDeviceContext {
387+
rv.r.load_image(mut rv.layout.ui.dd.Context, path)
388+
}
388389
rv.visible_pixels()
389390
rv.update_bounds()
390391
rv.layout.update_layout()

component/treeview.v

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ fn treeview_init(layout &ui.Stack) {
251251
}
252252
}
253253

254-
fn treeview_draw(d ui.DrawDevice, c &ui.CanvasLayout) {
254+
fn treeview_draw(mut d ui.DrawDevice, c &ui.CanvasLayout) {
255255
tv := treeview_component(c)
256256
dx := tv.indent * tv.levels[c.id]
257257
if tv.types[c.id] == 'root' {

examples/7guis/circledrawer.v

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ fn main() {
178178
ui.run(window)
179179
}
180180

181-
fn (app &App) draw_circles(d ui.DrawDevice, c &ui.CanvasLayout) {
181+
fn (app &App) draw_circles(mut d ui.DrawDevice, c &ui.CanvasLayout) {
182182
for i, circle in app.state.circles {
183183
if i == app.hover {
184184
c.draw_device_circle_filled(d, circle.x, circle.y, circle.radius, gx.light_gray)

examples/component/dirbrowser.v

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,7 @@ fn on_click_ok(b &ui.Button) {
3131
}
3232

3333
fn on_click_cancel(b &ui.Button) {
34-
b.ui.gg.quit()
34+
if b.ui.dd is ui.DrawDeviceContext {
35+
b.ui.dd.quit()
36+
}
3537
}

examples/component/filebrowser.v

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,7 @@ fn on_click_ok(b &ui.Button) {
3030
}
3131

3232
fn on_click_cancel(b &ui.Button) {
33-
b.ui.gg.quit()
33+
if b.ui.dd is ui.DrawDeviceContext {
34+
b.ui.dd.quit()
35+
}
3436
}

examples/demo_canvaslayout.v

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ fn lb_change_multi(lb &ui.ListBox) {
195195
println(lb.items.map('${it.text}: ${it.selected} ${it.disabled}'))
196196
}
197197

198-
fn draw(d ui.DrawDevice, c &ui.CanvasLayout) {
198+
fn draw(mut d ui.DrawDevice, c &ui.CanvasLayout) {
199199
w, h := c.full_width, c.full_height
200200
c.draw_device_rect_filled(d, 0, 0, w, h, gx.white)
201201
}

examples/demo_text_style.v

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fn window_init(mut w ui.Window) {
9595
// dtw.set_style('arial')
9696
}
9797

98-
fn (app &App) on_draw(d ui.DrawDevice, c &ui.CanvasLayout) {
98+
fn (app &App) on_draw(mut d ui.DrawDevice, c &ui.CanvasLayout) {
9999
mut dtw := ui.DrawTextWidget(c)
100100
dtw.load_style()
101101
c.draw_device_text(d, 10, 10, app.text)

examples/group2_resizable.v

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ fn main() {
3131
children: [
3232
ui.group(
3333
title: 'First group'
34+
clipping: true
3435
children: [
3536
ui.textbox(
3637
max_len: 20
@@ -54,6 +55,7 @@ fn main() {
5455
),
5556
ui.group(
5657
title: 'Second group'
58+
clipping: true
5759
children: [
5860
ui.textbox(
5961
max_len: 20

0 commit comments

Comments
 (0)