mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 05:37:04 +00:00
Contract stubs: craft-ui-canvas craft-ui-shell
This commit is contained in:
@@ -175,7 +175,7 @@ impl Rules {
|
||||
if corner && !lines.is_empty() && self.hold(mods) != AspectHold::Free {
|
||||
// The reach at the press view: the rule `Snap::at` sets the tolerance with; a crop drag never
|
||||
// changes the zoom.
|
||||
let Some(reach) = snap_tolerance(drag.press_view.as_ref().unwrap_or(view), mods, self.os, false) else {
|
||||
let Some(reach) = snap_tolerance(drag.press_view.as_ref().unwrap_or(view), mods, self.os, snap.options().suspend, false) else {
|
||||
return (to, Vec::new());
|
||||
};
|
||||
match slid_along(point, point - candidate.center(), lines, reach) {
|
||||
|
||||
@@ -171,9 +171,26 @@ pub struct CropOverlay<'a> {
|
||||
/// Nothing is painted and a press anywhere on the canvas draws a new frame.
|
||||
#[prop(flag)]
|
||||
hidden: bool,
|
||||
/// What the crop is bounded by: the document, or one placed picture's source.
|
||||
#[prop]
|
||||
scope: CropScope,
|
||||
report: Report,
|
||||
}
|
||||
|
||||
/// What a crop is of.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub enum CropScope {
|
||||
/// The document.
|
||||
#[default]
|
||||
Document,
|
||||
/// One placed picture, bounded by its source.
|
||||
Object {
|
||||
/// The picture's source rectangle, in document units; it bounds the drag rules.
|
||||
source: DocRect,
|
||||
},
|
||||
}
|
||||
|
||||
impl<'a> CropOverlay<'a> {
|
||||
/// An overlay named `label` over `crop`. A mixed value shows the whole document.
|
||||
pub fn new(label: impl Into<Label>, crop: Bind<'a, CropBox>) -> Self {
|
||||
@@ -192,6 +209,7 @@ impl<'a> CropOverlay<'a> {
|
||||
auto_center: false,
|
||||
fills_uncovered: false,
|
||||
hidden: false,
|
||||
scope: CropScope::default(),
|
||||
report: Report::default(),
|
||||
}
|
||||
.label(label)
|
||||
|
||||
@@ -26,7 +26,7 @@ mod tool_groups;
|
||||
mod tool_host;
|
||||
|
||||
pub use crate::canvas_data::{Guide, GuideColor, GuideDrag, GuideKey, GuideLine, NavigatorOptions, NavigatorSettings, ProxyColor};
|
||||
pub use crop::{CropOverlay, CropOverlayOutput, CropShield, CropStyle, ShieldColor, paint_outside};
|
||||
pub use crop::{CropOverlay, CropOverlayOutput, CropScope, CropShield, CropStyle, ShieldColor, paint_outside};
|
||||
pub use frame_step::{FRAME_STEP_MAX, frame_step};
|
||||
pub(crate) use march::{MARCH_SECONDS, MARCH_TICK, march_shift};
|
||||
pub use readout::{ShowReadouts, hud, readout};
|
||||
@@ -37,7 +37,7 @@ pub use words::CanvasWords;
|
||||
pub use tool::tool_probe;
|
||||
pub use tool::{CanvasTool, NoTool, ToolAccess, ToolAction, ToolAnchor, ToolClaims, ToolContext, ToolKey, ToolPointer, ToolRegion, ViewEase};
|
||||
pub use tool_groups::{PickStep, tool_pick};
|
||||
pub use tool_host::{ContextRequest, StandInKey, ToolHost, ToolHostResponse, ToolInput, ToolReadout, ViewPan, tool_pass};
|
||||
pub use tool_host::{ContextRequest, ContextSource, StandInKey, ToolHost, ToolHostResponse, ToolInput, ToolReadout, ViewPan, tool_pass};
|
||||
|
||||
mod raster_source;
|
||||
pub use raster_source::{PixelRect, RasterSource};
|
||||
@@ -72,7 +72,8 @@ mod zoom_motion;
|
||||
|
||||
pub use momentary::{Momentary, MomentaryCommands, MomentaryTool};
|
||||
pub use navigate::{
|
||||
Autoscroll, FlickPan, NavigateBar, NavigateBarOutput, NavigationOptions, PageKey, TouchpadGlide, WheelAction, WheelInput, WheelNavigation, pan,
|
||||
Autoscroll, FlickPan, MiddleButton, NavigateBar, NavigateBarOutput, NavigationOptions, PageKey, TouchpadGlide, WheelAction, WheelInput,
|
||||
WheelNavigation, WheelScheme, pan,
|
||||
};
|
||||
pub use rotate::{RotateView, RotateViewOutput, RotateViewStyle, ViewTurn};
|
||||
pub use tools::{HandTool, LayerBounds, RotateViewTool, ViewCommands, ViewRequest, ViewTarget, ZoomTool};
|
||||
@@ -100,8 +101,10 @@ pub use navigator::NavigatorStyle;
|
||||
pub mod navigator_panel;
|
||||
|
||||
use crate::contract::{
|
||||
Bind, Common, Component, Container, ContainerProps, Cx, Focus as _, NoValue, Outcome, PaintUi, PartsCx, Pointer as _, Props as _, Role, Sizing,
|
||||
Bind, Common, Component, Container, ContainerProps, Cx, EditorHandle, Focus as _, NoValue, Outcome, PaintUi, PartsCx, Pointer as _, Props as _,
|
||||
Role, Sizing,
|
||||
};
|
||||
use crate::primitives::{EditorPurpose, ImeStamp};
|
||||
use crate::runtime::commands::{CommandSet as _, CommandState, Commands as _};
|
||||
use crate::runtime::env::Label;
|
||||
use crate::runtime::focus::KeyUse;
|
||||
@@ -112,10 +115,11 @@ use crate::style::{ComponentStyle, Stateful, StyleCx, SurfaceKind, SurfaceLook};
|
||||
use craft_behavior::geometry::crop::normalized_angle;
|
||||
use craft_behavior::kurbo::{Point, Rect as DocRect, Size};
|
||||
use craft_behavior::{
|
||||
CanvasTransform, CanvasView, EditEvent, HitLevel, HitPriority, HitShape, Intent, Metrics, Mixed, PartKey, PointerButton, PressPhase, PressState,
|
||||
Sense, WheelNotch,
|
||||
CanvasTransform, CanvasView, EditEvent, EditorInput, HitLevel, HitPriority, HitShape, Intent, Metrics, Mixed, PartKey, PointerButton, PressPhase,
|
||||
PressState, Sense, WheelNotch,
|
||||
};
|
||||
use egui::{Pos2, Rect, Response, Vec2};
|
||||
use egui::{Context, Pos2, Rect, Response, Vec2};
|
||||
use std::sync::Arc;
|
||||
use zoom_motion::{Steer, ViewMotion};
|
||||
|
||||
pub(crate) const BACKGROUND: PartKey = PartKey::new("background");
|
||||
@@ -196,6 +200,10 @@ pub struct Canvas<'a> {
|
||||
/// body that pages its document itself (a page view).
|
||||
#[prop]
|
||||
keys_to_body: bool,
|
||||
/// The canvas registers one editor part of this purpose: the part's widget is the component's focus holder and the
|
||||
/// input-method owner, and keys arrive as editor input.
|
||||
#[prop]
|
||||
editor: Option<EditorPurpose>,
|
||||
/// The rulers' units and zero point, published to the body in its [`CanvasSpace`].
|
||||
rulers: Option<CanvasRulers>,
|
||||
/// The snapping of the coordinates the pointer sets on this canvas (View > Snap To), as data over the document's
|
||||
@@ -274,6 +282,7 @@ impl<'a> Canvas<'a> {
|
||||
navigation: NavigationOptions::default(),
|
||||
show_rulers: false,
|
||||
keys_to_body: false,
|
||||
editor: None,
|
||||
pasteboard: PasteboardColor::Default,
|
||||
precise_cursors: false,
|
||||
rulers: None,
|
||||
@@ -556,6 +565,8 @@ impl<'a> Canvas<'a> {
|
||||
snap: self.snapped(cx.env.shell().os),
|
||||
document: self.document_size(),
|
||||
navigation: self.navigation,
|
||||
editor_input: Arc::from([]), // P3(canvas-w1): cv.K6
|
||||
editor: None, // P3(canvas-w1): cv.K6
|
||||
}
|
||||
}
|
||||
|
||||
@@ -583,6 +594,8 @@ pub struct CanvasOutput {
|
||||
/// target; the canvas shows the way there itself. [`ToolHost::run`] carries it in [`ToolHostResponse::view`]
|
||||
/// when no tool set a view, so an app with a tool host copies that one view.
|
||||
pub view: Option<CanvasView>,
|
||||
/// The mark of a running middle-button autoscroll, for captures.
|
||||
pub autoscroll: Option<Pos2>,
|
||||
}
|
||||
|
||||
impl CanvasOutput {
|
||||
@@ -617,9 +630,26 @@ pub struct ToolPass {
|
||||
pub(crate) snap: Option<Snap>,
|
||||
pub(crate) document: Option<Size>,
|
||||
pub(crate) navigation: NavigationOptions,
|
||||
/// The editor part's inputs of this pass, in the order they arrived; the body applies them to its own document.
|
||||
pub editor_input: Arc<[EditorInput]>,
|
||||
/// The editor part of this pass, through which the body reports its editor state; `None` without an editor.
|
||||
pub editor: Option<EditorHandle>,
|
||||
}
|
||||
|
||||
impl ToolPass {
|
||||
/// Notes the input-method receipt between the stamps `before` and `after` for the canvas's editor part; true when the
|
||||
/// stamps prove the engine applied it.
|
||||
pub fn ime_receipt(&self, ctx: &Context, before: ImeStamp, after: ImeStamp) -> bool {
|
||||
let _ = (ctx, before, after);
|
||||
todo!("cv.K7")
|
||||
}
|
||||
|
||||
/// Notes an input-method application change for the canvas's editor part.
|
||||
pub fn ime_application_change(&self, ctx: &Context) {
|
||||
let _ = ctx;
|
||||
todo!("cv.K7")
|
||||
}
|
||||
|
||||
/// `view` as the canvas keeps it: inside the document's edges with Overscroll off. The tool host passes a tool's
|
||||
/// view through it.
|
||||
pub(crate) fn clamped(&self, view: CanvasView) -> CanvasView {
|
||||
@@ -723,7 +753,7 @@ impl Component for Canvas<'_> {
|
||||
|
||||
fn finish(self, cx: Cx<'_, Self>) -> CanvasOutput {
|
||||
let pass = self.tool_pass(&cx);
|
||||
CanvasOutput { response: cx.response.clone(), press: pass.press, space: pass.space, view: pass.view }
|
||||
CanvasOutput { response: cx.response.clone(), press: pass.press, space: pass.space, view: pass.view, autoscroll: None }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
//! `MiddleAutoscroll`: the press, dead zone, mark and end of a middle-button autoscroll.
|
||||
|
||||
use egui::{Pos2, Vec2};
|
||||
|
||||
/// A middle click's autoscroll: the press, the dead zone, the mark and the end. The speed is the canvas's one autoscroll
|
||||
/// rule, `Autoscroll::step`.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
#[allow(dead_code)] // P3(canvas-w1): cv.K4
|
||||
pub(crate) struct MiddleAutoscroll {
|
||||
origin: Option<Pos2>,
|
||||
dragged: bool,
|
||||
last: Option<f64>,
|
||||
}
|
||||
|
||||
#[allow(dead_code)] // P3(canvas-w1): cv.K4
|
||||
impl MiddleAutoscroll {
|
||||
/// Starts the autoscroll with the mark at `at`.
|
||||
pub(crate) fn press(&mut self, at: Pos2) {
|
||||
let _ = (&mut *self, at);
|
||||
todo!("cv.K4")
|
||||
}
|
||||
|
||||
/// The view's step this pass for the pointer at `pointer`, `clock` being the pass clock in seconds.
|
||||
pub(crate) fn step(&mut self, pointer: Pos2, clock: f64) -> Vec2 {
|
||||
let _ = (&mut *self, pointer, clock);
|
||||
todo!("cv.K4")
|
||||
}
|
||||
|
||||
/// Ends the autoscroll.
|
||||
pub(crate) fn end(&mut self) {
|
||||
let _ = &mut *self;
|
||||
todo!("cv.K4")
|
||||
}
|
||||
|
||||
/// The mark's position while the autoscroll runs.
|
||||
pub(crate) fn mark(&self) -> Option<Pos2> {
|
||||
let _ = self;
|
||||
todo!("cv.K4")
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
//! `craft_behavior::canvas::zoom` and clamp to the [`ZoomLadder`](craft_behavior::ZoomLadder). With Overscroll off
|
||||
//! the caller clamps the result with the canvas's scroll limits.
|
||||
|
||||
mod autoscroll;
|
||||
mod bar;
|
||||
mod keys;
|
||||
mod options;
|
||||
@@ -13,9 +14,10 @@ mod options;
|
||||
mod stories;
|
||||
mod wheel;
|
||||
|
||||
pub(crate) use autoscroll::MiddleAutoscroll;
|
||||
pub use bar::{NavigateBar, NavigateBarOutput};
|
||||
pub use keys::PageKey;
|
||||
pub use options::NavigationOptions;
|
||||
pub use options::{MiddleButton, NavigationOptions, WheelScheme};
|
||||
pub use wheel::{WheelAction, WheelInput, WheelNavigation};
|
||||
|
||||
use super::frame_step;
|
||||
|
||||
@@ -1,6 +1,28 @@
|
||||
//! `NavigationOptions`: the user's navigation choices (Photoshop's Preferences, General, Tools and Enhanced Controls
|
||||
//! rows), which the app owns and hands to the navigation pieces and the view tools.
|
||||
|
||||
/// How the wheel navigates.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub enum WheelScheme {
|
||||
/// Photoshop's: the wheel scrolls, and Zoom with Scroll Wheel decides what zooms.
|
||||
#[default]
|
||||
Photoshop,
|
||||
/// A document's: Ctrl/Cmd+wheel zooms by zoom ladder rungs and Shift+wheel scrolls sideways.
|
||||
Document,
|
||||
}
|
||||
|
||||
/// What the middle button does on the canvas.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub enum MiddleButton {
|
||||
/// A middle drag pans.
|
||||
#[default]
|
||||
Pan,
|
||||
/// A middle click starts autoscroll and a middle drag pans.
|
||||
Autoscroll,
|
||||
}
|
||||
|
||||
/// The navigation choices, with Photoshop's defaults.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
@@ -28,6 +50,10 @@ pub struct NavigationOptions {
|
||||
pub trackpad_rotate: bool,
|
||||
/// Enhanced Controls, Enable Gestures: a touch screen's two-finger pinch and twist. On.
|
||||
pub touch_gestures: bool,
|
||||
/// How the wheel navigates. Photoshop's.
|
||||
pub wheel: WheelScheme,
|
||||
/// What the middle button does. A pan.
|
||||
pub middle_button: MiddleButton,
|
||||
}
|
||||
|
||||
impl Default for NavigationOptions {
|
||||
@@ -44,6 +70,8 @@ impl Default for NavigationOptions {
|
||||
pinch_zooms: true,
|
||||
trackpad_rotate: false,
|
||||
touch_gestures: true,
|
||||
wheel: WheelScheme::default(),
|
||||
middle_button: MiddleButton::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! The tick rule of a ruler: which values carry a tick and which of them are labelled.
|
||||
|
||||
use crate::primitives::TickRank;
|
||||
use crate::runtime::env::UnitKind;
|
||||
use craft_behavior::RulerUnits;
|
||||
use std::ops::RangeInclusive;
|
||||
|
||||
@@ -79,6 +80,14 @@ pub enum TickRule<'a> {
|
||||
Steps(StepLadder),
|
||||
}
|
||||
|
||||
impl TickRule<'static> {
|
||||
/// The rule for a ruler counting `kind`: Word's sixteenths for inches, `Metric` otherwise.
|
||||
pub fn of_unit(kind: UnitKind) -> TickRule<'static> {
|
||||
let _ = kind;
|
||||
todo!("cv.K12")
|
||||
}
|
||||
}
|
||||
|
||||
/// One tick of `ticks`.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
|
||||
@@ -176,12 +176,15 @@ pub struct CanvasScrollbars<'a> {
|
||||
/// horizontal bar or corner is shown.
|
||||
#[prop(flag)]
|
||||
vertical_only: bool,
|
||||
/// While the vertical thumb drags, the bars show this tip beside the thumb on the reading-start side.
|
||||
#[prop(into)]
|
||||
tip: Option<Label>,
|
||||
}
|
||||
|
||||
impl<'a> CanvasScrollbars<'a> {
|
||||
/// Scroll bars named `label` that edit `view`, a view over the document `document` (document units).
|
||||
pub fn new(label: impl Into<Label>, view: Bind<'a, CanvasView>, document: DocRect) -> Self {
|
||||
CanvasScrollbars { common: Common::new(), view, document, overscroll: false, vertical_only: false }.label(label)
|
||||
CanvasScrollbars { common: Common::new(), view, document, overscroll: false, vertical_only: false, tip: None }.label(label)
|
||||
}
|
||||
|
||||
/// Applies overscroll off to `view` over the document `doc`: the view can't leave the document's edges, and a
|
||||
@@ -312,7 +315,7 @@ impl Component for CanvasScrollbars<'_> {
|
||||
.into_iter()
|
||||
.any(|part| cx.part_if_declared(part).is_some_and(|result| result.hovered || result.press.phase.is_press()))
|
||||
});
|
||||
CanvasScrollbarsOutput { view: cx.edit_response(), over }
|
||||
CanvasScrollbarsOutput { view: cx.edit_response(), over, dragging: None }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,6 +327,8 @@ pub struct CanvasScrollbarsOutput {
|
||||
pub view: EditResponse<CanvasView>,
|
||||
/// The pointer is over a bar or dragging one: the canvas leaves it alone.
|
||||
pub over: bool,
|
||||
/// The thumb being dragged this pass.
|
||||
pub dragging: Option<Axis>,
|
||||
}
|
||||
|
||||
impl Deref for CanvasScrollbarsOutput {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! `Snap`: a canvas's snapping of a coordinate the pointer sets.
|
||||
|
||||
use crate::runtime::env::{AppValues, EnvValue, EnvView};
|
||||
use craft_behavior::geometry::{SNAP_PX, SnapLine, SnapOptions, SnapTargets};
|
||||
use craft_behavior::geometry::{SNAP_PX, SnapLine, SnapOptions, SnapSuspend, SnapTargets};
|
||||
use craft_behavior::kurbo::{Point, Vec2};
|
||||
use craft_behavior::{Axis, CanvasView};
|
||||
use craft_keymap::{Mods, Platform};
|
||||
@@ -27,16 +27,16 @@ pub struct Snap {
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
#[non_exhaustive]
|
||||
pub struct GestureSnap {
|
||||
/// Whether the gesture reads the Control key itself, so Control does not suspend snapping.
|
||||
pub reads_control: bool,
|
||||
/// Whether the gesture reads the suspend key itself, so that key does not suspend snapping.
|
||||
pub reads_suspend_key: bool,
|
||||
/// The kinds of target the gesture snaps to (an explicit Distort snaps its corners to guides only).
|
||||
pub kinds: craft_behavior::geometry::SnapKinds,
|
||||
}
|
||||
|
||||
impl GestureSnap {
|
||||
/// These options with the gesture reading Control itself when `reads_control`.
|
||||
pub fn reads_control(mut self, reads_control: bool) -> Self {
|
||||
self.reads_control = reads_control;
|
||||
/// These options with the gesture reading the suspend key itself when `reads_suspend_key`.
|
||||
pub fn reads_suspend_key(mut self, reads_suspend_key: bool) -> Self {
|
||||
self.reads_suspend_key = reads_suspend_key;
|
||||
self
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ impl Snap {
|
||||
/// `point` snapped on both axes to the targets of `gesture.kinds`, with the lines to draw; the input and no lines
|
||||
/// when snapping is off.
|
||||
pub fn point(&self, point: Point, mods: Mods, gesture: GestureSnap) -> (Point, Vec<SnapLine>) {
|
||||
let (at, lines) = match self.reach(mods, gesture.reads_control) {
|
||||
let (at, lines) = match self.reach(mods, gesture.reads_suspend_key) {
|
||||
Some(tolerance) => self.targets.snap_point_of(point, tolerance, gesture.kinds),
|
||||
None => (point, Vec::new()),
|
||||
};
|
||||
@@ -104,10 +104,10 @@ impl Snap {
|
||||
}
|
||||
|
||||
/// The snapping distance in document units for this pass, or `None` when snapping is off, the canvas has not given
|
||||
/// this snap its pass (`at`) or the Control key suspends it (unless `reads_control`): the one gate of
|
||||
/// this snap its pass (`at`) or the suspend key suspends it (unless `reads_key`): the one gate of
|
||||
/// `apply`, `point` and `rect`, and the reach a gesture's snapped lines were found with.
|
||||
pub fn reach(&self, mods: Mods, reads_control: bool) -> Option<f64> {
|
||||
self.tolerance.filter(|_| self.options.on && !snap_suspended(mods, self.os, reads_control))
|
||||
pub fn reach(&self, mods: Mods, reads_key: bool) -> Option<f64> {
|
||||
self.tolerance.filter(|_| self.options.on && !snap_suspended(mods, self.os, self.options.suspend, reads_key))
|
||||
}
|
||||
|
||||
/// The View > Snap To options this snap was built with.
|
||||
@@ -148,15 +148,16 @@ impl std::fmt::Debug for Snap {
|
||||
/// Whether the modifiers held now turn snapping off: the Control key (Control without ⌘ on macOS, Ctrl elsewhere)
|
||||
/// suspends it while held, Photoshop's rule, unless the gesture reads that key itself (`tool_reads_control`: off macOS
|
||||
/// Ctrl on a transform box corner distorts). Every snapped drag applies it, whatever its targets are.
|
||||
pub fn snap_suspended(mods: Mods, os: Platform, tool_reads_control: bool) -> bool {
|
||||
pub fn snap_suspended(mods: Mods, os: Platform, suspend: SnapSuspend, gesture_reads_key: bool) -> bool {
|
||||
let _ = suspend; // P3(canvas-w4): cv.K9
|
||||
let control = if os.is_mac() { mods.ctrl && !mods.cmd } else { mods.cmd };
|
||||
control && !tool_reads_control
|
||||
control && !gesture_reads_key
|
||||
}
|
||||
|
||||
/// How far, in document units under `view`, a dragged point still snaps to a target: [`SNAP_PX`] screen points, or
|
||||
/// `None` while [`snap_suspended`] holds.
|
||||
pub fn snap_tolerance(view: &CanvasView, mods: Mods, os: Platform, tool_reads_control: bool) -> Option<f64> {
|
||||
(!snap_suspended(mods, os, tool_reads_control)).then(|| view.doc_len(SNAP_PX as f32))
|
||||
pub fn snap_tolerance(view: &CanvasView, mods: Mods, os: Platform, suspend: SnapSuspend, gesture_reads_key: bool) -> Option<f64> {
|
||||
(!snap_suspended(mods, os, suspend, gesture_reads_key)).then(|| view.doc_len(SNAP_PX as f32))
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
|
||||
@@ -274,6 +274,18 @@ pub struct ContextRequest {
|
||||
pub mods: Mods,
|
||||
/// The momentary tool in effect at the press (a Space-held Hand).
|
||||
pub momentary: Option<MomentaryTool>,
|
||||
/// How the canvas menu was asked for: by the pointer or by a key.
|
||||
pub source: ContextSource,
|
||||
}
|
||||
|
||||
/// How the canvas menu was asked for.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub enum ContextSource {
|
||||
/// The secondary button was released.
|
||||
Pointer,
|
||||
/// The Menu key, Shift+F10 or the accessibility context-menu action.
|
||||
Key,
|
||||
}
|
||||
|
||||
/// A pan of the view, from [`ToolHostResponse::pan`].
|
||||
@@ -1165,7 +1177,8 @@ impl<'a, 't: 'a> Run<'a, 't> {
|
||||
fn menu_key(&mut self) {
|
||||
let Some(space) = self.space else { return };
|
||||
if space.background().context_key && self.response.context.is_none() {
|
||||
self.response.context = Some(ContextRequest { at: space.view.rect.center(), mods: self.mods, momentary: self.momentary });
|
||||
self.response.context =
|
||||
Some(ContextRequest { at: space.view.rect.center(), mods: self.mods, momentary: self.momentary, source: ContextSource::Key });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1257,7 +1270,7 @@ impl<'a, 't: 'a> Run<'a, 't> {
|
||||
if let (Some(asked), Some(at)) = (self.state.secondary.take(), context_click(press))
|
||||
&& (!asked.taken || press.phase.is_click())
|
||||
{
|
||||
self.response.context = Some(ContextRequest { at, mods: asked.mods, momentary: asked.momentary });
|
||||
self.response.context = Some(ContextRequest { at, mods: asked.mods, momentary: asked.momentary, source: ContextSource::Pointer });
|
||||
}
|
||||
}
|
||||
PressPhase::Cancel { reason, .. } => {
|
||||
|
||||
@@ -130,6 +130,9 @@ pub(crate) struct ViewMotion {
|
||||
pub(crate) animation: ZoomAnimation,
|
||||
/// What the tool host or the Navigator asked of the ease since the canvas's last pass.
|
||||
pub(crate) steer: Option<Steer>,
|
||||
/// The middle button's autoscroll.
|
||||
#[allow(dead_code)] // P3(canvas-w1): cv.K4
|
||||
pub(crate) autoscroll: super::navigate::MiddleAutoscroll,
|
||||
}
|
||||
|
||||
impl ViewMotion {
|
||||
|
||||
@@ -7,7 +7,7 @@ pub(super) mod stories;
|
||||
|
||||
use crate::canvas::{CanvasSpace, GuideLine, canvas_space};
|
||||
use crate::contract::{Access, Common, Component, Cx, MeasureCx, PaintUi, Props as _, Role};
|
||||
use crate::primitives::{GridInk, GridLook, GridStroke, grid_lines_with};
|
||||
use crate::primitives::{GridCrowding, GridInk, GridLook, GridStroke, grid_lines_with};
|
||||
use crate::runtime::env::Label;
|
||||
use crate::runtime::memory::Remember as _;
|
||||
use crate::style::{ComponentStyle, DataColor, StyleColor, StyleCx};
|
||||
@@ -115,6 +115,9 @@ pub struct CanvasGrid {
|
||||
/// Draws nothing while the view's device zoom (1 is 100 percent) is below this (VectorCraft's pixel grid: 6).
|
||||
#[prop(quantity = "device zoom")]
|
||||
min_zoom: Option<f64>,
|
||||
/// What the grid does when its lines come closer than the minimum step: `Thin` keeps it visible zoomed out.
|
||||
#[prop]
|
||||
crowding: GridCrowding,
|
||||
}
|
||||
|
||||
impl CanvasGrid {
|
||||
@@ -129,6 +132,7 @@ impl CanvasGrid {
|
||||
color: None,
|
||||
line: GridLine::Solid,
|
||||
min_zoom: None,
|
||||
crowding: GridCrowding::default(),
|
||||
}
|
||||
.label(label)
|
||||
}
|
||||
@@ -154,7 +158,7 @@ impl CanvasGrid {
|
||||
if !(extent.x0.is_finite() && extent.y0.is_finite() && extent.x1.is_finite() && extent.y1.is_finite()) {
|
||||
return GridLines::default();
|
||||
}
|
||||
GridLines::document(view, extent, self.spacing, self.origin, self.subdivisions)
|
||||
GridLines::document(view, extent, self.spacing, self.origin, self.subdivisions, self.crowding)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ pub use line_preview::{LineGuideStyle, StraightLinePreview};
|
||||
pub use marquee::{Marquee, MarqueeLook, MarqueeShape, MarqueeStyle, Run};
|
||||
pub use outline::{HoverMask, HoverOutline, HoverShape, OutlineStyle, SelectionOutline, SelectionOutlineLook, path_runs};
|
||||
pub use pixel_grid::{GridSegment, PixelGrid, PixelGridStyle};
|
||||
pub use task_bar::{TaskBar, TaskBarCx, TaskBarOutput, TaskBarPlace};
|
||||
pub use task_bar::{TaskBar, TaskBarCx, TaskBarDismiss, TaskBarKind, TaskBarOutput, TaskBarPlace};
|
||||
// End of canvas-controls-b.
|
||||
|
||||
// Brush overlays.
|
||||
|
||||
@@ -70,6 +70,37 @@ pub struct TaskBar<'a> {
|
||||
label: Label,
|
||||
anchor: &'a [Point],
|
||||
place: Bind<'a, TaskBarPlace>,
|
||||
/// Which bar this is: the task bar, or a bar over a selection.
|
||||
#[prop]
|
||||
kind: TaskBarKind,
|
||||
/// The side of the anchor the bar hangs on; `None` gives the kind's side: above for `Selection`, below for `Task`.
|
||||
#[prop]
|
||||
side: Option<Side>,
|
||||
/// What an outside press does to the bar.
|
||||
#[prop]
|
||||
dismiss: TaskBarDismiss,
|
||||
}
|
||||
|
||||
/// Which bar a [`TaskBar`] is.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub enum TaskBarKind {
|
||||
/// The contextual task bar, hung below its anchor.
|
||||
#[default]
|
||||
Task,
|
||||
/// A bar anchored above a selection.
|
||||
Selection,
|
||||
}
|
||||
|
||||
/// What an outside press does to a [`TaskBar`].
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub enum TaskBarDismiss {
|
||||
/// An outside press closes the bar.
|
||||
#[default]
|
||||
Close,
|
||||
/// The bar survives outside presses while its graphic is selected.
|
||||
Keep,
|
||||
}
|
||||
|
||||
/// What the task bar reports.
|
||||
@@ -82,6 +113,8 @@ pub struct TaskBarOutput {
|
||||
pub hide: bool,
|
||||
/// The bar's rect on screen.
|
||||
pub rect: Rect,
|
||||
/// The bar was closed by an outside press.
|
||||
pub closed: bool,
|
||||
}
|
||||
|
||||
impl Outcome for TaskBarOutput {
|
||||
@@ -148,12 +181,20 @@ impl MoreMenu {
|
||||
impl<'a> TaskBar<'a> {
|
||||
/// A bar named `label` hung below the screen bounds of `anchor` (document points) until `place` moves it.
|
||||
pub fn new(label: impl Into<Label>, anchor: &'a [Point], place: Bind<'a, TaskBarPlace>) -> Self {
|
||||
TaskBar { label: label.into(), anchor, place }
|
||||
TaskBar { label: label.into(), anchor, place, kind: TaskBarKind::Task, side: None, dismiss: TaskBarDismiss::Close }
|
||||
}
|
||||
|
||||
/// A bar named `label` anchored above or at `side` of a selection whose bounds are `anchor` (document points),
|
||||
/// flipped and clamped to fit.
|
||||
pub fn selection(label: impl Into<Label>, anchor: &'a [Point]) -> Self {
|
||||
let _ = (label.into(), anchor);
|
||||
todo!("cv.K13")
|
||||
}
|
||||
|
||||
/// Shows the bar inside `area`; `body` fills its members.
|
||||
pub fn show<R>(self, ui: &mut Ui, area: Rect, mut body: impl FnMut(&mut Ui, &mut TaskBarCx<'_>) -> R) -> Inner<TaskBarOutput, R> {
|
||||
let TaskBar { label, anchor, mut place } = self;
|
||||
let TaskBar { label, anchor, mut place, kind, side, dismiss } = self;
|
||||
let _ = (kind, side, dismiss); // P3(canvas-w8): cv.K13
|
||||
let env = Env::of(ui);
|
||||
let words = env.words::<CanvasControlWords>();
|
||||
// The anchor maps through this pass's view, so the bar follows a scroll or zoom in the same pass.
|
||||
@@ -194,7 +235,7 @@ impl<'a> TaskBar<'a> {
|
||||
let _ = shown.settle(|cx, _| place.reborrow().write(cx, &event));
|
||||
}
|
||||
}
|
||||
let output = TaskBarOutput { response: shown.output.response, hide: pick == Some(MenuPick::Hide), rect };
|
||||
let output = TaskBarOutput { response: shown.output.response, hide: pick == Some(MenuPick::Hide), rect, closed: false };
|
||||
match shown.inner {
|
||||
Some(bar) => Inner { output, inner: bar.inner, settle: bar.settle },
|
||||
None => Inner { output, inner: None, settle: None },
|
||||
|
||||
@@ -95,7 +95,7 @@ fn snap_targets_snap_points_and_boxes_unless_control_suspends() {
|
||||
assert_eq!(snap.apply(Axis::Y, 103.0, Mods::CTRL), 103.0);
|
||||
assert_eq!(snap.apply(Axis::Y, 103.0, Mods::CMD), 100.0);
|
||||
assert_eq!(
|
||||
snap.point(NEAR, Mods::CTRL, GestureSnap::default().reads_control(true)).0,
|
||||
snap.point(NEAR, Mods::CTRL, GestureSnap::default().reads_suspend_key(true)).0,
|
||||
Point::new(100.0, 200.0),
|
||||
"a gesture that reads Control keeps snapping"
|
||||
);
|
||||
|
||||
@@ -10,7 +10,7 @@ pub use self::dialogs::{ShellDialogsCx, WindowDialogs};
|
||||
use super::canvas_shell::slots as keys;
|
||||
use super::regions::{Claim, SlotSize, layout};
|
||||
use super::reveal::{Aim, Reveal, Tracking};
|
||||
use super::screen_mode::{ScreenMode, ScreenModeCommands, ScreenModeFollow};
|
||||
use super::screen_mode::{ScreenMode, ScreenModeCommands, ScreenModeFollow, ScreenModeSet};
|
||||
use super::words::ShellWords;
|
||||
use crate::contract::overlay::Resize;
|
||||
use crate::contract::{
|
||||
@@ -288,6 +288,12 @@ pub struct AppShell<'a, S> {
|
||||
/// The screen mode. Without a binding the shell keeps it, starting at `Standard`.
|
||||
#[prop]
|
||||
screen_mode: Bind<'a, ScreenMode>,
|
||||
/// Which screen modes the F key cycles through. The shell publishes it to its regions.
|
||||
#[prop]
|
||||
mode_set: ScreenModeSet,
|
||||
/// Whether the drop-down slot of a Focus window is shown. A body press edge or a mode change clears it.
|
||||
#[prop]
|
||||
dropped: Bind<'a, bool>,
|
||||
/// Whether the Tab reveal and the edge reveal work in body-only mode. Off for a presentation.
|
||||
#[prop]
|
||||
allow_reveal: bool,
|
||||
@@ -320,6 +326,8 @@ impl<'a, S> AppShell<'a, S> {
|
||||
embedded: false,
|
||||
content_room: None,
|
||||
screen_mode: Bind::kept(),
|
||||
mode_set: ScreenModeSet::default(),
|
||||
dropped: Bind::kept(),
|
||||
allow_reveal: true,
|
||||
edge_reveal: true,
|
||||
document_tabs: true,
|
||||
@@ -391,6 +399,12 @@ impl<'a, S> AppShell<'a, S> {
|
||||
self.place(PaneEdge::Start, slot, add)
|
||||
}
|
||||
|
||||
/// A page that, while `shown`, fills the window under a move band with the window's ends; dialogs run over it.
|
||||
pub fn page(mut self, shown: bool, add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a) -> Self {
|
||||
let _ = (&mut self, shown, add);
|
||||
todo!("ch.C5")
|
||||
}
|
||||
|
||||
/// A slot at the reading end, inside the ones added before it.
|
||||
pub fn end(self, slot: Slot, add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a) -> Self {
|
||||
self.place(PaneEdge::End, slot, add)
|
||||
@@ -430,6 +444,8 @@ impl<'a, S> AppShell<'a, S> {
|
||||
embedded,
|
||||
content_room,
|
||||
mut screen_mode,
|
||||
mode_set,
|
||||
dropped: _dropped, // P3(chrome-w1): ch.C3
|
||||
allow_reveal,
|
||||
edge_reveal,
|
||||
document_tabs,
|
||||
@@ -467,7 +483,7 @@ impl<'a, S> AppShell<'a, S> {
|
||||
let mut kept = cx.keep::<ShellState>().clone();
|
||||
|
||||
let name: Arc<str> = words.screen_mode.as_str().into();
|
||||
let (mode, changed) = kept.screen.follow(&ctx, cx, screen_mode.reborrow(), name, !embedded);
|
||||
let (mode, changed) = kept.screen.follow(&ctx, cx, screen_mode.reborrow(), name, !embedded, mode_set);
|
||||
if changed {
|
||||
kept.reveal.clear();
|
||||
}
|
||||
@@ -485,7 +501,8 @@ impl<'a, S> AppShell<'a, S> {
|
||||
|
||||
// Every shown slot's rect and the body's, before any slot runs. Slots that a reveal shows in body-only mode
|
||||
// cover the body.
|
||||
let visible: Vec<bool> = slots.iter().map(|placed| !bare && kept.reveal.shows(&placed.slot, placed.edge, only, allow_reveal)).collect();
|
||||
let visible: Vec<bool> =
|
||||
slots.iter().map(|placed| !bare && kept.reveal.shows(&placed.slot, placed.edge, only, allow_reveal, mode, false)).collect();
|
||||
// A pass with no title bar has no move band: the OS moves the window from nowhere in it.
|
||||
if !embedded && !slots.iter().zip(&visible).any(|(placed, shown)| placed.title && *shown) {
|
||||
super::title_bar::set_window_movable(&ctx, false);
|
||||
|
||||
@@ -27,17 +27,19 @@ mod screen_mode_button;
|
||||
pub use app_shell::{AppShell, AppShellOutput, ShellDialogsCx, ShellRegion, ShellRegionOutput, WindowDialogs};
|
||||
pub use canvas_shell::{CanvasPanel, CanvasPanelOutput, slots};
|
||||
pub use opening::{OpeningCard, OpeningCardOutput};
|
||||
pub use screen_mode::{ScreenMode, ScreenModeCommands};
|
||||
pub use screen_mode::{ScreenMode, ScreenModeCommands, ScreenModeSet};
|
||||
pub use screen_mode_button::{ScreenModeButton, ScreenModeButtonOutput};
|
||||
pub use words::ShellWords;
|
||||
|
||||
// Start screen and app windows.
|
||||
mod recent;
|
||||
mod recent_list;
|
||||
mod start;
|
||||
mod viewport_window;
|
||||
|
||||
pub use recent::{RecentFile, RecentSort, RecentView, Template, ThumbKey, sort_recent};
|
||||
pub use start::{StartAction, StartLink, StartLinkTarget, StartOutput, StartPinnedCommands, StartRecentCommands, StartScreen};
|
||||
pub use recent_list::RecentList;
|
||||
pub use start::{StartAction, StartLayout, StartLink, StartLinkTarget, StartOutput, StartPinnedCommands, StartRecentCommands, StartScreen};
|
||||
pub use viewport_window::{ViewportWindow, ViewportWindowOutput};
|
||||
|
||||
// Caption buttons: the four families' button, its slot layout and the icon-theme glyphs.
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
//! `RecentList`: the recent files as rows with their age and thumbnail.
|
||||
|
||||
use super::recent::{RecentFile, ThumbKey};
|
||||
use super::start::StartOutput;
|
||||
use crate::primitives::{ThumbSource, Thumbnails};
|
||||
use crate::runtime::env::Label;
|
||||
use egui::Ui;
|
||||
|
||||
/// The recent files as rows, with the commands of a recent file and its context menu.
|
||||
#[must_use = "show the list with `show`"]
|
||||
pub struct RecentList<'a> {
|
||||
recent: &'a [RecentFile],
|
||||
max_recent: usize,
|
||||
empty: Option<Label>,
|
||||
now: Option<i64>,
|
||||
thumbnails: Option<(&'a Thumbnails<ThumbKey>, &'a dyn ThumbSource<ThumbKey>)>,
|
||||
}
|
||||
|
||||
impl<'a> RecentList<'a> {
|
||||
/// A list of `recent` files.
|
||||
pub fn new(recent: &'a [RecentFile]) -> Self {
|
||||
RecentList { recent, max_recent: usize::MAX, empty: None, now: None, thumbnails: None }
|
||||
}
|
||||
|
||||
/// At most this many recent files show.
|
||||
#[must_use]
|
||||
pub fn max_recent(mut self, max_recent: usize) -> Self {
|
||||
self.max_recent = max_recent;
|
||||
self
|
||||
}
|
||||
|
||||
/// The text shown when there are no recent files.
|
||||
#[must_use]
|
||||
pub fn empty(mut self, empty: impl Into<Label>) -> Self {
|
||||
self.empty = Some(empty.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// The time the age lines count from, in seconds since the Unix epoch. Without it the rows show no age.
|
||||
#[must_use]
|
||||
pub fn now(mut self, now: Option<i64>) -> Self {
|
||||
self.now = now;
|
||||
self
|
||||
}
|
||||
|
||||
/// Rows ask `thumbnails.state(..)` for what they show; `source` gives each key's revision.
|
||||
pub fn thumbnails(mut self, thumbnails: &'a Thumbnails<ThumbKey>, source: &'a dyn ThumbSource<ThumbKey>) -> Self {
|
||||
self.thumbnails = Some((thumbnails, source));
|
||||
self
|
||||
}
|
||||
|
||||
/// Shows the rows and reports what the user did.
|
||||
pub fn show(self, ui: &mut Ui) -> StartOutput {
|
||||
let _ = (self.recent, self.max_recent, self.empty, self.now, self.thumbnails, ui);
|
||||
todo!("ch.C7")
|
||||
}
|
||||
}
|
||||
@@ -90,6 +90,16 @@ impl Slot {
|
||||
self
|
||||
}
|
||||
|
||||
/// Marks the slot as the screen bar: it shows in Focus and Immersive and claims room as a non-overlay claim.
|
||||
pub fn screen_bar(self) -> Self {
|
||||
todo!("ch.C3")
|
||||
}
|
||||
|
||||
/// Marks the slot as the drop-down slot of Focus: it shows while the shell's `dropped` flag is set.
|
||||
pub fn drops(self) -> Self {
|
||||
todo!("ch.C3")
|
||||
}
|
||||
|
||||
/// The name of the slot's AccessKit region ("Options", "Tools", "Status").
|
||||
pub fn label(mut self, label: impl Into<Label>) -> Self {
|
||||
self.label = Some(label.into());
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use crate::contract::PaneEdge;
|
||||
use crate::runtime::env::RevealEdge;
|
||||
use crate::runtime::frame::ChromeToggle;
|
||||
use crate::shell::Slot;
|
||||
use crate::shell::{ScreenMode, Slot};
|
||||
use egui::{Pos2, Rect, pos2};
|
||||
|
||||
/// The width of the strip along a window edge where the pointer reveals the edge's hidden slots.
|
||||
@@ -159,7 +159,8 @@ impl Reveal {
|
||||
|
||||
/// Whether `slot` on `edge` shows: its `visible` flag in normal mode; in body-only mode, if it reveals and a Tab
|
||||
/// or edge reveal shows it.
|
||||
pub(crate) fn shows(&self, slot: &Slot, edge: PaneEdge, only: bool, allow_reveal: bool) -> bool {
|
||||
pub(crate) fn shows(&self, slot: &Slot, edge: PaneEdge, only: bool, allow_reveal: bool, mode: ScreenMode, dropped: bool) -> bool {
|
||||
let _ = (mode, dropped); // P3(chrome-w1): ch.C3
|
||||
if !only {
|
||||
return slot.is_visible();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ use crate::contract::{BindMut, BodyCx};
|
||||
use crate::runtime::commands::Commands as _;
|
||||
use crate::runtime::egui::pass;
|
||||
use crate::runtime::windows::{WindowAction, WindowHost, os_of};
|
||||
use crate::style::SurfaceKind;
|
||||
use craft_behavior::{EditEvent, Mixed};
|
||||
use craft_host::target::{Os, WindowState};
|
||||
use egui::Context;
|
||||
@@ -22,9 +23,37 @@ pub enum ScreenMode {
|
||||
FullScreenWithMenuBar,
|
||||
/// The body only.
|
||||
FullScreen,
|
||||
/// The body only, with the screen bar; the surround is black.
|
||||
Focus,
|
||||
/// The body only, with the screen bar, filling the pages' canvas.
|
||||
Immersive,
|
||||
}
|
||||
|
||||
/// Which screen modes the F key cycles through. The shell publishes its set to its regions as an env value.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, craft_ui_macros::EnvValue)]
|
||||
#[env(style)]
|
||||
#[non_exhaustive]
|
||||
pub enum ScreenModeSet {
|
||||
/// Standard, Full Screen With Menu Bar and Full Screen.
|
||||
#[default]
|
||||
Panels,
|
||||
/// Standard, Full Screen With Menu Bar, Focus and Immersive; F11 gives Full Screen With Menu Bar.
|
||||
Document,
|
||||
}
|
||||
|
||||
impl ScreenModeSet {
|
||||
/// The modes the set cycles through, in order.
|
||||
pub fn modes(self) -> &'static [ScreenMode] {
|
||||
todo!("ch.C2")
|
||||
}
|
||||
}
|
||||
|
||||
impl ScreenMode {
|
||||
/// The surface around the body in this mode: `Some(Scrim)` for `Focus` only, `None` for every other mode.
|
||||
pub fn surround(self) -> Option<SurfaceKind> {
|
||||
todo!("ch.C2")
|
||||
}
|
||||
|
||||
/// Whether the shell shows the body only.
|
||||
pub fn body_only(self) -> bool {
|
||||
self == Self::FullScreen
|
||||
@@ -41,20 +70,24 @@ impl ScreenMode {
|
||||
}
|
||||
|
||||
/// The mode the F key selects: Standard, Full Screen With Menu Bar, Full Screen, Standard.
|
||||
pub fn next(self) -> Self {
|
||||
pub fn next(self, set: ScreenModeSet) -> Self {
|
||||
let _ = set; // P3(chrome-w1): ch.C2
|
||||
match self {
|
||||
Self::Standard => Self::FullScreenWithMenuBar,
|
||||
Self::FullScreenWithMenuBar => Self::FullScreen,
|
||||
Self::FullScreen => Self::Standard,
|
||||
Self::Focus | Self::Immersive => todo!("ch.C2"),
|
||||
}
|
||||
}
|
||||
|
||||
/// The mode Shift+F selects.
|
||||
pub fn previous(self) -> Self {
|
||||
pub fn previous(self, set: ScreenModeSet) -> Self {
|
||||
let _ = set; // P3(chrome-w1): ch.C2
|
||||
match self {
|
||||
Self::Standard => Self::FullScreen,
|
||||
Self::FullScreenWithMenuBar => Self::Standard,
|
||||
Self::FullScreen => Self::FullScreenWithMenuBar,
|
||||
Self::Focus | Self::Immersive => todo!("ch.C2"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,6 +107,12 @@ pub enum ScreenModeCommands {
|
||||
/// The body only.
|
||||
#[command(label = "Full Screen Mode", kind = "radio", group = "screen_mode", alias = "screenMode.fullScreen")]
|
||||
FullScreen,
|
||||
/// The body only, with the screen bar; the surround is black.
|
||||
#[command(label = "Focus Screen Mode", kind = "radio", group = "screen_mode")]
|
||||
Focus,
|
||||
/// The body only, with the screen bar, filling the pages' canvas.
|
||||
#[command(label = "Immersive Screen Mode", kind = "radio", group = "screen_mode")]
|
||||
Immersive,
|
||||
/// The next mode.
|
||||
#[command(label = "Cycle Screen Mode", default = "F", icon = "app_window")]
|
||||
Cycle,
|
||||
@@ -89,17 +128,21 @@ impl ScreenModeCommands {
|
||||
ScreenMode::Standard => ScreenModeCommands::Standard,
|
||||
ScreenMode::FullScreenWithMenuBar => ScreenModeCommands::FullScreenWithMenuBar,
|
||||
ScreenMode::FullScreen => ScreenModeCommands::FullScreen,
|
||||
ScreenMode::Focus => ScreenModeCommands::Focus,
|
||||
ScreenMode::Immersive => ScreenModeCommands::Immersive,
|
||||
}
|
||||
}
|
||||
|
||||
/// The mode the command leaves a window in that is in `current`.
|
||||
pub fn apply(self, current: ScreenMode) -> ScreenMode {
|
||||
pub fn apply(self, current: ScreenMode, set: ScreenModeSet) -> ScreenMode {
|
||||
match self {
|
||||
ScreenModeCommands::Standard => ScreenMode::Standard,
|
||||
ScreenModeCommands::FullScreenWithMenuBar => ScreenMode::FullScreenWithMenuBar,
|
||||
ScreenModeCommands::FullScreen => ScreenMode::FullScreen,
|
||||
ScreenModeCommands::Cycle => current.next(),
|
||||
ScreenModeCommands::CycleBack => current.previous(),
|
||||
ScreenModeCommands::Focus => ScreenMode::Focus,
|
||||
ScreenModeCommands::Immersive => ScreenMode::Immersive,
|
||||
ScreenModeCommands::Cycle => current.next(set),
|
||||
ScreenModeCommands::CycleBack => current.previous(set),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -132,6 +175,7 @@ impl ScreenModeFollow {
|
||||
mut bind: BindMut<'_, ScreenMode>,
|
||||
name: Arc<str>,
|
||||
os: bool,
|
||||
set: ScreenModeSet,
|
||||
) -> (ScreenMode, bool) {
|
||||
let before = match bind.read(cx) {
|
||||
Some(Mixed::Same(held)) => held,
|
||||
@@ -140,7 +184,7 @@ impl ScreenModeFollow {
|
||||
let last = self.applied;
|
||||
let mut mode = before;
|
||||
while let Some((command, _)) = cx.take_command::<ScreenModeCommands>() {
|
||||
mode = command.apply(mode);
|
||||
mode = command.apply(mode, set);
|
||||
}
|
||||
if os {
|
||||
mode = self.follow_window(ctx, mode);
|
||||
|
||||
@@ -104,6 +104,19 @@ pub enum StartAction {
|
||||
UnpinFolder(PathBuf),
|
||||
/// A template card was chosen; the string is [`Template::id`].
|
||||
UseTemplate(String),
|
||||
/// The "more templates" link: the app shows its template gallery.
|
||||
MoreTemplates,
|
||||
}
|
||||
|
||||
/// How the start screen is laid out.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub enum StartLayout {
|
||||
/// The recent files and templates as a gallery.
|
||||
#[default]
|
||||
Gallery,
|
||||
/// Word's greeting start page.
|
||||
Greeting,
|
||||
}
|
||||
|
||||
/// What a start screen pass reports.
|
||||
@@ -172,6 +185,15 @@ pub struct StartScreen<'a> {
|
||||
/// With no recent files, the Recent body is a drop card with this hint that opens a file on a click.
|
||||
#[prop(into)]
|
||||
drop_hint: Option<Label>,
|
||||
/// How the page is laid out.
|
||||
#[prop]
|
||||
layout: StartLayout,
|
||||
/// The page's heading.
|
||||
#[prop(into)]
|
||||
title: Option<Label>,
|
||||
/// The text of the link that fires [`StartAction::MoreTemplates`].
|
||||
#[prop(into)]
|
||||
more_templates: Option<Label>,
|
||||
}
|
||||
|
||||
/// A link on the start screen's rail.
|
||||
@@ -222,6 +244,9 @@ impl<'a> StartScreen<'a> {
|
||||
thumbnails: None,
|
||||
links: &[],
|
||||
drop_hint: None,
|
||||
layout: StartLayout::default(),
|
||||
title: None,
|
||||
more_templates: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,7 +366,9 @@ fn read_events<K: Clone, E>(events: Vec<CollectionEvent<K, E>>, lead: &mut Optio
|
||||
impl StartScreen<'_> {
|
||||
/// Shows the page across the available room and reports what the user did.
|
||||
pub fn show(self, ui: &mut Ui) -> StartOutput {
|
||||
let StartScreen { view, sort, recent, pinned, templates, max_recent, now, thumbnails, links, drop_hint } = self;
|
||||
let StartScreen { view, sort, recent, pinned, templates, max_recent, now, thumbnails, links, drop_hint, layout, title, more_templates } =
|
||||
self;
|
||||
let _ = (layout, title, more_templates); // P3(chrome-w2): ch.C7
|
||||
let env = Env::of(ui);
|
||||
let collator = env.collator();
|
||||
let words = env.words::<ShellWords>();
|
||||
|
||||
@@ -23,6 +23,7 @@ pub fn set_window_movable(ctx: &Context, movable: bool) {
|
||||
// The bar, its title and its two ends.
|
||||
mod bar;
|
||||
mod measure;
|
||||
mod page_band;
|
||||
mod style;
|
||||
mod title;
|
||||
|
||||
|
||||
@@ -35,6 +35,8 @@ pub struct TitleBarOutput {
|
||||
pub caption_clicked: Option<Caption>,
|
||||
/// The Close button was clicked. The bar never closes the window: the app runs its unsaved-documents path.
|
||||
pub close_requested: bool,
|
||||
/// The title was activated in this pass; only a title with an action can be.
|
||||
pub title_activated: bool,
|
||||
}
|
||||
|
||||
impl Outcome for TitleBarOutput {
|
||||
@@ -246,7 +248,7 @@ impl Component for TitleBar<'_> {
|
||||
}
|
||||
|
||||
fn finish(self, cx: Cx<'_, Self>) -> TitleBarOutput {
|
||||
TitleBarOutput { response: cx.response.clone(), caption_clicked: self.clicked, close_requested: self.close }
|
||||
TitleBarOutput { response: cx.response.clone(), caption_clicked: self.clicked, close_requested: self.close, title_activated: false }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
//! `PageBand`: the move band the shell's page shows over the window.
|
||||
|
||||
/// The band over a shown page that moves the window, with the window's ends.
|
||||
#[allow(dead_code)] // P3(chrome-w1): ch.C5
|
||||
pub(crate) struct PageBand;
|
||||
@@ -3,6 +3,7 @@
|
||||
use crate::contract::{BodyCx, Props as _, WordSetCx as _};
|
||||
use crate::display::{Elide, Text};
|
||||
use crate::layout::{Placed, arrange};
|
||||
use crate::runtime::env::Label;
|
||||
use crate::shell::{ShellWords, slots};
|
||||
use craft_behavior::Arrangement;
|
||||
use egui::{Rect, Ui, Vec2, vec2};
|
||||
@@ -30,6 +31,13 @@ impl Title {
|
||||
Title { text: text.into(), unsaved: true }
|
||||
}
|
||||
|
||||
/// Makes the title a focusable button named by the shown title, with `tooltip`. Without it the title is text.
|
||||
#[must_use]
|
||||
pub fn action(self, tooltip: impl Into<Label>) -> Self {
|
||||
let _ = (self, tooltip.into());
|
||||
todo!("ch.C6")
|
||||
}
|
||||
|
||||
/// The text shown: the title, followed by an asterisk while the document has unsaved changes.
|
||||
pub fn shown(&self, words: &ShellWords) -> String {
|
||||
if self.unsaved { words.unsaved_title.fill(&[("title", self.text.as_str())]) } else { self.text.clone() }
|
||||
|
||||
@@ -14,7 +14,7 @@ use craft_ui::testing::trial;
|
||||
use craft_ui::testing::windows::NoWindows;
|
||||
use craft_ui_test_kit::windows::Windows;
|
||||
use craft_window::policy::{Decision, Desktop, DesktopKind};
|
||||
use egui::{Pos2, Rect, Vec2, ViewportCommand, ViewportId, vec2};
|
||||
use egui::{Align2, Pos2, Rect, Vec2, ViewportCommand, ViewportId, vec2};
|
||||
use std::cell::Cell;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -39,7 +39,7 @@ fn a_modals_strip_stands_for_the_hit_sink() {
|
||||
bar.set(TitleBar::new().show_titled(ui, Title::new("Landscape.psd"), |_, _| {}, |_, _| {}).response.rect);
|
||||
let mut open = true;
|
||||
let shown = Dialog::new("Grid options")
|
||||
.first_place(at)
|
||||
.first_place(at, Align2::LEFT_TOP) // P3(chrome-w7): ch.C20b
|
||||
.opened(Bind::bound(&mut open))
|
||||
.buttons([FooterButton::new("OK", DialogRole::Accept), FooterButton::new("Cancel", DialogRole::Cancel)])
|
||||
.show(ui, |ui, _| {
|
||||
|
||||
Reference in New Issue
Block a user