mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 02:54:25 +00:00
Toggle columns: one width from the toggle-column mechanism, a control and the inline gap (ColumnWidth::Toggle, ColumnSpec::toggle)
This commit is contained in:
@@ -5,8 +5,8 @@ use craft_behavior::{ColumnWidth, EditEvent, IconId, Mixed, Selection};
|
||||
use craft_theme::variant::Tone;
|
||||
use craft_ui::buttons::Button;
|
||||
use craft_ui::contract::{
|
||||
Bind, CollectionEvent, ColumnKey, ColumnKind, ColumnSpec, ListDrag, OpenChange, Outcome as _, Pad, Props as _, ReorderMove, ReorderRule, Scroll,
|
||||
SelectMode, Show as _, ShowCollection as _, ShowContainer as _, Sizing, SpaceAction, ToggleColumn, ToggleEdit, request_rename,
|
||||
Bind, CollectionEvent, ColumnKey, ColumnSpec, ListDrag, OpenChange, Outcome as _, Pad, Props as _, ReorderMove, ReorderRule, Scroll, SelectMode,
|
||||
Show as _, ShowCollection as _, ShowContainer as _, Sizing, SpaceAction, ToggleColumn, ToggleEdit, request_rename,
|
||||
};
|
||||
use craft_ui::display::Text;
|
||||
use craft_ui::layout_components::{Row, Stack};
|
||||
@@ -154,10 +154,8 @@ fn show_tree(ui: &mut Ui, body: &Body<'_>, state: &mut ActionsPanelState, sessio
|
||||
request_rename(ui.ctx(), list_id, &ActionSelection::Action(index));
|
||||
}
|
||||
let columns = vec![
|
||||
ColumnSpec::new(INCLUDE_COLUMN, Label::Empty, ColumnWidth::Controls(1.0)).kind(ColumnKind::Toggle(ToggleColumn::sweepable())),
|
||||
ColumnSpec::new(DIALOG_COLUMN, Label::Empty, ColumnWidth::Controls(1.0))
|
||||
.kind(ColumnKind::Toggle(ToggleColumn::sweepable()))
|
||||
.icon(IconId::new("note")),
|
||||
ColumnSpec::toggle(INCLUDE_COLUMN, Label::Empty, ToggleColumn::sweepable()),
|
||||
ColumnSpec::toggle(DIALOG_COLUMN, Label::Empty, ToggleColumn::sweepable()).icon(IconId::new("note")),
|
||||
ColumnSpec::new(NAME_COLUMN, Label::Empty, ColumnWidth::fill(1.0)),
|
||||
];
|
||||
let mut widget = List::new(words.name.clone())
|
||||
|
||||
@@ -57,6 +57,9 @@ pub enum ColumnWidth {
|
||||
/// This many control heights; the owner that knows the control height resolves it with
|
||||
/// [`ColumnWidth::in_unit`] before the widths are computed.
|
||||
Controls(f32),
|
||||
/// As wide as a toggle cell: a control and the inline gap. The owner that knows the control size resolves it
|
||||
/// before the widths are computed.
|
||||
Toggle,
|
||||
/// A share of the remaining width, by weight.
|
||||
#[non_exhaustive]
|
||||
Fill {
|
||||
|
||||
@@ -5,8 +5,8 @@ use crate::flow::Flow;
|
||||
use emath::{Pos2, Rect, Vec2};
|
||||
|
||||
/// The width of each column in `room`: `Fixed` is the app's width, `Content` the widest child of last pass
|
||||
/// (`content[i]`, zero when unknown), and `Fill` columns share what is left by weight. `Controls` widths take
|
||||
/// no room until `ColumnWidth::in_unit` resolves them.
|
||||
/// (`content[i]`, zero when unknown), and `Fill` columns share what is left by weight. `Controls` and `Toggle`
|
||||
/// widths take no room until their owner resolves them.
|
||||
pub fn resolve_columns(columns: &[ColumnWidth], content: &[f32], room: f32, gap: f32) -> Vec<f32> {
|
||||
let known = |i: usize| content.get(i).copied().unwrap_or(0.0);
|
||||
let mut widths: Vec<f32> = columns
|
||||
@@ -14,7 +14,7 @@ pub fn resolve_columns(columns: &[ColumnWidth], content: &[f32], room: f32, gap:
|
||||
.enumerate()
|
||||
.map(|(i, column)| match column {
|
||||
ColumnWidth::Fixed(width) => *width,
|
||||
ColumnWidth::Fill { .. } | ColumnWidth::Controls(_) => 0.0,
|
||||
ColumnWidth::Fill { .. } | ColumnWidth::Controls(_) | ColumnWidth::Toggle => 0.0,
|
||||
_ => known(i),
|
||||
})
|
||||
.collect();
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
use craft_behavior::{ColumnKey, ColumnWidth, DisplayOrder, IconId, ItemSource, Mixed, Selection, SelectionChange, SizeHint, Value};
|
||||
use craft_keymap::{Chord, Key, Mods};
|
||||
use craft_ui::contract::{
|
||||
ActivateOn, Bind, CollectionEvent, ColumnKind, ColumnSpec, Outcome, Props as _, Remember as _, SelectMode, ShowCollection as _,
|
||||
ShowContainer as _, Sizing, SpaceAction, SweepApply, SweepStep, ToggleColumn, ToggleEdit,
|
||||
ActivateOn, Bind, CollectionEvent, ColumnSpec, Outcome, Props as _, Remember as _, SelectMode, ShowCollection as _, ShowContainer as _, Sizing,
|
||||
SpaceAction, SweepApply, SweepStep, ToggleColumn, ToggleEdit,
|
||||
};
|
||||
use craft_ui::layout_components::Stack;
|
||||
use craft_ui::list::{ListRow, ToggleCell, ToggleState};
|
||||
@@ -273,13 +273,10 @@ impl<'a, K: Value + Eq + Hash> BrushSectionList<'a, K> {
|
||||
let lock_name = Label::from(words.lock.fill(&[("name", "{row}")]));
|
||||
let switch_name = Label::from("{row}".to_owned());
|
||||
let columns = || {
|
||||
let toggle = ColumnKind::Toggle(ToggleColumn::default());
|
||||
vec![
|
||||
ColumnSpec::new(CHECK, Label::Empty, ColumnWidth::Controls(1.0)).kind(toggle),
|
||||
ColumnSpec::toggle(CHECK, Label::Empty, ToggleColumn::default()),
|
||||
ColumnSpec::new(NAME, Label::Empty, ColumnWidth::Content),
|
||||
ColumnSpec::new(LOCK, Label::Empty, ColumnWidth::Controls(1.0))
|
||||
.kind(ColumnKind::Toggle(ToggleColumn::default().key(Chord::new(Mods::SHIFT, Key::Space))))
|
||||
.icon(IconId::new("lock")),
|
||||
ColumnSpec::toggle(LOCK, Label::Empty, ToggleColumn::default().key(Chord::new(Mods::SHIFT, Key::Space))).icon(IconId::new("lock")),
|
||||
]
|
||||
};
|
||||
let shown_stack = Stack::new().show(ui, |ui, cx| {
|
||||
|
||||
@@ -8,8 +8,8 @@ use std::hash::Hash;
|
||||
use craft_behavior::geometry::selection_op::SelectionOperation;
|
||||
use craft_behavior::{ColumnKey, ColumnWidth, DisplayOrder, EditEvent, IconId, ItemSource, Selection, SelectionChange};
|
||||
use craft_ui::contract::{
|
||||
Bind, CollectionEvent, ColumnKind, ColumnSpec, ListDrag, Props as _, ReorderRule, ShowCollection as _, ShowContainer as _, SweepApply,
|
||||
ToggleColumn, request_rename,
|
||||
Bind, CollectionEvent, ColumnSpec, ListDrag, Props as _, ReorderRule, ShowCollection as _, ShowContainer as _, SweepApply, ToggleColumn,
|
||||
request_rename,
|
||||
};
|
||||
use craft_ui::layout_components::Stack;
|
||||
use craft_ui::list::{List, RowEvent, ThumbSize};
|
||||
@@ -176,9 +176,7 @@ impl<'a, K: Clone + Eq + Hash + Debug + Send + Sync + 'static> ChannelsPanel<'a,
|
||||
let payload_kinds = kinds.clone();
|
||||
let kind_of = |key: &K| kinds.iter().find(|(k, _)| k == key).map(|(_, kind)| *kind);
|
||||
let columns = vec![
|
||||
ColumnSpec::new(EYE, Label::Empty, ColumnWidth::Controls(1.0))
|
||||
.kind(ColumnKind::Toggle(ToggleColumn::sweepable()))
|
||||
.icon(IconId::new("eye")),
|
||||
ColumnSpec::toggle(EYE, Label::Empty, ToggleColumn::sweepable()).icon(IconId::new("eye")),
|
||||
ColumnSpec::new(NAME, Label::Empty, ColumnWidth::fill(1.0)),
|
||||
];
|
||||
let out = List::new(words.list.clone())
|
||||
|
||||
@@ -4,8 +4,8 @@ use std::borrow::Cow;
|
||||
|
||||
use craft_behavior::{ColumnKey, ColumnWidth, DisplayOrder, EditEvent, IconId, ItemSource, Selection};
|
||||
use craft_ui::contract::{
|
||||
CollectionEvent, ColumnKind, ColumnSpec, NoValue, Outcome, Remember as _, ReorderMove, ReorderRule, SelectMode, ShowCollection as _,
|
||||
ShowContainer as _, SweepApply, SweepStep, ToggleColumn,
|
||||
CollectionEvent, ColumnSpec, NoValue, Outcome, Remember as _, ReorderMove, ReorderRule, SelectMode, ShowCollection as _, ShowContainer as _,
|
||||
SweepApply, SweepStep, ToggleColumn,
|
||||
};
|
||||
use craft_ui::layout_components::Stack;
|
||||
use craft_ui::list::{List, ListRow, RowInk, ToggleCell};
|
||||
@@ -108,7 +108,7 @@ impl<'a> EffectStack<'a> {
|
||||
let layers = Layers { effects, index };
|
||||
let mut selection = Selection::single(current);
|
||||
let columns = vec![
|
||||
ColumnSpec::new(EYE, words.visibility_of.clone(), ColumnWidth::Controls(1.0)).kind(ColumnKind::Toggle(ToggleColumn::sweepable())),
|
||||
ColumnSpec::toggle(EYE, words.visibility_of.clone(), ToggleColumn::sweepable()),
|
||||
ColumnSpec::new(NAME, words.filter.clone(), ColumnWidth::fill(1.0)),
|
||||
];
|
||||
let mut change = None;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//! The effect list on the dialog's left.
|
||||
|
||||
use craft_behavior::{ColumnKey, ColumnWidth, DisplayOrder, IconId, ItemSource, Selection, SelectionChange};
|
||||
use craft_behavior::{ColumnKey, DisplayOrder, IconId, ItemSource, Selection, SelectionChange};
|
||||
use craft_ui::contract::{
|
||||
ActivateOn, Bind, BodyCx, CollectionEvent, ColumnKind, ColumnSpec, CommandSet, Commands as _, Props as _, Remember as _, SelectMode,
|
||||
ShowCollection as _, Sizing, SpaceAction, SweepApply, SweepStep, ToggleColumn,
|
||||
ActivateOn, Bind, BodyCx, CollectionEvent, ColumnSpec, CommandSet, Commands as _, Props as _, Remember as _, SelectMode, ShowCollection as _,
|
||||
Sizing, SpaceAction, SweepApply, SweepStep, ToggleColumn,
|
||||
};
|
||||
use craft_ui::list::{List, ListRow, RowEvent, RowInk, ToggleCell, ToggleState, TrailingFace, TrailingPart};
|
||||
use craft_ui::primitives::IconSpec;
|
||||
@@ -143,7 +143,7 @@ pub(super) fn effect_list(
|
||||
let shown = rows.iter().find(|row| row.page() == Some(draft.page)).cloned();
|
||||
let selection = shown.clone().map_or_else(Selection::default, Selection::single);
|
||||
let source = Rows { rows: &rows, draft };
|
||||
let columns = vec![ColumnSpec::new(CHECK, Label::Empty, ColumnWidth::Controls(1.0)).kind(ColumnKind::Toggle(ToggleColumn::default()))];
|
||||
let columns = vec![ColumnSpec::toggle(CHECK, Label::Empty, ToggleColumn::default())];
|
||||
|
||||
let out = List::<EffectRow>::new(words.effects.clone())
|
||||
.select(SelectMode::Single)
|
||||
|
||||
@@ -12,8 +12,7 @@ use rows::{RevealPlan, list_selection};
|
||||
use craft_behavior::{ColumnWidth, IconId};
|
||||
use craft_keymap::Mods;
|
||||
use craft_ui::contract::{
|
||||
Bind, CollectionEvent, ColumnKind, ColumnSpec, DropAt, DropKind, DropPlace, ListDrag, PendingDrop, Props as _, ReorderRule, ShowCollection as _,
|
||||
ToggleColumn,
|
||||
Bind, CollectionEvent, ColumnSpec, DropAt, DropKind, DropPlace, ListDrag, PendingDrop, Props as _, ReorderRule, ShowCollection as _, ToggleColumn,
|
||||
};
|
||||
use craft_ui::list::List;
|
||||
use craft_ui::runtime::env::Label;
|
||||
@@ -58,13 +57,9 @@ pub(super) fn show_body<T: LayerTree>(
|
||||
});
|
||||
|
||||
let eye = cx.visibility_key.map_or(ToggleColumn::sweepable(), |key| ToggleColumn::sweepable().key(key));
|
||||
let mut columns = vec![ColumnSpec::new(EYE, Label::Empty, ColumnWidth::Controls(1.0)).kind(ColumnKind::Toggle(eye)).icon(IconId::new("eye"))];
|
||||
let mut columns = vec![ColumnSpec::toggle(EYE, Label::Empty, eye).icon(IconId::new("eye"))];
|
||||
if cx.lock_column {
|
||||
columns.push(
|
||||
ColumnSpec::new(LOCK, Label::Empty, ColumnWidth::Controls(1.0))
|
||||
.kind(ColumnKind::Toggle(ToggleColumn::sweepable()))
|
||||
.icon(IconId::new("lock")),
|
||||
);
|
||||
columns.push(ColumnSpec::toggle(LOCK, Label::Empty, ToggleColumn::sweepable()).icon(IconId::new("lock")));
|
||||
}
|
||||
columns.push(ColumnSpec::new(NAME, Label::Empty, ColumnWidth::fill(1.0)));
|
||||
let parent_of = |id: &T::Id| tree.parent(id);
|
||||
|
||||
@@ -25,8 +25,8 @@ mod stories;
|
||||
|
||||
use craft_behavior::{ColumnKey, ColumnWidth, EditEvent, IconId, Mixed, Selection, SelectionChange, keyed};
|
||||
use craft_ui::contract::{
|
||||
Bind, CollectionEvent, ColumnKind, ColumnSpec, ContextMenuRequest, ListDrag, NoValue, Outcome, ReorderMove, ReorderRule, SelectMode,
|
||||
ShowCollection as _, ShowContainer as _, SweepApply, SweepStep, ToggleColumn, ToggleEdit, request_rename,
|
||||
Bind, CollectionEvent, ColumnSpec, ContextMenuRequest, ListDrag, NoValue, Outcome, ReorderMove, ReorderRule, SelectMode, ShowCollection as _,
|
||||
ShowContainer as _, SweepApply, SweepStep, ToggleColumn, ToggleEdit, request_rename,
|
||||
};
|
||||
use craft_ui::list::{ListRow, RowEvent, ToggleCell, TrailingFace, TrailingPart};
|
||||
use craft_ui::primitives::IconSpec;
|
||||
@@ -230,8 +230,8 @@ impl<'a> PageList<'a> {
|
||||
// With several rows picked the field opens empty, so the typed name goes to all of them.
|
||||
let several = (picked.items.len() > 1).then(|| picked.items.clone());
|
||||
let columns = vec![
|
||||
ColumnSpec::new(VISIBLE, words.visible.clone(), ColumnWidth::Controls(1.0)).kind(ColumnKind::Toggle(ToggleColumn::sweepable())),
|
||||
ColumnSpec::new(LOCKED, words.lock.clone(), ColumnWidth::Controls(1.0)).kind(ColumnKind::Toggle(ToggleColumn::sweepable())),
|
||||
ColumnSpec::toggle(VISIBLE, words.visible.clone(), ToggleColumn::sweepable()),
|
||||
ColumnSpec::toggle(LOCKED, words.lock.clone(), ToggleColumn::sweepable()),
|
||||
ColumnSpec::new(NAME, words.name.clone(), ColumnWidth::fill(1.0)),
|
||||
];
|
||||
let events = RefCell::new(Vec::new());
|
||||
|
||||
@@ -8,8 +8,8 @@ use std::sync::Arc;
|
||||
use craft_behavior::{ColumnKey, ColumnWidth, DisplayOrder, EditEvent, IconId, ItemSource, Mixed};
|
||||
use craft_ui::buttons::Button;
|
||||
use craft_ui::contract::{
|
||||
CollectionEvent, ColumnKind, ColumnSpec, DropAt, DropKind, DropPlace, ListDrag, Pattern, Props as _, Remember, ReorderMove, ReorderRule,
|
||||
RowAlign, Show as _, ShowCollection as _, ShowContainer as _, SweepApply, SweepStep, ToggleColumn, Trigger, clicked,
|
||||
CollectionEvent, ColumnSpec, DropAt, DropKind, DropPlace, ListDrag, Pattern, Props as _, Remember, ReorderMove, ReorderRule, RowAlign, Show as _,
|
||||
ShowCollection as _, ShowContainer as _, SweepApply, SweepStep, ToggleColumn, Trigger, clicked,
|
||||
};
|
||||
use craft_ui::display::{Divider, Shade, Text};
|
||||
use craft_ui::layout_components::{Grid, Row, Stack};
|
||||
@@ -493,7 +493,7 @@ impl Model<'_> {
|
||||
/// The checklist of source fields.
|
||||
fn checklist(&self, ui: &mut Ui, cx: &mut impl Remember, edits: &Edits) {
|
||||
let source = Checklist { fields: self.fields, ticked: self.fields.iter().map(|field| self.ticked(&field.name)).collect() };
|
||||
let columns = vec![ColumnSpec::new(CHECK, Label::Empty, ColumnWidth::Controls(1.0)).kind(ColumnKind::Toggle(ToggleColumn::sweepable()))];
|
||||
let columns = vec![ColumnSpec::toggle(CHECK, Label::Empty, ToggleColumn::sweepable())];
|
||||
let separator = self.words.samples_separator.as_str();
|
||||
let out =
|
||||
List::<String>::new(self.words.choose.clone()).max_rows(8).columns(columns).header(false).show_items(ui, &source, &mut |key, icx| {
|
||||
|
||||
@@ -116,6 +116,11 @@ impl ColumnSpec {
|
||||
}
|
||||
}
|
||||
|
||||
/// A toggle column as wide as a toggle cell, with a header; the other settings off.
|
||||
pub fn toggle(key: ColumnKey, header: impl Into<Label>, toggle: ToggleColumn) -> Self {
|
||||
ColumnSpec::new(key, header, ColumnWidth::Toggle).kind(ColumnKind::Toggle(toggle))
|
||||
}
|
||||
|
||||
/// Activating the header sorts.
|
||||
#[must_use]
|
||||
pub fn sortable(mut self) -> Self {
|
||||
|
||||
@@ -160,6 +160,8 @@ pub(super) struct Header {
|
||||
on: bool,
|
||||
/// The control height, the unit of `ColumnWidth::Controls`.
|
||||
unit: f32,
|
||||
/// The width of a toggle column (`ColumnWidth::Toggle`): a control and the inline gap.
|
||||
toggle: f32,
|
||||
cells: Vec<Cell>,
|
||||
events: Vec<ColumnEvent>,
|
||||
/// A header menu asked for in this pass.
|
||||
@@ -199,6 +201,7 @@ impl Header {
|
||||
pub(super) fn measure(&mut self, scx: &StyleCx<'_>) {
|
||||
let control = scx.control();
|
||||
self.unit = control.height;
|
||||
self.toggle = control.height + control.gap;
|
||||
// The row shows only when the props ask for it and some column has a header to show (17.3).
|
||||
self.height = if !self.on || self.specs.iter().all(|spec| spec.header.as_str().is_empty()) {
|
||||
0.0
|
||||
@@ -211,7 +214,8 @@ impl Header {
|
||||
}
|
||||
|
||||
fn width_of(&self, spec: &ColumnSpec) -> ColumnWidth {
|
||||
match spec.width.in_unit(self.unit) {
|
||||
let width = if spec.width == ColumnWidth::Toggle { ColumnWidth::Fixed(self.toggle) } else { spec.width.in_unit(self.unit) };
|
||||
match width {
|
||||
fixed @ ColumnWidth::Fixed(_) => fixed,
|
||||
_ => self.memory.widths.iter().find(|(key, _)| *key == spec.key).map_or(spec.width, |(_, width)| ColumnWidth::Fixed(*width)),
|
||||
}
|
||||
@@ -453,7 +457,10 @@ impl Header {
|
||||
if (width - shown).abs() <= f32::EPSILON {
|
||||
return;
|
||||
}
|
||||
let owned_by_app = self.specs.iter().any(|spec| spec.key == *key && matches!(spec.width, ColumnWidth::Fixed(_) | ColumnWidth::Controls(_)));
|
||||
let owned_by_app = self
|
||||
.specs
|
||||
.iter()
|
||||
.any(|spec| spec.key == *key && matches!(spec.width, ColumnWidth::Fixed(_) | ColumnWidth::Controls(_) | ColumnWidth::Toggle));
|
||||
if !owned_by_app {
|
||||
match self.memory.widths.iter_mut().find(|(held, _)| held == key) {
|
||||
Some((_, held)) => *held = width,
|
||||
|
||||
@@ -7,8 +7,8 @@ use super::{
|
||||
};
|
||||
use crate::buttons::Button;
|
||||
use crate::contract::{
|
||||
Bind, CollectionEvent, ColumnKind, ColumnSpec, Entry, Show as _, ShowCollection as _, ShowContainer as _, ToggleColumn, ToggleEdit,
|
||||
WordSetCx as _, request_rename,
|
||||
Bind, CollectionEvent, ColumnSpec, Entry, Show as _, ShowCollection as _, ShowContainer as _, ToggleColumn, ToggleEdit, WordSetCx as _,
|
||||
request_rename,
|
||||
};
|
||||
use crate::layout_components::Stack;
|
||||
use crate::menu::Menu;
|
||||
@@ -114,9 +114,7 @@ impl ItemSource<usize> for EyedNames<'_> {
|
||||
#[story(List<'static, usize>, covers = [Default, Many], drive = Drive::Never)]
|
||||
fn list_many(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let columns = vec![
|
||||
ColumnSpec::new(EYE, Label::Empty, ColumnWidth::Controls(1.0))
|
||||
.kind(ColumnKind::Toggle(ToggleColumn::sweepable().key(Chord::new(Mods::CMD, Key::Comma))))
|
||||
.icon(IconId::new("eye")),
|
||||
ColumnSpec::toggle(EYE, Label::Empty, ToggleColumn::sweepable().key(Chord::new(Mods::CMD, Key::Comma))).icon(IconId::new("eye")),
|
||||
ColumnSpec::new(NAME, Label::Empty, ColumnWidth::fill(1.0)),
|
||||
];
|
||||
let LayerRows { names, visible, selection, last } = data.value("rows", LayerRows::new(40));
|
||||
@@ -219,8 +217,8 @@ fn set_toggle(layers: &mut [Layer], cell: &ToggleEdit<usize>) {
|
||||
#[story(List<'static, usize>, covers = [], drive = Drive::Never, group = "Layers", title = "Layers")]
|
||||
fn list_layers(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let columns = vec![
|
||||
ColumnSpec::new(EYE, Label::Empty, ColumnWidth::Controls(1.0)).kind(ColumnKind::Toggle(ToggleColumn::sweepable())).icon(IconId::new("eye")),
|
||||
ColumnSpec::new(LOCK, Label::Empty, ColumnWidth::Controls(1.0)).kind(ColumnKind::Toggle(ToggleColumn::sweepable())).icon(IconId::new("lock")),
|
||||
ColumnSpec::toggle(EYE, Label::Empty, ToggleColumn::sweepable()).icon(IconId::new("eye")),
|
||||
ColumnSpec::toggle(LOCK, Label::Empty, ToggleColumn::sweepable()).icon(IconId::new("lock")),
|
||||
ColumnSpec::new(NAME, Label::Empty, ColumnWidth::fill(1.0)),
|
||||
];
|
||||
let rows = data.value("layers", layers()).clone();
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
use super::Table;
|
||||
use super::words::MetadataWords;
|
||||
use crate::contract::{
|
||||
Bind, CollectionEvent, CollectionResponse, ColumnKind, ColumnSpec, NoValue, Outcome, Pad, Pattern, Props, Remember as _, RowHeight, SelectMode,
|
||||
Show as _, ShowCollection as _, ShowContainer as _, Sizing, ToggleColumn,
|
||||
Bind, CollectionEvent, CollectionResponse, ColumnSpec, NoValue, Outcome, Pad, Pattern, Props, Remember as _, RowHeight, SelectMode, Show as _,
|
||||
ShowCollection as _, ShowContainer as _, Sizing, ToggleColumn,
|
||||
};
|
||||
use crate::layout_components::Stack;
|
||||
use crate::list::{ListRow, RowEvent, ToggleCell, ToggleState};
|
||||
@@ -262,10 +262,7 @@ impl<'a> MetadataTable<'a> {
|
||||
ColumnSpec::new(VALUE, words.value.clone(), ColumnWidth::fill(1.0)),
|
||||
];
|
||||
if checks {
|
||||
columns.insert(
|
||||
0,
|
||||
ColumnSpec::new(SHOW, words.show.clone(), ColumnWidth::Controls(1.0)).kind(ColumnKind::Toggle(ToggleColumn::sweepable())),
|
||||
);
|
||||
columns.insert(0, ColumnSpec::toggle(SHOW, words.show.clone(), ToggleColumn::sweepable()));
|
||||
}
|
||||
let source = Fields { keys, entries, chosen: held.as_deref() };
|
||||
let table = Table::<FieldKey>::new(label.clone(), columns)
|
||||
|
||||
@@ -66,7 +66,7 @@ fn pressing_a_check_box_changes_its_fill_whether_off_or_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::contract::{ColumnSpec, ShowCollection as _, ToggleColumn};
|
||||
use craft_ui::list::{ListRow, ToggleCell, ToggleState};
|
||||
use craft_ui::table::Table;
|
||||
const CHECK: ColumnKey = ColumnKey::new("check");
|
||||
@@ -77,9 +77,9 @@ fn a_row_press_shows_on_the_check_cell_that_follows_it_and_a_cell_press_on_its_o
|
||||
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::toggle(CHECK, "", ToggleColumn::default()),
|
||||
ColumnSpec::new(NAME, "", ColumnWidth::fill(1.0)),
|
||||
ColumnSpec::new(LOCK, "", ColumnWidth::Controls(1.0)).kind(ColumnKind::Toggle(ToggleColumn::default())),
|
||||
ColumnSpec::toggle(LOCK, "", ToggleColumn::default()),
|
||||
];
|
||||
let order = [0usize];
|
||||
let source = keyed(&order, |&row| row);
|
||||
|
||||
@@ -484,7 +484,7 @@ fn a_cell_field_stands_in_its_cell_takes_the_click_and_reports_its_edit() {
|
||||
#[trial]
|
||||
fn a_rows_label_takes_the_empty_toggle_columns_next_to_it() {
|
||||
use craft_behavior::{ColumnKey, ColumnWidth};
|
||||
use craft_ui::contract::{ColumnKind, ColumnSpec, ToggleColumn};
|
||||
use craft_ui::contract::{ColumnSpec, ToggleColumn};
|
||||
use craft_ui::list::{ToggleCell, ToggleState};
|
||||
use std::cell::Cell;
|
||||
const INCLUDE: ColumnKey = ColumnKey::new("include");
|
||||
@@ -494,7 +494,7 @@ fn a_rows_label_takes_the_empty_toggle_columns_next_to_it() {
|
||||
let ends = Rc::new(Cell::new((0.0_f32, 0.0_f32)));
|
||||
let held = ends.clone();
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let toggle = |key| ColumnSpec::new(key, "", ColumnWidth::Controls(1.0)).kind(ColumnKind::Toggle(ToggleColumn::default()));
|
||||
let toggle = |key| ColumnSpec::toggle(key, "", ToggleColumn::default());
|
||||
let columns = vec![toggle(INCLUDE), toggle(DIALOG), ColumnSpec::new(NAME, "", ColumnWidth::fill(1.0))];
|
||||
let keys = [0_usize, 1, 2];
|
||||
let source = keyed(&keys, |key: &usize| *key);
|
||||
@@ -528,6 +528,34 @@ fn a_rows_label_takes_the_empty_toggle_columns_next_to_it() {
|
||||
assert!(start("Step") > dialog, "a row with both toggles starts its label past them");
|
||||
}
|
||||
|
||||
/// A toggle column holds one control-high toggle with room on each side: wider than its control-high row, narrower
|
||||
/// than two toggles.
|
||||
#[trial]
|
||||
fn a_toggle_column_holds_one_toggle_with_room_on_each_side() {
|
||||
use craft_behavior::{ColumnKey, ColumnWidth};
|
||||
use craft_ui::contract::{ColumnSpec, ToggleColumn};
|
||||
use craft_ui::list::ToggleCell;
|
||||
use std::cell::Cell;
|
||||
const EYE: ColumnKey = ColumnKey::new("eye");
|
||||
const NAME: ColumnKey = ColumnKey::new("name");
|
||||
let eye = Rc::new(Cell::new(egui::Rect::NOTHING));
|
||||
let held = eye.clone();
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let columns = vec![ColumnSpec::toggle(EYE, "", ToggleColumn::sweepable()), ColumnSpec::new(NAME, "", ColumnWidth::fill(1.0))];
|
||||
let keys = [0_usize];
|
||||
let source = keyed(&keys, |key: &usize| *key);
|
||||
let _ = List::new("Layers").columns(columns).show_items(ui, &source, &mut |key, icx| {
|
||||
held.set(icx.cell(&EYE).unwrap_or(egui::Rect::NOTHING));
|
||||
ListRow::new(NAMES[*key]).cells(icx.cells()).toggle(ToggleCell::eye(EYE, true))
|
||||
});
|
||||
});
|
||||
fixture.room(Vec2::new(300.0, 200.0));
|
||||
fixture.settle();
|
||||
let cell = eye.get();
|
||||
assert!(cell.width() > cell.height(), "the toggle column is wider than its control-high row: {cell:?}");
|
||||
assert!(cell.width() < 2.0 * cell.height(), "the toggle column holds one toggle: {cell:?}");
|
||||
}
|
||||
|
||||
/// Every filled rect among `shapes`, nested lists included.
|
||||
fn fills(shapes: &[egui::Shape], out: &mut Vec<(egui::Rect, egui::Color32)>) {
|
||||
for shape in shapes {
|
||||
|
||||
Reference in New Issue
Block a user