Skip to content

Commit dfb86f4

Browse files
committed
refactor: Rename get_text_width and get_text_width_no_cache functions to text_width and text_width_no_cache, remove unused caching logic for simpler handling
1 parent 1387cd5 commit dfb86f4

13 files changed

Lines changed: 39 additions & 56 deletions

examples/icon_font_demo.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fn icon_catalog(mut w gui.Window) gui.View {
106106
// find the longest text
107107
if app.longest == 0 {
108108
for s in gui.icons_map.keys() {
109-
app.longest = f32_max(gui.get_text_width(s, gui.theme().n4, mut w), app.longest)
109+
app.longest = f32_max(gui.text_width(s, gui.theme().n4, mut w), app.longest)
110110
}
111111
}
112112

examples/showcase.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1348,7 +1348,7 @@ fn icon_catalog(mut w gui.Window) gui.View {
13481348
// find the longest text
13491349
mut longest := f32(0)
13501350
for s in gui.icons_map.keys() {
1351-
longest = f32_max(gui.get_text_width(s, gui.theme().n4, mut w), longest)
1351+
longest = f32_max(gui.text_width(s, gui.theme().n4, mut w), longest)
13521352
}
13531353

13541354
// Break the icons_maps into rows

stats.v

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ fn (vs ViewState) view_state_stats() string {
125125
tx << 'input_state length ${cm(usize(vs.input_state.len)):8}'
126126
tx << 'scroll_x length ${cm(usize(vs.scroll_x.len)):8}'
127127
tx << 'scroll_y length ${cm(usize(vs.scroll_y.len)):8}'
128-
tx << 'text_widths length ${cm(usize(vs.text_widths.len)):8}'
129128
tx << 'menu_state length ${cm(usize(vs.menu_state.len)):8}'
130129
tx << 'image_map length ${cm(usize(vs.image_map.len)):8}'
131130
tx << 'select_state length ${cm(usize(vs.select_state.len)):8}'

view_date_picker.v

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,17 +395,17 @@ fn dates(times []time.Time) []time.Time {
395395

396396
fn (cfg DatePickerCfg) cell_size(w &Window) f32 {
397397
w_size := match cfg.weekdays_len {
398-
.one_letter { get_text_width_no_cache('W', cfg.text_style, w) }
399-
.three_letter { get_text_width_no_cache('Wed', cfg.text_style, w) }
400-
.full { get_text_width_no_cache('Wednesday', cfg.text_style, w) }
398+
.one_letter { text_width_no_cache('W', cfg.text_style, w) }
399+
.three_letter { text_width_no_cache('Wed', cfg.text_style, w) }
400+
.full { text_width_no_cache('Wednesday', cfg.text_style, w) }
401401
}
402-
d_size := get_text_width_no_cache('00', cfg.text_style, w)
402+
d_size := text_width_no_cache('00', cfg.text_style, w)
403403
return f32_max(w_size, d_size) + gui_theme.button_style.padding.width() + padding_two.width()
404404
}
405405

406406
fn (cfg DatePickerCfg) month_picker_width(w &Window) f32 {
407-
return get_text_width_no_cache('May', cfg.text_style, w) +
408-
gui_theme.button_style.padding.width() + gui_theme.button_style.padding_border.width()
407+
return text_width_no_cache('May', cfg.text_style, w) + gui_theme.button_style.padding.width() +
408+
gui_theme.button_style.padding_border.width()
409409
}
410410

411411
fn (cfg DatePickerCfg) disabled(date time.Time, state DatePickerState) bool {

view_pulsar.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub fn (window &Window) pulsar(cfg PulsarCfg) View {
2222

2323
width := match cfg.width > 0 {
2424
true { cfg.width }
25-
else { get_text_width_no_cache(cfg.icon1, text_style, window) }
25+
else { text_width_no_cache(cfg.icon1, text_style, window) }
2626
}
2727
txt := if window.view_state.input_cursor_on { cfg.icon1 } else { cfg.icon2 }
2828

view_state.v

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ mut:
1010
input_date_state map[string]bool // [id] -> visible
1111
scroll_x map[u32]f32 // [id_scroll] -> scroll offset x
1212
scroll_y map[u32]f32 // [id_scroll] -> scroll offset y
13-
text_widths map[u32]f32 // [text + hash(text_style)] -> text width
1413
mouse_cursor sapp.MouseCursor // arrow, finger, ibeam, etc.
1514
menu_state map[u32]string // [id_menubar] -> id of menu
1615
menu_key_nav bool // true, menu navigated by keyboard

view_table.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ fn (mut window Window) table_column_widths(cfg &TableCfg) []f32 {
207207
if cell.head_cell { cfg.text_style_head } else { cfg.text_style }
208208
}
209209

210-
width := get_text_width(row.cells[idx].value, text_style, mut window)
210+
width := text_width(row.cells[idx].value, text_style, mut window)
211211
longest = f32_max(width, longest)
212212
}
213213
column_widths << longest

view_text.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fn (mut tv TextView) generate_layout(mut window Window) Layout {
6464
on_click: tv.on_click
6565
}
6666
}
67-
layout.shape.width = text_width(layout.shape, mut window)
67+
layout.shape.width = text_width_shape(layout.shape, mut window)
6868
layout.shape.height = text_height(layout.shape, mut window)
6969
if tv.mode == .single_line || layout.shape.sizing.width == .fixed {
7070
layout.shape.min_width = f32_max(layout.shape.width, layout.shape.min_width)

view_tree.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn (cfg &TreeCfg) node_content(node TreeNodeCfg, mut window Window) []View {
7171
is_open { icon_drop_down }
7272
else { icon_drop_right }
7373
}
74-
min_width_icon := get_text_width('${icon_bar} ', node.text_style_icon, mut window)
74+
min_width_icon := text_width('${icon_bar} ', node.text_style_icon, mut window)
7575

7676
mut content := []View{cap: 2}
7777
cfg_id := cfg.id

xtra_rtf.v

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn rtf_simple_wrap(spans datatypes.LinkedList[TextSpan], mut window Window) data
3737
x = 0
3838
y += span.style.size + span.style.line_spacing
3939
}
40-
width := get_text_width(line, span.style, mut window)
40+
width := text_width(line, span.style, mut window)
4141
tspans.push(TextSpan{
4242
x: x
4343
y: y
@@ -91,7 +91,7 @@ fn rtf_wrap_text(spans datatypes.LinkedList[TextSpan], width f32, tab_size u32,
9191
continue
9292
}
9393
if tspan.text.len == 0 {
94-
field_width := get_text_width(field, tspan.style, mut window)
94+
field_width := text_width(field, tspan.style, mut window)
9595
if x + field_width > width {
9696
x = 0
9797
y += h
@@ -105,9 +105,9 @@ fn rtf_wrap_text(spans datatypes.LinkedList[TextSpan], width f32, tab_size u32,
105105
continue
106106
}
107107
line := tspan.text + field
108-
line_width := get_text_width(line, tspan.style, mut window)
108+
line_width := text_width(line, tspan.style, mut window)
109109
if x + line_width > width {
110-
tspan.w = get_text_width(tspan.text, tspan.style, mut window)
110+
tspan.w = text_width(tspan.text, tspan.style, mut window)
111111
tspans.push(tspan)
112112
x = 0
113113
y += h

0 commit comments

Comments
 (0)