Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: Replace generic parameters with ScrollableWidget #598

Merged
merged 1 commit into from
Mar 2, 2025
Merged
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
82 changes: 25 additions & 57 deletions src/interface_scrollable.v
Original file line number Diff line number Diff line change
Expand Up @@ -117,31 +117,21 @@ pub fn scrollview_add[T](mut w T) {
// TODO: documentation
pub fn scrollview_widget_set_orig_xy(w Widget, reset_offset bool) {
if w is Stack {
if has_scrollview(w) {
scrollview_set_orig_xy(w, reset_offset)
}
scrollview_set_orig_xy(w, reset_offset)
for child in w.children {
scrollview_widget_set_orig_xy(child, reset_offset)
}
} else if w is CanvasLayout {
if has_scrollview(w) {
scrollview_set_orig_xy(w, reset_offset)
}
scrollview_set_orig_xy(w, reset_offset)
for child in w.children {
scrollview_widget_set_orig_xy(child, reset_offset)
}
} else if w is ListBox {
if has_scrollview(w) {
scrollview_set_orig_xy(w, reset_offset)
}
scrollview_set_orig_xy(w, reset_offset)
} else if w is ChunkView {
if has_scrollview(w) {
scrollview_set_orig_xy(w, reset_offset)
}
scrollview_set_orig_xy(w, reset_offset)
} else if w is TextBox {
if has_scrollview(w) {
scrollview_set_orig_xy(w, reset_offset)
}
scrollview_set_orig_xy(w, reset_offset)
} else if w is Group {
// if has_scrollview(w) {
// scrollview_set_orig_xy(w)
Expand All @@ -150,9 +140,7 @@ pub fn scrollview_widget_set_orig_xy(w Widget, reset_offset bool) {
scrollview_widget_set_orig_xy(child, reset_offset)
}
} else if w is BoxLayout {
if has_scrollview(w) {
scrollview_set_orig_xy(w, reset_offset)
}
scrollview_set_orig_xy(w, reset_offset)
for child in w.children {
scrollview_widget_set_orig_xy(child, reset_offset)
}
Expand Down Expand Up @@ -207,7 +195,7 @@ fn has_parent_scrolling(w Widget) bool {
}

// TODO: documentation
pub fn scrollview_set_orig_xy[T](w &T, reset_offset bool) {
pub fn scrollview_set_orig_xy(w &ScrollableWidget, reset_offset bool) {
if has_scrollview(w) {
mut sv := w.scrollview
// rest values
Expand All @@ -234,32 +222,24 @@ pub fn scrollview_set_orig_xy[T](w &T, reset_offset bool) {
// TODO: documentation
pub fn scrollview_widget_save_offset(w Widget) {
if w is Stack {
if has_scrollview(w) {
scrollview_save_offset(w)
}
scrollview_save_offset(w)
for child in w.children {
scrollview_widget_save_offset(child)
}
} else if w is CanvasLayout {
if has_scrollview(w) {
scrollview_save_offset(w)
}
scrollview_save_offset(w)
for child in w.children {
scrollview_widget_save_offset(child)
}
} else if w is ListBox {
if has_scrollview(w) {
scrollview_save_offset(w)
}
scrollview_save_offset(w)
} else if w is TextBox {
if has_scrollview(w) {
scrollview_save_offset(w)
}
scrollview_save_offset(w)
}
}

// TODO: documentation
pub fn scrollview_save_offset[T](w &T) {
pub fn scrollview_save_offset(w &ScrollableWidget) {
if has_scrollview(w) {
mut sv := w.scrollview
// Save prev values
Expand All @@ -271,32 +251,24 @@ pub fn scrollview_save_offset[T](w &T) {
// TODO: documentation
pub fn scrollview_widget_restore_offset(w Widget, orig bool) {
if w is Stack {
if has_scrollview(w) {
scrollview_restore_offset(w, orig)
}
scrollview_restore_offset(w, orig)
for child in w.children {
scrollview_widget_restore_offset(child, orig)
}
} else if w is CanvasLayout {
if has_scrollview(w) {
scrollview_restore_offset(w, orig)
}
scrollview_restore_offset(w, orig)
for child in w.children {
scrollview_widget_restore_offset(child, orig)
}
} else if w is ListBox {
if has_scrollview(w) {
scrollview_restore_offset(w, orig)
}
scrollview_restore_offset(w, orig)
} else if w is TextBox {
if has_scrollview(w) {
scrollview_restore_offset(w, orig)
}
scrollview_restore_offset(w, orig)
}
}

// TODO: documentation
pub fn scrollview_restore_offset[T](w &T, orig bool) {
pub fn scrollview_restore_offset(w &ScrollableWidget, orig bool) {
if has_scrollview(w) {
mut sv := w.scrollview
sv.update_active()
Expand All @@ -320,17 +292,17 @@ pub fn scrollview_restore_offset[T](w &T, orig bool) {
}

// TODO: documentation
pub fn scrollview_delegate_parent_scrollview[T](mut w T) {
pub fn scrollview_delegate_parent_scrollview(mut w Widget) {
parent := w.parent
if parent is Stack {
if parent is Stack && mut w is ScrollableWidget {
w.scrollview = parent.scrollview
} else if parent is CanvasLayout {
} else if parent is CanvasLayout && mut w is ScrollableWidget {
w.scrollview = parent.scrollview
}
}

// TODO: documentation
pub fn scrollview_update[T](w &T) {
pub fn scrollview_update(w &ScrollableWidget) {
if has_scrollview(w) {
mut sv := w.scrollview
sv.update()
Expand All @@ -340,17 +312,15 @@ pub fn scrollview_update[T](w &T) {
// TODO: documentation
pub fn scrollview_widget_update(w Widget) {
if w is Stack {
if has_scrollview(w) {
scrollview_update(w)
}
scrollview_update(w)
for child in w.children {
scrollview_widget_update(child)
}
}
}

// TODO: documentation
pub fn scrollview_update_active[T](w &T) {
pub fn scrollview_update_active(w &ScrollableWidget) {
if has_scrollview(w) {
mut sv := w.scrollview
sv.update_active()
Expand All @@ -360,9 +330,7 @@ pub fn scrollview_update_active[T](w &T) {
// TODO: documentation
pub fn scrollview_widget_update_active(w Widget) {
if w is Stack {
if has_scrollview(w) {
scrollview_update_active(w)
}
scrollview_update_active(w)
for child in w.children {
scrollview_widget_update_active(child)
}
Expand Down Expand Up @@ -391,7 +359,7 @@ pub fn scrollview_draw_begin[T](mut w T, d DrawDevice) {
}

// TODO: documentation
pub fn scrollview_draw_end[T](w &T, d DrawDevice) {
pub fn scrollview_draw_end(w &ScrollableWidget, d DrawDevice) {
if has_scrollview(w) {
sv := w.scrollview
sv.draw_device(d)
Expand Down