Skip to content

Commit 8e8ded5

Browse files
committed
Replace offset_x and offset_y with gap_edge and gap_end in scrollbar configuration for improved clarity and consistency. Ensure adjustments are reflected across related components and examples.
1 parent a163c6d commit 8e8ded5

File tree

6 files changed

+60
-47
lines changed

6 files changed

+60
-47
lines changed

examples/showcase.v

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,13 @@ fn side_bar(mut w gui.Window) gui.View {
118118
fn gallery(mut w gui.Window) gui.View {
119119
mut app := w.state[ShowcaseApp]()
120120
return gui.column(
121-
id_scroll: id_scroll_gallery
122-
sizing: gui.fill_fill
123-
spacing: gui.spacing_large * 2
124-
content: match app.selected_tab {
121+
id_scroll: id_scroll_gallery
122+
scrollbar_cfg_y: &gui.ScrollbarCfg{
123+
gap_edge: 4
124+
}
125+
sizing: gui.fill_fill
126+
spacing: gui.spacing_large * 2
127+
content: match app.selected_tab {
125128
.tab_stock {
126129
[buttons(w), inputs(w), toggles(w), select_drop_down(w),
127130
list_box(w), expand_panel(w), progress_bars(w),

styles.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ pub:
218218
fill_background bool
219219
radius f32 = radius_small
220220
radius_thumb f32 = radius_small
221-
offset_x f32 = -3
222-
offset_y f32 = -3
221+
gap_edge f32 = 3
222+
gap_end f32 = 2
223223
}
224224

225225
pub struct SelectStyle {

theme.v

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ pub:
318318
scroll_multiplier f32 = scroll_multiplier
319319
scroll_delta_line f32 = scroll_delta_line
320320
scroll_delta_page f32 = scroll_delta_page
321+
scroll_gap_edge f32 = 3 // gap between edge of scrollbar and container
322+
scroll_gap_end f32 = 2 // gap between end of scrollbar and container
321323
}
322324

323325
// Good practice to expose theme configs to users.
@@ -590,6 +592,8 @@ pub fn theme_maker(cfg &ThemeCfg) Theme {
590592
color_thumb: cfg.color_active
591593
radius: if cfg.radius == radius_none { radius_none } else { cfg.radius_small }
592594
radius_thumb: if cfg.radius == radius_none { radius_none } else { cfg.radius_small }
595+
gap_edge: cfg.scroll_gap_edge
596+
gap_end: cfg.scroll_gap_end
593597
}
594598
select_style: SelectStyle{
595599
color: cfg.color_interior

view_input.v

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ pub:
6969
on_text_changed fn (&Layout, string, mut Window) = unsafe { nil }
7070
on_enter fn (&Layout, mut Event, mut Window) = unsafe { nil }
7171
on_click_icon fn (&Layout, mut Event, mut Window) = unsafe { nil }
72+
scrollbar_cfg_x &ScrollbarCfg = unsafe { nil }
73+
scrollbar_cfg_y &ScrollbarCfg = unsafe { nil }
74+
tooltip &TooltipCfg = unsafe { nil }
7275
sizing Sizing
7376
text_style TextStyle = gui_theme.input_style.text_style
7477
placeholder_style TextStyle = gui_theme.input_style.placeholder_style
@@ -82,6 +85,8 @@ pub:
8285
radius f32 = gui_theme.input_style.radius
8386
radius_border f32 = gui_theme.input_style.radius_border
8487
id_focus u32 // 0 = readonly, >0 = focusable and tabbing order
88+
id_scroll u32
89+
scroll_mode ScrollMode
8590
padding Padding = gui_theme.input_style.padding
8691
padding_border Padding = gui_theme.input_style.padding_border
8792
color Color = gui_theme.input_style.color
@@ -145,26 +150,30 @@ pub fn input(cfg InputCfg) View {
145150
mode := if cfg.mode == .single_line { TextMode.single_line } else { TextMode.wrap_keep_spaces }
146151

147152
return row(
148-
name: 'input border'
149-
id: cfg.id
150-
id_focus: cfg.id_focus
151-
width: cfg.width
152-
height: cfg.height
153-
min_width: cfg.min_width
154-
max_width: cfg.max_width
155-
min_height: cfg.min_height
156-
max_height: cfg.max_height
157-
padding: cfg.padding_border
158-
color: cfg.color_border
159-
fill: cfg.fill_border
160-
sizing: cfg.sizing
161-
radius: cfg.radius_border
162-
disabled: cfg.disabled
163-
invisible: cfg.invisible
164-
on_char: cfg.on_char
165-
amend_layout: cfg.amend_layout
166-
on_hover: cfg.hover
167-
content: [
153+
name: 'input border'
154+
id: cfg.id
155+
id_focus: cfg.id_focus
156+
id_scroll: cfg.id_scroll
157+
scrollbar_cfg_x: cfg.scrollbar_cfg_x
158+
scrollbar_cfg_y: cfg.scrollbar_cfg_y
159+
tooltip: cfg.tooltip
160+
width: cfg.width
161+
height: cfg.height
162+
min_width: cfg.min_width
163+
max_width: cfg.max_width
164+
min_height: cfg.min_height
165+
max_height: cfg.max_height
166+
padding: cfg.padding_border
167+
color: cfg.color_border
168+
fill: cfg.fill_border
169+
sizing: cfg.sizing
170+
radius: cfg.radius_border
171+
disabled: cfg.disabled
172+
invisible: cfg.invisible
173+
on_char: cfg.on_char
174+
amend_layout: cfg.amend_layout
175+
on_hover: cfg.hover
176+
content: [
168177
row(
169178
name: 'input interior'
170179
color: cfg.color

view_listbox.v

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,14 @@ pub fn list_box(cfg ListBoxCfg) View {
136136
sizing: cfg.sizing
137137
content: [
138138
column(
139-
name: 'list_box interior'
140-
id_scroll: cfg.id_scroll
141-
scrollbar_cfg_y: &ScrollbarCfg{
142-
offset_x: -1
143-
}
144-
color: cfg.color
145-
fill: cfg.fill
146-
padding: cfg.padding
147-
sizing: cfg.sizing
148-
spacing: 0
149-
content: list
139+
name: 'list_box interior'
140+
id_scroll: cfg.id_scroll
141+
color: cfg.color
142+
fill: cfg.fill
143+
padding: cfg.padding
144+
sizing: cfg.sizing
145+
spacing: 0
146+
content: list
150147
),
151148
]
152149
)

view_scrollbar.v

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ pub:
4343
size f32 = gui_theme.scrollbar_style.size
4444
radius f32 = gui_theme.scrollbar_style.radius
4545
radius_thumb f32 = gui_theme.scrollbar_style.radius_thumb
46-
offset_x f32 = gui_theme.scrollbar_style.offset_x // x and y are swapped in
47-
offset_y f32 = gui_theme.scrollbar_style.offset_y // horizontal orientation
46+
gap_edge f32 = gui_theme.scrollbar_style.gap_edge
47+
gap_end f32 = gui_theme.scrollbar_style.gap_end
4848
id_track u32
4949
overflow ScrollbarOverflow
5050
orientation ScrollbarOrientation
@@ -209,12 +209,12 @@ fn (cfg &ScrollbarCfg) amend_layout(mut layout Layout, mut w Window) {
209209

210210
match cfg.orientation == .horizontal {
211211
true {
212-
layout.shape.x = parent.shape.x + parent.shape.padding.left
213-
layout.shape.y = parent.shape.y + parent.shape.height - cfg.size + cfg.offset_y
214-
layout.shape.width = parent.shape.width - parent.shape.padding.width()
212+
layout.shape.x = parent.shape.x + parent.shape.padding.left + cfg.gap_end
213+
layout.shape.y = parent.shape.y + parent.shape.height - cfg.size - cfg.gap_edge
214+
layout.shape.width = parent.shape.width - parent.shape.padding.width() - cfg.gap_end
215215
layout.shape.height = cfg.size
216216

217-
total_width := content_width(parent)
217+
total_width := content_width(parent) - cfg.gap_end
218218
t_width := layout.shape.width * (layout.shape.width / total_width)
219219
thumb_width := f32_clamp(t_width, min_thumb_size, layout.shape.width)
220220

@@ -237,12 +237,12 @@ fn (cfg &ScrollbarCfg) amend_layout(mut layout Layout, mut w Window) {
237237
}
238238
}
239239
else {
240-
layout.shape.x = parent.shape.x + parent.shape.width - cfg.size + cfg.offset_x
241-
layout.shape.y = parent.shape.y + parent.shape.padding.top
240+
layout.shape.x = parent.shape.x + parent.shape.width - cfg.size - cfg.gap_edge
241+
layout.shape.y = parent.shape.y + parent.shape.padding.top + cfg.gap_end
242242
layout.shape.width = cfg.size
243-
layout.shape.height = parent.shape.height - parent.shape.padding.height()
243+
layout.shape.height = parent.shape.height - parent.shape.padding.height() - cfg.gap_end
244244

245-
total_height := content_height(parent)
245+
total_height := content_height(parent) - cfg.gap_end
246246
t_height := layout.shape.height * (layout.shape.height / total_height)
247247
thumb_height := f32_clamp(t_height, min_thumb_size, layout.shape.height)
248248

0 commit comments

Comments
 (0)