mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 18:04:48 +00:00
Merge branch 'red/f2' into fw/mac1
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
//! the palette supplies the rows and paints each preset's thumbnail as a gradient ramp.
|
||||
|
||||
use craft_ui::contract::{Bind, NoValue, Outcome, Pattern};
|
||||
use craft_ui::patterns::presets::{CellShape, PresetBrowser, PresetEvent, PresetRow, PresetState};
|
||||
use craft_ui::patterns::presets::{CellShape, PresetBrowser, PresetEvent, PresetRow, PresetState, PresetTiles};
|
||||
use craft_ui::runtime::env::{Env, Label};
|
||||
use egui::{Response, Ui};
|
||||
|
||||
@@ -13,7 +13,7 @@ mod stories;
|
||||
use craft_color::ui::gradient::{GradientRamp, GradientStops, Sampler, StopRows, default_sampler};
|
||||
|
||||
/// The presets take their content height up to this many small control heights, then scroll.
|
||||
const MAX_ROWS: f32 = 5.0;
|
||||
const MAX_ROWS: f32 = 6.0;
|
||||
|
||||
/// A named group of gradient presets.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
@@ -103,7 +103,8 @@ impl GradientRef {
|
||||
/// left; the gradients are not), Up and Down to the nearest cell in the row above or below
|
||||
/// across group labels, Home and End to the first and last. In List, Up, Down, Home and End
|
||||
/// move and Left and Right do nothing. A focus move scrolls the cell into view.
|
||||
/// - The presets take their content height up to five small control heights and scroll past it, also in a host
|
||||
/// - The grid shows the presets as small chips (`PresetTiles::Chips`) under their group names.
|
||||
/// - The presets take their content height up to six small control heights and scroll past it, also in a host
|
||||
/// that sizes to its content (a popover), where a filling browser would take the whole room.
|
||||
/// - AccessKit: Grid is a `Group` named `label` with `Button` cells; List is a `ListBox` of
|
||||
/// `ListBoxOption`s with `selected` on the chosen one. Cells carry their place and the set's
|
||||
@@ -208,7 +209,11 @@ impl<'a> GradientPalette<'a> {
|
||||
};
|
||||
let (wide, high) = GradientRamp::CHIP_ASPECT;
|
||||
let most = Env::of(ui).tokens.size.control.sm * MAX_ROWS;
|
||||
let mut browser = PresetBrowser::new(self.label, self.state, &rows).cell_shape(CellShape::ratio(wide, high)).room_height(most).thumb(thumb);
|
||||
let mut browser = PresetBrowser::new(self.label, self.state, &rows)
|
||||
.cell_shape(CellShape::ratio(wide, high))
|
||||
.tiles(PresetTiles::Chips)
|
||||
.room_height(most)
|
||||
.thumb(thumb);
|
||||
if let Some(selected) = self.selected {
|
||||
browser = browser.selected(selected);
|
||||
}
|
||||
|
||||
@@ -14,14 +14,14 @@ pub use reorder::PresetReorder;
|
||||
|
||||
use super::event::{PresetEvent, PresetOutput};
|
||||
use super::footer::{PresetFooter, PresetFooterEvent, PresetFooterOptions};
|
||||
use super::model::{CellShape, PresetRow, ThumbInfo, children_end, has_captions};
|
||||
use super::model::{CellShape, PresetRow, PresetTiles, ThumbInfo, children_end, has_captions};
|
||||
use super::state::{DefaultOpen, PresetState, PresetView};
|
||||
use super::words::PresetWords;
|
||||
use crate::bars::{Bar, BarKind};
|
||||
use crate::choice::Segmented;
|
||||
use crate::contract::{
|
||||
Bind, BodyCx, CollectionEvent, DropMark, DropTarget, DropZone, Entry, ListDrag, OpenChange, Pattern, Props, Rename, ReorderMove, ReorderRule,
|
||||
SelectMode, Show as _, ShowCollection as _, ShowContainer as _, request_rename,
|
||||
RowHeight, SelectMode, Show as _, ShowCollection as _, ShowContainer as _, request_rename,
|
||||
};
|
||||
use crate::display::Divider;
|
||||
use crate::layout_components::Stack;
|
||||
@@ -197,6 +197,9 @@ pub struct PresetBrowser<'a, K: Clone + Eq + Hash + Send + Sync + 'static> {
|
||||
/// The shape of a grid tile's picture.
|
||||
#[prop]
|
||||
cell_shape: CellShape,
|
||||
/// How large the grid view's tiles are; the list view is the same for both.
|
||||
#[prop]
|
||||
tiles: PresetTiles,
|
||||
/// The zoom the thumbnails span and how it steps; the footer's slider uses the same.
|
||||
#[prop]
|
||||
thumb_range: TileZoom,
|
||||
@@ -274,6 +277,7 @@ impl<'a, K: Clone + Eq + Hash + Send + Sync + 'static> PresetBrowser<'a, K> {
|
||||
rows,
|
||||
selected: None,
|
||||
cell_shape: CellShape::Square,
|
||||
tiles: PresetTiles::Thumbnails,
|
||||
thumb_range: TileZoom::Ladder,
|
||||
default_open: DefaultOpen::All,
|
||||
toolbar: false,
|
||||
@@ -557,6 +561,7 @@ impl<K: Clone + Eq + Hash + Send + Sync + 'static> PresetBrowser<'_, K> {
|
||||
rows,
|
||||
selected,
|
||||
cell_shape,
|
||||
tiles: tile_size,
|
||||
thumb_range,
|
||||
default_open,
|
||||
toolbar,
|
||||
@@ -683,16 +688,24 @@ impl<K: Clone + Eq + Hash + Send + Sync + 'static> PresetBrowser<'_, K> {
|
||||
let tiles = Shown { rows, at: plan.tiles.clone(), open: vec![false; plan.tiles.len()], tree: false, actions: 0 };
|
||||
let tail: Vec<TailRow<BrowserKey<K>>> =
|
||||
actions.iter().enumerate().map(|(at, label)| TailRow::new(BrowserKey::Action(at), label.clone())).collect();
|
||||
let captions = if has_captions(rows) { CaptionPlace::Below } else { CaptionPlace::None };
|
||||
let mut grid = TileGrid::<BrowserKey<K>>::new(label.clone())
|
||||
let aspect = card_aspect(cell_shape);
|
||||
let grid = TileGrid::<BrowserKey<K>>::new(label.clone())
|
||||
.id(list_id)
|
||||
.select(SelectMode::Single)
|
||||
.arrows_select(false)
|
||||
.selection(Bind::given(selection))
|
||||
.caption(captions)
|
||||
.thumb_size(ThumbSize::Large)
|
||||
.aspect(card_aspect(cell_shape))
|
||||
.zoom(zoom as f32)
|
||||
.aspect(aspect);
|
||||
let grid = match tile_size {
|
||||
PresetTiles::Thumbnails => {
|
||||
let captions = if has_captions(rows) { CaptionPlace::Below } else { CaptionPlace::None };
|
||||
grid.caption(captions).thumb_size(ThumbSize::Large).zoom(zoom as f32)
|
||||
}
|
||||
// The zoom is a factor on the picture's width: a wide chip is the small thumbnail high.
|
||||
PresetTiles::Chips => {
|
||||
grid.caption(CaptionPlace::None).thumb_size(ThumbSize::Small).zoom(aspect.max(1.0)).row_height(RowHeight::Text)
|
||||
}
|
||||
};
|
||||
let mut grid = grid
|
||||
.groups(&plan.groups)
|
||||
.tail(&tail)
|
||||
.collapsible()
|
||||
|
||||
@@ -4,7 +4,7 @@ use super::{PresetBrowser, PresetReorder};
|
||||
use crate::choice::SwatchFace;
|
||||
use crate::contract::Bind;
|
||||
use crate::list::ThumbAspect;
|
||||
use crate::patterns::presets::{PresetEvent, PresetFooterOptions, PresetRow, PresetState};
|
||||
use crate::patterns::presets::{PresetEvent, PresetFooterOptions, PresetRow, PresetState, PresetTiles};
|
||||
use crate::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use craft_theme::Srgba;
|
||||
use egui::Ui;
|
||||
@@ -79,3 +79,26 @@ fn preset_browser(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
};
|
||||
StoryOutput::from(out).readout(readout)
|
||||
}
|
||||
|
||||
/// The chips variant: the same library as small bare chips under text-high group names, as a palette in a popover.
|
||||
#[story(PresetBrowser<'static, u32>, covers = [], drive = Drive::Never)]
|
||||
fn preset_browser_chips(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let rows = library_rows();
|
||||
let selected = *data.value("selected", None::<u32>);
|
||||
let mut browser = PresetBrowser::new("Swatches", Bind::bound(data.value("state", PresetState::<u32>::new())), &rows).tiles(PresetTiles::Chips);
|
||||
if let Some(key) = selected {
|
||||
browser = browser.selected(key);
|
||||
}
|
||||
let out = browser.show(ui);
|
||||
let selected = data.value("selected", None::<u32>);
|
||||
for event in &out.events {
|
||||
if let PresetEvent::Select { key, .. } | PresetEvent::Activate { key, .. } = event {
|
||||
*selected = Some(*key);
|
||||
}
|
||||
}
|
||||
let readout = match *selected {
|
||||
Some(n) => format!("Selected: Preset {n}"),
|
||||
None => String::from("Nothing selected."),
|
||||
};
|
||||
StoryOutput::from(out).readout(readout)
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ pub use files::{PresetExport, PresetFileEvent, PresetFileFailure, PresetFileRequ
|
||||
pub use footer::{PresetFooter, PresetFooterEvent, PresetFooterOptions, PresetFooterOutput};
|
||||
pub use manager::{HostedPresetManager, PresetManager, PresetManagerOutput, PresetManagerTaken};
|
||||
pub use model::{
|
||||
CellShape, GroupPath, PresetChange, PresetError, PresetGroup, PresetId, PresetItem, PresetKey, PresetKind, PresetLibrary, PresetRow, Preview,
|
||||
PreviewPaint, ThumbInfo, children_end, has_captions, nest_allowed,
|
||||
CellShape, GroupPath, PresetChange, PresetError, PresetGroup, PresetId, PresetItem, PresetKey, PresetKind, PresetLibrary, PresetRow, PresetTiles,
|
||||
Preview, PreviewPaint, ThumbInfo, children_end, has_captions, nest_allowed,
|
||||
};
|
||||
pub use named::{NameCheck, NamedPresetCommands, NamedPresetEvent, NamedPresetOutput, NamedPresetRow, NamedPresetStyle};
|
||||
pub use panel_menu::{PresetCommands, PresetMenuAction, PresetPanelMenu};
|
||||
|
||||
@@ -45,6 +45,19 @@ impl CellShape {
|
||||
}
|
||||
}
|
||||
|
||||
/// How large the grid view's tiles are.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub enum PresetTiles {
|
||||
/// Thumbnails at the browser's zoom, with captions when the rows have them, under control-high group headers: a
|
||||
/// library panel.
|
||||
#[default]
|
||||
Thumbnails,
|
||||
/// Small bare chips, as a palette in a popover shows them: each picture a small thumbnail on its short edge, no
|
||||
/// captions (the name stays the tooltip and the accessible name), group headers a text row high, and no zoom.
|
||||
Chips,
|
||||
}
|
||||
|
||||
/// What the thumbnail painter is told about the cell it paints.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
#[non_exhaustive]
|
||||
|
||||
@@ -15,7 +15,7 @@ use super::{CaptionPlace, Tile, TilePartEvent, ZoomStep};
|
||||
use crate::contract::{
|
||||
Access, Bind, BindMut, Collection, CollectionEvent, CollectionProps, CollectionResponse, ColumnKind, ColumnSpec, Common, Component,
|
||||
ContainerProps, Cx, DropKind, EditResponse, Focus as _, ListDrag, Meta as _, NoValue, Notch, Outcome, PaintUi, PartsCx, Pointer as _, Props as _,
|
||||
Role, RowState, SelectMode, Sizing, SpaceAction, SweepApply, SweepStep, ToggleColumn, section_part,
|
||||
Role, RowHeight, RowState, SelectMode, Sizing, SpaceAction, SweepApply, SweepStep, ToggleColumn, section_part,
|
||||
};
|
||||
use crate::controls::disclosure::Disclosure;
|
||||
use crate::list::{DropTest, ListRow, ListRowStyle, RowTest, ThumbSize};
|
||||
@@ -142,18 +142,18 @@ struct GridSizes {
|
||||
thumbs: [f32; 3],
|
||||
/// What a tile adds around its picture.
|
||||
around: AroundPicture,
|
||||
/// The gaps of the arrangement and the height of a group header (a heading row, as high as the grid's other rows),
|
||||
/// for captioned tiles and for bare ones.
|
||||
/// The gaps of the arrangement and the height of a group header (a heading row, as high as the grid's rows: the
|
||||
/// collection's row height), for captioned tiles and for bare ones.
|
||||
spacing: ArrangeSpacing,
|
||||
bare_spacing: ArrangeSpacing,
|
||||
}
|
||||
|
||||
impl GridSizes {
|
||||
fn of(cx: &StyleCx<'_>, card: bool) -> GridSizes {
|
||||
fn of(cx: &StyleCx<'_>, card: bool, rows: RowHeight) -> GridSizes {
|
||||
let spacing = ArrangeSpacing::new(
|
||||
if card { cx.tokens.space.gap.section } else { cx.tokens.space.gap.stack },
|
||||
cx.tokens.space.gap.inline,
|
||||
ListRow::row_height(cx, ThumbSize::None, false),
|
||||
rows.of(cx),
|
||||
);
|
||||
GridSizes {
|
||||
card: cx.tokens.size.thumb.card,
|
||||
@@ -394,7 +394,7 @@ impl<'a, K: Clone + Eq + Hash + Send + Sync + 'static> TileGrid<'a, K> {
|
||||
/// The layout of this pass: `previous` when it was made from the same recipe, else a new arrangement. A card is
|
||||
/// the picture plus what the tile adds around it in every tiling.
|
||||
fn laid_out(&self, previous: Option<GridLayout>, source: &dyn ItemSource<K>, width: f32, item: Option<Vec2>, cx: &StyleCx<'_>) -> GridLayout {
|
||||
let style = GridSizes::of(cx, self.card);
|
||||
let style = GridSizes::of(cx, self.card, self.items.row_height);
|
||||
let spacing = style.spacing(self.caption);
|
||||
let around = style.around.get(self.caption, self.detail_line);
|
||||
// A card never outgrows the grid: in a column narrower than a card the card takes the column.
|
||||
@@ -405,7 +405,7 @@ impl<'a, K: Clone + Eq + Hash + Send + Sync + 'static> TileGrid<'a, K> {
|
||||
side = ((free - (columns - 1.0) * gap) / columns - around.size().x).max(1.0);
|
||||
}
|
||||
let aspect = if self.aspect.is_finite() && self.aspect > 0.0 { self.aspect } else { 1.0 };
|
||||
let tail_height = ListRow::row_height(cx, ThumbSize::None, false);
|
||||
let tail_height = self.items.row_height.of(cx);
|
||||
let recipe = self.items.rows_stamp.map(|stamp| Recipe {
|
||||
stamp,
|
||||
width,
|
||||
@@ -414,6 +414,7 @@ impl<'a, K: Clone + Eq + Hash + Send + Sync + 'static> TileGrid<'a, K> {
|
||||
aspect,
|
||||
justified: self.justified,
|
||||
around,
|
||||
group_header: spacing.group_header,
|
||||
groups: self.groups.iter().map(|group| (group.start, group.count, group.open)).collect(),
|
||||
tail: (self.tail.len(), tail_height),
|
||||
});
|
||||
@@ -480,7 +481,7 @@ impl<'a, K: Clone + Eq + Hash + Send + Sync + 'static> TileGrid<'a, K> {
|
||||
/// The header row of `group`: a heading at the group's depth, with its icon and its detail at the end, and a
|
||||
/// disclosure column the grid owns when the groups open and close.
|
||||
fn header_row(&self, group: &TileGroup<K>, state: RowState) -> ListRow<'static> {
|
||||
let mut row = ListRow::new(group.title.clone()).heading().node(false).depth(group.depth).state(state);
|
||||
let mut row = ListRow::new(group.title.clone()).heading().rows(self.items.row_height).node(false).depth(group.depth).state(state);
|
||||
if self.collapsible {
|
||||
row = row.group(group.open).disclosure_by_host();
|
||||
}
|
||||
@@ -686,7 +687,7 @@ impl<K: Clone + Eq + Hash + Send + Sync + 'static> Component for TileGrid<'_, K>
|
||||
ui.draw().edge_rule(RuleKind::Divider, rect, RectSide::Top);
|
||||
}
|
||||
let state = RowState { emphasized: lead == Some(Slot::Tail(at)), ..RowState::default() };
|
||||
ui.face(section_part(&row.key), ListRow::new(row.label.clone()).node(false).state(state));
|
||||
ui.face(section_part(&row.key), ListRow::new(row.label.clone()).rows(self.items.row_height).node(false).state(state));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -804,7 +805,7 @@ impl<K: Clone + Eq + Hash + Send + Sync + 'static> Collection for TileGrid<'_, K
|
||||
if self.card_columns == 0 {
|
||||
return 0.0;
|
||||
}
|
||||
let style = GridSizes::of(cx, self.card);
|
||||
let style = GridSizes::of(cx, self.card, self.items.row_height);
|
||||
let aspect = if self.aspect.is_finite() && self.aspect > 0.0 { self.aspect } else { 1.0 };
|
||||
let around = style.around.get(self.caption, self.detail_line);
|
||||
let card = style.card(self.picture_side(&style, item, around), aspect, around).x;
|
||||
|
||||
@@ -512,6 +512,8 @@ pub(super) struct Recipe {
|
||||
pub(super) aspect: f32,
|
||||
pub(super) justified: bool,
|
||||
pub(super) around: Around,
|
||||
/// A group header's height.
|
||||
pub(super) group_header: f32,
|
||||
/// Each group's first tile, count and open state.
|
||||
pub(super) groups: Vec<(usize, usize, bool)>,
|
||||
/// How many tail rows follow, and their height.
|
||||
|
||||
Reference in New Issue
Block a user