diff --git a/crates/ui-canvas/src/canvas_controls/mod.rs b/crates/ui-canvas/src/canvas_controls/mod.rs index b3445cfd4..0d0145a52 100644 --- a/crates/ui-canvas/src/canvas_controls/mod.rs +++ b/crates/ui-canvas/src/canvas_controls/mod.rs @@ -1,4 +1,5 @@ -//! The canvas controls: leaves a `Canvas` body shows (`#[component(canvas_control)]`). +//! The canvas controls: leaves a `Canvas` body shows (`#[component(canvas_control)]`), and the contextual task bar +//! (`TaskBar`), a pattern a canvas body shows over its document. mod words; diff --git a/crates/ui-canvas/src/canvas_controls/task_bar.rs b/crates/ui-canvas/src/canvas_controls/task_bar.rs index c6a1f8ddd..102426b0a 100644 --- a/crates/ui-canvas/src/canvas_controls/task_bar.rs +++ b/crates/ui-canvas/src/canvas_controls/task_bar.rs @@ -1,10 +1,27 @@ //! `TaskBar`: the contextual task bar over a canvas, hung below its anchor until the user moves it. -use crate::contract::{Bind, Inner}; -use crate::runtime::env::Label; +#[cfg(feature = "testing")] +mod stories; + +use super::CanvasControlWords; +use crate::bars::{Bar, BarKind}; +use crate::buttons::IconButton; +use crate::canvas::canvas_space; +use crate::contract::overlay::{Anchor, Place, PlacementChange, PlacementKind}; +use crate::contract::{ + Bind, BindMut, BodyCx, Common, Component, Container, ContainerProps, Cx, DragBand, HeaderRegion, Inner, Mount, NoValue, Outcome, Overlay, + Pad, PopupKind, Props as _, Role, Show as _, ShowContainer as _, Sizing, Trigger, +}; +use crate::display::Icon; +use crate::menu::{Menu, MenuItem}; +use crate::primitives::IconSpec; +use crate::runtime::env::{Env, Label}; +use crate::style::{ComponentStyle, StyleCx, SurfaceKind}; use craft_behavior::kurbo::Point; -use egui::{Rect, Response, Ui}; -use std::marker::PhantomData; +use craft_behavior::overlay::{Align, Side}; +use craft_behavior::{EditEvent, IconId, Metrics, Mixed, Sense}; +use egui::{Pos2, Rect, Response, Ui}; +use std::sync::Arc; /// Where the task bar sits: pinned or following its anchor, and where the user moved it. The one owner of the bar's /// place; the serde shape is PhotoCraft's, so saved preferences load unchanged, and a non-finite `at` counts as unset. @@ -18,17 +35,34 @@ pub struct TaskBarPlace { pub at: Option<[f32; 2]>, } +impl TaskBarPlace { + /// The bar's top left in `area` while it has a place; `None` while it follows its anchor. A non-finite `at` + /// counts as unset. + fn placed_in(&self, area: Rect) -> Option { + let [x, y] = self.at.filter(|at| at.iter().all(|v| v.is_finite()))?; + Some(Pos2::new(area.min.x + x, area.min.y + y)) + } +} + /// The contextual task bar: a movable modeless layer hung below the screen bounds of `anchor` while its place is /// unset, with a body of members and a More menu (Hide, Reset, Pin). One place, pin and Hide setting for Crop and /// Frame. +/// +/// - Place: centred under the anchor's bounds on screen, a section gap below them, following the anchor each pass. +/// Dragged by its grip (any free point of the bar), it stays where it is dropped and keeps its left edge while the +/// anchor moves or the bar grows; a press with no drag changes nothing. Pinned, it stays where it shows. +/// - Area: the bar shows inside `area` (the canvas rect): a move stays inside it, and a stored place outside it comes +/// back inside, its left and top edges winning where the bar does not fit. +/// - Menu: Hide bar reports `hide`; Reset bar position clears the place, so the bar follows its anchor again; Pin bar +/// position keeps it where it shows. +/// - Nothing shows outside a canvas, or while the anchor's bounds or `area` is not finite or `area` has no size. +/// - `place` is the caller's value (`Bind::bound`): the bar reads it before it shows and writes the pass's change +/// after. #[must_use = "show the task bar with `show`"] #[derive(crate::contract::Pattern, crate::contract::Props)] pub struct TaskBar<'a> { - #[allow(dead_code)] // P3(tools-w16): tl.T49 label: Label, - #[allow(dead_code)] // P3(tools-w16): tl.T49 anchor: &'a [Point], - #[allow(dead_code)] // P3(tools-w16): tl.T49 place: Bind<'a, TaskBarPlace>, } @@ -44,17 +78,64 @@ pub struct TaskBarOutput { pub rect: Rect, } +impl Outcome for TaskBarOutput { + type Value = NoValue; + + fn response(&self) -> &Response { + &self.response + } +} + /// The context the task bar's body gets. pub struct TaskBarCx<'a> { - marker: PhantomData<&'a mut ()>, + menu: &'a mut MoreMenu, } impl TaskBarCx<'_> { /// Places the More menu button here, before the members that follow it (the Crop bar puts Cancel and Done after /// it); without the call the button comes after the body. pub fn more_menu(&mut self, ui: &mut Ui) { - let _ = ui; - todo!("tl.T49") + self.menu.place(ui); + } +} + +/// A row of the More menu. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum MenuPick { + Hide, + Reset, + Pin, +} + +/// The More button and its menu, placed once per run of the bar's body. +struct MoreMenu { + words: Arc, + placed: bool, + pick: Option, +} + +impl MoreMenu { + /// Shows the button and its menu here unless this run of the body showed them already. + fn place(&mut self, ui: &mut Ui) { + if std::mem::replace(&mut self.placed, true) { + return; + } + let words = Arc::clone(&self.words); + let more = IconButton::new(IconId::new("more")).popup(PopupKind::Menu).label(words.task_bar_more.clone()).show(ui); + let mut pick = None; + let rows = [ + (MenuPick::Hide, "eye_off", &words.task_bar_hide), + (MenuPick::Reset, "reset", &words.task_bar_reset), + (MenuPick::Pin, "pin", &words.task_bar_pin), + ]; + let _ = Menu::new(words.task_bar_more.clone()).opened_by(&more, Trigger::Click).show(ui, |ui, _| { + for (row, icon, name) in rows { + if MenuItem::new(name.clone()).icon(IconSpec::svg(IconId::new(icon))).show(ui).ran { + pick = Some(row); + } + } + }); + self.pick = pick.or(self.pick); } } @@ -65,8 +146,179 @@ impl<'a> TaskBar<'a> { } /// Shows the bar inside `area`; `body` fills its members. - pub fn show(self, ui: &mut Ui, area: Rect, body: impl FnOnce(&mut Ui, &mut TaskBarCx<'_>) -> R) -> Inner { - let _ = (ui, area, body); - todo!("tl.T49") + pub fn show(self, ui: &mut Ui, area: Rect, mut body: impl FnMut(&mut Ui, &mut TaskBarCx<'_>) -> R) -> Inner { + let TaskBar { label, anchor, mut place } = self; + let env = Env::of(ui); + let words = env.words::(); + // The anchor maps through this pass's view, so the bar follows a scroll or zoom in the same pass. + let bounds = canvas_space(&env.view()).map_or(Rect::NOTHING, |space| { + anchor.iter().fold(Rect::NOTHING, |mut bounds, point| { + bounds.extend_with(space.view.to_screen(*point)); + bounds + }) + }); + let shows = bounds.is_finite() && area.is_finite() && area.is_positive(); + let held = match place.reborrow().get() { + Some(Mixed::Same(held)) => held, + _ => TaskBarPlace::default(), + }; + let hang = shows.then(|| hang_rect(bounds, env.tokens.space.gap.section)); + let layer = TaskBarLayer::new(label, words.task_bar_move.clone(), layer_overlay(&held, hang, area), shows); + let mut menu = MoreMenu { words: Arc::clone(&words), placed: false, pick: None }; + let mut shown = layer.show(ui, |ui, _| { + Bar::new(Label::Empty, BarKind::Tool).show(ui, |ui, _| { + menu.placed = false; + let inner = body(ui, &mut TaskBarCx { menu: &mut menu }); + menu.place(ui); + inner + }) + }); + let rect = shown.output.response.rect; + let pick = menu.pick; + if shows { + let moved = shown.output.moved.filter(|moved| moved.min != rect.min); + let next = settled(held, rect, area, moved, pick); + if next != held { + let word = match pick { + Some(MenuPick::Reset) => &words.task_bar_reset, + Some(MenuPick::Pin) => &words.task_bar_pin, + _ => &words.task_bar_move, + }; + let event = EditEvent::set(Mixed::Same(held), next, Arc::from(word.as_str()), None); + let _ = shown.settle(|cx, _| place.reborrow().write(cx, &event)); + } + } + let output = TaskBarOutput { response: shown.output.response, hide: pick == Some(MenuPick::Hide), rect }; + match shown.inner { + Some(bar) => Inner { output, inner: bar.inner, settle: bar.settle }, + None => Inner { output, inner: None, settle: None }, + } + } +} + +/// The rect the bar hangs below: the anchor's screen `bounds` grown by `gap` at the bottom. The overlay host keeps the +/// layer inside `Overlay::bounds`. +fn hang_rect(bounds: Rect, gap: f32) -> Rect { + Rect::from_min_max(bounds.min, Pos2::new(bounds.max.x, bounds.max.y + gap)) +} + +/// The layer the bar shows in: hung below `hang` while `held` has no place, at its place once it has one. A move stays +/// inside `area`. A bar that does not show (`hang` is `None`) gets a closed layer with no place. +fn layer_overlay(held: &TaskBarPlace, hang: Option, area: Rect) -> Overlay { + let overlay = Overlay::floating().modeless().movable(true).body_scroll(false); + let Some(hang) = hang else { return overlay }; + let overlay = overlay.bounds(area); + match held.placed_in(area) { + Some(at) => overlay.placed_at(at), + None => overlay.place(Place::anchored(Anchor::Rect(hang), Side::Below, Align::Center)), + } +} + +/// The place after a pass that showed the bar at `shown`. A move (`moved`, a rect other than `shown`) keeps the bar +/// where it was dropped; Reset clears the place; Pin, and a pinned bar with no place, keep the bar at `shown`. A +/// non-finite place is cleared. With no move and no pick, the place stays unchanged; the overlay host keeps the layer +/// inside the area. +fn settled(held: TaskBarPlace, shown: Rect, area: Rect, moved: Option, pick: Option) -> TaskBarPlace { + let offset = |rect: Rect| -> [f32; 2] { (rect.min - area.min).into() }; + let placed = held.placed_in(area).is_some(); + let mut next = TaskBarPlace { at: held.at.filter(|_| placed), ..held }; + if let Some(moved) = moved { + next.at = Some(offset(moved)); + } + match pick { + Some(MenuPick::Reset) => next = TaskBarPlace::default(), + Some(MenuPick::Pin) => next = TaskBarPlace { pinned: true, at: Some(offset(shown)) }, + Some(MenuPick::Hide) | None => {} + } + if next.pinned && next.at.is_none() { + next.at = Some(offset(shown)); + } + next +} + +/// The style of the task bar's layer: the surface comes from the container. +#[derive(Clone, Debug, Default, PartialEq, ComponentStyle)] +#[non_exhaustive] +pub struct TaskBarLayerStyle { + #[style(metrics)] + metrics: Metrics, +} + +/// What the task bar's layer reports: its response and the last move of this pass. +#[derive(Debug)] +struct TaskBarLayerOutput { + response: Response, + moved: Option, +} + +impl Outcome for TaskBarLayerOutput { + type Value = NoValue; + + fn response(&self) -> &Response { + &self.response + } +} + +/// The task bar's layer: a floating surface whose line starts with the grip and holds the bar. The move band lies +/// under the whole line, so the grip and every free point between the members move the layer. +#[derive(crate::contract::Component)] +#[component(container, unregistered)] +struct TaskBarLayer { + #[common] + common: Common, + #[container] + props: ContainerProps, + grip: Label, + /// Open while the bar shows; the caller shows the bar again each pass it wants it. + open: Bind<'static, bool>, + moved: Option, +} + +impl TaskBarLayer { + fn new(label: Label, grip: Label, overlay: Overlay, open: bool) -> Self { + let props = ContainerProps::new() + .mount(Mount::Layer(overlay)) + .surface(SurfaceKind::Floating) + .pad(Pad::None) + .sizing(Sizing::Content) + .header(HeaderRegion::new().band(DragBand::Move).inline(true)); + TaskBarLayer { common: Common::new(), props, grip, open: Bind::given(open), moved: None }.label(label).id_salt("task-bar") + } +} + +impl Component for TaskBarLayer { + const ROLE: Role = Role::GROUP; + const PARTS: bool = false; + const STOPS: bool = false; + type Style = TaskBarLayerStyle; + type Output = TaskBarLayerOutput; + + fn style(_: &StyleCx<'_>, _: TaskBarLayerStyleKey) -> TaskBarLayerStyle { + TaskBarLayerStyle::default() + } + + fn sense(&self) -> Sense { + Sense::empty() + } + + fn finish(self, cx: Cx<'_, Self>) -> TaskBarLayerOutput { + TaskBarLayerOutput { response: cx.response.clone(), moved: self.moved } + } +} + +impl Container for TaskBarLayer { + fn open(&mut self) -> Option> { + Some(self.open.reborrow()) + } + + /// The grip glyph, named for the move it offers. + fn header(&mut self, ui: &mut Ui, _: &mut BodyCx<'_>) { + let _ = Icon::new(IconSpec::svg(IconId::new("grip"))).label(self.grip.clone()).show(ui); + } + + fn placement_changed(&mut self, change: &PlacementChange) { + if change.kind == PlacementKind::Move { + self.moved = Some(change.rect); + } } } diff --git a/crates/ui-canvas/src/canvas_controls/task_bar/stories.rs b/crates/ui-canvas/src/canvas_controls/task_bar/stories.rs new file mode 100644 index 000000000..420e56235 --- /dev/null +++ b/crates/ui-canvas/src/canvas_controls/task_bar/stories.rs @@ -0,0 +1,51 @@ +//! Stories of `TaskBar`. + +use super::{TaskBar, TaskBarPlace}; +use crate::buttons::{Button, IconButton}; +use crate::canvas::testing::canvas_story::{StoryDocument, on_canvas}; +use crate::contract::{Bind, Props as _, Show as _}; +use crate::testing::{Drive, StoryData, StoryOutput, story}; +use craft_behavior::IconId; +use craft_behavior::kurbo::{Point, Vec2}; +use egui::Ui; + +/// The corners of a crop frame turned by a few degrees about the document's middle: the Crop tool hangs its bar from +/// them, so the bar sits under the frame's lowest corner. +fn turned_frame() -> [Point; 4] { + let centre = StoryDocument::STANDARD.centre(); + let (sin, cos) = 0.2_f64.sin_cos(); + [(-220.0, -130.0), (220.0, -130.0), (220.0, 130.0), (-220.0, 130.0)].map(|(x, y)| centre + Vec2::new(x * cos - y * sin, x * sin + y * cos)) +} + +/// The Crop tool's bar: three buttons, the More menu, then Cancel and Done after it. +#[story(TaskBar<'static>, covers = [], drive = Drive::Never)] +fn crop_bar(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + let corners = turned_frame(); + on_canvas(ui, |ui, area, _| { + let place = data.value("place", TaskBarPlace::default()); + TaskBar::new("Crop", &corners, Bind::bound(place)) + .show(ui, area, |ui, cx| { + for (icon, name) in [("rotate_ccw", "Rotate left"), ("rotate_cw", "Rotate right"), ("grid", "Overlay")] { + let _ = IconButton::new(IconId::new(icon)).label(name).show(ui); + } + cx.more_menu(ui); + let _ = Button::new("Cancel").show(ui); + let _ = Button::new("Done").show(ui); + }) + .output + }) +} + +/// A bar the user moved and pinned: it keeps its place near the canvas's top left while the frame stays where it is. +#[story(TaskBar<'static>, covers = [], drive = Drive::Never)] +fn placed_and_pinned(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + let corners = turned_frame(); + on_canvas(ui, |ui, area, _| { + let place = data.value("place", TaskBarPlace { pinned: true, at: Some([24.0, 24.0]) }); + TaskBar::new("Crop", &corners, Bind::bound(place)) + .show(ui, area, |ui, _| { + let _ = Button::new("Done").show(ui); + }) + .output + }) +} diff --git a/crates/ui-canvas/tests/it/canvas_controls/mod.rs b/crates/ui-canvas/tests/it/canvas_controls/mod.rs index ba9e9ac03..489a64a7f 100644 --- a/crates/ui-canvas/tests/it/canvas_controls/mod.rs +++ b/crates/ui-canvas/tests/it/canvas_controls/mod.rs @@ -7,3 +7,5 @@ mod grid; mod guides; mod marquee; + +mod task_bar; diff --git a/crates/ui-canvas/tests/it/canvas_controls/task_bar.rs b/crates/ui-canvas/tests/it/canvas_controls/task_bar.rs new file mode 100644 index 000000000..1a9bd02b4 --- /dev/null +++ b/crates/ui-canvas/tests/it/canvas_controls/task_bar.rs @@ -0,0 +1,136 @@ +//! The contextual task bar (N6): hung centred under its anchor's screen bounds, following the anchor until the grip +//! moves it, reset and pinned from its More menu, and kept inside the canvas area whatever place it is given. + +use craft_behavior::kurbo::{Point, Vec2 as DocVec}; +use craft_ui::buttons::Button; +use craft_ui::canvas_controls::{TaskBar, TaskBarPlace}; +use craft_ui::contract::{Bind, Show as _}; +use craft_ui::testing::canvas_story::on_canvas; +use craft_ui::testing::{Fixture, trial}; +use egui::{Rect, Vec2}; +use std::cell::RefCell; +use std::rc::Rc; + +const SLACK: f32 = 1.5; + +/// What the trial's canvas shows and what the bar reported in the last pass. +#[derive(Clone)] +struct Scene { + /// The anchor, in document points: a crop frame's corners. + anchor: Vec, + place: TaskBarPlace, + /// The anchor's bounds on screen. + bounds: Rect, + /// The canvas rect the bar is kept in. + area: Rect, + /// The bar's rect. + rect: Rect, +} + +/// A frame of the story document, moved by `by` document points. It lies high on the story canvas (360 points tall), +/// so the bar hangs below it after every move and drop the trial makes. +fn frame(by: DocVec) -> Vec { + [(120.0, 40.0), (520.0, 40.0), (520.0, 200.0), (120.0, 200.0)].into_iter().map(|(x, y)| Point::new(x, y) + by).collect() +} + +/// A canvas that shows the bar for the scene's anchor and place, with the More menu before a Done button. +fn fixture(scene: &Rc>) -> Fixture { + let shared = Rc::clone(scene); + let mut fixture = Fixture::new(move |ui| { + let _ = on_canvas(ui, |ui, area, view| { + let mut held = shared.borrow_mut(); + let scene = &mut *held; + scene.bounds = Rect::from_points(&scene.anchor.iter().map(|point| view.to_screen(*point)).collect::>()); + scene.area = area; + let shown = TaskBar::new("Crop", &scene.anchor, Bind::bound(&mut scene.place)).show(ui, area, |ui, cx| { + cx.more_menu(ui); + let _ = Button::new("Done").show(ui); + }); + scene.rect = shown.output.rect; + shown.output + }); + }); + fixture.room(Vec2::new(1120.0, 720.0)); + fixture +} + +fn seen(scene: &Rc>) -> Scene { + scene.borrow().clone() +} + +fn centred_under_anchor(scene: &Scene) -> bool { + (scene.rect.center().x - scene.bounds.center().x).abs() < SLACK && scene.rect.top() > scene.bounds.bottom() +} + +fn inside_area(scene: &Scene) -> bool { + scene.area.expand(SLACK).contains_rect(scene.rect) +} + +/// Opens the More menu and runs its row `row`. +fn pick(fixture: &mut Fixture, row: &str) { + let more = fixture.by_label("More options").expect("the bar has its More button"); + fixture.click(&more).settle(); + let row = fixture.by_label(row).expect("the More menu lists the row"); + fixture.click(&row).settle(); +} + +#[trial] +fn the_task_bar_follows_its_anchor_until_moved_and_stays_inside_the_area() { + let scene = Rc::new(RefCell::new(Scene { + anchor: frame(DocVec::ZERO), + place: TaskBarPlace::default(), + bounds: Rect::NOTHING, + area: Rect::NOTHING, + rect: Rect::NOTHING, + })); + let mut fixture = fixture(&scene); + fixture.settle(); + let first = seen(&scene); + assert!(first.rect.is_positive(), "the bar shows: {:?}", first.rect); + assert!(centred_under_anchor(&first), "centred below the anchor {:?}: {:?}", first.bounds, first.rect); + assert!(inside_area(&first), "inside the canvas {:?}: {:?}", first.area, first.rect); + + scene.borrow_mut().anchor = frame(DocVec::new(40.0, 30.0)); + fixture.settle(); + let followed = seen(&scene); + assert!(centred_under_anchor(&followed), "the bar follows the anchor {:?}: {:?}", followed.bounds, followed.rect); + assert!(followed.rect.center().x > first.rect.center().x, "it moved with the anchor"); + + // A press on the grip that does not drag leaves the bar on its anchor. + let grip = fixture.by_label("Move bar").expect("the grip is named"); + fixture.click(&grip).settle(); + assert_eq!(seen(&scene).place, TaskBarPlace::default(), "a click moves nothing"); + + let by = Vec2::new(-120.0, 60.0); + fixture.drag(&grip, by).settle(); + let dropped = seen(&scene); + assert!(dropped.place.at.is_some(), "the drag gave the bar a place"); + assert!((dropped.rect.min - (followed.rect.min + by)).length() < 2.0 * SLACK, "the bar stays where it was dropped: {:?}", dropped.rect); + + scene.borrow_mut().anchor = frame(DocVec::new(90.0, 10.0)); + fixture.settle(); + let kept = seen(&scene); + assert!((kept.rect.min - dropped.rect.min).length() < SLACK, "a moved bar keeps its left edge while the anchor moves: {:?}", kept.rect); + + pick(&mut fixture, "Reset bar position"); + let reset = seen(&scene); + assert_eq!(reset.place, TaskBarPlace::default(), "Reset clears the place"); + assert!(centred_under_anchor(&reset), "the bar follows its anchor again {:?}: {:?}", reset.bounds, reset.rect); + + pick(&mut fixture, "Pin bar position"); + let pinned = seen(&scene); + assert!(pinned.place.pinned && pinned.place.at.is_some(), "Pin keeps the place: {:?}", pinned.place); + scene.borrow_mut().anchor = frame(DocVec::new(-60.0, -40.0)); + fixture.settle(); + assert!((seen(&scene).rect.min - pinned.rect.min).length() < SLACK, "a pinned bar stays while the anchor moves"); + + scene.borrow_mut().place = TaskBarPlace { pinned: false, at: Some([f32::NAN, 0.0]) }; + fixture.settle(); + let unset = seen(&scene); + assert!(centred_under_anchor(&unset), "a non-finite place counts as unset: {:?}", unset.rect); + + scene.borrow_mut().place = TaskBarPlace { pinned: false, at: Some([1.0e30, -1.0e30]) }; + fixture.settle(); + let far = seen(&scene); + assert!(inside_area(&far), "a place far outside comes back inside {:?}: {:?}", far.area, far.rect); +} diff --git a/crates/ui-contract/icons/ATTRIBUTION.md b/crates/ui-contract/icons/ATTRIBUTION.md index 3292efbe9..085f8720a 100644 --- a/crates/ui-contract/icons/ATTRIBUTION.md +++ b/crates/ui-contract/icons/ATTRIBUTION.md @@ -11,7 +11,7 @@ Each folder holds only the files `icons.toml` lists, unchanged from the pinned s Carbon's licence file is the repository's root `LICENSE` (the icons package has none of its own). -Every set folder's files come from the npm package of the version in the table (`@phosphor-icons/core` 2.0.8, `lucide-static` 1.63.0, `@carbon/icons` 11.91.0, `@tabler/icons` 3.50.0), the same releases as the tags above. Phosphor files are `regular` weight, except `star-filled.svg` and `circle-filled.svg`, which are Phosphor's `fill` weight (`star-fill.svg`, `circle-fill.svg`), and `panel-right.svg`, which is Phosphor's `sidebar-simple` mirrored. +Every set folder's files come from the npm package of the version in the table (`@phosphor-icons/core` 2.0.8, `lucide-static` 1.63.0, `@carbon/icons` 11.91.0, `@tabler/icons` 3.50.0), the same releases as the tags above. Phosphor files are `regular` weight, except `star-filled.svg` and `circle-filled.svg`, which are Phosphor's `fill` weight (`star-fill.svg`, `circle-fill.svg`). `panel-left.svg` is Phosphor's `sidebar-simple` unchanged, and `panel-right.svg` is the same glyph mirrored. `phosphor/` also holds drawings made for the suite, for glyphs the pinned Phosphor release lacks. They follow Phosphor's regular style (256 view box, 16-unit round-capped strokes, some converted to filled outlines), take their shapes from PhotoCraft's glyphs, and carry the suite's own licence: @@ -23,3 +23,4 @@ Every set folder's files come from the npm package of the version in the table ( - `sync-lock`, `mark-in`, `mark-out`, `insert-clip`, `overwrite-clip`, `lift-clip`, `extract-clip` (the timeline's lock and edit glyphs, after Premiere Pro's), `keyframe-linear`, `keyframe-bezier`, `keyframe-auto-bezier`, `keyframe-hold`, `keyframe-ease-in`, `keyframe-ease-out` (keyframe nodes after After Effects' shapes: diamond, square for Bezier, circle for Auto Bezier) - `key-linear`, `key-linear-filled`, `key-hold`, `key-bezier`, `key-auto-bezier`, `key-continuous-bezier`, `key-ease-in`, `key-ease-out`, `keyframe-easy-ease` (the timeline's single keyframe marks and the graph editor's Easy Ease button, after FilmCraft's diamond, square and circle and After Effects' keys; solid shapes except the outline diamond and the rings) - `font-variable`, `scaling`, `slice-select`, `square-dashed-mouse-pointer`, `text-warp`, `triangle-right`, `type-mask`, `type-mask-vertical` +- `crop-overlay-*` (the crop overlay menu's glyphs), `text-align-top`, `text-align-middle`, `text-align-bottom` (the vertical type options), `dash-align-exact`, `dash-align-corners` (the dash alignment options) diff --git a/crates/ui-contract/icons/carbon/draggable.svg b/crates/ui-contract/icons/carbon/draggable.svg new file mode 100644 index 000000000..043c353d1 --- /dev/null +++ b/crates/ui-contract/icons/carbon/draggable.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/crates/ui-contract/icons/carbon/open-panel--left.svg b/crates/ui-contract/icons/carbon/open-panel--left.svg new file mode 100644 index 000000000..f9b685deb --- /dev/null +++ b/crates/ui-contract/icons/carbon/open-panel--left.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/crates/ui-contract/icons/carbon/pin.svg b/crates/ui-contract/icons/carbon/pin.svg new file mode 100644 index 000000000..2c8ac50f3 --- /dev/null +++ b/crates/ui-contract/icons/carbon/pin.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/crates/ui-contract/icons/icons.toml b/crates/ui-contract/icons/icons.toml index 380cd5352..94ac327cc 100644 --- a/crates/ui-contract/icons/icons.toml +++ b/crates/ui-contract/icons/icons.toml @@ -30,8 +30,10 @@ kind = "fill" base = true drawing_stroke_width = 16.0 stroke_drawings = [ - "adjustment-layer", "bandage-sparkle", "brush-replace", "clip-below", "clip-release", "convert-point", "dash-align-corners", - "dash-align-exact", "direct-select", "distribute-bottom", "distribute-hcenter", "distribute-horizontal", "distribute-left", + "adjustment-layer", "bandage-sparkle", "brush-replace", "clip-below", "clip-release", "convert-point", + "crop-overlay-diagonal", "crop-overlay-golden-ratio", "crop-overlay-golden-spiral", "crop-overlay-grid", + "crop-overlay-thirds", "crop-overlay-triangle", "dash-align-corners", "dash-align-exact", + "direct-select", "distribute-bottom", "distribute-hcenter", "distribute-horizontal", "distribute-left", "distribute-right", "distribute-top", "distribute-vcenter", "distribute-vertical", "eraser-background", "eraser-magic", "extract-clip", "font-similar", "fx", "gradient-angle", "gradient-diamond", "gradient-linear", "gradient-radial", "gradient-reflected", "insert-clip", "key-auto-bezier", "key-bezier", "key-continuous-bezier", @@ -42,7 +44,8 @@ stroke_drawings = [ "pen-curvature", "pen-delete-anchor", "pen-freeform", "quick-selection", "route-curved", "route-elbow", "route-straight", "stroke-align-center", "stroke-align-inside", "stroke-align-outside", "stroke-cap-butt", "stroke-cap-round", "stroke-cap-square", "stroke-join-bevel", "stroke-join-miter", "stroke-join-round", - "symmetry-diagonal", "symmetry-dual", "symmetry-horizontal", "symmetry-vertical", "sync-lock" + "symmetry-diagonal", "symmetry-dual", "symmetry-horizontal", "symmetry-vertical", "sync-lock", + "text-align-bottom", "text-align-middle", "text-align-top" ] [[set]] @@ -666,6 +669,52 @@ phosphor = "crop" carbon = "crop" tabler = "crop" +[[icon]] +name = "crop_overlay_thirds" +directional = false +phosphor = "crop-overlay-thirds" # drawn in Phosphor's style: no match in any set + +[[icon]] +name = "crop_overlay_grid" +directional = false +phosphor = "crop-overlay-grid" # drawn in Phosphor's style: no match in any set + +[[icon]] +name = "crop_overlay_diagonal" +directional = false +phosphor = "crop-overlay-diagonal" # drawn in Phosphor's style: no match in any set + +[[icon]] +name = "crop_overlay_triangle" +directional = false +phosphor = "crop-overlay-triangle" # drawn in Phosphor's style: no match in any set + +[[icon]] +name = "crop_overlay_golden_ratio" +directional = false +phosphor = "crop-overlay-golden-ratio" # drawn in Phosphor's style: no match in any set + +[[icon]] +name = "crop_overlay_golden_spiral" +directional = false +phosphor = "crop-overlay-golden-spiral" # drawn in Phosphor's style: no match in any set + +[[icon]] +name = "pin" +directional = false +lucide = "pin" +phosphor = "push-pin" +carbon = "pin" +tabler = "pin" + +[[icon]] +name = "grip" +directional = false +lucide = "grip-vertical" +phosphor = "dots-six-vertical" +carbon = "draggable" +tabler = "grip-vertical" + [[icon]] name = "diamond" directional = false @@ -1042,6 +1091,14 @@ phosphor = "panel-right" carbon = "open-panel--right" tabler = "layout-sidebar-right" +[[icon]] +name = "panel_left" +directional = false +lucide = "panel-left" +phosphor = "panel-left" +carbon = "open-panel--left" +tabler = "layout-sidebar" + [[icon]] name = "pen_add_anchor" directional = false @@ -1440,6 +1497,21 @@ lucide = "case-sensitive" phosphor = "text-t" # near: no capitals mark in Phosphor tabler = "letter-case" +[[icon]] +name = "text_align_top" +directional = false +phosphor = "text-align-top" # drawn in Phosphor's style: no match in any set + +[[icon]] +name = "text_align_middle" +directional = false +phosphor = "text-align-middle" # drawn in Phosphor's style: no match in any set + +[[icon]] +name = "text_align_bottom" +directional = false +phosphor = "text-align-bottom" # drawn in Phosphor's style: no match in any set + [[icon]] name = "ligature" directional = false diff --git a/crates/ui-contract/icons/lucide/grip-vertical.svg b/crates/ui-contract/icons/lucide/grip-vertical.svg new file mode 100644 index 000000000..08fef8a4d --- /dev/null +++ b/crates/ui-contract/icons/lucide/grip-vertical.svg @@ -0,0 +1,20 @@ + + + + + + + + + diff --git a/crates/ui-contract/icons/lucide/panel-left.svg b/crates/ui-contract/icons/lucide/panel-left.svg new file mode 100644 index 000000000..d1a918b8c --- /dev/null +++ b/crates/ui-contract/icons/lucide/panel-left.svg @@ -0,0 +1,16 @@ + + + + + diff --git a/crates/ui-contract/icons/lucide/pin.svg b/crates/ui-contract/icons/lucide/pin.svg new file mode 100644 index 000000000..81c8119f4 --- /dev/null +++ b/crates/ui-contract/icons/lucide/pin.svg @@ -0,0 +1,16 @@ + + + + + diff --git a/crates/ui-contract/icons/phosphor/crop-overlay-diagonal.svg b/crates/ui-contract/icons/phosphor/crop-overlay-diagonal.svg new file mode 100644 index 000000000..d436c448a --- /dev/null +++ b/crates/ui-contract/icons/phosphor/crop-overlay-diagonal.svg @@ -0,0 +1 @@ + diff --git a/crates/ui-contract/icons/phosphor/crop-overlay-golden-ratio.svg b/crates/ui-contract/icons/phosphor/crop-overlay-golden-ratio.svg new file mode 100644 index 000000000..e2003085f --- /dev/null +++ b/crates/ui-contract/icons/phosphor/crop-overlay-golden-ratio.svg @@ -0,0 +1 @@ + diff --git a/crates/ui-contract/icons/phosphor/crop-overlay-golden-spiral.svg b/crates/ui-contract/icons/phosphor/crop-overlay-golden-spiral.svg new file mode 100644 index 000000000..29124afcd --- /dev/null +++ b/crates/ui-contract/icons/phosphor/crop-overlay-golden-spiral.svg @@ -0,0 +1 @@ + diff --git a/crates/ui-contract/icons/phosphor/crop-overlay-grid.svg b/crates/ui-contract/icons/phosphor/crop-overlay-grid.svg new file mode 100644 index 000000000..d3e58a8fa --- /dev/null +++ b/crates/ui-contract/icons/phosphor/crop-overlay-grid.svg @@ -0,0 +1 @@ + diff --git a/crates/ui-contract/icons/phosphor/crop-overlay-thirds.svg b/crates/ui-contract/icons/phosphor/crop-overlay-thirds.svg new file mode 100644 index 000000000..573ca72af --- /dev/null +++ b/crates/ui-contract/icons/phosphor/crop-overlay-thirds.svg @@ -0,0 +1 @@ + diff --git a/crates/ui-contract/icons/phosphor/crop-overlay-triangle.svg b/crates/ui-contract/icons/phosphor/crop-overlay-triangle.svg new file mode 100644 index 000000000..0308778df --- /dev/null +++ b/crates/ui-contract/icons/phosphor/crop-overlay-triangle.svg @@ -0,0 +1 @@ + diff --git a/crates/ui-contract/icons/phosphor/dots-six-vertical.svg b/crates/ui-contract/icons/phosphor/dots-six-vertical.svg new file mode 100644 index 000000000..159b35bd8 --- /dev/null +++ b/crates/ui-contract/icons/phosphor/dots-six-vertical.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/crates/ui-contract/icons/phosphor/panel-left.svg b/crates/ui-contract/icons/phosphor/panel-left.svg new file mode 100644 index 000000000..0abec37f4 --- /dev/null +++ b/crates/ui-contract/icons/phosphor/panel-left.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/crates/ui-contract/icons/phosphor/push-pin.svg b/crates/ui-contract/icons/phosphor/push-pin.svg new file mode 100644 index 000000000..26dd7b80c --- /dev/null +++ b/crates/ui-contract/icons/phosphor/push-pin.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/crates/ui-contract/icons/phosphor/text-align-bottom.svg b/crates/ui-contract/icons/phosphor/text-align-bottom.svg new file mode 100644 index 000000000..57cc35f7c --- /dev/null +++ b/crates/ui-contract/icons/phosphor/text-align-bottom.svg @@ -0,0 +1 @@ + diff --git a/crates/ui-contract/icons/phosphor/text-align-middle.svg b/crates/ui-contract/icons/phosphor/text-align-middle.svg new file mode 100644 index 000000000..9480661c9 --- /dev/null +++ b/crates/ui-contract/icons/phosphor/text-align-middle.svg @@ -0,0 +1 @@ + diff --git a/crates/ui-contract/icons/phosphor/text-align-top.svg b/crates/ui-contract/icons/phosphor/text-align-top.svg new file mode 100644 index 000000000..c3c71ac6b --- /dev/null +++ b/crates/ui-contract/icons/phosphor/text-align-top.svg @@ -0,0 +1 @@ + diff --git a/crates/ui-contract/icons/tabler/grip-vertical.svg b/crates/ui-contract/icons/tabler/grip-vertical.svg new file mode 100644 index 000000000..0a6af2a5a --- /dev/null +++ b/crates/ui-contract/icons/tabler/grip-vertical.svg @@ -0,0 +1,20 @@ + + + + + + + + + \ No newline at end of file diff --git a/crates/ui-contract/icons/tabler/layout-sidebar.svg b/crates/ui-contract/icons/tabler/layout-sidebar.svg new file mode 100644 index 000000000..ce1674855 --- /dev/null +++ b/crates/ui-contract/icons/tabler/layout-sidebar.svg @@ -0,0 +1,16 @@ + + + + + \ No newline at end of file diff --git a/crates/ui-contract/icons/tabler/pin.svg b/crates/ui-contract/icons/tabler/pin.svg new file mode 100644 index 000000000..705bf43bf --- /dev/null +++ b/crates/ui-contract/icons/tabler/pin.svg @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/crates/ui-contract/src/contract/body/placement.rs b/crates/ui-contract/src/contract/body/placement.rs index 620291941..c2d28528f 100644 --- a/crates/ui-contract/src/contract/body/placement.rs +++ b/crates/ui-contract/src/contract/body/placement.rs @@ -28,7 +28,8 @@ impl Placement { /// The placement the caller of `overlay` gives, when it places the layer. fn given(overlay: &crate::contract::Overlay) -> Option { - overlay.placed.map(Placement::at).or_else(|| overlay.placed_at.map(Placement::at_pos)) + let kept = |rect: Rect| overlay.bounds.map_or(rect, |bounds| super::window::keep_inside(rect, bounds)); + overlay.placed.map(|rect| Placement::at(kept(rect))).or_else(|| overlay.placed_at.map(Placement::at_pos)) } /// The rect it names, taking the position and size it lacks from `rect`. @@ -43,8 +44,9 @@ pub(crate) fn placement_id(id: Id) -> Id { /// The one store of a layer's placement: the saved tier when `save` is set, else shown memory. A layer whose overlay /// is `placed` has the caller's rect instead: the slot reads it and writes nothing, since the caller owns the -/// placement and learns of the user's changes from `PlacementChange` reports. A layer hung from its anchor that the -/// user cannot move keeps only its size: each opening places it from its anchor at that size. +/// placement and learns of the user's changes from `PlacementChange` reports. A layer hung from its anchor keeps only +/// its size, whether or not the user can move it: each opening places it from its anchor at that size, and a caller +/// that keeps a moved layer where it was dropped places it (`placed_at`) from the change it was told of. pub(super) struct PlacementSlot<'s> { stage: &'s mut MemoryStage, id: Id, @@ -55,7 +57,7 @@ pub(super) struct PlacementSlot<'s> { impl<'s> PlacementSlot<'s> { pub(super) fn new(stage: &'s mut MemoryStage, id: Id, save: Option<&'s SaveKey>, overlay: &crate::contract::Overlay) -> Self { - let anchored = matches!(overlay.place, Place::Anchored { .. }) && !overlay.movable; + let anchored = matches!(overlay.place, Place::Anchored { .. }); PlacementSlot { stage, id, save, controlled: Placement::given(overlay), anchored } } @@ -115,8 +117,10 @@ pub(crate) fn shown_placement( let room = (screen.size() - Vec2::splat(2.0 * screen_inset)).max(Vec2::ZERO); let least = overlay.size_limits.min.min(room); let size = default.max(least).min(overlay.size_limits.max.unwrap_or(Vec2::INFINITY)).min(room); - let pos = placement.pos.map(Pos2::from).or(float.pos).unwrap_or_else(|| screen.center() - size / 2.0); - let pos = Pos2::new(pos.x.min(screen.right() - size.x).max(screen.left()), pos.y.min(screen.bottom() - size.y).max(screen.top())); + // The layer centres, and is kept, inside the screen cut to `bounds`; bounds that miss the screen leave it whole. + let region = overlay.bounds.map(|bounds| screen.intersect(bounds)).filter(|region| region.is_positive()).unwrap_or(screen); + let pos = placement.pos.map(Pos2::from).or(float.pos).unwrap_or_else(|| region.center() - size / 2.0); + let pos = super::window::keep_inside(Rect::from_min_size(pos, size), region).min; placement.pos = Some(pos.into()); placement.size = Some(size.into()); placement @@ -140,7 +144,7 @@ pub(super) fn measure_layer(props: &ContainerProps, id: Id, ui: &Ui) -> areas::L areas::layer_of(crate::runtime::overlay::layer_tier(ui.ctx(), overlay.rank), area) } Mount::FullWindow => { - areas::layer_of(crate::runtime::overlay::layer_tier(ui.ctx(), crate::contract::mount::full_window_overlay(props.focus).rank), area) + areas::layer_of(crate::runtime::overlay::layer_tier(ui.ctx(), crate::contract::Overlay::full_window(props.focus).rank), area) } _ => ui.layer_id(), } diff --git a/crates/ui-contract/src/contract/level_table.rs b/crates/ui-contract/src/contract/level_table.rs index 46d8a6c44..32b88db91 100644 --- a/crates/ui-contract/src/contract/level_table.rs +++ b/crates/ui-contract/src/contract/level_table.rs @@ -9,9 +9,12 @@ use super::level::Surface::{self, Canvas, Chrome, Own}; /// `(crate target, type name, surface)`, sorted by crate target and name. pub(super) const SURFACES: &[(&str, &str, Surface)] = &[ + ("craft_color", "ColorHud", Canvas), ("craft_color", "ColorSamplerMarks", Canvas), ("craft_color", "EyedropperBar", Chrome), + ("craft_color", "SampleSizeSelect", Chrome), ("craft_draw", "AddBesideHandles", Canvas), + ("craft_draw", "ArrowheadsPopover", Chrome), ("craft_draw", "ArtboardOverlay", Canvas), ("craft_draw", "BezierOverlay", Canvas), ("craft_draw", "ConnectorHandles", Canvas), @@ -19,20 +22,28 @@ pub(super) const SURFACES: &[(&str, &str, Surface)] = &[ ("craft_draw", "CropBar", Chrome), ("craft_draw", "CropOptionsMenu", Chrome), ("craft_draw", "CropOverlayMenu", Chrome), + ("craft_draw", "CropPresetList", Chrome), ("craft_draw", "GradientOverlay", Canvas), + ("craft_draw", "PaintBar", Chrome), ("craft_draw", "PathOptionsPopover", Canvas), + ("craft_draw", "PerspectiveCropBar", Chrome), ("craft_draw", "PerspectiveCropQuad", Canvas), ("craft_draw", "RulerOverlay", Canvas), + ("craft_draw", "ShapeMenu", Chrome), ("craft_draw", "SliceOverlay", Canvas), + ("craft_draw", "StrokeCells", Chrome), ("craft_draw", "SymmetryHandles", Canvas), ("craft_draw", "SymmetryOverlay", Canvas), ("craft_draw", "TransformBox", Canvas), ("craft_draw", "TransformFields", Chrome), ("craft_draw", "TransformOverlay", Canvas), + ("craft_draw", "VectorModeSelect", Chrome), ("craft_imaging", "BlurPinsOverlay", Canvas), ("craft_imaging", "ClippingOverlay", Canvas), + ("craft_imaging", "ColorRangeDialog", Own), ("craft_imaging", "ConstraintLines", Canvas), ("craft_imaging", "ContentAwareFillWorkspace", Canvas), + ("craft_imaging", "CylinderWarp", Canvas), ("craft_imaging", "FillBar", Chrome), ("craft_imaging", "FilterGalleryWorkspace", Own), ("craft_imaging", "LassoLine", Canvas), @@ -42,6 +53,7 @@ pub(super) const SURFACES: &[(&str, &str, Surface)] = &[ ("craft_imaging", "OutlineTrace", Canvas), ("craft_imaging", "PerspectiveWarp", Canvas), ("craft_imaging", "PinWarp", Canvas), + ("craft_imaging", "RawDevelopWorkspace", Own), ("craft_imaging", "SelectMaskBar", Chrome), ("craft_imaging", "SelectMaskWorkspace", Canvas), ("craft_imaging", "SelectionOverlay", Canvas), @@ -58,10 +70,13 @@ pub(super) const SURFACES: &[(&str, &str, Surface)] = &[ ("craft_pages", "PagePictures", Canvas), ("craft_pages", "TextFrameMarks", Canvas), ("craft_pages", "TextMarks", Canvas), + ("craft_print", "PrintDialog", Own), ("craft_review", "AnnotationOverlay", Canvas), ("craft_review", "CommentPins", Canvas), ("craft_review", "RemoteCursor", Canvas), ("craft_review", "RemoteCursors", Canvas), + ("craft_text", "PathTextMarkers", Canvas), + ("craft_text", "TypeBar", Chrome), ("craft_ui", "AboutDialog", Own), ("craft_ui", "Alert", Own), ("craft_ui", "AppShell", Own), @@ -107,6 +122,7 @@ pub(super) const SURFACES: &[(&str, &str, Surface)] = &[ ("craft_ui", "NavigatorZoomRow", Canvas), ("craft_ui", "NewGuideDialog", Own), ("craft_ui", "NoticeCenter", Canvas), + ("craft_ui", "OpeningCard", Own), ("craft_ui", "PaneArea", Own), ("craft_ui", "PaneFrame", Own), ("craft_ui", "Panel", Own), @@ -116,6 +132,7 @@ pub(super) const SURFACES: &[(&str, &str, Surface)] = &[ ("craft_ui", "PasswordDialog", Own), ("craft_ui", "Pasteboard", Canvas), ("craft_ui", "PixelGrid", Canvas), + ("craft_ui", "PresetManager", Own), ("craft_ui", "PreviewPane", Own), ("craft_ui", "PreviewZoom", Own), ("craft_ui", "Prompt", Own), @@ -125,9 +142,11 @@ pub(super) const SURFACES: &[(&str, &str, Surface)] = &[ ("craft_ui", "ReportDialog", Own), ("craft_ui", "RotateView", Canvas), ("craft_ui", "Rulers", Canvas), + ("craft_ui", "ScreenModeButton", Chrome), ("craft_ui", "SelectionOutline", Canvas), ("craft_ui", "ShellRegion", Own), ("craft_ui", "SmartGuides", Canvas), + ("craft_ui", "SourceMarker", Canvas), ("craft_ui", "SplitArea", Own), ("craft_ui", "SplitViews", Canvas), ("craft_ui", "Splitter", Own), @@ -136,6 +155,8 @@ pub(super) const SURFACES: &[(&str, &str, Surface)] = &[ ("craft_ui", "StartScreen", Own), ("craft_ui", "StatusReadout", Chrome), ("craft_ui", "StraightLinePreview", Canvas), + ("craft_ui", "StrokeTrail", Canvas), + ("craft_ui", "TaskBar", Canvas), ("craft_ui", "TipCell", Canvas), ("craft_ui", "TitleBar", Chrome), ("craft_ui", "ToolRail", Chrome),