Layer Style dialog fits a scrolling dialog body: the effect list takes its natural height, the Styles grid shows five rows and scrolls the rest (PresetBrowser max_rows)

This commit is contained in:
aiongg
2026-11-12 14:32:49 +00:00
parent 9c8c6a93d2
commit 8a7d2ca627
3 changed files with 19 additions and 1 deletions
@@ -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 {
+6 -1
View File
@@ -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::<PresetState<String>>::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);
@@ -216,6 +216,10 @@ pub struct PresetBrowser<'a, K: Clone + Eq + Hash + Send + Sync + 'static> {
/// of presets.
#[prop]
footer: Option<PresetFooterOptions<'a>>,
/// 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<u16>,
}
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<K: Clone + Eq + Hash + Send + Sync + 'static> PresetBrowser<'_, K> {
extra_items,
actions,
footer,
max_rows,
} = self;
let env = Env::of(ui);
let words = env.words::<PresetWords>();
@@ -636,6 +642,9 @@ impl<K: Clone + Eq + Hash + Send + Sync + 'static> PresetBrowser<'_, K> {
if reorder.is_some() {
grid = grid.reorder(ReorderRule::new()).drag_payload(app_drag::<K>);
}
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<K: Clone + Eq + Hash + Send + Sync + 'static> PresetBrowser<'_, K> {
if reorder.is_some() {
list = list.reorder(ReorderRule::new().into_groups()).drag_payload(app_drag::<K>);
}
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();