From ba763904aa593b2d12a7e7112f7051a780f92a37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Tue, 2 Jan 2024 11:41:30 +0100 Subject: [PATCH] Rename lists to stacks --- examples/layout/src/draggable_sidebar.rs | 10 ++-- examples/layout/src/holy_grail.rs | 16 +++--- examples/layout/src/left_sidebar.rs | 10 ++-- examples/layout/src/right_sidebar.rs | 10 ++-- examples/virtual_list/src/main.rs | 10 ++-- examples/widget-gallery/src/lists.rs | 16 +++--- examples/widget-gallery/src/main.rs | 10 ++-- src/views/{list.rs => dyn_stack.rs} | 10 ++-- src/views/mod.rs | 8 +-- .../{virtual_list.rs => virtual_stack.rs} | 54 +++++++++---------- src/window_handle.rs | 6 +-- 11 files changed, 80 insertions(+), 80 deletions(-) rename src/views/{list.rs => dyn_stack.rs} (97%) rename src/views/{virtual_list.rs => virtual_stack.rs} (88%) diff --git a/examples/layout/src/draggable_sidebar.rs b/examples/layout/src/draggable_sidebar.rs index bc59c65e..abb1c717 100644 --- a/examples/layout/src/draggable_sidebar.rs +++ b/examples/layout/src/draggable_sidebar.rs @@ -5,8 +5,8 @@ use floem::{ style::{CursorStyle, Position}, view::View, views::{ - container, h_stack, label, scroll, virtual_list, Decorators, VirtualListDirection, - VirtualListItemSize, + container, h_stack, label, scroll, virtual_stack, Decorators, VirtualStackDirection, + VirtualStackItemSize, }, EventPropagation, }; @@ -20,9 +20,9 @@ pub fn draggable_sidebar_view() -> impl View { let is_sidebar_dragging = create_rw_signal(false); let side_bar = scroll({ - virtual_list( - VirtualListDirection::Vertical, - VirtualListItemSize::Fixed(Box::new(|| 22.0)), + virtual_stack( + VirtualStackDirection::Vertical, + VirtualStackItemSize::Fixed(Box::new(|| 22.0)), move || long_list.get(), move |item| *item, move |item| { diff --git a/examples/layout/src/holy_grail.rs b/examples/layout/src/holy_grail.rs index 4dbec04d..0ec5b370 100644 --- a/examples/layout/src/holy_grail.rs +++ b/examples/layout/src/holy_grail.rs @@ -5,8 +5,8 @@ use floem::{ style::Position, view::View, views::{ - container, h_stack, label, scroll, v_stack, virtual_list, Decorators, VirtualListDirection, - VirtualListItemSize, + container, h_stack, label, scroll, v_stack, virtual_stack, Decorators, + VirtualStackDirection, VirtualStackItemSize, }, }; @@ -21,9 +21,9 @@ pub fn holy_grail_view() -> impl View { .style(|s| s.padding(10.0).width_full().height(TOPBAR_HEIGHT)); let side_bar_right = scroll({ - virtual_list( - VirtualListDirection::Vertical, - VirtualListItemSize::Fixed(Box::new(|| 22.0)), + virtual_stack( + VirtualStackDirection::Vertical, + VirtualStackItemSize::Fixed(Box::new(|| 22.0)), move || long_list.get(), move |item| *item, move |item| { @@ -48,9 +48,9 @@ pub fn holy_grail_view() -> impl View { }); let side_bar_left = scroll({ - virtual_list( - VirtualListDirection::Vertical, - VirtualListItemSize::Fixed(Box::new(|| 22.0)), + virtual_stack( + VirtualStackDirection::Vertical, + VirtualStackItemSize::Fixed(Box::new(|| 22.0)), move || long_list.get(), move |item| *item, move |item| { diff --git a/examples/layout/src/left_sidebar.rs b/examples/layout/src/left_sidebar.rs index f771fa73..120c1e4a 100644 --- a/examples/layout/src/left_sidebar.rs +++ b/examples/layout/src/left_sidebar.rs @@ -5,8 +5,8 @@ use floem::{ style::Position, view::View, views::{ - container, h_stack, label, scroll, v_stack, virtual_list, Decorators, VirtualListDirection, - VirtualListItemSize, + container, h_stack, label, scroll, v_stack, virtual_stack, Decorators, + VirtualStackDirection, VirtualStackItemSize, }, }; @@ -21,9 +21,9 @@ pub fn left_sidebar_view() -> impl View { .style(|s| s.padding(10.0).width_full().height(TOPBAR_HEIGHT)); let side_bar = scroll({ - virtual_list( - VirtualListDirection::Vertical, - VirtualListItemSize::Fixed(Box::new(|| 22.0)), + virtual_stack( + VirtualStackDirection::Vertical, + VirtualStackItemSize::Fixed(Box::new(|| 22.0)), move || long_list.get(), move |item| *item, move |item| { diff --git a/examples/layout/src/right_sidebar.rs b/examples/layout/src/right_sidebar.rs index 11b99614..7c7bf54a 100644 --- a/examples/layout/src/right_sidebar.rs +++ b/examples/layout/src/right_sidebar.rs @@ -5,8 +5,8 @@ use floem::{ style::Position, view::View, views::{ - container, h_stack, label, scroll, v_stack, virtual_list, Decorators, VirtualListDirection, - VirtualListItemSize, + container, h_stack, label, scroll, v_stack, virtual_stack, Decorators, + VirtualStackDirection, VirtualStackItemSize, }, }; @@ -21,9 +21,9 @@ pub fn right_sidebar_view() -> impl View { .style(|s| s.padding(10.0).width_full().height(TOPBAR_HEIGHT)); let side_bar = scroll({ - virtual_list( - VirtualListDirection::Vertical, - VirtualListItemSize::Fixed(Box::new(|| 22.0)), + virtual_stack( + VirtualStackDirection::Vertical, + VirtualStackItemSize::Fixed(Box::new(|| 22.0)), move || long_list.get(), move |item| *item, move |item| { diff --git a/examples/virtual_list/src/main.rs b/examples/virtual_list/src/main.rs index 31d96696..d768bf4d 100644 --- a/examples/virtual_list/src/main.rs +++ b/examples/virtual_list/src/main.rs @@ -2,9 +2,9 @@ use floem::{ reactive::create_signal, unit::UnitExt, view::View, - views::virtual_list, + views::virtual_stack, views::Decorators, - views::{container, label, scroll, VirtualListDirection, VirtualListItemSize}, + views::{container, label, scroll, VirtualStackDirection, VirtualStackItemSize}, }; fn app_view() -> impl View { @@ -13,9 +13,9 @@ fn app_view() -> impl View { container( scroll( - virtual_list( - VirtualListDirection::Vertical, - VirtualListItemSize::Fixed(Box::new(|| 20.0)), + virtual_stack( + VirtualStackDirection::Vertical, + VirtualStackItemSize::Fixed(Box::new(|| 20.0)), move || long_list.get(), move |item| *item, move |item| label(move || item.to_string()).style(|s| s.height(20.0)), diff --git a/examples/widget-gallery/src/lists.rs b/examples/widget-gallery/src/lists.rs index 8dc6958e..8863e83e 100644 --- a/examples/widget-gallery/src/lists.rs +++ b/examples/widget-gallery/src/lists.rs @@ -7,8 +7,8 @@ use floem::{ style::{CursorStyle, JustifyContent}, view::View, views::{ - container, label, scroll, stack, virtual_list, Decorators, VirtualListDirection, - VirtualListItemSize, + container, label, scroll, stack, virtual_stack, Decorators, VirtualStackDirection, + VirtualStackItemSize, }, widgets::checkbox, EventPropagation, @@ -29,9 +29,9 @@ fn simple_list() -> impl View { let long_list: im::Vector = (0..100).collect(); let (long_list, _set_long_list) = create_signal(long_list); scroll( - virtual_list( - VirtualListDirection::Vertical, - VirtualListItemSize::Fixed(Box::new(|| 20.0)), + virtual_stack( + VirtualStackDirection::Vertical, + VirtualStackItemSize::Fixed(Box::new(|| 20.0)), move || long_list.get(), move |item| *item, move |item| label(move || item.to_string()).style(|s| s.height(24.0)), @@ -49,9 +49,9 @@ fn enhanced_list() -> impl View { let list_width = 180.0; let item_height = 32.0; scroll( - virtual_list( - VirtualListDirection::Vertical, - VirtualListItemSize::Fixed(Box::new(|| 32.0)), + virtual_stack( + VirtualStackDirection::Vertical, + VirtualStackItemSize::Fixed(Box::new(|| 32.0)), move || long_list.get(), move |item| *item, move |item| { diff --git a/examples/widget-gallery/src/main.rs b/examples/widget-gallery/src/main.rs index 04ee5bae..6055e36d 100644 --- a/examples/widget-gallery/src/main.rs +++ b/examples/widget-gallery/src/main.rs @@ -18,8 +18,8 @@ use floem::{ unit::UnitExt, view::View, views::{ - container, container_box, h_stack, label, scroll, stack, tab, v_stack, virtual_list, - Decorators, VirtualListDirection, VirtualListItemSize, + container, container_box, h_stack, label, scroll, stack, tab, v_stack, virtual_stack, + Decorators, VirtualStackDirection, VirtualStackItemSize, }, widgets::button, EventPropagation, @@ -44,9 +44,9 @@ fn app_view() -> impl View { let (active_tab, set_active_tab) = create_signal(0); let list = scroll({ - virtual_list( - VirtualListDirection::Vertical, - VirtualListItemSize::Fixed(Box::new(|| 36.0)), + virtual_stack( + VirtualStackDirection::Vertical, + VirtualStackItemSize::Fixed(Box::new(|| 36.0)), move || tabs.get(), move |item| *item, move |item| { diff --git a/src/views/list.rs b/src/views/dyn_stack.rs similarity index 97% rename from src/views/list.rs rename to src/views/dyn_stack.rs index 98d6c772..0774480a 100644 --- a/src/views/list.rs +++ b/src/views/dyn_stack.rs @@ -19,7 +19,7 @@ pub(crate) type FxIndexSet = indexmap::IndexSet(#[educe(Debug(ignore))] pub(crate) T); -pub struct List +pub struct DynStack where V: View, T: 'static, @@ -30,7 +30,7 @@ where phantom: PhantomData, } -pub fn list(each_fn: IF, key_fn: KF, view_fn: VF) -> List +pub fn dyn_stack(each_fn: IF, key_fn: KF, view_fn: VF) -> DynStack where IF: Fn() -> I + 'static, I: IntoIterator, @@ -69,7 +69,7 @@ where HashRun(hashed_items) }); let view_fn = Box::new(as_child_of_current_scope(view_fn)); - List { + DynStack { data: ViewData::new(id), children: Vec::new(), view_fn, @@ -77,7 +77,7 @@ where } } -impl View for List { +impl View for DynStack { fn view_data(&self) -> &ViewData { &self.data } @@ -119,7 +119,7 @@ impl View for List { } fn debug_name(&self) -> std::borrow::Cow<'static, str> { - "List".into() + "DynStack".into() } fn update(&mut self, cx: &mut UpdateCx, state: Box) { diff --git a/src/views/mod.rs b/src/views/mod.rs index 2022d4bd..a41fbf2a 100644 --- a/src/views/mod.rs +++ b/src/views/mod.rs @@ -9,8 +9,8 @@ pub use label::*; mod rich_text; pub use rich_text::*; -mod list; -pub use list::*; +mod dyn_stack; +pub use dyn_stack::*; mod svg; pub use svg::*; @@ -30,8 +30,8 @@ pub use dyn_container::*; mod decorator; pub use decorator::*; -mod virtual_list; -pub use virtual_list::*; +mod virtual_stack; +pub use virtual_stack::*; pub mod scroll; pub use scroll::{scroll, Scroll}; diff --git a/src/views/virtual_list.rs b/src/views/virtual_stack.rs similarity index 88% rename from src/views/virtual_list.rs rename to src/views/virtual_stack.rs index ef105c20..6672f631 100644 --- a/src/views/virtual_list.rs +++ b/src/views/virtual_stack.rs @@ -14,17 +14,17 @@ use crate::{ use super::{apply_diff, diff, Diff, DiffOpAdd, FxIndexSet, HashRun}; #[derive(Clone, Copy)] -pub enum VirtualListDirection { +pub enum VirtualStackDirection { Vertical, Horizontal, } -pub enum VirtualListItemSize { +pub enum VirtualStackItemSize { Fn(Box f64>), Fixed(Box f64>), } -pub trait VirtualListVector { +pub trait VirtualStackVector { type ItemIterator: Iterator; fn total_len(&self) -> usize; @@ -40,12 +40,12 @@ pub trait VirtualListVector { fn slice(&mut self, range: Range) -> Self::ItemIterator; } -pub struct VirtualList +pub struct VirtualStack where T: 'static, { data: ViewData, - direction: VirtualListDirection, + direction: VirtualStackDirection, children: Vec>, viewport: Rect, set_viewport: WriteSignal, @@ -57,23 +57,23 @@ where after_node: Option, } -struct VirtualListState { +struct VirtualStackState { diff: Diff, before_size: f64, after_size: f64, } -pub fn virtual_list( - direction: VirtualListDirection, - item_size: VirtualListItemSize, +pub fn virtual_stack( + direction: VirtualStackDirection, + item_size: VirtualStackItemSize, each_fn: IF, key_fn: KF, view_fn: VF, -) -> VirtualList +) -> VirtualStack where T: 'static, IF: Fn() -> I + 'static, - I: VirtualListVector, + I: VirtualStackVector, KF: Fn(&T) -> K + 'static, K: Eq + Hash + 'static, VF: Fn(T) -> V + 'static, @@ -87,19 +87,19 @@ where let mut items_vector = each_fn(); let viewport = viewport.get(); let min = match direction { - VirtualListDirection::Vertical => viewport.y0, - VirtualListDirection::Horizontal => viewport.x0, + VirtualStackDirection::Vertical => viewport.y0, + VirtualStackDirection::Horizontal => viewport.x0, }; let max = match direction { - VirtualListDirection::Vertical => viewport.height() + viewport.y0, - VirtualListDirection::Horizontal => viewport.width() + viewport.x0, + VirtualStackDirection::Vertical => viewport.height() + viewport.y0, + VirtualStackDirection::Horizontal => viewport.width() + viewport.x0, }; let mut items = Vec::new(); let mut before_size = 0.0; let mut after_size = 0.0; match &item_size { - VirtualListItemSize::Fixed(item_size) => { + VirtualStackItemSize::Fixed(item_size) => { let item_size = item_size(); let total_len = items_vector.total_len(); let start = if item_size > 0.0 { @@ -121,7 +121,7 @@ where after_size = item_size * (total_len.saturating_sub(start).saturating_sub(items.len())) as f64; } - VirtualListItemSize::Fn(size_fn) => { + VirtualStackItemSize::Fn(size_fn) => { let mut main_axis = 0.0; let total_len = items_vector.total_len(); let total_size = items_vector.total_size(); @@ -172,7 +172,7 @@ where if !diff.is_empty() || prev_before_size != before_size || prev_after_size != after_size { id.update_state( - VirtualListState { + VirtualStackState { diff, before_size, after_size, @@ -185,7 +185,7 @@ where let view_fn = Box::new(as_child_of_current_scope(view_fn)); - VirtualList { + VirtualStack { data: ViewData::new(id), direction, children: Vec::new(), @@ -200,7 +200,7 @@ where } } -impl View for VirtualList { +impl View for VirtualStack { fn view_data(&self) -> &ViewData { &self.data } @@ -242,11 +242,11 @@ impl View for VirtualList { } fn debug_name(&self) -> std::borrow::Cow<'static, str> { - "VirtualList".into() + "VirtualStack".into() } fn update(&mut self, cx: &mut crate::context::UpdateCx, state: Box) { - if let Ok(state) = state.downcast::>() { + if let Ok(state) = state.downcast::>() { if self.before_size == state.before_size && self.after_size == state.after_size && state.diff.is_empty() @@ -274,21 +274,21 @@ impl View for VirtualList { .filter_map(|child| Some(cx.layout_view(&mut child.as_mut()?.0))) .collect::>(); let before_size = match self.direction { - VirtualListDirection::Vertical => taffy::prelude::Size { + VirtualStackDirection::Vertical => taffy::prelude::Size { width: Dimension::Percent(1.0), height: Dimension::Points(self.before_size as f32), }, - VirtualListDirection::Horizontal => taffy::prelude::Size { + VirtualStackDirection::Horizontal => taffy::prelude::Size { width: Dimension::Points(self.before_size as f32), height: Dimension::Percent(1.0), }, }; let after_size = match self.direction { - VirtualListDirection::Vertical => taffy::prelude::Size { + VirtualStackDirection::Vertical => taffy::prelude::Size { width: Dimension::Percent(1.0), height: Dimension::Points(self.after_size as f32), }, - VirtualListDirection::Horizontal => taffy::prelude::Size { + VirtualStackDirection::Horizontal => taffy::prelude::Size { width: Dimension::Points(self.after_size as f32), height: Dimension::Percent(1.0), }, @@ -347,7 +347,7 @@ impl View for VirtualList { } } -impl VirtualListVector for im::Vector { +impl VirtualStackVector for im::Vector { type ItemIterator = im::vector::ConsumingIter; fn total_len(&self) -> usize { diff --git a/src/window_handle.rs b/src/window_handle.rs index 8ea39934..1017b7e0 100644 --- a/src/window_handle.rs +++ b/src/window_handle.rs @@ -1238,7 +1238,7 @@ fn context_menu_view( use crate::{ app::{add_app_update_event, AppUpdateEvent}, - views::{empty, list, svg, text}, + views::{dyn_stack, empty, svg, text}, }; #[derive(Clone, PartialEq, Eq, Hash)] @@ -1352,7 +1352,7 @@ fn context_menu_view( .active(|s| s.border_radius(10.0).background(Color::rgb8(92, 92, 92))) .disabled(|s| s.color(Color::rgb8(92, 92, 92))) }), - list( + dyn_stack( move || menu.children.clone().unwrap_or_default(), move |s| s.clone(), move |menu| { @@ -1429,7 +1429,7 @@ fn context_menu_view( } let on_child_submenu = create_rw_signal(false); - let view = list( + let view = dyn_stack( move || context_menu_items.get().unwrap_or_default(), move |s| s.clone(), move |menu| view_fn(window_id, menu, context_menu, focus_count, on_child_submenu),