mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 00:34:25 +00:00
New Workspace's Capture boxes sit in a titled group box; contract API lists the workspace captures
This commit is contained in:
@@ -288,13 +288,7 @@ impl<P> From<StoredSet<P>> for WorkspaceSet<P> {
|
||||
if let Some(layout) = saved {
|
||||
workspace.layout = layout;
|
||||
}
|
||||
NamedWorkspace {
|
||||
id: named.id,
|
||||
name: named.name,
|
||||
layout: workspace,
|
||||
chrome: named.chrome,
|
||||
keeps: named.keeps,
|
||||
}
|
||||
NamedWorkspace { id: named.id, name: named.name, layout: workspace, chrome: named.chrome, keeps: named.keeps }
|
||||
})
|
||||
.collect();
|
||||
let mut edited = BTreeMap::new();
|
||||
|
||||
@@ -126,7 +126,8 @@ fn a_workspace_set_with_a_floating_group_round_trips_through_json() {
|
||||
fn a_workspace_with_a_bottom_pane_opens_and_closes_it_on_switch() {
|
||||
const TIMELINE: u32 = 9;
|
||||
let photography = Workspace::new(Layout::new(Some(tabs(&[1, 2], 0)), Vec::new()));
|
||||
let motion = Workspace::new(Layout::new(Some(Node::split(Axis::Y, SplitSize::FixedSecond(200.0), tabs(&[1, 2], 0), tabs(&[TIMELINE], 0))), Vec::new()));
|
||||
let motion =
|
||||
Workspace::new(Layout::new(Some(Node::split(Axis::Y, SplitSize::FixedSecond(200.0), tabs(&[1, 2], 0), tabs(&[TIMELINE], 0))), Vec::new()));
|
||||
let mut set = WorkspaceSet::new(vec![
|
||||
NamedWorkspace::new("photography", "Photography", photography.clone()),
|
||||
NamedWorkspace::new("motion", "Motion", motion),
|
||||
|
||||
@@ -24,7 +24,8 @@ pub fn fit_widths(columns: &[(f32, Option<f32>)], room: f32) -> Vec<f32> {
|
||||
if total <= room {
|
||||
return columns.iter().map(|(width, _)| *width).collect();
|
||||
}
|
||||
let bounded: Vec<(f32, (f32, f32))> = columns.iter().map(|&(width, floor)| (width, (floor.map_or(width, |floor| floor.min(width)), width))).collect();
|
||||
let bounded: Vec<(f32, (f32, f32))> =
|
||||
columns.iter().map(|&(width, floor)| (width, (floor.map_or(width, |floor| floor.min(width)), width))).collect();
|
||||
scale_widths(&bounded, room)
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,9 @@ mod dock_column;
|
||||
mod flyout;
|
||||
mod iconic;
|
||||
|
||||
pub use dock_column::{DockColumn, DockColumnOutput, DockColumnStyle, GroupSize, GroupView, fit_widths, group_heights, scale_widths, stacked, width_bounds};
|
||||
pub use dock_column::{
|
||||
DockColumn, DockColumnOutput, DockColumnStyle, GroupSize, GroupView, fit_widths, group_heights, scale_widths, stacked, width_bounds,
|
||||
};
|
||||
pub use flyout::{Flyout, GroupAt};
|
||||
pub use iconic::{IconicColumn, IconicColumnOutput, IconicColumnStyle, IconicSizes};
|
||||
pub use window_menu::{WindowMenuRows, WindowMenuRowsOutput};
|
||||
|
||||
@@ -126,7 +126,13 @@ impl DockSizes {
|
||||
/// [`Action::ResizeIconic`] for an iconic one, which keeps its expanded width. Apply them together
|
||||
/// ([`Workspace::apply_all`](craft_behavior::dock::Workspace::apply_all)). Empty when the side has no dock or the
|
||||
/// columns already add up to the width; a column without panels keeps its width.
|
||||
pub fn resize_side<P: Clone + Eq + std::hash::Hash>(&self, layout: &Layout<P>, side: DockEdge, spec: &dyn Fn(&P) -> PanelSpec, total: f32) -> Vec<Action<P>> {
|
||||
pub fn resize_side<P: Clone + Eq + std::hash::Hash>(
|
||||
&self,
|
||||
layout: &Layout<P>,
|
||||
side: DockEdge,
|
||||
spec: &dyn Fn(&P) -> PanelSpec,
|
||||
total: f32,
|
||||
) -> Vec<Action<P>> {
|
||||
let columns = match layout.dock_path(side).and_then(|path| node_at(layout.root.as_ref()?, &path)) {
|
||||
Some(Node::Dock { columns, .. }) => columns,
|
||||
_ => return Vec::new(),
|
||||
|
||||
@@ -8,11 +8,12 @@ use super::words::WorkspaceDialogWords;
|
||||
use crate::choice::Checkbox;
|
||||
use crate::contract::{Bind, Entry, NoValue, Outcome, Props as _, Show as _, ShowContainer as _};
|
||||
use crate::display::{Shade, Text};
|
||||
use crate::form::{Field, FieldGroup, Help};
|
||||
use crate::form::{Field, Help};
|
||||
use crate::patterns::form_dialogs::FormDialog;
|
||||
use crate::pickers::Select;
|
||||
use crate::runtime::env::{Env, Label};
|
||||
use crate::runtime::overlay::CloseReason;
|
||||
use crate::sections::GroupBox;
|
||||
use crate::style::TypeRole;
|
||||
use crate::text::TextField;
|
||||
use craft_behavior::dock::{WorkspaceError, WorkspaceKeeps, WorkspaceSet};
|
||||
@@ -102,7 +103,7 @@ impl<'a, P: Clone + Eq + Hash> NewWorkspaceDialog<'a, P> {
|
||||
});
|
||||
if offered != WorkspaceKeeps::NONE {
|
||||
let keeps = &mut value.keeps;
|
||||
FieldGroup::new(words.capture.clone()).show(ui, |ui, _| {
|
||||
GroupBox::new(words.capture.clone(), None).show(ui, |ui, _| {
|
||||
Text::new(words.capture_note.clone()).role(TypeRole::Caption).shade(Shade::Muted).show(ui);
|
||||
let boxes = [
|
||||
(offered.shortcuts, &words.shortcuts, &mut keeps.shortcuts),
|
||||
|
||||
@@ -36,7 +36,8 @@ fn default_heights_give_way_to_the_group_that_fills_before_it_gets_less() {
|
||||
fn end_dock_layout() -> Layout<u32> {
|
||||
let mut iconic = Column::new(vec![Group::new(vec![4], 0)]).with_width(300.0);
|
||||
iconic.iconic = true;
|
||||
let columns = vec![Column::new(vec![Group::new(vec![2], 0)]).with_width(250.0), Column::new(vec![Group::new(vec![3], 0)]).with_width(250.0), iconic];
|
||||
let columns =
|
||||
vec![Column::new(vec![Group::new(vec![2], 0)]).with_width(250.0), Column::new(vec![Group::new(vec![3], 0)]).with_width(250.0), iconic];
|
||||
Layout::new(Some(Node::split(Axis::X, SplitSize::Ratio(0.7), Node::tabs(vec![1], 0), Node::dock(DockEdge::End, columns))), Vec::new())
|
||||
}
|
||||
|
||||
@@ -63,10 +64,12 @@ fn a_dock_sides_total_width_scales_its_columns_within_their_bounds() {
|
||||
let spec: &dyn Fn(&u32) -> PanelSpec = &spec;
|
||||
let mut live = Workspace::new(end_dock_layout());
|
||||
let widths = |live: &Workspace<u32>| end_columns(&live.layout).iter().map(|column| sizes.width(column, spec)).collect::<Vec<f32>>();
|
||||
let within = |live: &Workspace<u32>| end_columns(&live.layout).iter().zip(widths(live)).all(|(column, width)| {
|
||||
let (lo, hi) = sizes.shown_bounds(column, spec);
|
||||
(lo - 0.01..=hi + 0.01).contains(&width)
|
||||
});
|
||||
let within = |live: &Workspace<u32>| {
|
||||
end_columns(&live.layout).iter().zip(widths(live)).all(|(column, width)| {
|
||||
let (lo, hi) = sizes.shown_bounds(column, spec);
|
||||
(lo - 0.01..=hi + 0.01).contains(&width)
|
||||
})
|
||||
};
|
||||
let start = widths(&live);
|
||||
|
||||
for total in [sum(&start) + 120.0, sum(&start) - 60.0] {
|
||||
|
||||
@@ -529,8 +529,8 @@ The dock model: the tree of splits over panel frames, the side of a group a drop
|
||||
- `pub fn new(anchor: Option<P>, placement: DockPlacement<P>) -> Self`. A location relative to `anchor` by `placement`, with no recorded sizes or siblings.
|
||||
- `craft_behavior::dock::MAX_DEPTH`: `pub const MAX_DEPTH: usize`. Limits are checked before cloning or recursively modifying an application layout.
|
||||
- `craft_behavior::dock::MAX_PANELS`: `pub const MAX_PANELS: usize`. Most panels a layout may hold. Larger layouts fail with [`DockError::LimitExceeded`](super::DockError::LimitExceeded).
|
||||
- `craft_behavior::dock::NamedWorkspace`: `pub struct NamedWorkspace<P> { pub id: String, pub name: String, pub layout: Workspace<P>, pub chrome: WorkspaceChrome, pub keeps_shortcuts: bool, pub keeps_menus: bool }`. One named workspace.
|
||||
- `pub fn new(id: impl Into<String>, name: impl Into<String>, layout: Workspace<P>) -> Self`. A workspace named `name` with the stable id `id`, showing every bar and keeping no shortcuts or menus.
|
||||
- `craft_behavior::dock::NamedWorkspace`: `pub struct NamedWorkspace<P> { pub id: String, pub name: String, pub layout: Workspace<P>, pub chrome: WorkspaceChrome, pub keeps: WorkspaceKeeps }`. One named workspace.
|
||||
- `pub fn new(id: impl Into<String>, name: impl Into<String>, layout: Workspace<P>) -> Self`. A workspace named `name` with the stable id `id`, showing every bar and capturing nothing beside the layout.
|
||||
- `craft_behavior::dock::Node`: `pub enum Node<P> { Split { axis: Axis, size: SplitSize, first: Box<Node<P>>, second: Box<Node<P>> }, Tabs { panels: Vec<P>, active: usize }, Stack { entries: Vec<StackEntry<P>> }, Dock { side: DockEdge, columns: Vec<Column<P>> } }`. A node of a layout tree.
|
||||
- `pub fn tabs(panels: Vec<P>, active: usize) -> Self`. A group of tabs with tab `active` selected.
|
||||
- `pub fn split(axis: Axis, size: SplitSize, first: Node<P>, second: Node<P>) -> Self`. Two children along `axis`, sharing the room by `size`.
|
||||
@@ -566,13 +566,18 @@ The dock model: the tree of splits over panel frames, the side of a group a drop
|
||||
- `pub fn apply_all(&mut self, actions: impl IntoIterator<Item = Action<P>>, locked: bool, permissions: impl Fn(&P) -> Permissions,) -> Result<Vec<P>, DockError>`. Apply every action in order, or none, as [`Self::apply`] does. Returns the panels the
|
||||
- `craft_behavior::dock::WorkspaceChrome`: `pub struct WorkspaceChrome { pub menu_bar: bool, pub tool_rail: bool, pub options_bar: bool, pub status_bar: bool }`. Chrome a workspace remembers beside the dock layout: which bars show. The default shows every bar.
|
||||
- `craft_behavior::dock::WorkspaceError`: `pub enum WorkspaceError { UnknownId, NameTaken, EmptyName, CurrentCannotBeDeleted }`. Why a [`WorkspaceSet`] edit was refused.
|
||||
- `craft_behavior::dock::WorkspaceKeeps`: `pub struct WorkspaceKeeps { pub shortcuts: bool, pub menus: bool, pub toolbar: bool }`. What a saved workspace captures beside the panel layout (the Capture boxes of New Workspace). The application
|
||||
- `pub const NONE: WorkspaceKeeps`. Captures nothing beside the layout.
|
||||
- `pub const ALL: WorkspaceKeeps`. Captures shortcuts, menus and toolbar.
|
||||
- `pub const fn new(shortcuts: bool, menus: bool, toolbar: bool) -> Self`. The keeps with shortcuts, menus and toolbar as given.
|
||||
- `craft_behavior::dock::WorkspaceSet`: `pub struct WorkspaceSet<P> { pub builtin: Vec<NamedWorkspace<P>>, pub saved: Vec<NamedWorkspace<P>>, pub current: String, pub locked: bool, pub edited: BTreeMap<String, Workspace<P>> }`. The app's workspaces: built-ins first, saved ones after, one current. It is a settings
|
||||
- `pub fn new(builtin: Vec<NamedWorkspace<P>>) -> Self`. A set of `builtin` workspaces with the first one current.
|
||||
- `pub fn current(&self) -> Option<&NamedWorkspace<P>>`. The current workspace, or `None` when `current` names none.
|
||||
- `pub fn find(&self, id: &str) -> Option<&NamedWorkspace<P>>`. The workspace with this id.
|
||||
- `pub fn layout(&self) -> Option<&Workspace<P>>`. The layout the current workspace shows: what it was left with, else its stored one.
|
||||
- `pub fn select(&mut self, id: &str, live: &mut Workspace<P>) -> Result<(), WorkspaceError>`. Switch to `id` and replace `live` with the layout it shows; the current workspace's live
|
||||
- `pub fn save(&mut self, name: &str, live: Workspace<P>, chrome: WorkspaceChrome) -> Result<String, WorkspaceError>`. Save `live` under `name` and make it current; a name a built-in has is refused. A saved
|
||||
- `pub fn check_name<'n>(&self, name: &'n str) -> Result<(&'n str, Option<&str>), WorkspaceError>`. Whether `name` can be saved: the trimmed name, and the id of the saved workspace it would replace (any case),
|
||||
- `pub fn save(&mut self, name: &str, live: Workspace<P>, chrome: WorkspaceChrome, keeps: WorkspaceKeeps) -> Result<String, WorkspaceError>`. Save `live` under `name`, capturing `keeps`, and make it current; [`check_name`](Self::check_name) refuses
|
||||
- `pub fn delete(&mut self, id: &str) -> Result<(), WorkspaceError>`. Delete a saved workspace; the current one can't be deleted (Photoshop greys it).
|
||||
- `pub fn reset(&mut self, live: &mut Workspace<P>) -> Result<(), WorkspaceError>`. Reset the current workspace: drop what it was left with and replace `live` with its stored
|
||||
- `craft_behavior::dock::ZoneSize`: `pub enum ZoneSize { Depth(f32), Fraction }`. How deep the side zones of a body are.
|
||||
|
||||
Reference in New Issue
Block a user