Skip to content

Commit 48037d4

Browse files
committed
Enhance documentation, improve theming, and refine GUI components
- Added detailed comments explaining module functionality in `view_rtf.v`, `fonts.v`, `stats.v`, and other key files. - Introduced a new `theme_blue_bordered` configuration in `theme.v`. - Improved font initialization logic in `fonts.v` for better reliability. - Refined color and style assignments to align with updated theming principles. - Fixed minor typos and enhanced clarity in event handling and rendering functions. - Updated examples to reflect the new `theme_blue_bordered` usage.
1 parent c29e413 commit 48037d4

File tree

10 files changed

+65
-24
lines changed

10 files changed

+65
-24
lines changed

_gui.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ __global gui_tooltip = TooltipState{}
1010
__global gui_stats = Stats{}
1111

1212
pub const version = '0.1.0'
13-
pub const app_title = 'GUI'
13+
pub const app_title = 'v-gui'

examples/test_layout.v

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn main() {
3131
w.set_id_focus(2)
3232
}
3333
)
34-
window.set_theme(gui.theme_dark_bordered)
34+
window.set_theme(gui.theme_blue_bordered)
3535
window.run()
3636
}
3737

@@ -44,7 +44,6 @@ fn main_view(w &gui.Window) gui.View {
4444
width: width
4545
height: height
4646
sizing: gui.fixed_fixed
47-
color: gui.dark_blue
4847
fill: true
4948
content: [
5049
gui.column(
@@ -78,9 +77,9 @@ fn main_view(w &gui.Window) gui.View {
7877
content: [
7978
gui.column(
8079
id: 'col'
80+
color: gui.theme().color_panel
8181
sizing: gui.fill_fill
8282
fill: true
83-
color: gui.rgb(0x30, 0x30, 0x30)
8483
spacing: gui.theme().spacing_large
8584
content: [
8685
gui.row(
@@ -151,9 +150,9 @@ fn main_view(w &gui.Window) gui.View {
151150
]
152151
),
153152
gui.column(
153+
color: gui.theme().color_panel
154154
fill: true
155155
sizing: gui.fill_fill
156-
color: gui.rgb(0x30, 0x30, 0x30)
157156
spacing: gui.spacing_large
158157
content: [
159158
gui.input(
@@ -169,7 +168,6 @@ fn main_view(w &gui.Window) gui.View {
169168
}
170169
),
171170
gui.column(
172-
color: gui.gray
173171
sizing: gui.fill_fit
174172
text: ' mode = .wrap '
175173
content: [
@@ -181,7 +179,6 @@ fn main_view(w &gui.Window) gui.View {
181179
]
182180
),
183181
gui.column(
184-
color: gui.gray
185182
sizing: gui.fill_fit
186183
text: ' model = .wrap_keep_spaces '
187184
content: [

fonts.v

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
module gui
22

3+
// Currently, `gg` only supports static font files like `.ttf`. If/when this
4+
// changes, support for variable fonts like those in Google fonts will be used.
5+
//
36
import log
47
import os
58
import os.font
@@ -13,12 +16,15 @@ pub:
1316
mono string
1417
}
1518

16-
pub const font_file_regular = os.join_path(os.data_dir(), 'gui_deja-vu-sans-regular.ttf')
17-
pub const font_file_bold = os.join_path(os.data_dir(), 'gui_deja-vu-sans-bold.ttf')
18-
pub const font_file_italic = os.join_path(os.data_dir(), 'gui_deja-vu-sans-italic.ttf')
19-
pub const font_file_mono = os.join_path(os.data_dir(), 'gui_deja-vu-sans-mono.ttf')
20-
pub const font_file_icon = os.join_path(os.data_dir(), 'gui_feathericon.ttf')
19+
pub const font_file_regular = os.join_path(os.data_dir(), 'v_gui_deja-vu-sans-regular.ttf')
20+
pub const font_file_bold = os.join_path(os.data_dir(), 'v_gui_deja-vu-sans-bold.ttf')
21+
pub const font_file_italic = os.join_path(os.data_dir(), 'v_gui_deja-vu-sans-italic.ttf')
22+
pub const font_file_mono = os.join_path(os.data_dir(), 'v_gui_deja-vu-sans-mono.ttf')
23+
pub const font_file_icon = os.join_path(os.data_dir(), 'v_gui_feathericon.ttf')
2124

25+
// initialize_fonts ensures all required font files exist in the data directory by checking for
26+
// each font file and writing the embedded font data if not found. It writes regular, bold,
27+
// italic, mono and icon font files.
2228
fn initialize_fonts() {
2329
if !os.exists(font_file_regular) {
2430
os.write_file(font_file_regular, $embed_file('assets/DejaVuSans-Regular.ttf').to_string()) or {
@@ -75,6 +81,8 @@ fn path_variant(path string, variant font.Variant) string {
7581
return if os.exists(vpath) { vpath } else { path }
7682
}
7783

84+
// Map of icons names to their unicode values. Describes only
85+
// the icons included in `assets/feathericon.ttf`
7886
pub const icons_map = {
7987
'icon_arrow_down': icon_arrow_down
8088
'icon_arrow_left': icon_arrow_left

stats.v

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
module gui
22

3+
// This file is intended to be active only during debug builds of the application.
4+
// Its primary purpose is to serve as a comprehensive monitoring tool for tracking
5+
// and analyzing the program's resource usage and internal state in real-time.
6+
//
7+
// The functionality provided within this file allows developers to:
8+
// - Monitor the instantiation and rendering of various UI components, such as
9+
// containers, text elements, images, and rich text fields, providing insight
10+
// into the complexity and overhead of the current view hierarchy.
11+
// - Track memory allocation and garbage collection statistics, including heap
12+
// usage, free memory, and total bytes allocated, which is crucial for identifying
13+
// memory leaks and optimizing performance.
14+
// - Inspect the memory footprint of core data structures used within the GUI
15+
// framework, helping to ensure that memory is being used efficiently.
16+
// - Visualize the internal state of the window and view system, including input
17+
// states, scroll offsets, and other dynamic properties that affect the user
18+
// experience.
19+
//
320
import gg
421

522
const stat_top_div = '=================================='

styles.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,9 @@ pub:
188188
size f32 = 7
189189
thumb_size f32 = 15
190190
color Color = color_interior_dark
191-
color_click Color = color_active_dark
192-
color_thumb Color = color_select_dark
193-
color_left Color = color_select_dark
191+
color_click Color = color_select_dark
192+
color_thumb Color = color_active_dark
193+
color_left Color = color_active_dark
194194
color_focus Color = color_focus_dark
195195
color_hover Color = color_hover_dark
196196
color_border Color = color_border_dark

theme.v

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,21 @@ pub const theme_light_bordered_cfg = ThemeCfg{
390390
}
391391
pub const theme_light_bordered = theme_maker(theme_light_bordered_cfg)
392392

393+
pub const theme_blue_bordered_cfg = ThemeCfg{
394+
...theme_dark_cfg
395+
name: 'blue-dark-bordered'
396+
color_background: color_from_string('#0c1d3a')
397+
color_panel: color_from_string('#122c58')
398+
color_interior: color_from_string('#193b75')
399+
color_hover: color_from_string('#1f4992')
400+
color_active: color_from_string('#2558b0')
401+
color_focus: color_from_string('#2c67cd')
402+
color_border: color_from_string('#467bd7')
403+
color_select: color_from_string('#427BDD')
404+
color_border_focus: color_from_string('#81a5e3')
405+
}
406+
pub const theme_blue_bordered = theme_maker(theme_blue_bordered_cfg)
407+
393408
// theme_maker sets all styles to a common set of values using
394409
// [ThemeCfg](#ThemeCfg). v-gui allows each view type (button,
395410
// input, etc) to be styled independent of the other view styles.
@@ -553,12 +568,12 @@ pub fn theme_maker(cfg &ThemeCfg) Theme {
553568
}
554569
range_slider_style: RangeSliderStyle{
555570
color: cfg.color_interior
556-
color_left: cfg.color_select
557-
color_thumb: cfg.color_select
558-
color_focus: cfg.color_focus
571+
color_left: cfg.color_active
572+
color_thumb: cfg.color_active
573+
color_focus: cfg.color_border_focus
559574
color_hover: cfg.color_hover
560575
color_border: cfg.color_border
561-
color_click: cfg.color_active
576+
color_click: cfg.color_select
562577
fill: true
563578
fill_border: true
564579
padding: padding_none

view_range_slider.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ fn (cfg &RangeSliderCfg) amend_layout_slide(mut layout Layout, mut w Window) {
186186
return
187187
}
188188
if w.is_focus(layout.shape.id_focus) {
189-
layout.children[0].shape.color = cfg.color_focus
189+
layout.children[0].children[1].shape.color = cfg.color_focus
190190
}
191191
}
192192

@@ -264,7 +264,7 @@ fn (cfg &RangeSliderCfg) on_mouse_down(layout &Layout, mut e Event, mut w Window
264264
e.is_handled = true
265265
}
266266

267-
// mouse_move expects the events mouse coordinates to MOT be adjusted (see on_mouse_down)
267+
// mouse_move expects the events mouse coordinates to NOT be adjusted (see on_mouse_down)
268268
fn (cfg &RangeSliderCfg) mouse_move(layout &Layout, mut e Event, mut w Window) {
269269
id := cfg.id
270270

view_rtf.v

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
module gui
22

3+
// view_rtf.v defines the Rich Text Format (RTF) view component.
4+
// It allows rendering text with multiple typefaces, sizes, and styles within a single view.
5+
// It supports text wrapping, clickable links, and custom text spans.
6+
//
37
import datatypes
48
import os
59

view_select.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub fn (window &Window) select(cfg SelectCfg) View {
142142
)
143143
}
144144

145-
fn option_view(cfg SelectCfg, option string) View {
145+
fn option_view(cfg &SelectCfg, option string) View {
146146
select_multiple := cfg.select_multiple
147147
on_select := cfg.on_select
148148
select_array := cfg.select
@@ -207,7 +207,7 @@ fn option_view(cfg SelectCfg, option string) View {
207207
)
208208
}
209209

210-
fn sub_header(cfg SelectCfg, option string) View {
210+
fn sub_header(cfg &SelectCfg, option string) View {
211211
return column(
212212
spacing: 0
213213
padding: padding(gui_theme.padding_medium.top, 0, 0, 0)

xtra_render.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn draw_rounded_rect_filled(x f32, y f32, w f32, h f32, radius f32, c gg.Color,
105105
// left top quarter
106106
sgl.c4b(c.r, c.g, c.b, 10)
107107
// Small offset to minimize visible seams on some platforms
108-
sgl_arc_triangle_strip_with_offset(p.ltx, p.lty, p.dxs, p.dys, -1, -1, -1, -1)
108+
sgl_arc_triangle_strip(p.ltx, p.lty, p.dxs, p.dys, -1, -1)
109109

110110
sgl.c4b(c.r, c.g, c.b, c.a)
111111
sgl_arc_triangle_strip(p.ltx, p.lty, p.dxs, p.dys, -1, -1)

0 commit comments

Comments
 (0)