mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 02:54:25 +00:00
Row press on toggle cells: the collection hands the press it holds on a row to the row as RowState::pressed, a held part paints pressed, and a toggle cell shows a press on itself or, with row_press, on its row; BrushSectionList's enable boxes follow the row
This commit is contained in:
@@ -185,7 +185,7 @@ fn show_tree(ui: &mut Ui, body: &Body<'_>, state: &mut ActionsPanelState, sessio
|
||||
}
|
||||
let shown: &ActionsPanelState = state;
|
||||
let out = widget.show_items(ui, &rows, &mut |key, item| {
|
||||
let mut row = build_row(body, shown, key).cells(item.cells()).state(item.row).depth(rows.depth_at(item.at));
|
||||
let mut row = build_row(body, shown, key).cells(item.cells()).state(item.row.clone()).depth(rows.depth_at(item.at));
|
||||
for cell in cells(body, key) {
|
||||
row = row.toggle(cell);
|
||||
}
|
||||
|
||||
@@ -221,7 +221,8 @@ impl<K: Clone + Eq> ItemSource<Slot<K>> for Rows<'_, K> {
|
||||
/// row and precedes the first switch row, taking room and having no AccessKit node. The link row has the brush
|
||||
/// icon.
|
||||
/// - **Pointer.** A click on a pane row reports `Select` and, if its box is clear, `Enable { on: true }`; the box
|
||||
/// toggles only the flag; the lock toggles only the lock; a click on a switch row toggles it (`Switch`).
|
||||
/// toggles only the flag; the lock toggles only the lock; a click on a switch row toggles it (`Switch`). A press on the row (not its lock)
|
||||
/// shows the box pressed.
|
||||
/// - **Keys.** One Tab stop. The list's own keys (Up, Down, Home, End, Page Up and Page Down) move the lead; onto a
|
||||
/// pane row it also reports `Select`. Space toggles the lead's box or switch, Shift+Space its lock; Enter selects a
|
||||
/// pane row and turns it on.
|
||||
@@ -299,12 +300,12 @@ impl<'a, K: Value + Eq + Hash> BrushSectionList<'a, K> {
|
||||
BrushSectionKind::Switch => {
|
||||
uses.insert(0, CHECK);
|
||||
let state = ToggleState::of(section.enabled == Some(true));
|
||||
row = row.toggle(ToggleCell::check(CHECK, state, switch_name.clone()));
|
||||
row = row.toggle(ToggleCell::check(CHECK, state, switch_name.clone()).row_press());
|
||||
}
|
||||
BrushSectionKind::Pane => {
|
||||
if let Some(on) = section.enabled {
|
||||
uses.insert(0, CHECK);
|
||||
row = row.toggle(ToggleCell::check(CHECK, ToggleState::of(on), enable_name.clone()));
|
||||
row = row.toggle(ToggleCell::check(CHECK, ToggleState::of(on), enable_name.clone()).row_press());
|
||||
}
|
||||
if let Some(locked) = section.locked {
|
||||
uses.push(LOCK);
|
||||
|
||||
@@ -205,7 +205,7 @@ impl<'a, K: Clone + Eq + Hash + Debug + Send + Sync + 'static> ChannelsPanel<'a,
|
||||
})
|
||||
.show_items(ui, &order, &mut |_key, item| {
|
||||
let at = item.at;
|
||||
channel_row(&row_cx, at).cells(item.cells()).state(item.row)
|
||||
channel_row(&row_cx, at).cells(item.cells()).state(item.row.clone())
|
||||
});
|
||||
|
||||
let mut found = Vec::new();
|
||||
|
||||
@@ -75,7 +75,7 @@ pub(super) fn show_body<T: LayerTree>(
|
||||
list = list.reveal(key);
|
||||
}
|
||||
let out = list.show_items(ui, rows, &mut |key, item| {
|
||||
let row = build_row(cx, key).cells(item.cells()).state(item.row);
|
||||
let row = build_row(cx, key).cells(item.cells()).state(item.row.clone());
|
||||
match rows.rows.get(item.at) {
|
||||
Some(shown) if shown.has_children => row.depth(shown.paint_depth).group(shown.open),
|
||||
Some(shown) => row.depth(shown.paint_depth),
|
||||
|
||||
@@ -7,6 +7,8 @@ mod response;
|
||||
|
||||
pub use columns::{ColumnAlign, ColumnKind, ColumnSort, ColumnSpec, ToggleColumn};
|
||||
pub use events::{CollectionEvent, ColumnEvent, ContextMenuRequest, HeaderMenuRequest, ListDrag, OpenChange, Rename, ReorderMove, ToggleEdit};
|
||||
pub use props::{ActivateOn, CollectionProps, DragPayload, ItemKeys, LeadOnOpen, LeadSource, ReorderRule, RowState, SelectMode, SpaceAction};
|
||||
pub use props::{
|
||||
ActivateOn, CollectionProps, DragPayload, ItemKeys, LeadOnOpen, LeadSource, ReorderRule, RowPressed, RowState, SelectMode, SpaceAction,
|
||||
};
|
||||
pub(crate) use response::Gestures;
|
||||
pub use response::{CollectionResponse, ShownRow};
|
||||
|
||||
@@ -489,8 +489,18 @@ impl CollectionProps {
|
||||
}
|
||||
}
|
||||
|
||||
/// Where the collection holds a primary press on a row, within slop.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub enum RowPressed {
|
||||
/// On the row's own area.
|
||||
Row,
|
||||
/// On the cell of this toggle column, which the press flips.
|
||||
Cell(ColumnKey),
|
||||
}
|
||||
|
||||
/// What an item reads of its place in the collection; the item step joins it to the item's flags at step 12.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||
pub struct RowState {
|
||||
/// The row is selected.
|
||||
pub selected: bool,
|
||||
@@ -512,4 +522,6 @@ pub struct RowState {
|
||||
pub open: bool,
|
||||
/// The pointer is over the row.
|
||||
pub hovered: bool,
|
||||
/// The collection holds a press on the row, which the item shows on the part it acts on.
|
||||
pub pressed: Option<RowPressed>,
|
||||
}
|
||||
|
||||
@@ -132,6 +132,13 @@ impl PartBuilder<'_> {
|
||||
self
|
||||
}
|
||||
|
||||
/// The component holds a press on the part that the part does not sense itself (a collection's press on a row's
|
||||
/// toggle cell): the part paints pressed.
|
||||
pub fn held(self, held: bool) -> Self {
|
||||
self.decl.held = held;
|
||||
self
|
||||
}
|
||||
|
||||
/// The part is the arrival of the component's part roving group: Tab and Shift+Tab into the group land here, not
|
||||
/// on the first member. The last part declared `selected` wins.
|
||||
pub fn selected(self) -> Self {
|
||||
|
||||
@@ -68,7 +68,7 @@ impl CxCore<'_> {
|
||||
flags |= Flags::FOCUS_VISIBLE;
|
||||
}
|
||||
}
|
||||
let pressed = result.press.phase.is_press();
|
||||
let pressed = result.pressed();
|
||||
let state = if !self.resolved.enabled || result.inactive {
|
||||
craft_theme::State::Disabled
|
||||
} else if pressed {
|
||||
|
||||
@@ -171,6 +171,8 @@ pub(super) struct ItemsHooks<'s, 'r, C: Collection> {
|
||||
drags: Drags<C::Key>,
|
||||
/// The row a key move brought to the lead in a collection without its own scroll: the page's scroll owner shows it.
|
||||
page_reveal: Option<usize>,
|
||||
/// The row the collection's own press is held on this pass, and where on it.
|
||||
pressed: Option<(usize, crate::contract::collection::RowPressed)>,
|
||||
}
|
||||
|
||||
/// The primary-ness, click count, position in the layout's coordinates and scroll offset of a press on a row.
|
||||
@@ -224,6 +226,7 @@ impl<'s, 'r, C: Collection> ItemsHooks<'s, 'r, C> {
|
||||
header: Header::default(),
|
||||
drags: Drags::default(),
|
||||
page_reveal: None,
|
||||
pressed: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -462,6 +462,7 @@ impl<C: Collection> ShapeHooks<C> for ItemsHooks<'_, '_, C> {
|
||||
current: current.as_ref() == Some(&key),
|
||||
open: self.source.has_children(at) && self.source.open(at),
|
||||
hovered: hover_at.is_some_and(|pos| row.contains(pos)),
|
||||
pressed: self.pressed.as_ref().filter(|(held, _)| *held == at).map(|(_, pressed)| pressed.clone()),
|
||||
..RowState::default()
|
||||
};
|
||||
let mut flags = crate::style::Flags::empty();
|
||||
@@ -495,7 +496,7 @@ impl<C: Collection> ShapeHooks<C> for ItemsHooks<'_, '_, C> {
|
||||
key: &key,
|
||||
at,
|
||||
rect: row,
|
||||
row: state,
|
||||
row: state.clone(),
|
||||
depth: self.source.depth(at),
|
||||
set: position,
|
||||
row_index: at,
|
||||
@@ -539,6 +540,7 @@ impl<C: Collection> ShapeHooks<C> for ItemsHooks<'_, '_, C> {
|
||||
columns: column_keys,
|
||||
toggles: toggle_keys,
|
||||
toggle_keys: self.header.toggle_keys(),
|
||||
pressed: state.pressed.clone(),
|
||||
}));
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -112,6 +112,7 @@ impl<'s, 'r, C: Collection> ItemsHooks<'s, 'r, C> {
|
||||
columns: columns.clone(),
|
||||
toggles: toggles.clone(),
|
||||
toggle_keys: Vec::new(),
|
||||
pressed: None,
|
||||
};
|
||||
let installed = Env::install_for(
|
||||
ui,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use super::drag::SlowClick;
|
||||
use super::{ItemsHooks, Placement, RowPress, SECTION};
|
||||
use crate::contract::collection::{ActivateOn, CollectionEvent, CollectionProps, ContextMenuRequest, LeadSource, SelectMode};
|
||||
use crate::contract::collection::{ActivateOn, CollectionEvent, CollectionProps, ContextMenuRequest, LeadSource, RowPressed, SelectMode};
|
||||
use crate::contract::{Collection, Cx, ItemOpener};
|
||||
use crate::runtime::egui::response;
|
||||
use crate::runtime::env::ArenaId;
|
||||
@@ -53,6 +53,20 @@ impl<C: Collection> ItemsHooks<'_, '_, C> {
|
||||
if layout.mirrors() && rtl { flow.to_physical(Rect::from_min_size(at, Vec2::ZERO)).min } else { at }
|
||||
};
|
||||
let mods_now = crate::runtime::pointer::frame(&ctx).mods;
|
||||
self.pressed = match cx.core.press.phase {
|
||||
PressPhase::Down { start, .. } | PressPhase::Held { start, .. }
|
||||
if start.button == craft_behavior::PointerButton::Primary && local(start.origin).y >= 0.0 =>
|
||||
{
|
||||
let origin = local(start.origin);
|
||||
layout.hit(origin, offset).filter(|&at| self.source.enabled(at) && layout.shown(at)).and_then(|at| {
|
||||
match self.toggle_cell(props, layout, at, offset, origin) {
|
||||
Some((column, _)) => self.toggle_open(at, &column).then_some((at, RowPressed::Cell(column))),
|
||||
None => Some((at, RowPressed::Row)),
|
||||
}
|
||||
})
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
if let PressPhase::Down { start, .. } = cx.core.press.phase
|
||||
&& local(start.origin).y >= 0.0
|
||||
{
|
||||
|
||||
@@ -50,7 +50,7 @@ pub use body::pad_of;
|
||||
pub use collection::{
|
||||
ActivateOn, CollectionEvent, CollectionProps, CollectionResponse, ColumnAlign, ColumnEvent, ColumnKind, ColumnSort, ColumnSpec,
|
||||
ContextMenuRequest, DragPayload, HeaderMenuRequest, ItemKeys, LeadOnOpen, LeadSource, ListDrag, OpenChange, Rename, ReorderMove, ReorderRule,
|
||||
RowState, SelectMode, ShownRow, SpaceAction, ToggleColumn, ToggleEdit,
|
||||
RowPressed, RowState, SelectMode, ShownRow, SpaceAction, ToggleColumn, ToggleEdit,
|
||||
};
|
||||
#[doc(hidden)]
|
||||
pub use container::InBar;
|
||||
|
||||
@@ -739,7 +739,8 @@ pub(crate) fn member_show<C: Show>(
|
||||
let resolved = steps::resolved(id, &step1, &common);
|
||||
let enabled = node.enabled && step1.enabled;
|
||||
let hovered = sensed.response.hovered();
|
||||
let result = crate::primitives::PartResult { rect: row, press: sensed.press, hovered, hover_pos: None, flags: node.flags, inactive: false };
|
||||
let result =
|
||||
crate::primitives::PartResult { rect: row, press: sensed.press, hovered, hover_pos: None, flags: node.flags, inactive: false, held: false };
|
||||
let part_state = steps::part_state(&result, enabled, None);
|
||||
let mut flags = part_state.flags | item.flags();
|
||||
if (shown.as_deref().map(|value| value as &dyn std::any::Any)).and_then(|value| value.downcast_ref::<bool>()) == Some(&true) {
|
||||
|
||||
@@ -29,7 +29,7 @@ pub(crate) fn part_state(result: &crate::primitives::PartResult, enabled: bool,
|
||||
flags |= Flags::FOCUS_VISIBLE;
|
||||
}
|
||||
}
|
||||
let pressed = result.press.phase.is_press();
|
||||
let pressed = result.pressed();
|
||||
let state = if !enabled || result.inactive {
|
||||
State::Disabled
|
||||
} else if pressed {
|
||||
|
||||
@@ -41,12 +41,26 @@ pub struct PartResult {
|
||||
/// The component declared the part inactive: it paints with the Disabled state and `PaintUi::draw_part` draws data
|
||||
/// colours with the disabled fill, and it keeps sensing.
|
||||
pub inactive: bool,
|
||||
/// The component holds a press on the part that the part does not sense itself: it paints pressed.
|
||||
pub held: bool,
|
||||
}
|
||||
|
||||
impl PartResult {
|
||||
/// What a read returns for a part with no press history: face mode, or a part first registered this pass.
|
||||
pub const IDLE: PartResult =
|
||||
PartResult { rect: Rect::NOTHING, press: PressState::IDLE, hovered: false, hover_pos: None, flags: Flags::empty(), inactive: false };
|
||||
pub const IDLE: PartResult = PartResult {
|
||||
rect: Rect::NOTHING,
|
||||
press: PressState::IDLE,
|
||||
hovered: false,
|
||||
hover_pos: None,
|
||||
flags: Flags::empty(),
|
||||
inactive: false,
|
||||
held: false,
|
||||
};
|
||||
|
||||
/// The part paints pressed: its own press, or one its component holds on it.
|
||||
pub fn pressed(&self) -> bool {
|
||||
self.press.phase.is_press() || self.held
|
||||
}
|
||||
}
|
||||
|
||||
/// A text part's result this pass.
|
||||
@@ -105,6 +119,8 @@ pub(crate) struct PartDecl {
|
||||
pub flags: Flags,
|
||||
/// The part paints with the Disabled state and its data colours take the theme's disabled fill. It keeps sensing.
|
||||
pub inactive: bool,
|
||||
/// The component holds a press on the part (`PartBuilder::held`).
|
||||
pub held: bool,
|
||||
}
|
||||
|
||||
impl PartDecl {
|
||||
@@ -120,6 +136,7 @@ impl PartDecl {
|
||||
over: false,
|
||||
flags: Flags::default(),
|
||||
inactive: false,
|
||||
held: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -831,6 +848,7 @@ fn part_results_in(
|
||||
hover_pos: read.hover_pos,
|
||||
flags: decl.flags,
|
||||
inactive: decl.inactive,
|
||||
held: decl.held,
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
@@ -237,6 +237,9 @@ pub struct ItemFacts {
|
||||
/// The keys of the toggle columns that have one (`ToggleColumn::key`), which their cells show in the tooltip.
|
||||
#[doc(hidden)]
|
||||
pub toggle_keys: Vec<(craft_behavior::ColumnKey, craft_keymap::Chord)>,
|
||||
/// Where the collection holds a press on the row (`RowState::pressed`).
|
||||
#[doc(hidden)]
|
||||
pub pressed: Option<crate::contract::RowPressed>,
|
||||
}
|
||||
|
||||
impl Scoped {
|
||||
|
||||
@@ -534,6 +534,7 @@ where
|
||||
columns: Vec::new(),
|
||||
toggles: Vec::new(),
|
||||
toggle_keys: Vec::new(),
|
||||
pressed: None,
|
||||
};
|
||||
let installed = crate::runtime::env::Env::install_for(
|
||||
ui,
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
use super::toggle::ToggleCell;
|
||||
use super::words::ListWords;
|
||||
use crate::contract::{ColumnSpec, Common, OpenChange, RowState, Show};
|
||||
use crate::contract::{ColumnSpec, Common, OpenChange, RowPressed, RowState, Show};
|
||||
use crate::primitives::{ContentPainterCx, HAlign, IconSpec};
|
||||
use crate::runtime::env::Label;
|
||||
use craft_behavior::ColumnKey;
|
||||
@@ -148,6 +148,8 @@ pub struct ListRow<'a> {
|
||||
pub(super) rule: bool,
|
||||
/// The rename editor replaces the label; `state` sets it from the collection's row state.
|
||||
pub(super) renaming: bool,
|
||||
/// Where the collection holds a press on the row, from its row state: the toggle cell it acts on shows it.
|
||||
pub(super) pressed: Option<RowPressed>,
|
||||
/// The thumbnails that drag instead of the row, each with what starts its drag session.
|
||||
pub(super) drags: Vec<(ThumbTarget, ThumbPayload)>,
|
||||
/// The icon or thumbnails come before the disclosure column instead of after it.
|
||||
@@ -244,6 +246,7 @@ impl<'a> ListRow<'a> {
|
||||
clipped: false,
|
||||
rule: false,
|
||||
renaming: false,
|
||||
pressed: None,
|
||||
drags: Vec::new(),
|
||||
leading_first: false,
|
||||
detail: None,
|
||||
@@ -295,10 +298,12 @@ impl<'a> ListRow<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
/// The row state the collection gives the item: the rename editor, the stripe and the app's mark.
|
||||
/// The row state the collection gives the item: the rename editor, the stripe, the app's mark and the press the
|
||||
/// collection holds on the row.
|
||||
#[must_use]
|
||||
pub fn state(mut self, row: RowState) -> Self {
|
||||
self.renaming = row.renaming;
|
||||
self.pressed = row.pressed;
|
||||
self.striped = row.striped;
|
||||
self.highlight |= row.emphasized;
|
||||
self
|
||||
|
||||
@@ -155,11 +155,15 @@ impl ListRow<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Takes the toggle columns and their keys from the facts the collection recorded for this row.
|
||||
/// Takes the toggle columns, their keys and the press the collection holds on the row from the facts it recorded
|
||||
/// for this row.
|
||||
pub(super) fn adopt_toggle_columns(&mut self, env: &EnvView<'_>, id: egui::Id) {
|
||||
if let Some(facts) = env.facts_of(id) {
|
||||
self.toggle_columns.clone_from(&facts.toggles);
|
||||
self.toggle_keys.clone_from(&facts.toggle_keys);
|
||||
if self.pressed.is_none() {
|
||||
self.pressed.clone_from(&facts.pressed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ use super::thumb::{RowThumb, target_at};
|
||||
use super::trailing::{TrailingFace, TrailingItem};
|
||||
use super::{ListRow, RowInk};
|
||||
use crate::contract::{
|
||||
Access, Bind, Component, Cx, DragPreview, MeasureCx, Name, OpenChange, PaintUi, PartsCx, Pointer as _, Props as _, Role, Styled as _,
|
||||
Access, Bind, Component, Cx, DragPreview, MeasureCx, Name, OpenChange, PaintUi, PartsCx, Pointer as _, Props as _, Role, RowPressed, Styled as _,
|
||||
WordSetCx as _,
|
||||
};
|
||||
use crate::controls::disclosure::Disclosure;
|
||||
@@ -188,7 +188,12 @@ impl Component for ListRow<'_> {
|
||||
}
|
||||
(None, None) => None,
|
||||
};
|
||||
let part = cx.part(TOGGLE.at(*at as u64), shape).flags(flags);
|
||||
let held = match &self.pressed {
|
||||
Some(RowPressed::Cell(column)) => *column == toggle.column,
|
||||
Some(RowPressed::Row) => toggle.row_press,
|
||||
_ => false,
|
||||
};
|
||||
let part = cx.part(TOGGLE.at(*at as u64), shape).flags(flags).held(held);
|
||||
let _ = match tip {
|
||||
Some(tip) => part.tooltip(tip),
|
||||
None => part,
|
||||
|
||||
@@ -83,13 +83,25 @@ pub struct ToggleCell {
|
||||
/// A screen reader announces a check box instead of a toggle button: for a setting the row carries rather than
|
||||
/// an action on the row.
|
||||
pub check_box: bool,
|
||||
/// A press on the row's own area shows on the cell: the row's click acts on what the cell shows.
|
||||
pub row_press: bool,
|
||||
}
|
||||
|
||||
impl ToggleCell {
|
||||
/// A cell of `column` showing `state` with `face`, named `name`: a whole pattern with `{row}` for the row's label
|
||||
/// ("Keep {row}").
|
||||
pub fn new(column: ColumnKey, face: ToggleFace, state: ToggleState, name: impl Into<Label>) -> Self {
|
||||
ToggleCell { column, face, state, name: CellName::Given(name.into()), tooltip: None, fill: None, always_visible: false, check_box: false }
|
||||
ToggleCell {
|
||||
column,
|
||||
face,
|
||||
state,
|
||||
name: CellName::Given(name.into()),
|
||||
tooltip: None,
|
||||
fill: None,
|
||||
always_visible: false,
|
||||
check_box: false,
|
||||
row_press: false,
|
||||
}
|
||||
}
|
||||
|
||||
/// An eye cell, named "Visibility {row}" unless [`name`](Self::name) says otherwise.
|
||||
@@ -149,4 +161,11 @@ impl ToggleCell {
|
||||
self.always_visible = true;
|
||||
self
|
||||
}
|
||||
|
||||
/// A press on the row's own area shows on the cell, for a row whose click turns on what the cell shows.
|
||||
#[must_use]
|
||||
pub fn row_press(mut self) -> Self {
|
||||
self.row_press = true;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,3 +60,54 @@ fn pressing_a_check_box_changes_its_fill_whether_off_or_on() {
|
||||
assert_ne!(fills(&pressed, rect), fills(&rest, rect), "a press shows on the box (on: {on})");
|
||||
}
|
||||
}
|
||||
|
||||
/// A press held on a table row shows on the check cell that follows the row's press and on a pressed cell, never on a
|
||||
/// lock cell the press is not on.
|
||||
#[trial]
|
||||
fn a_row_press_shows_on_the_check_cell_that_follows_it_and_a_cell_press_on_its_own_cell() {
|
||||
use craft_behavior::{ColumnKey, ColumnWidth, keyed};
|
||||
use craft_ui::contract::{ColumnKind, ColumnSpec, ShowCollection as _, ToggleColumn};
|
||||
use craft_ui::list::{ListRow, ToggleCell, ToggleState};
|
||||
use craft_ui::table::Table;
|
||||
const CHECK: ColumnKey = ColumnKey::new("check");
|
||||
const NAME: ColumnKey = ColumnKey::new("name");
|
||||
const LOCK: ColumnKey = ColumnKey::new("lock");
|
||||
let cells = Cell::new([Rect::NOTHING; 3]);
|
||||
let mut show = |ui: &mut egui::Ui| {
|
||||
let region = Rect::from_min_size(pos2(0.0, 0.0), vec2(240.0, 80.0));
|
||||
in_region(ui, region, |ui| {
|
||||
let columns = vec![
|
||||
ColumnSpec::new(CHECK, "", ColumnWidth::Controls(1.0)).kind(ColumnKind::Toggle(ToggleColumn::default())),
|
||||
ColumnSpec::new(NAME, "", ColumnWidth::fill(1.0)),
|
||||
ColumnSpec::new(LOCK, "", ColumnWidth::Controls(1.0)).kind(ColumnKind::Toggle(ToggleColumn::default())),
|
||||
];
|
||||
let order = [0usize];
|
||||
let source = keyed(&order, |&row| row);
|
||||
let shown = Table::new("Sections", columns).header(false).show_items(ui, &source, &mut |_, icx| {
|
||||
let mut found = [Rect::NOTHING; 3];
|
||||
for (at, key) in [CHECK, NAME, LOCK].iter().enumerate() {
|
||||
found[at] = icx.cell(key).unwrap_or(Rect::NOTHING);
|
||||
}
|
||||
cells.set(found);
|
||||
ListRow::new("Shape Dynamics")
|
||||
.cells(icx.cells())
|
||||
.toggle(ToggleCell::check(CHECK, ToggleState::Off, "Enable {row}").row_press())
|
||||
.toggle(ToggleCell::check(LOCK, ToggleState::Off, "Lock {row}"))
|
||||
});
|
||||
let _ = shown.response;
|
||||
});
|
||||
};
|
||||
let mut held = |at: fn([Rect; 3]) -> egui::Pos2| {
|
||||
let mut frames = Frames::new();
|
||||
let rest = frames.frame_shapes(&mut show);
|
||||
let [check, _, lock] = cells.get();
|
||||
let point = at(cells.get());
|
||||
frames.frame(vec![pointer::moved(point), pointer::press(point)], &mut show);
|
||||
frames.frame(vec![], &mut show);
|
||||
let pressed = frames.frame_shapes(&mut show);
|
||||
(fills(&rest, check) != fills(&pressed, check), fills(&rest, lock) != fills(&pressed, lock))
|
||||
};
|
||||
assert_eq!(held(|[_, name, _]| name.center()), (true, false), "a press on the row shows on the check cell, not the lock");
|
||||
assert_eq!(held(|[_, _, lock]| lock.center()), (false, true), "a press on the lock shows on the lock only");
|
||||
assert_eq!(held(|[check, _, _]| check.center()), (true, false), "a press on the check cell shows on it");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user