Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,17 @@ jobs:
- name: Run tests
env:
VFLAGS: -no-parallel -cc clang
run: v test gui/
run: |
test_manifest="${RUNNER_TEMP}/gui-test-files"
git -C gui ls-files '*_test.v' | LC_ALL=C sort > "$test_manifest"
test_count="$(wc -l < "$test_manifest" | tr -d ' ')"
echo "Test files: $test_count"
i=0
while IFS= read -r file; do
i=$((i + 1))
echo "[$i/$test_count] gui/$file"
done < "$test_manifest"
v test gui/
- name: Check compilation of examples
if: github.event_name == 'pull_request'
env:
Expand Down Expand Up @@ -387,7 +397,13 @@ jobs:
VFLAGS: -no-parallel -cc msvc
VJOBS: 1
VTEST_ONLY_FN: test_*
run: v test gui/
run: |
$testFiles = @(git -C gui ls-files '*_test.v' | Sort-Object)
Write-Host "Test files: $($testFiles.Count)"
for ($i = 0; $i -lt $testFiles.Count; $i++) {
Write-Host ("[{0}/{1}] gui/{2}" -f ($i + 1), $testFiles.Count, $testFiles[$i])
}
v test gui/
- name: Check compilation of examples
if: github.event_name == 'pull_request'
env:
Expand Down
12 changes: 6 additions & 6 deletions _data_source_orm_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ fn test_grid_orm_data_source_mutate_create_update_delete() {
mut source := GridOrmDataSource{
columns: orm_test_columns()
fetch_fn: orm_test_fetch_ok
create_fn: fn (rows []gui.GridRow, _ &GridAbortSignal) ![]gui.GridRow {
create_fn: fn (rows []GridRow, _ &GridAbortSignal) ![]GridRow {
assert rows.len == 1
return [
GridRow{
Expand All @@ -266,7 +266,7 @@ fn test_grid_orm_data_source_mutate_create_update_delete() {
},
]
}
update_fn: fn (_ []gui.GridRow, edits []gui.GridCellEdit, _ &GridAbortSignal) ![]gui.GridRow {
update_fn: fn (_ []GridRow, edits []GridCellEdit, _ &GridAbortSignal) ![]GridRow {
assert edits.len == 1
return [
GridRow{
Expand Down Expand Up @@ -414,10 +414,10 @@ fn test_grid_orm_capabilities_with_mutation_fns() {
mut source := GridOrmDataSource{
columns: orm_test_columns()
fetch_fn: orm_test_fetch_ok
create_fn: fn (_ []gui.GridRow, _ &GridAbortSignal) ![]gui.GridRow {
create_fn: fn (_ []GridRow, _ &GridAbortSignal) ![]GridRow {
return []GridRow{}
}
update_fn: fn (_ []gui.GridRow, _ []gui.GridCellEdit, _ &GridAbortSignal) ![]gui.GridRow {
update_fn: fn (_ []GridRow, _ []GridCellEdit, _ &GridAbortSignal) ![]GridRow {
return []GridRow{}
}
delete_many_fn: fn (_ []string, _ &GridAbortSignal) ![]string {
Expand Down Expand Up @@ -474,7 +474,7 @@ fn test_grid_orm_data_source_mutate_honors_abort() {
mut source := GridOrmDataSource{
columns: orm_test_columns()
fetch_fn: orm_test_fetch_ok
create_fn: fn (_ []gui.GridRow, _ &GridAbortSignal) ![]gui.GridRow {
create_fn: fn (_ []GridRow, _ &GridAbortSignal) ![]GridRow {
return []GridRow{}
}
}
Expand Down Expand Up @@ -1018,7 +1018,7 @@ fn orm_test_columns() []GridOrmColumnSpec {
]
}

fn orm_test_rows(ids []string) []gui.GridRow {
fn orm_test_rows(ids []string) []GridRow {
mut rows := []GridRow{cap: ids.len}
for id in ids {
rows << GridRow{
Expand Down
126 changes: 126 additions & 0 deletions _dock_layout_tree_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
module gui

fn dock_test_group(id string, panel_ids []string, selected_id string) &DockNode {
return dock_panel_group(id, panel_ids, selected_id)
}

fn dock_test_root() &DockNode {
left := dock_test_group('left', ['left_a', 'left_b'], 'left_b')
right := dock_test_group('right', ['right_a'], 'right_a')
return dock_split('root', .horizontal, 0.35, left, right)
}

fn dock_same_node(a &DockNode, b &DockNode) bool {
return unsafe { a == b }
}

fn test_dock_tree_remove_absent_panel_returns_same_root() {
root := dock_test_root()
same_root := dock_tree_remove_panel(root, 'missing')

assert dock_same_node(same_root, root)
assert root.kind == .split
assert root.first.panel_ids == ['left_a', 'left_b']
assert root.first.selected_id == 'left_b'
assert root.second.panel_ids == ['right_a']
}

fn test_dock_tree_remove_selected_tab_selects_first_remaining_tab() {
root := dock_test_root()
new_root := dock_tree_remove_panel(root, 'left_b')

assert !dock_same_node(new_root, root)
assert !dock_same_node(new_root.first, root.first)
assert dock_same_node(new_root.second, root.second)
assert new_root.first.panel_ids == ['left_a']
assert new_root.first.selected_id == 'left_a'
assert root.first.panel_ids == ['left_a', 'left_b']
assert root.first.selected_id == 'left_b'
}

fn test_dock_tree_remove_last_panel_collapses_split_to_sibling() {
root := dock_test_root()
new_root := dock_tree_remove_panel(root, 'right_a')

assert dock_same_node(new_root, root.first)
assert new_root.id == 'left'
assert new_root.panel_ids == ['left_a', 'left_b']
}

fn test_dock_tree_add_tab_appends_and_selects_added_panel() {
root := dock_test_root()
new_root := dock_tree_add_tab(root, 'right', 'right_b')

assert !dock_same_node(new_root, root)
assert dock_same_node(new_root.first, root.first)
assert !dock_same_node(new_root.second, root.second)
assert new_root.second.panel_ids == ['right_a', 'right_b']
assert new_root.second.selected_id == 'right_b'
assert root.second.panel_ids == ['right_a']
assert root.second.selected_id == 'right_a'
}

fn test_dock_tree_split_at_preserves_direction_and_child_ordering() {
base := dock_test_group('target', ['existing'], 'existing')

left := dock_tree_split_at(base, 'target', 'new_left', .left)
assert left.dir == .horizontal
assert left.first.panel_ids == ['new_left']
assert left.second.panel_ids == ['existing']

right := dock_tree_split_at(base, 'target', 'new_right', .right)
assert right.dir == .horizontal
assert right.first.panel_ids == ['existing']
assert right.second.panel_ids == ['new_right']

top := dock_tree_split_at(base, 'target', 'new_top', .top)
assert top.dir == .vertical
assert top.first.panel_ids == ['new_top']
assert top.second.panel_ids == ['existing']

bottom := dock_tree_split_at(base, 'target', 'new_bottom', .bottom)
assert bottom.dir == .vertical
assert bottom.first.panel_ids == ['existing']
assert bottom.second.panel_ids == ['new_bottom']
}

fn test_dock_tree_move_center_removes_then_adds_tab() {
root := dock_test_root()
new_root := dock_tree_move_panel(root, 'left_b', 'right', .center)

assert new_root.kind == .split
assert new_root.first.panel_ids == ['left_a']
assert new_root.first.selected_id == 'left_a'
assert new_root.second.panel_ids == ['right_a', 'left_b']
assert new_root.second.selected_id == 'left_b'
assert root.first.panel_ids == ['left_a', 'left_b']
assert root.second.panel_ids == ['right_a']
}

fn test_dock_tree_move_window_edge_wraps_after_remove() {
root := dock_test_root()
new_root := dock_tree_move_panel(root, 'left_b', '', .window_right)

assert new_root.kind == .split
assert new_root.dir == .horizontal
assert new_root.ratio == f32(0.8)
assert new_root.first.kind == .split
assert new_root.first.first.panel_ids == ['left_a']
assert new_root.first.second.panel_ids == ['right_a']
assert new_root.second.panel_ids == ['left_b']
assert new_root.second.selected_id == 'left_b'
}

fn test_dock_tree_select_panel_noop_and_change_behavior() {
root := dock_test_root()
same_root := dock_tree_select_panel(root, 'left', 'left_b')
new_root := dock_tree_select_panel(root, 'left', 'left_a')

assert dock_same_node(same_root, root)
assert !dock_same_node(new_root, root)
assert !dock_same_node(new_root.first, root.first)
assert dock_same_node(new_root.second, root.second)
assert new_root.first.panel_ids == ['left_a', 'left_b']
assert new_root.first.selected_id == 'left_a'
assert root.first.selected_id == 'left_b'
}
4 changes: 2 additions & 2 deletions _window_lifetime_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ fn lifetime_grid_columns() []GridColumnCfg {
]
}

fn lifetime_grid_rows() []gui.GridRow {
fn lifetime_grid_rows() []GridRow {
return [
GridRow{
id: 'row-1'
Expand Down Expand Up @@ -827,7 +827,7 @@ fn start_lifetime_capturing_crud_save(mut w Window, mut harness &LifetimeCrudSav
on_crud_error: fn [payload, mut harness] (_ string, mut _ Event, mut _ Window) {
harness.error_sum = payload[0] + payload[payload.len - 1]
}
on_rows_change: fn [payload, mut harness] (_ []gui.GridRow, mut _ Event, mut _ Window) {
on_rows_change: fn [payload, mut harness] (_ []GridRow, mut _ Event, mut _ Window) {
harness.rows_change_sum = payload[0] + payload[payload.len - 1]
}
selection: GridSelection{
Expand Down
2 changes: 1 addition & 1 deletion animation.v
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ fn max_animation_refresh_kind(current AnimationRefreshKind, incoming AnimationRe
return .none
}

fn update_animate(mut an Animate, mut w Window, mut deferred []AnimationCallback) bool {
fn update_animate(mut an Animate, mut _ Window, mut deferred []AnimationCallback) bool {
if !an.stopped {
if time.since(an.start) > an.delay {
// Capture callback to call after lock release
Expand Down
2 changes: 1 addition & 1 deletion animation_hero.v
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ fn capture_heroes_recursive(layout Layout, mut snapshots map[string]HeroSnapshot
}
}

fn update_hero_transition(mut ht HeroTransition, mut w Window, mut deferred []AnimationCallback) bool {
fn update_hero_transition(mut ht HeroTransition, mut _ Window, mut deferred []AnimationCallback) bool {
if ht.stopped {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion animation_keyframe.v
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fn (_ KeyframeAnimation) refresh_kind() AnimationRefreshKind {
return .layout
}

fn update_keyframe(mut kf KeyframeAnimation, mut w Window, mut deferred []AnimationCallback) bool {
fn update_keyframe(mut kf KeyframeAnimation, mut _ Window, mut deferred []AnimationCallback) bool {
if kf.stopped {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion animation_layout.v
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ fn capture_recursive(layout Layout, mut snapshots map[string]LayoutSnapshot) {
}
}

fn update_layout_transition(mut lt LayoutTransition, mut w Window, mut deferred []AnimationCallback) bool {
fn update_layout_transition(mut lt LayoutTransition, mut _ Window, mut deferred []AnimationCallback) bool {
if lt.stopped {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion animation_spring.v
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ pub fn (mut s SpringAnimation) retarget(to f32) {
s.stopped = false
}

fn update_spring(mut sp SpringAnimation, mut w Window, dt f32, mut deferred []AnimationCallback) bool {
fn update_spring(mut sp SpringAnimation, mut _ Window, dt f32, mut deferred []AnimationCallback) bool {
if sp.stopped || sp.state.at_rest {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion animation_tween.v
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ fn (_ TweenAnimation) refresh_kind() AnimationRefreshKind {
return .layout
}

fn update_tween(mut tw TweenAnimation, mut w Window, mut deferred []AnimationCallback) bool {
fn update_tween(mut tw TweenAnimation, mut _ Window, mut deferred []AnimationCallback) bool {
if tw.stopped {
return false
}
Expand Down
6 changes: 3 additions & 3 deletions color_hsv.v
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ pub fn (c Color) to_hex_string() string {

// hex_byte formats a u8 as a two-character uppercase hex string.
fn hex_byte(b u8) string {
hex := '0123456789ABCDEF'
hi := hex[b >> 4]
lo := hex[b & 0x0F]
hex_digits := '0123456789ABCDEF'
hi := hex_digits[b >> 4]
lo := hex_digits[b & 0x0F]
mut res := []u8{len: 2}
res[0] = hi
res[1] = lo
Expand Down
20 changes: 10 additions & 10 deletions dock_layout_drag.v
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ fn dock_drag_cancel(dock_id string, mut w Window) {
// panel_nodes is pre-collected at drag activation to avoid per-move
// allocations.
fn dock_drag_detect_zone(dock_id string, panel_nodes []&DockNode,
mouse_x f32, mouse_y f32, source_group string, panel_id string,
mouse_x f32, mouse_y f32, source_group string, _ string,
w &Window) (DockDropZone, string) {
// 1. Check window-edge zones first.
dock_layout := w.find_layout_by_id(dock_id) or { return DockDropZone.none, '' }
clip := dock_layout.shape.shape_clip
dock_layout_node := w.find_layout_by_id(dock_id) or { return DockDropZone.none, '' }
clip := dock_layout_node.shape.shape_clip
if clip.width <= 0 || clip.height <= 0 {
return DockDropZone.none, ''
}
Expand Down Expand Up @@ -281,32 +281,32 @@ fn dock_drag_amend_overlay(dock_id string, color_zone Color, mut layout Layout,
}

// Determine target rect.
mut tx, mut ty, mut tw, mut th := f32(0), f32(0), f32(0), f32(0)
mut tx, mut ty, mut tw, mut target_h := f32(0), f32(0), f32(0), f32(0)

if state.hover_zone == .window_top || state.hover_zone == .window_bottom
|| state.hover_zone == .window_left || state.hover_zone == .window_right {
tx = layout.shape.x
ty = layout.shape.y
tw = layout.shape.width
th = layout.shape.height
target_h = layout.shape.height
} else if state.hover_group_id.len > 0 {
group_layout := layout.find_by_id(state.hover_group_id) or { return }
tx = group_layout.shape.x
ty = group_layout.shape.y
tw = group_layout.shape.width
th = group_layout.shape.height
target_h = group_layout.shape.height
} else {
return
}

// Subdivide based on zone.
match state.hover_zone {
.top, .window_top {
th = th * 0.5
target_h = target_h * 0.5
}
.bottom, .window_bottom {
ty = ty + th * 0.5
th = th * 0.5
ty = ty + target_h * 0.5
target_h = target_h * 0.5
}
.left, .window_left {
tw = tw * 0.5
Expand All @@ -322,6 +322,6 @@ fn dock_drag_amend_overlay(dock_id string, color_zone Color, mut layout Layout,
layout.children[overlay_idx].shape.x = tx
layout.children[overlay_idx].shape.y = ty
layout.children[overlay_idx].shape.width = tw
layout.children[overlay_idx].shape.height = th
layout.children[overlay_idx].shape.height = target_h
layout.children[overlay_idx].shape.color = color_zone
}
Loading
Loading