From 8866addcc2758effe4d0bd773840f844921077a7 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 2 Oct 2022 16:17:36 +0300 Subject: [PATCH 1/8] wrap Enum(int) with unsafe{} --- src/extra_draw.v | 2 +- src/interface_scrollable.v | 2 +- src/layout_stack.v | 2 +- src/layout_window.v | 14 +++++++------- src/style_button.v | 4 ++-- src/style_checkbox.v | 4 ++-- src/style_label.v | 4 ++-- src/style_listbox.v | 4 ++-- src/style_menu.v | 4 ++-- src/style_radio.v | 4 ++-- src/style_rectangle.v | 4 ++-- src/tool_key.v | 8 ++++---- src/widget_button.v | 2 +- 13 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/extra_draw.v b/src/extra_draw.v index 07bf7529..f3f8062b 100644 --- a/src/extra_draw.v +++ b/src/extra_draw.v @@ -89,7 +89,7 @@ mut: // No text_size to not conflict with fn get_text_size(w DrawText, text_ string) (int, int) { - w.ui.gg.set_cfg(w.text_cfg) + w.ui.gg.set_text_cfg(w.text_cfg) return w.ui.gg.text_size(text_) } diff --git a/src/interface_scrollable.v b/src/interface_scrollable.v index 646a45ea..bab5eddc 100644 --- a/src/interface_scrollable.v +++ b/src/interface_scrollable.v @@ -827,7 +827,7 @@ fn scrollview_mouse_move(mut sv ScrollView, e &MouseMoveEvent, zzz voidptr) { sv.offset_y = sv.orig_offset + int(f32(e.y - sv.drag_offset) / a_y) // println("move: $sv.offset_y = $sv.orig_offset + ($e.y - $sv.drag_offset) / $a_y") } - sv.change_value(ScrollViewPart(sv.dragging)) + sv.change_value(unsafe { ScrollViewPart(sv.dragging) }) } } diff --git a/src/layout_stack.v b/src/layout_stack.v index 71f02a7e..b968bbb9 100644 --- a/src/layout_stack.v +++ b/src/layout_stack.v @@ -524,7 +524,7 @@ fn (mut s Stack) set_cache_sizes() { c.adj_widths, c.adj_heights = [0].repeat(len), [0].repeat(len) c.fixed_widths, c.fixed_heights = [0].repeat(len), [0].repeat(len) c.weight_widths, c.weight_heights = [0.0].repeat(len), [0.0].repeat(len) - c.width_type, c.height_type = [ChildSize(0)].repeat(len), [ChildSize(0)].repeat(len) + c.width_type, c.height_type = [ChildSize.compact].repeat(len), [ChildSize.compact].repeat(len) $if s_scas ? { s.debug_ids = env('UI_IDS').split(',').clone() diff --git a/src/layout_window.v b/src/layout_window.v index 2f5c2741..8ac7f5ee 100644 --- a/src/layout_window.v +++ b/src/layout_window.v @@ -683,7 +683,7 @@ fn window_key_down(event gg.Event, ui &UI) { // println('window_keydown $event') e := KeyEvent{ key: Key(event.key_code) - mods: KeyMod(event.modifiers) + mods: unsafe { KeyMod(event.modifiers) } codepoint: event.char_code code: int(event.key_code) // action: action @@ -746,7 +746,7 @@ fn window_char(event gg.Event, ui &UI) { window := ui.window e := KeyEvent{ codepoint: event.char_code - mods: KeyMod(event.modifiers) + mods: unsafe { KeyMod(event.modifiers) } } if window.char_fn != WindowKeyFn(0) { window.char_fn(window, e) @@ -764,9 +764,9 @@ fn window_mouse_down(event gg.Event, mut ui UI) { x: int(event.mouse_x / ui.gg.scale) y: int(event.mouse_y / ui.gg.scale) button: MouseButton(event.mouse_button) - mods: KeyMod(event.modifiers) + mods: unsafe { KeyMod(event.modifiers) } } - ui.keymods = KeyMod(event.modifiers) + ui.keymods = unsafe { KeyMod(event.modifiers) } if int(event.mouse_button) < 3 { ui.btn_down[int(event.mouse_button)] = true } @@ -825,7 +825,7 @@ fn window_mouse_up(event gg.Event, mut ui UI) { x: int(event.mouse_x / ui.gg.scale) y: int(event.mouse_y / ui.gg.scale) button: MouseButton(event.mouse_button) - mods: KeyMod(event.modifiers) + mods: unsafe { KeyMod(event.modifiers) } } if unsafe { window.child_window == 0 } && window.mouse_up_fn != WindowMouseFn(0) { // && action == voidptr(0) { @@ -853,7 +853,7 @@ fn window_mouse_up(event gg.Event, mut ui UI) { drag_child_dropped(mut window) } mut gui := unsafe { ui } - gui.keymods = KeyMod(0) + gui.keymods = unsafe { KeyMod(0) } } // OBSOLETE see window_click_or_touch_pad @@ -1029,7 +1029,7 @@ fn window_files_droped(event gg.Event, mut ui UI) { x: int(event.mouse_x / ui.gg.scale) y: int(event.mouse_y / ui.gg.scale) button: MouseButton(event.mouse_button) - mods: KeyMod(event.modifiers) + mods: unsafe { KeyMod(event.modifiers) } } if window.files_droped_fn != WindowMouseFn(0) { // && action == voidptr(0) { window.files_droped_fn(window, e) diff --git a/src/style_button.v b/src/style_button.v index 09192163..bb07e3df 100644 --- a/src/style_button.v +++ b/src/style_button.v @@ -64,8 +64,8 @@ pub fn (mut bs ButtonStyle) from_toml(a toml.Any) { bs.text_font_name = a.value('text_font_name').string() bs.text_color = HexColor(a.value('text_color').string()).color() bs.text_size = a.value('text_size').int() - bs.text_align = TextHorizontalAlign(a.value('text_align').int()) - bs.text_vertical_align = TextVerticalAlign(a.value('text_vertical_align').int()) + bs.text_align = unsafe { TextHorizontalAlign(a.value('text_align').int()) } + bs.text_vertical_align = unsafe { TextVerticalAlign(a.value('text_vertical_align').int()) } } pub fn (mut b Button) load_style() { diff --git a/src/style_checkbox.v b/src/style_checkbox.v index 41d50ee7..dbb3dcb0 100644 --- a/src/style_checkbox.v +++ b/src/style_checkbox.v @@ -56,8 +56,8 @@ pub fn (mut cbs CheckBoxStyle) from_toml(a toml.Any) { cbs.text_font_name = a.value('text_font_name').string() cbs.text_color = HexColor(a.value('text_color').string()).color() cbs.text_size = a.value('text_size').int() - cbs.text_align = TextHorizontalAlign(a.value('text_align').int()) - cbs.text_vertical_align = TextVerticalAlign(a.value('text_vertical_align').int()) + cbs.text_align = unsafe { TextHorizontalAlign(a.value('text_align').int()) } + cbs.text_vertical_align = unsafe { TextVerticalAlign(a.value('text_vertical_align').int()) } } pub fn (mut cb CheckBox) load_style() { diff --git a/src/style_label.v b/src/style_label.v index 14dd2a9f..9b614311 100644 --- a/src/style_label.v +++ b/src/style_label.v @@ -32,8 +32,8 @@ pub fn (mut ls LabelStyle) from_toml(a toml.Any) { ls.text_font_name = a.value('text_font_name').string() ls.text_color = HexColor(a.value('text_color').string()).color() ls.text_size = a.value('text_size').int() - ls.text_align = TextHorizontalAlign(a.value('text_align').int()) - ls.text_vertical_align = TextVerticalAlign(a.value('text_vertical_align').int()) + ls.text_align = unsafe { TextHorizontalAlign(a.value('text_align').int()) } + ls.text_vertical_align = unsafe { TextVerticalAlign(a.value('text_vertical_align').int()) } } pub fn (mut l Label) load_style() { diff --git a/src/style_listbox.v b/src/style_listbox.v index 320b308c..893c552a 100644 --- a/src/style_listbox.v +++ b/src/style_listbox.v @@ -64,8 +64,8 @@ pub fn (mut lbs ListBoxStyle) from_toml(a toml.Any) { lbs.text_font_name = a.value('text_font_name').string() lbs.text_color = HexColor(a.value('text_color').string()).color() lbs.text_size = a.value('text_size').int() - lbs.text_align = TextHorizontalAlign(a.value('text_align').int()) - lbs.text_vertical_align = TextVerticalAlign(a.value('text_vertical_align').int()) + lbs.text_align = unsafe { TextHorizontalAlign(a.value('text_align').int()) } + lbs.text_vertical_align = unsafe { TextVerticalAlign(a.value('text_vertical_align').int()) } } pub fn (mut lb ListBox) load_style() { diff --git a/src/style_menu.v b/src/style_menu.v index d60ef09f..f132cd98 100644 --- a/src/style_menu.v +++ b/src/style_menu.v @@ -60,8 +60,8 @@ pub fn (mut ms MenuStyle) from_toml(a toml.Any) { ms.text_font_name = a.value('text_font_name').string() ms.text_color = HexColor(a.value('text_color').string()).color() ms.text_size = a.value('text_size').int() - ms.text_align = TextHorizontalAlign(a.value('text_align').int()) - ms.text_vertical_align = TextVerticalAlign(a.value('text_vertical_align').int()) + ms.text_align = unsafe { TextHorizontalAlign(a.value('text_align').int()) } + ms.text_vertical_align = unsafe { TextVerticalAlign(a.value('text_vertical_align').int()) } } pub fn (mut m Menu) load_style() { diff --git a/src/style_radio.v b/src/style_radio.v index a5715de3..c9cd2547 100644 --- a/src/style_radio.v +++ b/src/style_radio.v @@ -56,8 +56,8 @@ pub fn (mut rs RadioStyle) from_toml(a toml.Any) { rs.text_font_name = a.value('text_font_name').string() rs.text_color = HexColor(a.value('text_color').string()).color() rs.text_size = a.value('text_size').int() - rs.text_align = TextHorizontalAlign(a.value('text_align').int()) - rs.text_vertical_align = TextVerticalAlign(a.value('text_vertical_align').int()) + rs.text_align = unsafe { TextHorizontalAlign(a.value('text_align').int()) } + rs.text_vertical_align = unsafe { TextVerticalAlign(a.value('text_vertical_align').int()) } } pub fn (mut r Radio) load_style() { diff --git a/src/style_rectangle.v b/src/style_rectangle.v index 6f2a80e4..158f2a6a 100644 --- a/src/style_rectangle.v +++ b/src/style_rectangle.v @@ -52,8 +52,8 @@ pub fn (mut rects RectangleStyle) from_toml(a toml.Any) { rects.text_font_name = a.value('text_font_name').string() rects.text_color = HexColor(a.value('text_color').string()).color() rects.text_size = a.value('text_size').int() - rects.text_align = TextHorizontalAlign(a.value('text_align').int()) - rects.text_vertical_align = TextVerticalAlign(a.value('text_vertical_align').int()) + rects.text_align = unsafe { TextHorizontalAlign(a.value('text_align').int()) } + rects.text_vertical_align = unsafe { TextVerticalAlign(a.value('text_vertical_align').int()) } } pub fn (mut rect Rectangle) load_style() { diff --git a/src/tool_key.v b/src/tool_key.v index dc87f5d3..e6b10918 100644 --- a/src/tool_key.v +++ b/src/tool_key.v @@ -24,7 +24,7 @@ fn parse_mods_shortcut(s string) (KeyMod, string) { } } } - return KeyMod(mods), parts[parts.len - 1].trim_space().to_lower() + return unsafe { KeyMod(mods) }, parts[parts.len - 1].trim_space().to_lower() } pub fn parse_char_key(key_str string) int { @@ -99,9 +99,9 @@ pub enum KeyMod { } pub enum KeyState { - press = 1 - release = 0 - repeat = 2 + release + press + repeat } pub struct KeyEvent { diff --git a/src/widget_button.v b/src/widget_button.v index 765ec977..744f241b 100644 --- a/src/widget_button.v +++ b/src/widget_button.v @@ -37,7 +37,7 @@ pub struct Button { height_ int pub mut: id string - state ButtonState = ButtonState(1) + state ButtonState = .normal height int width int z_index int From fb83c200647d73324c8c360252b7c0290d6b0117 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 20 Oct 2022 21:34:58 +0300 Subject: [PATCH 2/8] fix compilation of ui with V from https://github.com/vlang/v/pull/16123 --- libvg/svg.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libvg/svg.v b/libvg/svg.v index 55e77a6a..02c1f587 100644 --- a/libvg/svg.v +++ b/libvg/svg.v @@ -49,7 +49,7 @@ pub fn (mut s Svg) end() { pub fn (mut s Svg) save(filepath string) ? { // write it to a file - os.write_file_array(filepath, *s.content)? + os.write_file_array(filepath, *s.content) or { return err } } [params] From 15c799b2e84be021f42bf8849ee47f750d6a9895 Mon Sep 17 00:00:00 2001 From: yuyi Date: Thu, 27 Oct 2022 15:32:10 +0800 Subject: [PATCH 3/8] all: change optional to result (#486) --- libvg/svg.v | 4 ++-- src/widget_listbox.v | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libvg/svg.v b/libvg/svg.v index 02c1f587..2ae6f04f 100644 --- a/libvg/svg.v +++ b/libvg/svg.v @@ -47,9 +47,9 @@ pub fn (mut s Svg) end() { s.content.write_string('\n') } -pub fn (mut s Svg) save(filepath string) ? { +pub fn (mut s Svg) save(filepath string) ! { // write it to a file - os.write_file_array(filepath, *s.content) or { return err } + os.write_file_array(filepath, *s.content)! } [params] diff --git a/src/widget_listbox.v b/src/widget_listbox.v index 6533be45..69b35d18 100644 --- a/src/widget_listbox.v +++ b/src/widget_listbox.v @@ -406,7 +406,7 @@ pub fn (lb &ListBox) indices() []int { } // Returns the id and the text of the selected item -pub fn (lb &ListBox) selected() ?(string, string) { +pub fn (lb &ListBox) selected() !(string, string) { if !lb.is_selected() { return error('Nothing is selected') } @@ -431,7 +431,7 @@ pub fn (lb &ListBox) items() []&ListItem { } // Returns the index of the selected item -pub fn (lb &ListBox) selected_at() ?int { +pub fn (lb &ListBox) selected_at() !int { if !lb.is_selected() { return error('Nothing is selected') } From 63c2286b871102293d7c6d57991a681b9f7813c1 Mon Sep 17 00:00:00 2001 From: Swastik Baranwal Date: Thu, 27 Oct 2022 20:28:07 +0530 Subject: [PATCH 4/8] all: add mut to interface smartcast (#487) --- src/interface_layout.v | 18 +++++++++--------- src/interface_widget.v | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/interface_layout.v b/src/interface_layout.v index 30039b36..0f17fee3 100644 --- a/src/interface_layout.v +++ b/src/interface_layout.v @@ -19,7 +19,7 @@ mut: pub fn (l &Layout) set_children_depth(z_index int) { for mut child in l.get_children() { - if child is Layout { + if mut child is Layout { l2 := child as Layout l2.set_children_depth(z_index) } @@ -30,7 +30,7 @@ pub fn (l &Layout) set_children_depth(z_index int) { pub fn (l &Layout) incr_children_depth(z_inc int) { // println("incr_children_depth $l.id z_inc=$z_inc") for mut child in l.get_children() { - if child is Layout { + if mut child is Layout { l2 := child as Layout l2.incr_children_depth(z_inc) } @@ -82,10 +82,10 @@ pub fn (l &Layout) has_child(widget &Widget) bool { pub fn (layout Layout) unfocus_all() { // println('window.unfocus_all()') for mut child in layout.get_children() { - if child is Layout { + if mut child is Layout { l := child as Layout l.unfocus_all() - } else if child is Focusable { + } else if mut child is Focusable { mut f := child as Focusable f.unfocus() } @@ -99,7 +99,7 @@ pub fn (layout Layout) set_focus_next() bool { $if focus ? { println('child to focus_next $child.id() ${child is Focusable} ') } - focused_found = if child is Layout { + focused_found = if mut child is Layout { l := child as Layout l.set_focus_next() } else { @@ -108,7 +108,7 @@ pub fn (layout Layout) set_focus_next() bool { if focused_found { break } - if child is Focusable { + if mut child is Focusable { mut f := child as Focusable if f.has_focusable() { // Focus on the next widget @@ -133,7 +133,7 @@ pub fn (layout Layout) set_focus_prev() bool { $if focus ? { println('child to focus_prev $child.id() $child.type_name() ${child is Focusable}') } - focused_found = if child is Layout { + focused_found = if mut child is Layout { l := child as Layout l.set_focus_prev() } else { @@ -142,7 +142,7 @@ pub fn (layout Layout) set_focus_prev() bool { if focused_found { break } - if child is Focusable { + if mut child is Focusable { mut f := child as Focusable if f.has_focusable() { // Focus on the next widget @@ -238,7 +238,7 @@ pub fn (l Layout) debug_show_children_tree(level int) { } for i, mut child in l.get_children() { println('${' '.repeat(level)} $level:$i -> $child.id ($child.type_name()) ($child.x, $child.y) $child.size() z_index: $child.z_index') - if child is Layout { + if mut child is Layout { c := child as Layout c.debug_show_children_tree(level + 1) } diff --git a/src/interface_widget.v b/src/interface_widget.v index a5e7a634..6ba5086a 100644 --- a/src/interface_widget.v +++ b/src/interface_widget.v @@ -74,13 +74,13 @@ pub fn (mut w Widget) scaled_bounds() gg.Rect { pub fn (w Widget) subwindow_parent() (bool, Layout) { mut p := w.parent for { - if p is Window { + if mut p is Window { break } - if p is SubWindow { + if mut p is SubWindow { return true, p } - if p is Widget { + if mut p is Widget { wp := p as Widget p = wp.parent continue From 95d98d81de4ee811ffe30bbbc58ef783f8a4f894 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 7 Nov 2022 10:06:51 +0200 Subject: [PATCH 5/8] make UI more robust to missing/invalid .toml files, by just ignoring them, and printing an error message, instead of panic-ing --- src/styles.v | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/styles.v b/src/styles.v index 73d6cb0c..fffbcb01 100644 --- a/src/styles.v +++ b/src/styles.v @@ -65,7 +65,10 @@ pub fn (s Style) to_toml() string { } pub fn parse_style_toml_file(path string) Style { - doc := toml.parse_file(path) or { panic(err) } + doc := toml.parse_file(path) or { + eprintln('UI: using the default UI style, since the .toml file `$path` was invalid. TOML parse error: $err') + return default_style() + } mut s := Style{} s.win.from_toml(doc.value('window')) s.btn.from_toml(doc.value('button')) From 188d3581496233ffe281fec734621607775da86b Mon Sep 17 00:00:00 2001 From: yuyi Date: Sat, 12 Nov 2022 17:25:43 +0800 Subject: [PATCH 6/8] textbox: fix textbox.draw_device() (fix #444 #483 #484) (#489) --- examples/7guis/timer.v | 3 ++- examples/demo_logview.v | 2 +- src/ui.v | 40 ++++++++++++++++++++++++---------------- src/ui_default.c.v | 6 ++---- src/widget_textbox.v | 11 +++++++++-- 5 files changed, 38 insertions(+), 24 deletions(-) diff --git a/examples/7guis/timer.v b/examples/7guis/timer.v index 5b9b7ac0..299eb2ea 100644 --- a/examples/7guis/timer.v +++ b/examples/7guis/timer.v @@ -74,6 +74,7 @@ fn main() { ] ) app.window = window + // go app.timer() ui.run(window) } @@ -84,7 +85,7 @@ fn (mut app App) on_value_changed(slider &ui.Slider) { fn (mut app App) on_reset(button &ui.Button) { app.elapsed_time = 0.0 - go app.timer() + spawn app.timer() } fn (mut app App) timer() { diff --git a/examples/demo_logview.v b/examples/demo_logview.v index 032f5430..80035657 100644 --- a/examples/demo_logview.v +++ b/examples/demo_logview.v @@ -49,5 +49,5 @@ fn (mut app App) wait_complete(mut tb ui.TextBox) { fn (mut app App) btn_connect(btn &ui.Button) { mut tb := app.window.textbox('tb') - go app.wait_complete(mut tb) + spawn app.wait_complete(mut tb) } diff --git a/src/ui.v b/src/ui.v index 2f58857e..e7bd0992 100644 --- a/src/ui.v +++ b/src/ui.v @@ -22,22 +22,28 @@ pub mut: bmp &DrawDeviceBitmap = unsafe { nil } layout_print bool show_cursor bool - last_type_time i64 // used only in textbox.v - clipboard &clipboard.Clipboard = unsafe { nil } - btn_down [3]bool - nb_click int - keymods KeyMod - styles map[string]Style - style_colors []gx.Color + last_type_time i64 + // used only in textbox.v + clipboard &clipboard.Clipboard = unsafe { nil } + btn_down [3]bool + nb_click int + keymods KeyMod + styles map[string]Style + style_colors []gx.Color mut: - cb_image gg.Image // used only in checkbox.v - radio_image gg.Image // used in radio.v but no use, in idle_loop() - radio_selected_image gg.Image // used only in radio.v - down_arrow gg.Image // used only in dropdown.v - resource_cache map[string]gg.Image // used only in picture.v - imgs map[string]gg.Image - closed bool - ticks int + cb_image gg.Image + // used only in checkbox.v + radio_image gg.Image + // used in radio.v but no use, in idle_loop() + radio_selected_image gg.Image + // used only in radio.v + down_arrow gg.Image + // used only in dropdown.v + resource_cache map[string]gg.Image + // used only in picture.v + imgs map[string]gg.Image + closed bool + ticks int // text styles and font set text_styles map[string]TextStyle fonts FontSet @@ -101,6 +107,7 @@ fn (mut gui UI) load_imgs() { gui.load_img('radio', $embed_file('assets/img/radio.png').to_bytes(), 'assets/img/radio.png') gui.radio_image = gui.img('radio') gui.radio_selected_image = gui.img('radio_selected') + // load mouse gui.load_img('blue', $embed_file('assets/img/cursor.png').to_bytes(), 'assets/img/cursor.png') gui.load_img('hand', $embed_file('assets/img/icons8-hand-cursor-50.png').to_bytes(), @@ -108,6 +115,7 @@ fn (mut gui UI) load_imgs() { gui.load_img('vmove', $embed_file('assets/img/icons8-cursor-67.png').to_bytes(), 'assets/img/icons8-cursor-67.png') gui.load_img('text', $embed_file('assets/img/icons8-text-cursor-50.png').to_bytes(), 'assets/img/icons8-text-cursor-50.png') + // v-logo gui.load_img('v-logo', $embed_file('assets/img/logo.png').to_bytes(), 'examples/assets/img/logo.png') } @@ -158,7 +166,7 @@ pub fn run(window &Window) { } $else { mut gui := window.ui gui.window = window // TODO: this can be removed since now in the window constructor - go gui.idle_loop() + spawn gui.idle_loop() gui.gg.run() gui.closed = true diff --git a/src/ui_default.c.v b/src/ui_default.c.v index ed7bacf2..072cb439 100644 --- a/src/ui_default.c.v +++ b/src/ui_default.c.v @@ -20,7 +20,7 @@ pub fn message_box(s string) { waitgroup: sync.new_waitgroup() } message_app.waitgroup.add(1) - go run_message_dialog(mut message_app, s) + spawn run_message_dialog(mut message_app, s) message_app.waitgroup.wait() } @@ -38,9 +38,7 @@ fn run_message_dialog(mut message_app MessageApp, s string) { mut height := 40 mut widgets := []Widget{} widgets = [ - // TODO: add hspace and vspace separators - label(text: ''), - ] + /* TODO: add hspace and vspace separators */ label(text: '')] for tline in text_lines { widgets << label(text: tline) height += 14 diff --git a/src/widget_textbox.v b/src/widget_textbox.v index 9d14dca7..c17e0b1a 100644 --- a/src/widget_textbox.v +++ b/src/widget_textbox.v @@ -336,8 +336,12 @@ pub fn (mut tb TextBox) draw_device(d DrawDevice) { } else { d.draw_rect_filled(tb.x, tb.y, tb.width, tb.height, tb.style.bg_color) if !tb.borderless { + mut is_error := false + if tb.is_error != 0 { + is_error = *(tb.is_error) + } draw_device_inner_border(tb.border_accentuated, d, tb.x, tb.y, tb.width, tb.height, - tb.is_error != 0 && *tb.is_error) + is_error) } } if tb.is_multiline { @@ -345,7 +349,10 @@ pub fn (mut tb TextBox) draw_device(d DrawDevice) { } else { dtw := DrawTextWidget(tb) dtw.draw_device_load_style(d) - text := *(tb.text) + mut text := '' + if tb.text != 0 { + text = *(tb.text) + } ustr := text.runes() text_len := ustr.len mut placeholder := tb.placeholder From 99c9fee2a68aa272607f158c84fa19b96fbc8dbd Mon Sep 17 00:00:00 2001 From: R cqls Date: Sat, 12 Nov 2022 13:03:03 +0100 Subject: [PATCH 7/8] vfmt --- examples/7guis/timer.v | 2 +- examples/demo_logview.v | 2 +- src/draw_device_bitmap.v | 22 ++++++------- src/draw_device_print.v | 10 +++--- src/draw_device_svg.v | 10 +++--- src/extra_draw.v | 4 +-- src/extra_text_syntax.v | 4 +-- src/interface_draw_device.v | 18 +++++------ src/interface_drawtextwidget.v | 42 ++++++++++++------------- src/interface_focusable.v | 40 ++++++++++++------------ src/layout_canvas.v | 2 +- src/layout_window.v | 50 +++++++++++++++--------------- src/tool_text_style.v | 56 +++++++++++++++++----------------- src/ui.v | 32 +++++++++---------- src/ui_default.c.v | 2 +- src/widget_button.v | 6 ++-- src/widget_canvas.v | 10 +++--- src/widget_listbox.v | 10 +++--- src/widget_picture.v | 6 ++-- src/widget_textbox_textview.v | 12 ++++---- 20 files changed, 170 insertions(+), 170 deletions(-) diff --git a/examples/7guis/timer.v b/examples/7guis/timer.v index 5b9b7ac0..430bfc4b 100644 --- a/examples/7guis/timer.v +++ b/examples/7guis/timer.v @@ -84,7 +84,7 @@ fn (mut app App) on_value_changed(slider &ui.Slider) { fn (mut app App) on_reset(button &ui.Button) { app.elapsed_time = 0.0 - go app.timer() + spawn app.timer() } fn (mut app App) timer() { diff --git a/examples/demo_logview.v b/examples/demo_logview.v index 032f5430..80035657 100644 --- a/examples/demo_logview.v +++ b/examples/demo_logview.v @@ -49,5 +49,5 @@ fn (mut app App) wait_complete(mut tb ui.TextBox) { fn (mut app App) btn_connect(btn &ui.Button) { mut tb := app.window.textbox('tb') - go app.wait_complete(mut tb) + spawn app.wait_complete(mut tb) } diff --git a/src/draw_device_bitmap.v b/src/draw_device_bitmap.v index fd838114..180dc330 100644 --- a/src/draw_device_bitmap.v +++ b/src/draw_device_bitmap.v @@ -75,19 +75,19 @@ pub fn (d &DrawDeviceBitmap) set_text_style(font_name string, font_path string, } } -fn (d &DrawDeviceBitmap) apply_text_config(mut ts &libvg.BitmapTextStyle, cfg gx.TextCfg) { +fn (d &DrawDeviceBitmap) apply_text_config(mut ts libvg.BitmapTextStyle, cfg gx.TextCfg) { ts.font_name = if cfg.family == 'system' { 'Systemfont' } else { cfg.family } ts.font_path = d.ts.font_path ts.size = cfg.size ts.color = cfg.color - ts.set_align( int( cfg.align ) ) - ts.set_vertical_align( int( cfg.vertical_align ) ) + ts.set_align(int(cfg.align)) + ts.set_vertical_align(int(cfg.vertical_align)) } pub fn (d &DrawDeviceBitmap) draw_text(x int, y int, text string, cfg gx.TextCfg) { // println('$d.id draw_text_default($x, $y, $text) $d.ts') - mut ts := libvg.BitmapTextStyle{} - d.apply_text_config(mut &ts, cfg) + mut ts := libvg.BitmapTextStyle{} + d.apply_text_config(mut &ts, cfg) mut r := d.r r.init_style(ts) // r.get_info_string() @@ -109,20 +109,20 @@ pub fn (d &DrawDeviceBitmap) draw_text_default(x int, y int, text string) { pub fn (d &DrawDeviceBitmap) draw_text_def(x int, y int, text string) {} pub fn (d &DrawDeviceBitmap) set_text_cfg(cfg gx.TextCfg) { - mut ts := d.ts - d.apply_text_config(mut &ts, cfg) + mut ts := d.ts + d.apply_text_config(mut &ts, cfg) } -pub fn (d &DrawDeviceBitmap) text_size(s string) (int,int) { - return 0, 0 +pub fn (d &DrawDeviceBitmap) text_size(s string) (int, int) { + return 0, 0 } pub fn (d &DrawDeviceBitmap) text_width(s string) int { - return 0 + return 0 } pub fn (d &DrawDeviceBitmap) text_height(s string) int { - return 0 + return 0 } pub fn (d &DrawDeviceBitmap) scissor_rect(x int, y int, w int, h int) {} diff --git a/src/draw_device_print.v b/src/draw_device_print.v index 54b4ad81..67da4ae3 100644 --- a/src/draw_device_print.v +++ b/src/draw_device_print.v @@ -35,7 +35,7 @@ pub fn (d &DrawDevicePrint) draw_text(x int, y int, text string, cfg gx.TextCfg) println('$d.id draw_text($x, $y, $text, $cfg)') } -//pub fn (d &DrawDevicePrint) draw_text_def(x int, y int, text string) { +// pub fn (d &DrawDevicePrint) draw_text_def(x int, y int, text string) { pub fn (d &DrawDevicePrint) draw_text_default(x int, y int, text string) { println('$d.id draw_text_default($x, $y, $text)') } @@ -44,16 +44,16 @@ pub fn (d &DrawDevicePrint) draw_text_def(x int, y int, text string) {} pub fn (d &DrawDevicePrint) set_text_cfg(c_ gx.TextCfg) {} -pub fn (d &DrawDevicePrint) text_size(s string) (int,int) { - return 0, 0 +pub fn (d &DrawDevicePrint) text_size(s string) (int, int) { + return 0, 0 } pub fn (d &DrawDevicePrint) text_width(s string) int { - return 0 + return 0 } pub fn (d &DrawDevicePrint) text_height(s string) int { - return 0 + return 0 } pub fn (d &DrawDevicePrint) scissor_rect(x int, y int, w int, h int) {} diff --git a/src/draw_device_svg.v b/src/draw_device_svg.v index 4737b20f..6ee81fbc 100644 --- a/src/draw_device_svg.v +++ b/src/draw_device_svg.v @@ -82,7 +82,7 @@ pub fn (d &DrawDeviceSVG) draw_text(x int, y int, text string, cfg gx.TextCfg) { s.text(x, y, text, 'none', d.ts) } -//pub fn (d &DrawDeviceSVG) draw_text_def(x int, y int, text string) { +// pub fn (d &DrawDeviceSVG) draw_text_def(x int, y int, text string) { pub fn (d &DrawDeviceSVG) draw_text_default(x int, y int, text string) { // println('$d.id draw_text_default($x, $y, $text)') mut s := d.s @@ -93,16 +93,16 @@ pub fn (d &DrawDeviceSVG) draw_text_def(x int, y int, text string) {} pub fn (d &DrawDeviceSVG) set_text_cfg(c gx.TextCfg) {} -pub fn (d &DrawDeviceSVG) text_size(s string) (int,int) { - return 0, 0 +pub fn (d &DrawDeviceSVG) text_size(s string) (int, int) { + return 0, 0 } pub fn (d &DrawDeviceSVG) text_width(s string) int { - return 0 + return 0 } pub fn (d &DrawDeviceSVG) text_height(s string) int { - return 0 + return 0 } pub fn (d &DrawDeviceSVG) scissor_rect(x int, y int, w int, h int) { diff --git a/src/extra_draw.v b/src/extra_draw.v index 444147e6..e10d8119 100644 --- a/src/extra_draw.v +++ b/src/extra_draw.v @@ -2,7 +2,7 @@ module ui import gx import math -//import sokol.sgl +// import sokol.sgl // const ( // empty_text_cfg = gx.TextCfg{} @@ -362,7 +362,7 @@ pub fn update_text_texture(sg_img C.sg_image, w int, h int, buf &u8) { // REMOVED: this function uses internals of gg.Context which we probably do not // want to reproduce in the DrawDevice interface -//pub fn (c &CanvasLayout) draw_texture(simg C.sg_image) { +// pub fn (c &CanvasLayout) draw_texture(simg C.sg_image) { // ctx := c.ui.gg // cx, cy := c.x + c.offset_x, c.y + c.offset_y // u0 := f32(0.0) diff --git a/src/extra_text_syntax.v b/src/extra_text_syntax.v index 090ec85c..2ea798a9 100644 --- a/src/extra_text_syntax.v +++ b/src/extra_text_syntax.v @@ -320,14 +320,14 @@ fn (sh &SyntaxHighLighter) is_not_included(from int, to int) bool { } fn (mut sh SyntaxHighLighter) add_chunk(typ string, y int, start int, end int) { - //x := sh.tv.tb.x + sh.tv.left_margin + int(sh.tv.text_width_additive(sh.ustr[0..start].string())) + // x := sh.tv.tb.x + sh.tv.left_margin + int(sh.tv.text_width_additive(sh.ustr[0..start].string())) x := sh.tv.tb.x + sh.tv.left_margin + int(sh.tv.text_width(sh.ustr[0..start].string())) text := sh.ustr[start..end].string() chunk := Chunk{ x: x y: y text: text - //width: int(sh.tv.text_width_additive(text)) + // width: int(sh.tv.text_width_additive(text)) width: int(sh.tv.text_width(text)) } sh.chunks[typ] << chunk diff --git a/src/interface_draw_device.v b/src/interface_draw_device.v index d88f1044..baf33b9c 100644 --- a/src/interface_draw_device.v +++ b/src/interface_draw_device.v @@ -8,18 +8,18 @@ interface DrawDevice { has_text_style() bool set_text_style(font_name string, font_path string, size int, color gx.Color, align int, vertical_align int) draw_text_default(x int, y int, text string) // (ui) default ui TextStyle - // text - draw_text(x int, y int, text string, cfg gx.TextCfg) + // text + draw_text(x int, y int, text string, cfg gx.TextCfg) draw_text_def(x int, y int, text string) // (gg.Context) use set_text_cfg - set_text_cfg(gx.TextCfg) - text_size(string) (int,int) - text_width(string) int - text_height(string) int + set_text_cfg(gx.TextCfg) + text_size(string) (int, int) + text_width(string) int + text_height(string) int // clipping scissor_rect(x int, y int, w int, h int) // drawing methods - //draw_pixel(x f32, y f32, c gx.Color) - //draw_pixels(points []f32, c gx.Color) + // draw_pixel(x f32, y f32, c gx.Color) + // draw_pixels(points []f32, c gx.Color) draw_image(x f32, y f32, width f32, height f32, img &gg.Image) draw_triangle_empty(x f32, y f32, x2 f32, y2 f32, x3 f32, y3 f32, color gx.Color) draw_triangle_filled(x f32, y f32, x2 f32, y2 f32, x3 f32, y3 f32, color gx.Color) @@ -38,7 +38,7 @@ interface DrawDevice { draw_convex_poly(points []f32, color gx.Color) draw_poly_empty(points []f32, color gx.Color) mut: - set_bg_color(color gx.Color) + set_bg_color(color gx.Color) } fn (d DrawDevice) draw_window(mut w Window) { diff --git a/src/interface_drawtextwidget.v b/src/interface_drawtextwidget.v index 229059bc..e674c26d 100644 --- a/src/interface_drawtextwidget.v +++ b/src/interface_drawtextwidget.v @@ -137,26 +137,26 @@ pub fn (mut w DrawTextWidget) load_style_(d DrawDevice, ts TextStyle) { int(ts.align), int(ts.vertical_align)) } $if !screenshot ? { - if mut w.ui.dd is gg.Context { - gg := w.ui.dd - fons := gg.ft.fons - fons.set_font(w.ui.fonts.hash[ts.font_name]) - - scale := if gg.ft.scale == 0 { f32(1) } else { gg.ft.scale } - size := if ts.mono { ts.size - 2 } else { ts.size } - fons.set_size(scale * f32(size)) - gg.ft.fons.set_align(int(ts.align) | int(ts.vertical_align)) - color := sfons.rgba(ts.color.r, ts.color.g, ts.color.b, ts.color.a) - if ts.color.a != 255 { - sgl.load_pipeline(gg.timage_pip) - } - gg.ft.fons.set_color(color) - ascender := f32(0.0) - descender := f32(0.0) - lh := f32(0.0) - fons.vert_metrics(&ascender, &descender, &lh) - // println("load style $ascender, $descender ${}") - } + if mut w.ui.dd is gg.Context { + gg := w.ui.dd + fons := gg.ft.fons + fons.set_font(w.ui.fonts.hash[ts.font_name]) + + scale := if gg.ft.scale == 0 { f32(1) } else { gg.ft.scale } + size := if ts.mono { ts.size - 2 } else { ts.size } + fons.set_size(scale * f32(size)) + gg.ft.fons.set_align(int(ts.align) | int(ts.vertical_align)) + color := sfons.rgba(ts.color.r, ts.color.g, ts.color.b, ts.color.a) + if ts.color.a != 255 { + sgl.load_pipeline(gg.timage_pip) + } + gg.ft.fons.set_color(color) + ascender := f32(0.0) + descender := f32(0.0) + lh := f32(0.0) + fons.vert_metrics(&ascender, &descender, &lh) + // println("load style $ascender, $descender ${}") + } } } @@ -195,7 +195,7 @@ pub fn (w DrawTextWidget) text_width(text string) int { // REMOVED: this function uses internals of gg.Context which we probably do not // want to reproduce in the DrawDevice interface -//pub fn (w DrawTextWidget) text_width_additive(text string) f64 { +// pub fn (w DrawTextWidget) text_width_additive(text string) f64 { // ctx := w.ui.gg // adv := ctx.ft.fons.text_bounds(0, 0, text, &f32(0)) // return adv / ctx.scale diff --git a/src/interface_focusable.v b/src/interface_focusable.v index 413461a7..2afaf62a 100644 --- a/src/interface_focusable.v +++ b/src/interface_focusable.v @@ -36,21 +36,21 @@ pub fn (mut f Focusable) set_focus() { return } if f.is_focused { - if mut w.ui.dd is gg.Context { - $if focus ? { - println('$f.id already has focus at $w.ui.dd.frame') - } - } + if mut w.ui.dd is gg.Context { + $if focus ? { + println('$f.id already has focus at $w.ui.dd.frame') + } + } return } Layout(w).unfocus_all() if f.has_focusable() { f.is_focused = true - if mut w.ui.dd is gg.Context { - $if focus ? { - println('$f.id has focus at $w.ui.dd.frame') - } - } + if mut w.ui.dd is gg.Context { + $if focus ? { + println('$f.id has focus at $w.ui.dd.frame') + } + } } // update drawing_children when focus is taken f.update_parent_drawing_children() @@ -60,20 +60,20 @@ pub fn (mut f Focusable) set_focus() { pub fn (mut f Focusable) force_focus() { mut w := f.ui.window if f.is_focused { - if mut w.ui.dd is gg.Context { - $if focus ? { - println('$f.id already has focus at $w.ui.dd.frame') - } - } + if mut w.ui.dd is gg.Context { + $if focus ? { + println('$f.id already has focus at $w.ui.dd.frame') + } + } return } Layout(w).unfocus_all() f.is_focused = true - if mut w.ui.dd is gg.Context { - $if focus ? { - println('$f.id has focus at $w.ui.dd.frame') - } - } + if mut w.ui.dd is gg.Context { + $if focus ? { + println('$f.id has focus at $w.ui.dd.frame') + } + } } pub fn (f Focusable) lock_focus() { diff --git a/src/layout_canvas.v b/src/layout_canvas.v index 0bcab2f6..53aef97b 100644 --- a/src/layout_canvas.v +++ b/src/layout_canvas.v @@ -625,7 +625,7 @@ fn (mut c CanvasLayout) draw_device(d DrawDevice) { fw, fh := c.full_size() if fw > 0 && fh > 0 { w = int(f32(fw) * c.ui.window.dpi_scale) - h = int(f32(fh) * c.ui.window.dpi_scale) + h = int(f32(fh) * c.ui.window.dpi_scale) } // println("$c.id ($w, $h)") if c.style.bg_radius > 0 { diff --git a/src/layout_window.v b/src/layout_window.v index 830cae7a..d1642878 100644 --- a/src/layout_window.v +++ b/src/layout_window.v @@ -347,13 +347,13 @@ fn gg_init(mut window Window) { } for mut child in window.children { - //println('init <$child.id>') + // println('init <$child.id>') window.register_child(*child) child.init(window) } // then subwindows for mut sw in window.subwindows { - //println('init $child.id') + // println('init $child.id') window.register_child(*sw) sw.init(window) } @@ -384,9 +384,9 @@ fn gg_cleanup(mut window Window) { } fn frame(mut w Window) { - if mut w.ui.dd is gg.Context { - w.ui.dd.begin() - } + if mut w.ui.dd is gg.Context { + w.ui.dd.begin() + } mut children := if unsafe { w.child_window == 0 } { w.children } else { w.child_window.children } @@ -417,15 +417,15 @@ fn frame(mut w Window) { } */ - if mut w.ui.dd is gg.Context { - w.ui.dd.end() - } + if mut w.ui.dd is gg.Context { + w.ui.dd.end() + } } fn frame_immediate(mut w Window) { - if mut w.ui.dd is gg.Context { - w.ui.dd.begin() - } + if mut w.ui.dd is gg.Context { + w.ui.dd.begin() + } for mut child in w.children_immediate { child.draw() @@ -452,9 +452,9 @@ fn frame_immediate(mut w Window) { w.needs_refresh = false - if mut w.ui.dd is gg.Context { - w.ui.dd.end() - } + if mut w.ui.dd is gg.Context { + w.ui.dd.end() + } } fn native_frame(mut w Window) { @@ -504,11 +504,11 @@ fn on_event(e &gg.Event, mut window Window) { } $if macos { - if mut window.ui.dd is gg.Context { - if window.ui.dd.native_rendering { - C.darwin_window_refresh() - } - } + if mut window.ui.dd is gg.Context { + if window.ui.dd.native_rendering { + C.darwin_window_refresh() + } + } } window.ui.ticks = 0 // window.ui.ticks_since_refresh = 0 @@ -1067,9 +1067,9 @@ pub fn (mut w Window) set_title(title string) { } pub fn (mut w Window) refresh() { - if mut w.ui.dd is gg.Context { - w.ui.dd.refresh_ui() - } + if mut w.ui.dd is gg.Context { + w.ui.dd.refresh_ui() + } $if macos { C.darwin_window_refresh() } @@ -1194,9 +1194,9 @@ pub fn (w &Window) get_subscriber() &eventbus.Subscriber { pub fn (mut window Window) resize(w int, h int) { window.width, window.height = w, h - if mut window.ui.dd is gg.Context { - window.ui.dd.resize(w, h) - } + if mut window.ui.dd is gg.Context { + window.ui.dd.resize(w, h) + } for mut child in window.children { if mut child is Stack { child.resize(w, h) diff --git a/src/tool_text_style.v b/src/tool_text_style.v index e6c31d0a..9abd8837 100644 --- a/src/tool_text_style.v +++ b/src/tool_text_style.v @@ -66,39 +66,39 @@ mut: } pub fn (mut ui UI) add_font(font_name string, font_path string) { - $if fontset ? { + $if fontset ? { println('add font $font_name at $font_path') } - if mut ui.dd is gg.Context { - // IMPORTANT: This fix issue that makes DrawTextFont not working for fontstash - // (in fons__getGlyph, added becomes 0) - ui.dd.ft.fons.reset_atlas(512, 512) - bytes := os.read_bytes(font_path) or { []u8{} } - // gg := ui.gg - // mut f := ui.fonts - if bytes.len > 0 { - font := ui.dd.ft.fons.add_font_mem('sans', bytes, false) - if font >= 0 { - ui.font_paths[font_name] = font_path - ui.fonts.hash[font_name] = font - $if fontset ? { - println('font $font $font_name added ($font_path)') - } - } else { - $if fontset ? { - println('font $font_name NOT added ($font_path)') - } - } - } else { - $if fontset ? { - println('font bytes unreadable') - } - } - } else { + if mut ui.dd is gg.Context { + // IMPORTANT: This fix issue that makes DrawTextFont not working for fontstash + // (in fons__getGlyph, added becomes 0) + ui.dd.ft.fons.reset_atlas(512, 512) + bytes := os.read_bytes(font_path) or { []u8{} } + // gg := ui.gg + // mut f := ui.fonts + if bytes.len > 0 { + font := ui.dd.ft.fons.add_font_mem('sans', bytes, false) + if font >= 0 { + ui.font_paths[font_name] = font_path + ui.fonts.hash[font_name] = font + $if fontset ? { + println('font $font $font_name added ($font_path)') + } + } else { + $if fontset ? { + println('font $font_name NOT added ($font_path)') + } + } + } else { + $if fontset ? { + println('font bytes unreadable') + } + } + } else { $if fontset ? { println('DrawDevice is not a gg.Context') } - } + } $if fontset ? { println('$ui.fonts') } diff --git a/src/ui.v b/src/ui.v index eb670cf2..e5eaec3b 100644 --- a/src/ui.v +++ b/src/ui.v @@ -56,14 +56,14 @@ fn (mut gui UI) idle_loop() { } else { gui.show_cursor = !gui.show_cursor } - if mut gui.dd is gg.Context { - gui.dd.refresh_ui() - $if macos { - if gui.dd.native_rendering { - C.darwin_window_refresh() - } - } - } + if mut gui.dd is gg.Context { + gui.dd.refresh_ui() + $if macos { + if gui.dd.native_rendering { + C.darwin_window_refresh() + } + } + } gui.ticks = 0 // glfw.post_empty_event() @@ -116,10 +116,10 @@ fn (mut gui UI) load_imgs() { // complete the drawing system pub fn (mut gui UI) load_img(id string, b []u8, path string) { - if mut gui.dd is gg.Context { - gui.imgs[id] = gui.dd.create_image_from_byte_array(b) - gui.imgs[id].path = path - } + if mut gui.dd is gg.Context { + gui.imgs[id] = gui.dd.create_image_from_byte_array(b) + gui.imgs[id].path = path + } } pub fn (gui &UI) img(id string) gg.Image { @@ -162,10 +162,10 @@ pub fn run(window &Window) { } $else { mut gui := window.ui gui.window = window // TODO: this can be removed since now in the window constructor - go gui.idle_loop() - if mut gui.dd is gg.Context { - gui.dd.run() - } + spawn gui.idle_loop() + if mut gui.dd is gg.Context { + gui.dd.run() + } gui.closed = true // the gui.idle_loop thread checks every 10 ms if gui.closed is true; diff --git a/src/ui_default.c.v b/src/ui_default.c.v index ed7bacf2..ce51a4f6 100644 --- a/src/ui_default.c.v +++ b/src/ui_default.c.v @@ -20,7 +20,7 @@ pub fn message_box(s string) { waitgroup: sync.new_waitgroup() } message_app.waitgroup.add(1) - go run_message_dialog(mut message_app, s) + spawn run_message_dialog(mut message_app, s) message_app.waitgroup.wait() } diff --git a/src/widget_button.v b/src/widget_button.v index 2c303c96..bd1a286b 100644 --- a/src/widget_button.v +++ b/src/widget_button.v @@ -151,9 +151,9 @@ fn (mut b Button) init(parent Layout) { ui := parent.get_ui() b.ui = ui if b.use_icon { - if mut b.ui.dd is gg.Context { - b.image = b.ui.dd.create_image(b.icon_path) - } + if mut b.ui.dd is gg.Context { + b.image = b.ui.dd.create_image(b.icon_path) + } } b.load_style() if b.tooltip.text != '' { diff --git a/src/widget_canvas.v b/src/widget_canvas.v index 3f856021..64355d09 100644 --- a/src/widget_canvas.v +++ b/src/widget_canvas.v @@ -23,8 +23,8 @@ pub mut: // component state for composable widget component voidptr mut: - parent Layout = empty_stack - draw_fn DrawFn = unsafe { nil } + parent Layout = empty_stack + draw_fn DrawFn = unsafe { nil } } [params] @@ -95,9 +95,9 @@ fn (mut c Canvas) draw() { fn (mut c Canvas) draw_device(d DrawDevice) { offset_start(mut c) if c.draw_fn != unsafe { nil } { - if mut c.ui.dd is gg.Context { - c.draw_fn(c.ui.dd, c) - } + if mut c.ui.dd is gg.Context { + c.draw_fn(c.ui.dd, c) + } } offset_end(mut c) } diff --git a/src/widget_listbox.v b/src/widget_listbox.v index f60585d6..d808c9d4 100644 --- a/src/widget_listbox.v +++ b/src/widget_listbox.v @@ -511,7 +511,7 @@ fn (mut lb ListBox) draw_device(d DrawDevice) { } } mut dtw := DrawTextWidget(lb) - dtw.draw_device_load_style(d) + dtw.draw_device_load_style(d) // scrollview_clip(mut lb) scrollview_draw_begin(mut lb, d) height := if lb.has_scrollview && lb.adj_height > lb.height { @@ -527,8 +527,8 @@ fn (mut lb ListBox) draw_device(d DrawDevice) { from, to := lb.visible_items() if lb.items.len == 0 { dtw = DrawTextWidget(lb) - dtw.draw_device_styled_text(d, lb.x + ui.listbox_text_offset_x, - lb.y + lb.text_offset_y, if lb.files_droped { + dtw.draw_device_styled_text(d, lb.x + ui.listbox_text_offset_x, lb.y + lb.text_offset_y, + if lb.files_droped { 'Empty listbox. Drop files here ...' } else { '' @@ -1037,8 +1037,8 @@ fn (li &ListItem) draw_device(d DrawDevice) { col) mut dtw := DrawTextWidget(lb) - dtw.draw_device_styled_text(d, li.x + li.offset_x + lb.x + - ui.listbox_text_offset_x, li.y + li.offset_y + lb.y + lb.text_offset_y, if lb.has_scrollview { + dtw.draw_device_styled_text(d, li.x + li.offset_x + lb.x + ui.listbox_text_offset_x, + li.y + li.offset_y + lb.y + lb.text_offset_y, if lb.has_scrollview { li.text } else { li.text() diff --git a/src/widget_picture.v b/src/widget_picture.v index f33cf6c1..c4f9e46d 100644 --- a/src/widget_picture.v +++ b/src/widget_picture.v @@ -101,9 +101,9 @@ fn (mut pic Picture) init(parent Layout) { } $if android { byte_ary := os.read_apk_asset(pic.path) or { panic(err) } - if mut pic.ui.dd is gg.Context { - pic.image = pic.ui.gg.create_image_from_byte_array(byte_ary) - } + if mut pic.ui.dd is gg.Context { + pic.image = pic.ui.gg.create_image_from_byte_array(byte_ary) + } } // If the user didn't set width or height, use the image's dimensions, otherwise it won't be displayed if pic.width == 0 || pic.height == 0 { diff --git a/src/widget_textbox_textview.v b/src/widget_textbox_textview.v index 145c082d..243607b6 100644 --- a/src/widget_textbox_textview.v +++ b/src/widget_textbox_textview.v @@ -323,7 +323,7 @@ fn (mut tv TextView) draw_device_selection(d DrawDevice) { fn (tv &TextView) draw_device_line_number(d DrawDevice, i int, y int) { tv.draw_device_styled_text(d, tv.tb.x + ui.textview_margin, y, (tv.tlv.from_j + i + 1).str(), - + color: gx.gray ) } @@ -1012,7 +1012,7 @@ pub fn (tv &TextView) text_pos_from_x(text string, x int) int { // if width != tv.text_width(ustr[..i].string()) { // // println("widthhhh $i $width ${tv.text_width(ustr[..i].string())}") // } - //width_cur = tv.text_width_additive(ustr[i..(i + 1)].string()) + // width_cur = tv.text_width_additive(ustr[i..(i + 1)].string()) width_cur = tv.text_width(ustr[i..(i + 1)].string()) width2 := if i < ustr.len { width + width_cur } else { width } if (prev_width + width) / 2 <= xx && xx <= (width + width2) / 2 { @@ -1062,7 +1062,7 @@ fn (tv &TextView) draw_styled_text(x int, y int, text string, ts TextStyleParams fn (tv &TextView) draw_device_styled_text(d DrawDevice, x int, y int, text string, ts TextStyleParams) { mut dtw := DrawTextWidget(tv.tb) - dtw.draw_device_styled_text(d, x, y, tv.fix_tab_char(text), ts) + dtw.draw_device_styled_text(d, x, y, tv.fix_tab_char(text), ts) } fn (tv &TextView) text_width(text string) int { @@ -1070,7 +1070,7 @@ fn (tv &TextView) text_width(text string) int { } //// Added to have mostly additive text width function -//fn (tv &TextView) text_width_additive(text string) f64 { +// fn (tv &TextView) text_width_additive(text string) f64 { // return DrawTextWidget(tv.tb).text_width_additive(tv.fix_tab_char(text)) //} @@ -1096,11 +1096,11 @@ pub fn (tv &TextView) update_style(ts TextStyleParams) { // Not called automatically as it is in gg pub fn (tv &TextView) load_style() { mut dtw := DrawTextWidget(tv.tb) - dtw.load_style() + dtw.load_style() } //// that's weird text_width is not additive function -//pub fn (tv &TextView) test_textwidth(text string) { +// pub fn (tv &TextView) test_textwidth(text string) { // ustr := text.runes() // mut width, mut width_bad := 0.0, 0.0 // println('(text_width_additive vs text_width)') From fd8b6e75cf7c73d23ce81574e8f9a10a3815dd29 Mon Sep 17 00:00:00 2001 From: R cqls Date: Sat, 12 Nov 2022 13:37:53 +0100 Subject: [PATCH 8/8] update --- src/draw_device_bitmap.v | 2 +- src/extra_draw.v | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/draw_device_bitmap.v b/src/draw_device_bitmap.v index 180dc330..da2f10bf 100644 --- a/src/draw_device_bitmap.v +++ b/src/draw_device_bitmap.v @@ -110,7 +110,7 @@ pub fn (d &DrawDeviceBitmap) draw_text_def(x int, y int, text string) {} pub fn (d &DrawDeviceBitmap) set_text_cfg(cfg gx.TextCfg) { mut ts := d.ts - d.apply_text_config(mut &ts, cfg) + d.apply_text_config(mut ts, cfg) } pub fn (d &DrawDeviceBitmap) text_size(s string) (int, int) { diff --git a/src/extra_draw.v b/src/extra_draw.v index 24c142a7..e10d8119 100644 --- a/src/extra_draw.v +++ b/src/extra_draw.v @@ -89,7 +89,7 @@ mut: // No text_size to not conflict with fn get_text_size(w DrawText, text_ string) (int, int) { - w.ui.dd.set_text_text_cfg(w.text_cfg) + w.ui.dd.set_text_cfg(w.text_cfg) return w.ui.dd.text_size(text_) }