mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 03:17:43 +00:00
craft-ui-panels, craft-ui-patterns: HidePanels::Except holds a Tracked set of panel keys; the dock derives its pruned layout and each group's tab titles under revisions
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
//! `DockEvent`, `FloatSpace` and `HidePanels`: what a dock reports to the host and the host tells a dock.
|
||||
|
||||
use super::{DockCommands, DockSizes, DragUnit};
|
||||
use super::{DockCommands, DockSizes, DragUnit, PanelKey};
|
||||
use crate::contract::{MemoKey, MemoProps, Tracked};
|
||||
use std::collections::BTreeSet;
|
||||
use egui::{Rect, Vec2};
|
||||
|
||||
/// A request for host state outside the layout, or a report of where something ended up.
|
||||
@@ -42,24 +44,33 @@ pub enum DockEvent<P> {
|
||||
/// Which panels the host hides. Protected panels always stay. While the shell hides the panels and keeps the tools
|
||||
/// (Shift+Tab), the panels `Except` names stay and every other panel hides; while it hides the dock (Tab), every panel
|
||||
/// hides.
|
||||
///
|
||||
/// The set is a `Tracked` value, so a dock keys what it shows by the set's revision and keeps the pruned layout until
|
||||
/// the set, the workspace or the shell's visibility changes.
|
||||
#[derive(Clone, Copy)]
|
||||
#[non_exhaustive]
|
||||
pub enum HidePanels<'a, P> {
|
||||
pub enum HidePanels<'a> {
|
||||
/// Hides none.
|
||||
None,
|
||||
/// Hides every panel.
|
||||
All,
|
||||
/// Every panel except those for which the function returns true.
|
||||
Except(&'a dyn Fn(&P) -> bool),
|
||||
/// Every panel except those whose [`PanelKey`] the set holds.
|
||||
Except(&'a Tracked<BTreeSet<PanelKey>>),
|
||||
}
|
||||
|
||||
impl<P> Clone for HidePanels<'_, P> {
|
||||
fn clone(&self) -> Self {
|
||||
*self
|
||||
impl MemoProps for HidePanels<'_> {
|
||||
fn key(&self, key: &mut MemoKey) {
|
||||
match self {
|
||||
HidePanels::None => key.write_u32(0),
|
||||
HidePanels::All => key.write_u32(1),
|
||||
HidePanels::Except(keep) => {
|
||||
key.write_u32(2);
|
||||
keep.key(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<P> Copy for HidePanels<'_, P> {}
|
||||
|
||||
/// Where a docking command floats a panel, group or column when it gives no rect. A dock records one each pass;
|
||||
/// the host reads it to turn a command into placements.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! What the tree adds around the groups: Maximize Frame, the hidden-panel prune and the outer edge bands.
|
||||
|
||||
use super::config::DockConfig;
|
||||
use super::PanelKey;
|
||||
use super::event::HidePanels;
|
||||
use super::targets::{DockSizes, DockSpot, DockTargets};
|
||||
use super::tree;
|
||||
@@ -27,6 +28,11 @@ pub struct FrameView<'a, P: Clone> {
|
||||
}
|
||||
|
||||
impl<P: Clone> FrameView<'_, P> {
|
||||
/// The view with its layout owned, to keep it past the layout it was made from.
|
||||
pub fn into_owned(self) -> FrameView<'static, P> {
|
||||
FrameView { layout: Cow::Owned(self.layout.into_owned()), maximized: self.maximized, hidden: self.hidden, paths: self.paths }
|
||||
}
|
||||
|
||||
/// Writes the split sizes of `edited`, an edit of the view's layout, into `layout`, the layout the view was made
|
||||
/// from. Panels the view left out keep their place; only the docked tree's split sizes change: floating windows
|
||||
/// have no splits.
|
||||
@@ -64,13 +70,13 @@ fn split_sizes<P>(node: &Node<P>, paths: &HashMap<Vec<bool>, Vec<bool>>) -> Vec<
|
||||
pub fn maximize<'a, P: Clone + Eq + Hash>(
|
||||
layout: &'a Layout<P>,
|
||||
maximized: Option<&P>,
|
||||
hide: HidePanels<'_, P>,
|
||||
hide: HidePanels<'_>,
|
||||
protected: &dyn Fn(&P) -> bool,
|
||||
) -> FrameView<'a, P> {
|
||||
let hidden = |panel: &P| match hide {
|
||||
HidePanels::None => false,
|
||||
HidePanels::All => !protected(panel),
|
||||
HidePanels::Except(keep) => !protected(panel) && !keep(panel),
|
||||
HidePanels::Except(keep) => !protected(panel) && !keep.contains(&PanelKey::of(panel)),
|
||||
};
|
||||
// Only a docked panel maximizes its frame.
|
||||
let frame = maximized.and_then(|panel| match layout.place(panel)? {
|
||||
|
||||
@@ -5,7 +5,7 @@ use super::commands::DockCommands;
|
||||
use super::drop::{self, DragUnit, start_group_drag};
|
||||
use super::targets::{DockSizes, DockSpot, DockTargets, ZoneRule};
|
||||
use super::words::DockWords;
|
||||
use super::{PanelDrag, PanelKey, PanelTitle};
|
||||
use super::{PanelDrag, PanelKey, PanelTitle, Titles};
|
||||
use crate::buttons::IconButton;
|
||||
use crate::contract::overlay::Anchor;
|
||||
use crate::contract::{
|
||||
@@ -245,7 +245,7 @@ pub struct DockGroup<'a, P: Clone + Hash + Send + Sync + 'static> {
|
||||
#[container]
|
||||
props: ContainerProps,
|
||||
anchor: P,
|
||||
panels: &'a [PanelTitle],
|
||||
panels: Titles,
|
||||
active: PanelKey,
|
||||
/// Only the header shows; the body and its drop spots are left out.
|
||||
#[prop(flag)]
|
||||
@@ -292,10 +292,10 @@ pub struct DockGroup<'a, P: Clone + Hash + Send + Sync + 'static> {
|
||||
impl<'a, P: Clone + Hash + Send + Sync + PartialEq + Debug + 'static> DockGroup<'a, P> {
|
||||
/// The group named by `anchor` (one of its panels) with its `panels`, `active` showing. The group is named by the
|
||||
/// active panel's title.
|
||||
pub fn new(anchor: P, panels: &'a [PanelTitle], active: PanelKey) -> Self {
|
||||
pub fn new(anchor: P, panels: Titles, active: PanelKey) -> Self {
|
||||
let props =
|
||||
ContainerProps::new().sizing(Sizing::Fill).header(HeaderRegion::new().fill(SurfaceKind::Background)).command_scope(DockCommands::SCOPE);
|
||||
let title = panels.iter().find(|panel| panel.key == active).map(|panel| panel.title.clone()).unwrap_or_default();
|
||||
let title = panels.as_slice().iter().find(|panel| panel.key == active).map(|panel| panel.title.clone()).unwrap_or_default();
|
||||
DockGroup {
|
||||
common: Common::new(),
|
||||
props,
|
||||
@@ -445,7 +445,7 @@ impl<P: Clone + PartialEq + Debug + Hash + Send + Sync + 'static> Component for
|
||||
let Some(dock) = self.dock else { return };
|
||||
let (rect, rtl, header) = (cx.rect, cx.flow.is_rtl(), cx.style.header);
|
||||
let strip = Rect::from_min_size(rect.min, Vec2::new(rect.width(), header));
|
||||
DockTargets::<P>::register(&cx.core.ctx, dock, DockSpot::tab(self.anchor.clone(), self.panels.len()), strip);
|
||||
DockTargets::<P>::register(&cx.core.ctx, dock, DockSpot::tab(self.anchor.clone(), self.panels.as_slice().len()), strip);
|
||||
if self.minimized {
|
||||
return;
|
||||
}
|
||||
@@ -518,7 +518,7 @@ impl<P: Clone + Hash + Send + Sync + PartialEq + Debug + 'static> Container for
|
||||
}
|
||||
let row = TabRow {
|
||||
anchor: self.anchor.clone(),
|
||||
panels: self.panels,
|
||||
panels: self.panels.clone(),
|
||||
active: self.active,
|
||||
closable: self.closable,
|
||||
wheel_selects: self.wheel_selects_tabs,
|
||||
@@ -585,7 +585,7 @@ struct TabRow<'a, P> {
|
||||
/// The group's anchor panel, which names its drop spots.
|
||||
#[memo_props(hash = "a dock's panels are plain values it keys by their hash")]
|
||||
anchor: P,
|
||||
panels: &'a [PanelTitle],
|
||||
panels: Titles,
|
||||
active: PanelKey,
|
||||
closable: bool,
|
||||
wheel_selects: bool,
|
||||
@@ -598,7 +598,7 @@ fn tab_row<P: Clone + PartialEq + Debug + Hash + Send + Sync + 'static>(row: &mu
|
||||
let env = crate::runtime::env::Env::of(ui);
|
||||
let name = Label::from(env.words::<DockWords>().panels.as_str().to_owned());
|
||||
let rtl = env.direction.is_rtl();
|
||||
let (panels, active, closable) = (row.panels, row.active, row.closable);
|
||||
let (panels, active, closable) = (row.panels.as_slice(), row.active, row.closable);
|
||||
let from = PanelKey::of(&row.anchor);
|
||||
let drags = crate::runtime::drag::started(ui.ctx());
|
||||
let source = keyed(panels, |panel: &PanelTitle| panel.key).with_text(|panel| Cow::Borrowed(panel.title.as_str()));
|
||||
|
||||
@@ -78,13 +78,14 @@ use craft_behavior::{Axis, EditEvents, Flow, Metrics, PartKey, Sense};
|
||||
use divider::{Divider, Drag};
|
||||
use egui::{Rect, Response, Vec2};
|
||||
use std::fmt::Debug;
|
||||
use std::sync::Arc;
|
||||
use std::hash::{DefaultHasher, Hash, Hasher};
|
||||
use tree::{FrameRules, SplitHandle};
|
||||
|
||||
const HANDLE: PartKey = PartKey::new("handle");
|
||||
|
||||
/// The stable key of a panel.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, crate::contract::MemoProps)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, crate::contract::MemoProps, crate::contract::PlainData)]
|
||||
#[non_exhaustive]
|
||||
pub struct PanelKey(pub u64);
|
||||
|
||||
@@ -114,6 +115,38 @@ pub struct PanelTitle {
|
||||
pub closable: bool,
|
||||
}
|
||||
|
||||
/// The tab titles of one group, with the key that stands for them in a memoized view's key. A host that keeps its
|
||||
/// titles derived from revisions gives [`Titles::new`] the key it derived them under, so the key does not walk the
|
||||
/// titles; [`Titles::from_content`] keys by the titles themselves.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Titles {
|
||||
list: Arc<Vec<PanelTitle>>,
|
||||
key: u128,
|
||||
}
|
||||
|
||||
impl Titles {
|
||||
/// The titles `list`, made from the inputs `key` follows: equal keys must mean equal titles.
|
||||
pub fn new<K: crate::contract::MemoProps + ?Sized>(key: &K, list: Arc<Vec<PanelTitle>>) -> Self {
|
||||
Titles { list, key: crate::contract::MemoKey::of(key) }
|
||||
}
|
||||
|
||||
/// The titles `list`, keyed by their content: the key walks them.
|
||||
pub fn from_content(list: Vec<PanelTitle>) -> Self {
|
||||
Titles { key: crate::contract::MemoKey::of(&list), list: Arc::new(list) }
|
||||
}
|
||||
|
||||
/// The titles in tab order.
|
||||
pub fn as_slice(&self) -> &[PanelTitle] {
|
||||
&self.list
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::contract::MemoProps for Titles {
|
||||
fn key(&self, key: &mut crate::contract::MemoKey) {
|
||||
self.key.key(key);
|
||||
}
|
||||
}
|
||||
|
||||
impl PanelTitle {
|
||||
/// A panel `key` titled `title`, not closable from its tab.
|
||||
pub fn new(key: PanelKey, title: impl Into<Label>) -> Self {
|
||||
|
||||
@@ -20,7 +20,7 @@ pub struct Placing<'a, P> {
|
||||
/// The panels that always show, such as a canvas.
|
||||
pub protected: &'a dyn Fn(&P) -> bool,
|
||||
/// The panels the area hides, as the shell's visibility leaves them.
|
||||
pub hide: HidePanels<'a, P>,
|
||||
pub hide: HidePanels<'a>,
|
||||
/// The panel whose frame the area shows maximized.
|
||||
pub maximized: Option<&'a P>,
|
||||
/// The floating window whose column the dock lays out, by its id; `None` for a dock area's docked tree.
|
||||
@@ -35,7 +35,7 @@ impl<'a, P> Placing<'a, P> {
|
||||
|
||||
/// The area hides `hide` and shows the frame of `maximized` alone.
|
||||
#[must_use]
|
||||
pub fn shown(mut self, hide: HidePanels<'a, P>, maximized: Option<&'a P>) -> Self {
|
||||
pub fn shown(mut self, hide: HidePanels<'a>, maximized: Option<&'a P>) -> Self {
|
||||
self.hide = hide;
|
||||
self.maximized = maximized;
|
||||
self
|
||||
|
||||
@@ -4,7 +4,7 @@ use super::SplitFramesCx as _;
|
||||
use super::group::MENU;
|
||||
use super::stack::{StackSection, StackSections};
|
||||
use super::tree::FrameRules;
|
||||
use super::{DockCommands, DockGroup, DragUnit, GroupGrip, HANDLE, PanelKey, PanelSpec, PanelSpecs, PanelTitle, SplitArea, Splitter, WindowMenuRows};
|
||||
use super::{DockCommands, DockGroup, DragUnit, GroupGrip, HANDLE, PanelKey, PanelSpec, PanelSpecs, PanelTitle, SplitArea, Splitter, Titles, WindowMenuRows};
|
||||
use crate::contract::SizeLimits;
|
||||
use crate::contract::{Bind, Props as _, Show as _, ShowContainer as _, Tracked, Validity};
|
||||
use crate::menu::{Menu, PanelRow};
|
||||
@@ -45,7 +45,7 @@ fn dock(ui: &mut Ui, bind: Bind<'_, Layout<usize>>, shown: &Layout<usize>) -> St
|
||||
let Some(Node::Tabs { panels, .. }) = shown.place(&anchor).and_then(|place| shown.node_of(&place)) else { continue };
|
||||
let panels = titles(panels);
|
||||
let active = panels.first().map_or(PanelKey::new(0), |panel| panel.key);
|
||||
DockGroup::new(anchor, &panels, active).show_at(ui, rect, |_, _| ());
|
||||
DockGroup::new(anchor, Titles::from_content(panels.clone()), active).show_at(ui, rect, |_, _| ());
|
||||
}
|
||||
});
|
||||
area.output.edit.into()
|
||||
@@ -84,14 +84,14 @@ fn a_dock_of_one_group(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
#[story(DockGroup<'static, usize>, covers = [Default])]
|
||||
fn two_panels(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
let panels = titles(&[LAYERS, CHANNELS]);
|
||||
DockGroup::new(LAYERS, &panels, panels[0].key).show(ui, |_, _| ()).output.into()
|
||||
DockGroup::new(LAYERS, Titles::from_content(panels.clone()), panels[0].key).show(ui, |_, _| ()).output.into()
|
||||
}
|
||||
|
||||
/// A group in a floating window: nothing goes beside it, so a drop on its body joins it or stacks above or below.
|
||||
#[story(DockGroup<'static, usize>, covers = [Default])]
|
||||
fn a_group_in_a_window(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
let panels = titles(&[LAYERS, CHANNELS]);
|
||||
DockGroup::new(LAYERS, &panels, panels[0].key).in_window().show(ui, |_, _| ()).output.into()
|
||||
DockGroup::new(LAYERS, Titles::from_content(panels.clone()), panels[0].key).in_window().show(ui, |_, _| ()).output.into()
|
||||
}
|
||||
|
||||
/// A click on the panel menu button opens the group's panel menu.
|
||||
@@ -106,7 +106,7 @@ fn open_panel_menu(fixture: &mut Fixture) {
|
||||
fn panel_menu(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
let panels = titles(&[LAYERS, CHANNELS]);
|
||||
let rows = [DockCommands::FloatPanel, DockCommands::FloatGroup].map(|command| PanelRow::Command(CommandRef::from(command))).to_vec();
|
||||
DockGroup::new(LAYERS, &panels, panels[0].key).menu(move || rows.clone()).show(ui, |_, _| ()).output.into()
|
||||
DockGroup::new(LAYERS, Titles::from_content(panels.clone()), panels[0].key).menu(move || rows.clone()).show(ui, |_, _| ()).output.into()
|
||||
}
|
||||
|
||||
#[story(GroupGrip<usize>, covers = [Default])]
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use craft_ui::buttons::Button;
|
||||
use craft_ui::contract::{Show as _, ShowContainer as _};
|
||||
use craft_ui::docking::{DockGroup, PanelKey, PanelTitle};
|
||||
use craft_ui::docking::{DockGroup, PanelKey, PanelTitle, Titles};
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
use egui::{Pos2, Rect, Vec2};
|
||||
use std::cell::Cell;
|
||||
@@ -17,7 +17,7 @@ fn a_minimized_group_runs_no_body() {
|
||||
let counted = Rc::clone(&runs);
|
||||
let panels = vec![PanelTitle::new(PanelKey::new(1), "Color")];
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let group = DockGroup::new(1usize, &panels, panels[0].key);
|
||||
let group = DockGroup::new(1usize, Titles::from_content(panels.clone()), panels[0].key);
|
||||
let group = if minimized { group.minimized() } else { group };
|
||||
let counted = Rc::clone(&counted);
|
||||
group.show_at(ui, Rect::from_min_size(Pos2::new(10.0, 10.0), Vec2::new(240.0, 200.0)), move |ui, _| {
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
//! `DockArea`: the docking pattern. It shows a workspace's docked tree, dock columns, flyouts and floating groups from
|
||||
//! the parts of `docking`, takes the drops of tab and group drags, and applies their actions to the workspace.
|
||||
|
||||
use super::hide::{self, Shown};
|
||||
use super::hide::{self, PruneKey};
|
||||
use crate::contract::overlay::{PlacementChange, PlacementKind};
|
||||
use crate::contract::{
|
||||
Bind, BindMut, BodyCx, Cx, Entry, NoValue, Outcome, Pad, Pointer as _, Props as _, ShowContainer as _, Sizing, Tracked, WordSetCx as _,
|
||||
Bind, BindMut, BodyCx, Cx, Entry, MemoKey, NoValue, Outcome, Pad, Pointer as _, Props as _, ShowContainer as _, Sizing, Tracked, WordSetCx as _,
|
||||
};
|
||||
use crate::contract::Revision;
|
||||
use crate::docking::SplitFramesCx as _;
|
||||
use crate::docking::stack::{StackSection, StackSections, section_heights};
|
||||
use crate::docking::{Arrangement, close_requests, cross_window, end_replaced_drags, float_drop, native, open_requests};
|
||||
use crate::docking::{
|
||||
ColumnArrow, ColumnBar, DockColumn, DockCommands, DockConfig, DockDropTarget, DockDropped, DockEvent, DockGroup, DockPanels, DockRoot, DockScene,
|
||||
DockSizes, DockSpot, DockTargets, DockTo, DockWords, DragUnit, FloatSpace, FloatingGroup, FlyoutResize, GroupAt, GroupDrag, HidePanels,
|
||||
IconicColumn, IconicSizes, PanelDrag, PanelKey, PanelSpec, PanelSpecs, PanelTitle, Placing, SpecSource, SplitArea, WindowColumn, actions,
|
||||
IconicColumn, IconicSizes, PanelDrag, PanelKey, PanelSpec, PanelSpecs, PanelTitle, Placing, SpecSource, Titles, SplitArea, WindowColumn, actions,
|
||||
column_cells, dock_states, frame, move_actions, with_area_rules,
|
||||
};
|
||||
use crate::menu::{GroupItem, MenuWords, PanelMenu, PanelRow};
|
||||
@@ -124,7 +125,7 @@ pub struct DockArea<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> {
|
||||
config: DockConfig,
|
||||
/// Which panels the host hides.
|
||||
#[prop]
|
||||
hide: HidePanels<'a, P>,
|
||||
hide: HidePanels<'a>,
|
||||
/// The panel whose frame shows alone.
|
||||
#[prop]
|
||||
maximized: Option<P>,
|
||||
@@ -214,7 +215,7 @@ struct Drops<'a, P> {
|
||||
permissions: &'a dyn Fn(&P) -> Permissions,
|
||||
config: &'a DockConfig,
|
||||
specs: &'a HashMap<P, PanelSpec>,
|
||||
hide: HidePanels<'a, P>,
|
||||
hide: HidePanels<'a>,
|
||||
maximized: Option<&'a P>,
|
||||
rtl: bool,
|
||||
}
|
||||
@@ -254,9 +255,19 @@ struct Report<P> {
|
||||
files: Vec<drag::OsFile>,
|
||||
}
|
||||
|
||||
/// The inputs of the workspace's derived values: the workspace, the panels' specs and the lock.
|
||||
#[derive(Clone, Copy, crate::contract::MemoProps)]
|
||||
pub(super) struct ModelKey {
|
||||
workspace: Revision,
|
||||
specs: Revision,
|
||||
locked: bool,
|
||||
}
|
||||
|
||||
/// What every part of one pass reads.
|
||||
struct Scene<'s, P> {
|
||||
dock: Id,
|
||||
/// The key the pruned layout was derived under: what every group's derived values follow.
|
||||
view: u128,
|
||||
sizes: DockSizes,
|
||||
config: &'s DockConfig,
|
||||
layout: &'s Layout<P>,
|
||||
@@ -348,7 +359,7 @@ struct Look {
|
||||
/// What a group's header shows besides its panels' bodies: the tab titles, the panel menu's rows and whether the host
|
||||
/// gave any, and the panel commands' states.
|
||||
struct GroupParts {
|
||||
titles: Vec<PanelTitle>,
|
||||
titles: Titles,
|
||||
hosted: bool,
|
||||
states: Vec<(DockCommands, CommandState)>,
|
||||
}
|
||||
@@ -409,7 +420,8 @@ impl<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> DockArea<'a, P> {
|
||||
Some(Mixed::Same(held)) => held,
|
||||
_ => Arc::default(),
|
||||
};
|
||||
let model = derived(&ctx, id, &(held.revision(), specs.revision(), locked), || DockModel::of(&held, specs, locked));
|
||||
let key = ModelKey { workspace: held.revision(), specs: specs.revision(), locked };
|
||||
let model = derived(&ctx, id, &key, || DockModel::of(&held, specs, locked));
|
||||
let error = model.error.clone();
|
||||
let current = if error.is_none() { held } else { Arc::default() };
|
||||
let rights = &model.rights;
|
||||
@@ -449,6 +461,7 @@ impl<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> DockArea<'a, P> {
|
||||
specs: &model.specs,
|
||||
keys: &model.keys,
|
||||
hide,
|
||||
model: key,
|
||||
maximized: maximized.as_ref(),
|
||||
auto_collapse,
|
||||
sizes,
|
||||
@@ -549,7 +562,8 @@ struct Input<'i, P> {
|
||||
config: &'i DockConfig,
|
||||
specs: &'i HashMap<P, PanelSpec>,
|
||||
keys: &'i HashMap<PanelKey, P>,
|
||||
hide: HidePanels<'i, P>,
|
||||
hide: HidePanels<'i>,
|
||||
model: ModelKey,
|
||||
maximized: Option<&'i P>,
|
||||
auto_collapse: bool,
|
||||
sizes: DockSizes,
|
||||
@@ -578,16 +592,19 @@ fn show_area<P: Clone + Eq + Hash + Debug + Send + Sync + 'static>(
|
||||
panels: &mut dyn DockPanels<P>,
|
||||
mut flyout: Option<&mut Bind<'_, Option<P>>>,
|
||||
) -> Passed<P> {
|
||||
let Input { id, ctx, current, config, specs, keys, hide, maximized, auto_collapse, sizes, rtl } = *input;
|
||||
let Input { id, ctx, current, config, specs, keys, hide, model, maximized, auto_collapse, sizes, rtl } = *input;
|
||||
let shell = body.shell();
|
||||
let mut memory = body.memory::<AreaMemory<P>>().clone();
|
||||
let protected = |panel: &P| rights.get(panel).is_some_and(|rights| rights.is_protected());
|
||||
let Shown { view, floating } = hide::shown(current.layout(), maximized, hide, shell.as_ref(), &protected);
|
||||
let (hide, floating) = hide::resolved(hide, shell.as_ref());
|
||||
let prune = PruneKey { model, hide, floating, maximized: maximized.map(PanelKey::of) };
|
||||
let view = derived(ctx, id.with("pruned"), &prune, || frame::maximize(current.layout(), maximized, hide, &protected).into_owned());
|
||||
let layout: &Layout<P> = &view.layout;
|
||||
let bounds = shell.as_ref().map_or(body.rect, ShellCx::float_bounds);
|
||||
let space = float_space(bounds, &sizes, config, specs);
|
||||
let scene = Scene {
|
||||
dock: id,
|
||||
view: MemoKey::of(&prune),
|
||||
sizes,
|
||||
config,
|
||||
layout,
|
||||
@@ -904,6 +921,7 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Pass<'_, P> {
|
||||
}
|
||||
let shown = &members[active];
|
||||
let words = body.words::<MenuWords>();
|
||||
let ctx = ui.ctx().clone();
|
||||
let panels = RefCell::new(&mut *self.panels);
|
||||
// The tab titles, the menu rows and the panel commands' states, built when the group runs.
|
||||
// The tab titles, whether the host gives menu rows and the panel commands' states, built once per pass; the
|
||||
@@ -911,10 +929,14 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Pass<'_, P> {
|
||||
let parts: OnceCell<GroupParts> = OnceCell::new();
|
||||
let parts_of = || {
|
||||
parts.get_or_init(|| {
|
||||
let titles = members
|
||||
.iter()
|
||||
.map(|panel| PanelTitle::new(PanelKey::of(panel), scene.spec(panel).label).closable(scene.permissions(panel).closable))
|
||||
.collect();
|
||||
let key = (scene.view, PanelKey::of(anchor));
|
||||
let list = derived(&ctx, scene.dock.with(("titles", key.1)), &key, || {
|
||||
members
|
||||
.iter()
|
||||
.map(|panel| PanelTitle::new(PanelKey::of(panel), scene.spec(panel).label).closable(scene.permissions(panel).closable))
|
||||
.collect::<Vec<_>>()
|
||||
});
|
||||
let titles = Titles::new(&key, list);
|
||||
let hosted = !panels.borrow_mut().panel_rows(shown).is_empty();
|
||||
let permissions = |panel: &P| scene.permissions(panel);
|
||||
let states = dock_states(&DockScene::new(scene.layout, scene.space, false, &permissions).floated(scene.floated), shown);
|
||||
@@ -926,7 +948,7 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Pass<'_, P> {
|
||||
let panels = &panels;
|
||||
let words = &words;
|
||||
let GroupParts { titles, hosted, states } = parts_of();
|
||||
let mut group = DockGroup::new(anchor.clone(), titles, PanelKey::of(&members[at]))
|
||||
let mut group = DockGroup::new(anchor.clone(), titles.clone(), PanelKey::of(&members[at]))
|
||||
.extra(move |ui, body| panels.borrow_mut().group_header(members, at, ui, body))
|
||||
.dock(self.dock)
|
||||
.zones(scene.config.zone_rule())
|
||||
|
||||
@@ -1,39 +1,27 @@
|
||||
//! The hidden-panel prune of a dock area: what the host hides, the shell's panel visibility and Maximize Frame
|
||||
//! decide which panels the area shows.
|
||||
//! decide which panels the area shows. The area derives the pruned layout under a [`PruneKey`] and keeps it while the
|
||||
//! key holds.
|
||||
|
||||
use crate::docking::HidePanels;
|
||||
use crate::docking::frame::{FrameView, maximize};
|
||||
use super::area::ModelKey;
|
||||
use crate::docking::{HidePanels, PanelKey};
|
||||
use crate::runtime::env::ShellCx;
|
||||
use craft_behavior::dock::Layout;
|
||||
use std::hash::Hash;
|
||||
|
||||
/// The layout as the area shows it, and whether its floating windows show.
|
||||
pub(super) struct Shown<'a, P: Clone> {
|
||||
/// The pruned layout with its write-back map.
|
||||
pub(super) view: FrameView<'a, P>,
|
||||
/// Floating windows show: the shell shows them, or it hides the panels and the view keeps what the host names.
|
||||
/// What the pruned layout is a function of: the workspace, the specs and the lock (the protected panels), what is
|
||||
/// hidden after the shell's visibility, whether floating windows show and the maximized panel.
|
||||
#[derive(crate::contract::MemoProps)]
|
||||
pub(super) struct PruneKey<'h> {
|
||||
pub(super) model: ModelKey,
|
||||
pub(super) hide: HidePanels<'h>,
|
||||
pub(super) floating: bool,
|
||||
}
|
||||
|
||||
/// `layout` with the host's `hide`, the shell's panel visibility and the frame of `maximized` applied. Protected
|
||||
/// panels always stay, so a canvas shows while the dock is hidden. While the shell hides the panels and keeps the
|
||||
/// tools (Shift+Tab), the panels the host's `HidePanels::Except` names stay, docked or floating, and every other panel
|
||||
/// hides; while the shell hides the dock (Tab, body-only mode), every panel hides. Size edits made on the view go back
|
||||
/// through `FrameView::write_back`.
|
||||
pub(super) fn shown<'a, P: Clone + Eq + Hash>(
|
||||
layout: &'a Layout<P>,
|
||||
maximized: Option<&P>,
|
||||
hide: HidePanels<'_, P>,
|
||||
shell: Option<&ShellCx>,
|
||||
protected: &dyn Fn(&P) -> bool,
|
||||
) -> Shown<'a, P> {
|
||||
let (hide, floating) = resolved(hide, shell);
|
||||
Shown { view: maximize(layout, maximized, hide, protected), floating }
|
||||
pub(super) maximized: Option<PanelKey>,
|
||||
}
|
||||
|
||||
/// The panels the area hides, the host's `hide` with the shell's panel visibility applied, and whether floating windows
|
||||
/// show (see [`shown`]).
|
||||
pub(super) fn resolved<'h, P>(hide: HidePanels<'h, P>, shell: Option<&ShellCx>) -> (HidePanels<'h, P>, bool) {
|
||||
/// show. Protected panels always stay, so a canvas shows while the dock is hidden. While the shell hides the panels and
|
||||
/// keeps the tools (Shift+Tab), the panels the host's `HidePanels::Except` names stay, docked or floating, and every
|
||||
/// other panel hides; while the shell hides the dock (Tab, body-only mode), every panel hides. Size edits made on the
|
||||
/// pruned view go back through `FrameView::write_back`.
|
||||
pub(super) fn resolved<'h>(hide: HidePanels<'h>, shell: Option<&ShellCx>) -> (HidePanels<'h>, bool) {
|
||||
match shell {
|
||||
None => (hide, true),
|
||||
Some(shell) if shell.panels_hidden() => (if let HidePanels::Except(keep) = hide { HidePanels::Except(keep) } else { HidePanels::All }, true),
|
||||
|
||||
@@ -6,7 +6,7 @@ use craft_behavior::dock::{Layout, Node, Permissions, SplitSize};
|
||||
use craft_ui::contract::SizeLimits;
|
||||
use craft_ui::contract::{Bind, Common, Component, Cx, MeasureCx, Pointer as _, Role, Show as _, ShowContainer as _};
|
||||
use craft_ui::docking::tree::{self, FrameRules};
|
||||
use craft_ui::docking::{DockDropTarget, DockDropped, DockGroup, DockSizes, GroupDrag, PanelDrag, PanelKey, PanelTitle, SplitArea};
|
||||
use craft_ui::docking::{DockDropTarget, DockDropped, DockGroup, DockSizes, GroupDrag, PanelDrag, PanelKey, PanelTitle, SplitArea, Titles};
|
||||
use craft_ui::runtime::drag;
|
||||
use craft_ui::style::{ComponentStyle, StyleCx};
|
||||
use craft_ui::testing::pointer::{moved, press, release};
|
||||
@@ -130,7 +130,7 @@ fn bed(layout: Layout<String>) -> Bed {
|
||||
for (anchor, panels, rect) in &placed {
|
||||
let titles: Vec<PanelTitle> = panels.iter().map(|panel| PanelTitle::new(PanelKey::of(panel), panel.clone())).collect();
|
||||
let active = titles.first().map_or(PanelKey::new(0), |title| title.key);
|
||||
DockGroup::new(anchor.clone(), &titles, active).dock(dock_id()).show_at(ui, *rect, |_, _| ());
|
||||
DockGroup::new(anchor.clone(), Titles::from_content(titles.clone()), active).dock(dock_id()).show_at(ui, *rect, |_, _| ());
|
||||
}
|
||||
});
|
||||
for dropped in shared_taken.borrow_mut().drain(..) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use craft_behavior::Axis;
|
||||
use craft_behavior::dock::{Column, DockEdge, Floating, Group, Layout, Node, Permissions, SplitSize, Workspace};
|
||||
use craft_ui::contract::{Bind, BodyCx, PlainData, Tracked};
|
||||
use craft_ui::docking::{DockConfig, DockPanels, HidePanels, PanelSpec, PanelSpecs};
|
||||
use craft_ui::docking::{DockConfig, DockPanels, HidePanels, PanelKey, PanelSpec, PanelSpecs};
|
||||
use craft_ui::patterns::dock::DockArea;
|
||||
use craft_ui::runtime::env::{BodyMode, ShellCx, ShellEntry, WindowKey};
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
@@ -65,7 +65,7 @@ fn shown_under(shell: ShellCx, keeps: bool) -> BTreeSet<usize> {
|
||||
let mut workspace = Arc::new(Workspace::new(layout()));
|
||||
let mut panels = Panels { shown: Rc::clone(&seen) };
|
||||
let specs = Tracked::new(Specs);
|
||||
let keep = |panel: &usize| *panel == TOOLBAR || *panel == PALETTE;
|
||||
let keep = Tracked::new(BTreeSet::from([PanelKey::of(&TOOLBAR), PanelKey::of(&PALETTE)]));
|
||||
let mut area = DockArea::new("Hidden dock", Bind::bound(&mut workspace), &specs, &mut panels, DockConfig::default());
|
||||
if keeps {
|
||||
area = area.hide(HidePanels::Except(&keep));
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
|
||||
use craft_behavior::Axis;
|
||||
use craft_behavior::dock::{Column, Group, Layout, Node, SplitSize};
|
||||
use craft_ui::contract::Role;
|
||||
use craft_ui::contract::{Role, Tracked};
|
||||
use craft_ui::docking::frame::maximize;
|
||||
use craft_ui::docking::tree;
|
||||
use craft_ui::docking::{DockColumn, HidePanels, PanelSpec};
|
||||
use craft_ui::docking::{DockColumn, HidePanels, PanelKey, PanelSpec};
|
||||
use craft_ui::testing::memory::global;
|
||||
use craft_ui::testing::pointer;
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
use egui::{Pos2, Rect};
|
||||
use std::collections::BTreeSet;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
@@ -64,7 +65,7 @@ fn a_column_divider_dragged_past_a_minimum_and_back_stays_under_the_pointer() {
|
||||
fn a_resize_under_a_pruned_view_keeps_the_hidden_panels() {
|
||||
let rest = Node::split(Axis::X, SplitSize::Ratio(0.5), Node::tabs(vec![1], 0), Node::tabs(vec![2], 0));
|
||||
let mut layout = Layout::new(Some(Node::split(Axis::X, SplitSize::Ratio(0.5), Node::tabs(vec![0], 0), rest)), Vec::new());
|
||||
let keep = |panel: &usize| *panel != 2;
|
||||
let keep = Tracked::new(BTreeSet::from([PanelKey::of(&0_usize), PanelKey::of(&1_usize)]));
|
||||
let none_protected = |_: &usize| false;
|
||||
let original = layout.clone();
|
||||
let view = maximize(&original, None, HidePanels::Except(&keep), &none_protected);
|
||||
|
||||
Reference in New Issue
Block a user