diff --git a/crates/imaging/src/ui/layer_style/list.rs b/crates/imaging/src/ui/layer_style/list.rs index 0f50eb0d5..544c7f69c 100644 --- a/crates/imaging/src/ui/layer_style/list.rs +++ b/crates/imaging/src/ui/layer_style/list.rs @@ -152,6 +152,7 @@ pub(super) fn effect_list( .header(false) .space(SpaceAction::ToggleCell) .sizing(Sizing::Content) + .natural_height(true) .columns(columns) .selection(Bind::given(selection)) .show_items(ui, &source, &mut |key, icx| match key { diff --git a/crates/imaging/src/ui/layer_style/styles.rs b/crates/imaging/src/ui/layer_style/styles.rs index ba14734c4..6bff51ead 100644 --- a/crates/imaging/src/ui/layer_style/styles.rs +++ b/crates/imaging/src/ui/layer_style/styles.rs @@ -9,6 +9,10 @@ use egui::{Rect, Ui}; use super::dialog::title_row; use super::labels::LayerStyleWords; +/// The rows of styles the Styles page shows before the grid scrolls: the user's style library can grow long, and the +/// dialog page around it scrolls too. +const STYLE_ROWS: u16 = 5; + /// The host's style presets for the Styles page: the rows (groups and presets keyed by the preset's name) and the /// painter of one preset's thumbnail. The page shows them in the library [`PresetBrowser`] grid and keeps the /// browser's view state itself. @@ -48,7 +52,8 @@ pub(super) fn styles_page(ui: &mut Ui, presets: Option<&StylePresets<'_>>, words if let Some(StylePresets { rows, thumb }) = presets { let browser = PresetBrowser::new(words.styles.clone(), Bind::>::kept(), rows) .thumb(move |cx, rect, info| thumb(cx, rect, info)) - .row_menu(false); + .row_menu(false) + .max_rows(STYLE_ROWS); for event in browser.show(ui).events { if let PresetEvent::Select { key, .. } | PresetEvent::Activate { key, .. } = event { out.apply_style = Some(key); diff --git a/crates/ui-patterns/src/patterns/presets/browser.rs b/crates/ui-patterns/src/patterns/presets/browser.rs index 12a82e612..f26f9183a 100644 --- a/crates/ui-patterns/src/patterns/presets/browser.rs +++ b/crates/ui-patterns/src/patterns/presets/browser.rs @@ -216,6 +216,10 @@ pub struct PresetBrowser<'a, K: Clone + Eq + Hash + Send + Sync + 'static> { /// of presets. #[prop] footer: Option>, + /// The most rows the presets show before they scroll, in either view: a library that can grow long shown inside a + /// body that scrolls (a dialog page) keeps its own scroll this way. + #[prop] + max_rows: Option, } impl<'a, K: Clone + Eq + Hash + Send + Sync + 'static> PresetBrowser<'a, K> { @@ -243,6 +247,7 @@ impl<'a, K: Clone + Eq + Hash + Send + Sync + 'static> PresetBrowser<'a, K> { extra_items: Vec::new(), actions: Vec::new(), footer: None, + max_rows: None, } } @@ -520,6 +525,7 @@ impl PresetBrowser<'_, K> { extra_items, actions, footer, + max_rows, } = self; let env = Env::of(ui); let words = env.words::(); @@ -636,6 +642,9 @@ impl PresetBrowser<'_, K> { if reorder.is_some() { grid = grid.reorder(ReorderRule::new()).drag_payload(app_drag::); } + if let Some(rows) = max_rows { + grid = grid.max_rows(rows); + } let aspect = cell_shape.aspect(); let out = grid.show_items(ui, &tiles, &mut |key, icx| { let Some(row) = tiles.index_of(key).and_then(|at| tiles.row(at)) else { return Tile::new(Label::default()) }; @@ -675,6 +684,9 @@ impl PresetBrowser<'_, K> { if reorder.is_some() { list = list.reorder(ReorderRule::new().into_groups()).drag_payload(app_drag::); } + if let Some(rows) = max_rows { + list = list.max_rows(rows); + } let aspect = cell_shape.aspect(); // The last preset row draws the divider above the action rows. let ruled = |at: usize| !actions.is_empty() && at + 1 == shown.len();