Contract stubs: craft-ui-contract

This commit is contained in:
Dylan M. Taylor
2026-11-17 22:38:38 -05:00
parent f0275a082a
commit aafc82051e
38 changed files with 407 additions and 29 deletions
@@ -121,7 +121,9 @@ impl<C: Container> ShapeHooks<C> for BodyHooks<'_> {
fn key_role(&self, comp: &C) -> KeyRole {
let props = comp.props(Internal::new());
KeyRole::new().reorderable(props.header.is_some_and(|header| header.band == DragBand::Reorder)).document(props.scroll_owner)
KeyRole::new()
.reorderable(props.header.is_some_and(|header| header.band == DragBand::Reorder).then_some(craft_behavior::ReorderKeys::Stacking)) // P3(pdf-workflows-w1): WF-W4
.document(props.scroll_owner)
}
fn position(&self, comp: &C) -> Option<SetPosition> {
@@ -28,7 +28,9 @@ impl BodyHooks<'_> {
keys::capture(&ctx, id, chord);
}
while keys::take_claimed(&ctx, id, chord) {
if let Some(intent) = key_table::reorder_intent(chord.key, chord.mods) {
if let Some(intent) = key_table::reorder_intent(chord.key, chord.mods, craft_behavior::ReorderKeys::Stacking, craft_behavior::Axis::Y)
{
// P3(pdf-workflows-w1): WF-W3
cx.core.intents.push(intent);
}
}
@@ -34,12 +34,21 @@ pub struct ReorderRule {
/// In a tree, a drop or a stacking-key move may land inside a group, and `ReorderMove::parent` names the group. A row
/// that `has_children` is a group; an open group without visible children takes items through the middle of its row.
pub into_groups: bool,
/// The key scheme that reorders the collection's items; default `Stacking`.
pub keys: craft_behavior::ReorderKeys,
}
impl ReorderRule {
/// A rule that only moves.
pub const fn new() -> Self {
ReorderRule { copy_with_alt: false, into_groups: false }
ReorderRule { copy_with_alt: false, into_groups: false, keys: craft_behavior::ReorderKeys::Stacking }
}
/// The key scheme that reorders the items.
#[must_use]
pub const fn keys(mut self, keys: craft_behavior::ReorderKeys) -> Self {
self.keys = keys;
self
}
/// Items may land inside the groups of a tree.
@@ -229,6 +238,8 @@ pub struct CollectionProps {
pub command_click: bool,
/// The distance one wheel notch scrolls the rows; unset, the default notch.
pub notch: Option<Notch>,
/// What a middle press does: pan or latched auto-scroll.
pub middle_button: craft_behavior::MiddleButton,
/// The axis the rows overflow along. A collection owns the scroll along it, so it sits only in a scrolling body
/// that does not scroll along it too: a strip of tabs (`Axis::X`) sits in a page that scrolls vertically.
pub overflow: Axis,
@@ -320,6 +331,7 @@ impl CollectionProps {
row_height: RowHeight::Control,
command_click: false,
notch: None,
middle_button: craft_behavior::MiddleButton::Pan,
overflow: Axis::Y,
pages: false,
current: None,
@@ -567,6 +579,13 @@ impl CollectionProps {
self
}
/// What a middle press does: pan, or latched auto-scroll (see [`CollectionProps::middle_button`]).
#[must_use]
pub const fn middle_button(mut self, button: craft_behavior::MiddleButton) -> Self {
self.middle_button = button;
self
}
/// The wheel distance of one notch, with a text line `line` points high: the set notch, else the default.
pub fn wheel_notch(&self, line: f32) -> craft_behavior::WheelNotch {
self.notch.map_or(craft_behavior::WheelNotch::DEFAULT, |notch| notch.wheel(line))
@@ -31,6 +31,8 @@ pub struct CollectionResponse<K, E> {
/// While a drag is over the collection, the drop its release would make; `None` when the collection would take
/// none. An app previews it (a layer move on the canvas); the drop itself comes as its event.
pub pending_drop: Option<PendingDrop<K>>,
/// The row under the pointer this pass; `None` during a drag.
pub hovered: Option<K>,
}
/// The drop a release would make on a collection now.
@@ -46,7 +48,7 @@ pub enum PendingDrop<K> {
impl<K, E> CollectionResponse<K, E> {
pub(crate) fn new(
response: Response,
ItemsOut { events, shown, activation_clicks, pending_drop }: ItemsOut<K, E>,
ItemsOut { events, shown, activation_clicks, pending_drop, hovered }: ItemsOut<K, E>,
visible: Range<usize>,
gestures: Gestures,
) -> Self {
@@ -60,6 +62,7 @@ impl<K, E> CollectionResponse<K, E> {
reorder: gestures.reorder,
activation_clicks,
pending_drop,
hovered,
}
}
@@ -76,11 +79,12 @@ pub(crate) struct ItemsOut<K, E> {
pub(crate) shown: Vec<ShownRow<K>>,
pub(crate) activation_clicks: u8,
pub(crate) pending_drop: Option<PendingDrop<K>>,
pub(crate) hovered: Option<K>,
}
impl<K, E> Default for ItemsOut<K, E> {
fn default() -> Self {
ItemsOut { events: Vec::new(), shown: Vec::new(), activation_clicks: 0, pending_drop: None }
ItemsOut { events: Vec::new(), shown: Vec::new(), activation_clicks: 0, pending_drop: None, hovered: None }
}
}
@@ -184,6 +184,8 @@ pub enum LeastWidth {
DialogSideButton,
/// `size.rail.width` per column: a tool rail of this many columns, as wide as the shell slot that holds it.
Rail(std::num::NonZeroU8),
/// `size.dock.column`: a fixed side pane is as wide as a dock column.
DockColumn,
}
impl LeastWidth {
@@ -195,6 +197,7 @@ impl LeastWidth {
LeastWidth::DialogButton => tokens.size.dialog.button,
LeastWidth::DialogSideButton => tokens.size.dialog.side_button,
LeastWidth::Rail(columns) => tokens.size.rail.width * f32::from(columns.get()),
LeastWidth::DockColumn => tokens.size.dock.column,
}
}
}
+33 -1
View File
@@ -7,7 +7,7 @@ use crate::runtime::drag::{self, DragPreview, DropTarget, DropZone, Typed, Windo
use crate::runtime::egui::areas;
use crate::runtime::{cursor, frame, pointer, wheel};
use craft_behavior::{Cursor, CursorPriority, DropOperation, PartKey, PartRef, PressCancel, PressState, Wheel};
use egui::{Id, Pos2};
use egui::{Id, Pos2, Vec2};
use std::any::{Any, TypeId};
use std::ops::Range;
use std::sync::Arc;
@@ -35,6 +35,14 @@ pub trait Pointer {
fn activated_member(&self) -> Option<Id>;
/// This pass's wheel share, once, with the pointer it came at (`Wheel::at`) in this component's egui layer space (8.3).
fn take_wheel(&mut self) -> Option<Wheel>;
/// Marks the wheel gesture this component owns, while it runs, as moved (its view changed): later shares of the
/// gesture report `Wheel::moved`.
fn mark_wheel_moved(&mut self);
/// Feeds `pan`, the line pan this pass gave, to this component's wheel ease and returns the eased step for this
/// pass. `Vec2::ZERO` on a pass with no line pan lets owed motion keep paying.
fn ease_wheel(&mut self, pan: Vec2) -> Vec2;
/// Drops this component's wheel ease and the motion it owes.
fn stop_wheel_ease(&mut self);
/// Requests `cursor` at `priority`; the highest priority of the pass wins.
fn cursor(&mut self, cursor: impl Into<Cursor>, priority: CursorPriority);
/// Ends every captured press of this viewport.
@@ -107,6 +115,18 @@ impl Pointer for CxCore<'_> {
Some(wheel)
}
fn mark_wheel_moved(&mut self) {
wheel::mark_moved(&self.ctx, self.id);
}
fn ease_wheel(&mut self, pan: Vec2) -> Vec2 {
wheel::ease(&self.ctx, self.id, pan)
}
fn stop_wheel_ease(&mut self) {
wheel::stop_ease(&self.ctx, self.id);
}
fn cursor(&mut self, cursor: impl Into<Cursor>, priority: CursorPriority) {
if self.cursor.as_ref().is_none_or(|(_, held)| priority > *held) {
self.cursor = Some((cursor.into(), priority));
@@ -198,6 +218,18 @@ impl<C: Component> Pointer for Cx<'_, C> {
self.core.take_wheel()
}
fn mark_wheel_moved(&mut self) {
self.core.mark_wheel_moved();
}
fn ease_wheel(&mut self, pan: Vec2) -> Vec2 {
self.core.ease_wheel(pan)
}
fn stop_wheel_ease(&mut self) {
self.core.stop_wheel_ease();
}
fn cursor(&mut self, cursor: impl Into<Cursor>, priority: CursorPriority) {
self.core.cursor(cursor, priority);
}
+25 -1
View File
@@ -30,6 +30,8 @@ struct Item<T> {
icon: Option<IconSpec<'static>>,
enabled: bool,
reason: Option<Label>,
#[allow(dead_code)] // P3(pdf-print-ocr-w2): PO-P10
description: Option<Label>,
checked: bool,
stepped: bool,
}
@@ -38,7 +40,17 @@ impl<T> Entry<T> {
/// An entry reporting `value` when picked, shown as `label`: enabled and unchecked, without an icon.
pub fn new(value: T, label: impl Into<Label>) -> Self {
Entry {
row: Row::Item(Item { value, label: label.into(), closed: None, icon: None, enabled: true, reason: None, checked: false, stepped: true }),
row: Row::Item(Item {
value,
label: label.into(),
closed: None,
icon: None,
enabled: true,
reason: None,
description: None,
checked: false,
stepped: true,
}),
}
}
@@ -168,6 +180,18 @@ impl<T> Entry<T> {
matches!(&self.row, Row::Item(item) if item.enabled && item.stepped)
}
/// An enabled entry's hover text and accessible description, beside the reason a disabled entry shows.
#[must_use]
pub fn description(self, text: impl Into<Label>) -> Self {
let _ = text;
todo!("PO-P10")
}
/// The entry's description, when it has one.
pub fn description_text(&self) -> Option<&Label> {
todo!("PO-P10")
}
/// Why the entry is disabled, while it is.
pub fn why_disabled(&self) -> Option<&Label> {
match &self.row {
+3
View File
@@ -171,6 +171,8 @@ pub(super) struct ItemsHooks<'s, 'r, C: Collection> {
visible: Range<usize>,
/// The rows built this pass with their rects, for `collection_response`.
shown: Vec<ShownRow<C::Key>>,
/// The row under the pointer this pass, for `collection_response`.
hovered: Option<C::Key>,
offset: f64,
offset_at_read: f64,
offset_x: f64,
@@ -242,6 +244,7 @@ impl<'s, 'r, C: Collection> ItemsHooks<'s, 'r, C> {
keyed_activation: None,
visible: 0..0,
shown: Vec::new(),
hovered: None,
offset: 0.0,
offset_at_read: 0.0,
offset_x: 0.0,
@@ -55,7 +55,8 @@ impl<C: Collection> ShapeHooks<C> for ItemsHooks<'_, '_, C> {
fn key_role(&self, comp: &C) -> craft_behavior::KeyRole {
let props = comp.items();
craft_behavior::KeyRole::new()
.reorderable(props.reorder.is_some())
.reorderable(props.reorder.map(|r| r.keys)) // P3(pdf-workflows-w1): WF-W4
.reorder_axis(props.overflow)
.pages(props.pages)
.rename(props.rename)
.type_ahead(props.type_ahead)
@@ -823,6 +824,7 @@ impl<C: Collection> ShapeHooks<C> for ItemsHooks<'_, '_, C> {
shown: std::mem::take(&mut self.shown),
activation_clicks: self.activation_clicks,
pending_drop: self.drags.pending.clone(),
hovered: self.hovered.take(),
}));
cx.core.visible_rows = self.visible.clone();
cx.core.gestures = Gestures::of(comp.items());
+1
View File
@@ -117,6 +117,7 @@ pub use crate::runtime::drag::{DragPreview, DropMark, DropTarget, DropZone, OsFi
pub(crate) use body::MOVE_BAND;
pub use craft_behavior::ColumnKey;
pub use craft_behavior::DropOperation;
pub use craft_behavior::MiddleButton;
pub(crate) use run::BarRules;
pub(crate) use run::measure_under;
#[cfg(feature = "testing")]
@@ -154,6 +154,7 @@ fn report_access(p: &dyn ErasedPass<'_>, facts: &TypeFacts, input: &ReportIn<'_>
read_only: resolved.read_only,
focusable,
clickable: resolved.enabled && input.sense.contains(Sense::CLICK),
context_menu: false, // P3(pdf-shell-w1): SH-C6
keeps_name: resolved.keeps_name,
scrolls: input.scrolls,
access: &access,
@@ -271,6 +272,7 @@ pub(crate) fn report_inert(core: &CxCore<'_>, facts: &TypeFacts) {
read_only: core.resolved.read_only,
focusable: false,
clickable: false,
context_menu: false,
keeps_name: false,
scrolls: (false, false),
access: &access,
+6
View File
@@ -47,6 +47,12 @@ impl FontRef {
FontRef(FontFamily::Monospace)
}
/// The signature face: always a family egui knows. Its chain is the craft-fonts faces of the signature role,
/// then the proportional chain; without one in the build, the proportional chain.
pub fn signature() -> FontRef {
todo!("FM-PF1a")
}
/// A family registered under `name`.
pub fn named(name: &str) -> FontRef {
FontRef(FontFamily::Name(name.into()))
+4 -1
View File
@@ -70,6 +70,9 @@ pub struct Family {
weight: u16,
lead: Option<String>,
monospaced: bool,
/// The craft-fonts face role that leads the family's chain.
#[allow(dead_code)] // P3(pdf-forms-w1): FM-PF1a
lead_role: Option<&'static str>,
}
impl Family {
@@ -89,7 +92,7 @@ impl Family {
}
fn of(family: FontRef, monospaced: bool) -> Self {
Self { family: family.family(), weight: REGULAR, lead: None, monospaced }
Self { family: family.family(), weight: REGULAR, lead: None, monospaced, lead_role: None }
}
/// The weight (`wght`) this family's faces draw at: bold craft faces are used from 600 up, and
+1 -1
View File
@@ -235,7 +235,7 @@ impl UiFonts<'_> {
}
for family in self.app_faces.iter().flat_map(|f| &f.families) {
if !specs.iter().any(|s| s.family == *family) {
specs.push(Family { family: family.clone(), weight: super::REGULAR, lead: None, monospaced: false });
specs.push(Family { family: family.clone(), weight: super::REGULAR, lead: None, monospaced: false, lead_role: None });
}
}
for declared in &self.families {
@@ -0,0 +1,37 @@
//! `AutoScrollMark`: the mark a latched middle-button auto-scroll shows at its anchor: a ring on the panel fill, a dot
//! and two arrowheads in text ink.
use crate::style::{StyleColor, UiTokens};
use egui::{Pos2, Shape};
/// The auto-scroll mark's colours and sizes.
#[derive(Clone, Copy, Debug, PartialEq)]
#[non_exhaustive]
pub struct AutoScrollMarkLook {
/// The ring colour.
pub ring: StyleColor,
/// The fill inside the ring.
pub fill: StyleColor,
/// The ink of the dot and the arrowheads.
pub ink: StyleColor,
/// The ring's line width.
pub ring_width: f32,
/// The mark's diameter.
pub diameter: f32,
}
pub(crate) fn auto_scroll_mark_look(tokens: &UiTokens) -> AutoScrollMarkLook {
let _ = tokens;
todo!("CV-C9")
}
/// The auto-scroll mark painter.
pub struct AutoScrollMark;
impl AutoScrollMark {
/// The mark centred on `anchor`, from the look's tokens.
pub fn shapes(look: &AutoScrollMarkLook, anchor: Pos2) -> Vec<Shape> {
let _ = (look, anchor);
todo!("CV-C9")
}
}
+22 -2
View File
@@ -13,6 +13,17 @@ use egui::epaint::{CircleShape, RectShape};
use egui::{Color32, CornerRadius, Painter, Pos2, Rect, Shape, Stroke, StrokeKind, TextureId, Vec2};
use std::cell::RefCell;
/// What a swatch well shows.
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum WellFill {
/// A colour.
Color(Srgba),
/// The mixed mark: the values differ.
Mixed,
/// The sunken "no colour" diagonal in `status.bad`.
None,
}
/// A shape `Draw::fill` and `Draw::stroke` paint.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
@@ -362,7 +373,7 @@ impl<'a> Draw<'a> {
let square = Rect::from_center_size(rect.center(), Vec2::splat(side));
match icon.source {
super::IconSource::Swatch(swatch) => {
self.swatch_well(square, CornerRadius::ZERO, swatch);
self.swatch_well(square, CornerRadius::ZERO, swatch.map_or(WellFill::Mixed, WellFill::Color)); // P3(pdf-comments-w5): CM-C25a
self.paint(&PaintShape::Rect(square, CornerRadius::ZERO), None, Some(Stroke::new(self.width(StrokeWidth::Thin), color)));
return;
}
@@ -396,6 +407,11 @@ impl<'a> Draw<'a> {
self.galley(square.center() - layout.size() / 2.0, &layout);
}
/// Paints the auto-scroll mark of `look` at `anchor`.
pub fn auto_scroll_mark(&self, look: &super::AutoScrollMarkLook, anchor: Pos2) {
self.painter.extend(super::AutoScrollMark::shapes(look, anchor));
}
/// Paints the reset mark of `look` centred on `center`: the dot while the value `differs`, else the ring.
pub fn reset_mark(&self, look: &crate::style::ResetMarkLook, center: Pos2, differs: bool) {
self.painter.extend(super::ResetMark::shapes(look, center, differs));
@@ -501,7 +517,11 @@ impl<'a> Draw<'a> {
/// Paints the well of a colour swatch over `well` with corners `radius`: the colour, over a checkerboard where it is
/// translucent, or for `None` (no colour of its own, or a mixed one) the empty well, `surface.sunken` with a
/// `text.muted` dash. `Swatch` and swatch icons paint their wells with it and add their own edges.
pub fn swatch_well(&self, well: Rect, radius: CornerRadius, color: Option<Srgba>) {
pub fn swatch_well(&self, well: Rect, radius: CornerRadius, fill: WellFill) {
let color = match fill {
WellFill::Color(color) => Some(color),
WellFill::Mixed | WellFill::None => None, // P3(pdf-comments-w5): CM-C25a
};
let shape = PaintShape::Rect(well, radius);
match color {
None => {
+8 -5
View File
@@ -1,5 +1,6 @@
//! Painters, `Draw`, the sensing core, the text adapter and `ImeSurface`.
mod auto_scroll_mark;
pub mod backdrop;
mod content;
mod draw;
@@ -31,8 +32,10 @@ mod text_input;
pub mod textures;
mod tool;
pub(crate) use auto_scroll_mark::auto_scroll_mark_look;
pub use auto_scroll_mark::{AutoScrollMark, AutoScrollMarkLook};
pub use content::{ContentPainterCx, DocRun, DocText};
pub use draw::{Dashes, DataStrokeWidth, DataWidth, Draw, PaintShape, StrokeColor, StrokeWidth};
pub use draw::{Dashes, DataStrokeWidth, DataWidth, Draw, PaintShape, StrokeColor, StrokeWidth, WellFill};
pub use faces::FacesCx;
pub use focus_ring::{FocusKind, FocusRing};
pub use handle::{Handle, HandleShape};
@@ -55,16 +58,16 @@ pub(crate) use surface::SurfaceSlot;
pub use surround::paint_surround;
pub use svg_set::{AppIcons, register_app_icons};
pub use text::{ChordText, HAlign, LayoutRun, ReadingMeasure, Span, TextLayout, TextRun, Wrap};
pub use text_input::{Completer, Completion, EditorLine, EditorPurpose, EditorRun, EditorState, TextKey, TextOptions};
pub use text_input::{Completer, Completion, EditorLine, EditorPurpose, EditorRun, EditorState, SubmitKey, TextKey, TextOptions};
pub use textures::TextureCache;
pub use tool::ToolIcon;
#[cfg(feature = "testing")]
pub use textures::FakeThumbSource;
pub use textures::{
CachedTexture, LoadFailure, LoadResult, LoadedPicture, LoaderOptions, MAX_TEXTURE, Priority, Revision, TextureBudget, TextureKey, TextureLoader,
TextureState, TextureStatistics, TextureStore, TextureStoreOptions, TextureWords, ThumbFit, ThumbJob, ThumbPaint, ThumbRender, ThumbRequest,
ThumbSource, ThumbnailOptions, Thumbnails, fit_image, fit_rect, reduce_image, texture_factor, texture_side, thumb_image,
CachedTexture, LoadFailure, LoadResult, LoadedPicture, LoaderOptions, MAX_TEXTURE, Priority, Revision, StateLook, TextureBudget, TextureKey,
TextureLoader, TextureState, TextureStatistics, TextureStore, TextureStoreOptions, TextureWords, ThumbFit, ThumbJob, ThumbPaint, ThumbRender,
ThumbRequest, ThumbSource, ThumbnailOptions, Thumbnails, fit_image, fit_rect, reduce_image, texture_factor, texture_side, thumb_image,
};
pub(crate) use draw::DataMode;
@@ -97,6 +97,20 @@ pub struct TextOptions {
/// A press on a part declared `holds_drafts`, or on a popup layer above the field, leaves the focused draft
/// unapplied.
pub holds_drafts: bool,
/// The key that submits a multi-line text: under `Enter`, plain, Cmd and Ctrl+Enter submit and Shift+Enter breaks
/// the line.
pub submit_key: SubmitKey,
}
/// Which Enter chord submits a multi-line text.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub enum SubmitKey {
/// Cmd or Ctrl+Enter submits; plain Enter breaks the line.
#[default]
CommandEnter,
/// Plain, Cmd and Ctrl+Enter submit; Shift+Enter breaks the line.
Enter,
}
impl Default for TextOptions {
@@ -127,6 +141,7 @@ impl Default for TextOptions {
own_menu: false,
tab_rewrites: false,
holds_drafts: false,
submit_key: SubmitKey::CommandEnter,
}
}
}
@@ -193,7 +193,8 @@ impl<K: TextureKey> TextureLoader<K> {
let ctx = ctx.clone();
Wake::new(move || repaint::request(&ctx))
};
let queue = Arc::new(JobQueue::new(jobs, wake, QueueOptions { lanes: options.lanes, name: "craft-textures" }));
let queue =
Arc::new(JobQueue::new(jobs, wake, QueueOptions { lanes: options.lanes, name: "craft-textures", ..QueueOptions::default() })); // P3(pdf-canvas-w7): SH-C32
memory::with(ctx, |pools: &mut Pools<K>| {
let pool = pools.by_salt.entry(id).or_insert_with(|| Pool::new(queue, options.lanes));
(Arc::clone(&pool.queue), pool.lanes)
@@ -20,7 +20,9 @@ mod thumbnails;
pub use thumbnails::FakeThumbSource;
#[cfg(feature = "testing")]
pub(crate) use thumbnails::fake_thumb_image;
pub use thumbnails::{ThumbFit, ThumbJob, ThumbPaint, ThumbRender, ThumbRequest, ThumbSource, ThumbnailOptions, Thumbnails, fit_rect, thumb_image};
pub use thumbnails::{
StateLook, ThumbFit, ThumbJob, ThumbPaint, ThumbRender, ThumbRequest, ThumbSource, ThumbnailOptions, Thumbnails, fit_rect, thumb_image,
};
use crate::runtime::egui::{memory, pass, textures};
use egui::{Color32, ColorImage, Context, TextureHandle, TextureId, TextureOptions};
@@ -180,11 +180,24 @@ pub struct ThumbPaint {
pub paper: Option<DataColor>,
/// Multiplies the picture (default untinted): a dimmed row's faint thumbnail.
pub tint: DataColor,
/// What a picture that is not ready, or failed, shows: a glyph or a caption (default `Glyph`).
pub states: StateLook,
}
/// What a thumbnail that is not ready, or failed, shows.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub enum StateLook {
/// The placeholder and the failure glyph.
#[default]
Glyph,
/// "Rendering…", then "Still rendering…" once the wait passes 6 s, then the failure text.
Captioned,
}
impl Default for ThumbPaint {
fn default() -> Self {
Self { fit: ThumbFit::Contain, checker: true, paper: None, tint: DataColor::new(super::UNTINTED) }
Self { fit: ThumbFit::Contain, checker: true, paper: None, tint: DataColor::new(super::UNTINTED), states: StateLook::Glyph }
}
}
@@ -217,6 +230,13 @@ impl ThumbPaint {
self.tint = tint;
self
}
/// Sets what a picture that is not ready, or failed, shows.
#[must_use]
pub fn states(mut self, states: StateLook) -> Self {
self.states = states;
self
}
}
/// The per-pass state of a [`Thumbnails`].
@@ -284,6 +304,12 @@ const _: () = {
};
impl<K: TextureKey> Thumbnails<K> {
/// Seconds `key` has waited for its picture, `None` when it is not waiting.
pub fn waited(&self, key: &K) -> Option<f64> {
let _ = key;
todo!("CV-C16")
}
/// The thumbnails stored in `ctx` under `salt`, made with `options` the first time; the loader and its store
/// live under the same salt.
pub fn in_context(ctx: &Context, salt: impl std::hash::Hash + std::fmt::Debug, options: ThumbnailOptions) -> Self {
@@ -6,5 +6,8 @@ craft_ui::words! {
missing: "textures.missing" = "The file is missing";
unreadable: "textures.unreadable" = "The picture could not be read";
panicked: "textures.panicked" = "The picture could not be made";
rendering: "thumbnails.rendering" = "Rendering…";
still_rendering: "thumbnails.stillRendering" = "Still rendering…";
failed: "thumbnails.failed" = "The thumbnail could not be made";
}
}
@@ -36,6 +36,8 @@ pub(crate) struct Own<'a> {
pub read_only: bool,
pub focusable: bool,
pub clickable: bool,
/// A `Trigger::Context` opener on the component this pass: the node declares the context menu action.
pub context_menu: bool,
pub keeps_name: bool,
/// The axes the component's body scrolls on, vertical then horizontal: the node serves the scroll actions.
pub scrolls: (bool, bool),
@@ -149,7 +151,8 @@ fn write_position(spec: &mut NodeSpec, position: Option<SetPosition>, level: Opt
}
/// The actions the interaction and the numeric facts declare.
fn declare_actions(spec: &mut NodeSpec, focusable: bool, clickable: bool, numeric: Option<&Numeric>) {
fn declare_actions(spec: &mut NodeSpec, focusable: bool, clickable: bool, context_menu: bool, numeric: Option<&Numeric>) {
let _ = context_menu; // P3(pdf-shell-w1): SH-C6
// A read-only value offers no action that would change it.
let numeric = numeric.filter(|_| !spec.read_only);
if focusable {
@@ -293,7 +296,7 @@ pub(crate) fn report(ctx: &Context, own: &Own<'_>) {
if let Some(expanded) = expanded {
spec.actions.push(if expanded { NodeAction::Collapse } else { NodeAction::Expand });
}
declare_actions(&mut spec, own.focusable, own.clickable, numeric);
declare_actions(&mut spec, own.focusable, own.clickable, own.context_menu, numeric);
declare_scroll_actions(&mut spec, (own.scrolls.0 || access.pans.0, own.scrolls.1 || access.pans.1));
custom_actions(&mut spec, &access.custom_actions);
write_node(ctx, own.id, &spec);
@@ -386,7 +389,7 @@ pub fn report_sub(ctx: &Context, decl: &SubDecl<'_>) {
spec.sort = node.sort;
spec.sortable = node.sortable;
write_states(&mut spec, flags, decl.enabled, false);
declare_actions(&mut spec, decl.focusable, decl.clickable, numeric);
declare_actions(&mut spec, decl.focusable, decl.clickable, false, numeric);
if node.steps && numeric.is_none() {
spec.actions.extend([NodeAction::Increment, NodeAction::Decrement]);
}
@@ -397,6 +397,7 @@ impl Board {
let chord = self.keymap.as_ref().and_then(|cache| cache.keymap.shown_chord(command));
let resolved = ResolvedCommand {
label: state.and_then(|s| s.title_ref().cloned()).unwrap_or_else(|| Arc::from(def.map_or(command.id.as_str(), |def| def.label.as_str()))),
catalog_label: Default::default(), // P3(pdf-chrome-w1): CH-C25
icon: def.and_then(|def| def.icon.clone()),
chord,
enabled: flags.enabled && modal && live && !matches!(declaring, Some(Declaration::Focused { inactive: true })),
@@ -674,6 +675,14 @@ pub(crate) fn take_fired(ctx: &Context) -> Vec<Fired> {
with(ctx, |board| std::mem::take(&mut board.out))
}
/// The app-scope commands a key press fired while only the app's own command state disabled them, since the last
/// call.
#[allow(dead_code)] // P3(pdf-chrome-w1): CH-C2
pub(crate) fn take_declined(ctx: &Context) -> Vec<Fired> {
let _ = ctx;
todo!("CH-C2")
}
/// The commands instances took since the last call.
pub(crate) fn take_delivered(ctx: &Context) -> Vec<Fired> {
with(ctx, |board| std::mem::take(&mut board.delivered))
@@ -257,6 +257,9 @@ impl CommandState {
pub struct ResolvedCommand {
/// The state's title, else the command's label, else its id.
pub label: Arc<str>,
/// The command's catalogue label (the registry's), whatever title the state sets; `None` for a command the
/// registry does not define.
pub catalog_label: Option<Arc<str>>,
/// The icon name.
pub icon: Option<Cow<'static, str>>,
/// The chord surfaces show: the first single-press binding that runs the command ([`chord`]).
+18 -2
View File
@@ -6,7 +6,6 @@ mod node;
mod patch;
mod roles;
mod text;
#[cfg(feature = "testing")]
mod tree;
use crate::runtime::pass_state;
@@ -22,7 +21,6 @@ pub(crate) use patch::{write_label_patch, write_merge_patch, write_status};
pub(crate) use text::{
NodeEnd, RunLink, RunNode, TextNode, fold_widget, is_text_request, requested_selection, requested_value, write_run, write_selection, write_text,
};
#[cfg(feature = "testing")]
pub use tree::{AccessTree, Declared, NodeKey};
/// The rect `id`'s response had in the last finished pass, converted as the node's bounds are; `None` when absent,
@@ -111,6 +109,9 @@ struct Emitted {
folded: IdMap<Id>,
/// Whether the runtime reported a focused node this pass.
focus_set: bool,
/// Components that offer a context menu this pass (a `Trigger::Context` opener on them).
#[allow(dead_code)] // P3(pdf-shell-w1): SH-C6
context: IdSet,
}
impl Emitted {
@@ -195,6 +196,21 @@ fn hide_behind_modal(ctx: &Context, viewport: ViewportId, written: &IdSet) {
}
}
/// Records that the component `id` has a `Trigger::Context` opener in this pass, so its node declares the context
/// menu action.
#[allow(dead_code)] // P3(pdf-shell-w1): SH-C6
pub(crate) fn offer_context_menu(ctx: &Context, id: Id) {
let _ = (ctx, id);
todo!("SH-C6")
}
/// Whether `id` has a `Trigger::Context` opener recorded in this pass.
#[allow(dead_code)] // P3(pdf-shell-w1): SH-C6
pub(crate) fn offers_context_menu(ctx: &Context, id: Id) -> bool {
let _ = (ctx, id);
todo!("SH-C6")
}
/// The tree update of a finished frame.
#[cfg(feature = "testing")]
pub(crate) fn tree_of(output: &mut FullOutput) -> Option<AccessTree> {
@@ -17,6 +17,8 @@ pub(crate) enum Toggle {
pub(crate) enum NodeAction {
Focus,
Click,
#[allow(dead_code)] // P3(pdf-shell-w1): SH-C6
ContextMenu,
Increment,
Decrement,
SetValue,
@@ -34,6 +36,7 @@ impl NodeAction {
match self {
NodeAction::Focus => accesskit::Action::Focus,
NodeAction::Click => accesskit::Action::Click,
NodeAction::ContextMenu => accesskit::Action::ShowContextMenu,
NodeAction::Increment => accesskit::Action::Increment,
NodeAction::Decrement => accesskit::Action::Decrement,
NodeAction::SetValue => accesskit::Action::SetValue,
@@ -12,10 +12,15 @@ pub struct NodeKey(u64);
impl NodeKey {
/// The AccessKit node number.
pub(crate) fn raw(self) -> u64 {
pub fn raw(self) -> u64 {
self.0
}
/// The key of the node with AccessKit number `raw`.
pub fn from_raw(raw: u64) -> NodeKey {
NodeKey(raw)
}
/// The key of the node of `id`.
pub fn of(id: Id) -> NodeKey {
NodeKey(node_key(id))
@@ -37,6 +42,8 @@ pub enum Declared {
Focus,
/// Click.
Click,
/// Open the node's context menu.
ContextMenu,
/// Increment.
Increment,
/// Decrement.
@@ -73,6 +80,7 @@ impl Declared {
Declared::Expand => Action::Expand,
Declared::Collapse => Action::Collapse,
Declared::Custom => Action::CustomAction,
Declared::ContextMenu => Action::ShowContextMenu,
Declared::ScrollUp => Action::ScrollUp,
Declared::ScrollDown => Action::ScrollDown,
Declared::ScrollLeft => Action::ScrollLeft,
@@ -365,12 +373,12 @@ impl AccessTree {
impl AccessTree {
/// The root node, when the frame made a tree.
pub(crate) fn root_key(&self) -> Option<NodeKey> {
pub fn root_key(&self) -> Option<NodeKey> {
self.update.tree.as_ref().map(|tree| NodeKey(tree.root.0))
}
/// The node AccessKit reports as focused.
pub(crate) fn focused_key(&self) -> NodeKey {
pub fn focused_key(&self) -> NodeKey {
NodeKey(self.update.focus.0)
}
@@ -19,6 +19,7 @@ use craft_behavior::{PointerButton, PointerSample};
use craft_keymap::{Key, Mods, Platform};
use egui::{Context, Event, Id, Modifiers, Pos2, Vec2, ViewportId};
use super::access::{Declared, NodeKey};
use super::memory::Service;
use super::{pass, repaint};
@@ -160,6 +161,18 @@ struct Step {
rest: f64,
pen: Option<PointerSample>,
hold: Option<Hold>,
/// Files the step hovers over the window, or drops.
#[allow(dead_code)] // P3(pdf-shell-w1): WF-W7
pub files: Option<InjectedFiles>,
}
/// Files an injected step hovers over a window, and whether the step after it drops them.
#[derive(Clone, Debug, PartialEq)]
pub struct InjectedFiles {
/// The paths of the files.
pub paths: Vec<std::path::PathBuf>,
/// Whether the files are dropped in the following injected step.
pub dropped: bool,
}
impl From<Frame> for Step {
@@ -644,6 +657,18 @@ pub(crate) fn inject_text(ctx: &Context, viewport: ViewportId, text: &str) {
});
}
/// Queues the hover of `paths` over `at` and, with `drop`, their drop in the following step.
pub(crate) fn inject_files(ctx: &Context, viewport: ViewportId, at: Option<Pos2>, paths: Vec<std::path::PathBuf>, drop: bool) {
let _ = (ctx, viewport, at, paths, drop);
todo!("WF-W7")
}
/// Queues one AccessKit action request (click, focus or context menu) on `node`, behind earlier injected input.
pub(crate) fn inject_access(ctx: &Context, viewport: ViewportId, node: NodeKey, action: Declared) {
let _ = (ctx, viewport, node, action);
todo!("SH-C9")
}
/// Queues one IME event (a preedit or a commit) with the held modifiers, behind earlier injected input.
pub(crate) fn inject_ime(ctx: &Context, viewport: ViewportId, event: egui::ImeEvent) {
queue(ctx, viewport, move |request| {
@@ -17,6 +17,11 @@ impl Plugin for RuntimePlugin {
frame::input_hook(ctx, input);
}
fn output_hook(&mut self, ctx: &Context, output: &mut egui::FullOutput) {
let _ = (ctx, output);
todo!("SH-C10")
}
fn on_begin_pass(&mut self, ui: &mut Ui) {
frame::begin_pass(ui);
}
+1 -1
View File
@@ -46,7 +46,7 @@ pub use craft_platform::appearance::SystemReader;
use host_words::{host_dates, host_format, host_words};
pub use overrides::{Overrides, ThemeScope, WheelScope, WordsOverride, with_env};
pub use root::{ResolvedRoot, RootEnv};
pub use system::{SystemState, system_appearance};
pub use system::{SystemState, system_appearance, system_text_scale};
pub(crate) use tokens::TokenInputs;
#[cfg(feature = "testing")]
pub(crate) use tokens::root_token_resolves;
+6
View File
@@ -36,6 +36,12 @@ pub fn system_appearance(ctx: &Context) -> SystemState {
})
}
/// The desktop text scale from the installed [`SystemReader`], `None` where the OS gives none.
pub fn system_text_scale(ctx: &Context) -> Option<f32> {
let _ = ctx;
todo!("SH-C4")
}
pub(crate) fn install(ctx: &Context, reader: SystemReader) {
Service::<Source>::run(ctx, |source| source.0 = reader);
}
+3
View File
@@ -104,6 +104,9 @@ pub struct FrameOutput {
/// The commands components took since the last call, in order, whatever fired them (a key, a menu row, the
/// palette): what ran inside the framework, for an app that records the commands it runs (an action recorder).
pub delivered: Vec<Fired>,
/// The app-scope commands a key press fired while only the app's own command state disabled them, in order.
/// Refusals by the gate or the modal rule are not listed.
pub declined: Vec<Fired>,
/// Text for the live announcement region.
pub announcements: Vec<String>,
/// The chrome toggles the windows asked for since the last call, in order: each names its viewport and whether the
+15
View File
@@ -69,6 +69,8 @@ pub struct Toast {
pub lines: Vec<Label>,
/// The actions after the message, in reading order.
pub actions: Vec<ToastAction>,
/// The fraction done, `0..=1`; a card with progress has no timer and is never the one the cap drops.
pub progress: Option<f32>,
}
impl Toast {
@@ -82,6 +84,7 @@ impl Toast {
title: None,
lines: Vec::new(),
actions: Vec::new(),
progress: Default::default(),
}
}
@@ -120,6 +123,18 @@ impl Toast {
self.politeness = politeness;
self
}
/// Sets the fraction done, clamped to `0..=1`.
pub fn progress(self, fraction: f32) -> Self {
let _ = fraction;
todo!("CH-C14")
}
}
/// Sets the fraction done of the toast `id` and, when given, its message.
pub fn set_progress(ctx: &Context, id: ToastId, fraction: f32, message: Option<Label>) {
let _ = (ctx, id, fraction, message);
todo!("CH-C14")
}
/// A posted toast's handle.
+27
View File
@@ -21,6 +21,33 @@ pub(crate) struct State {
shares: Vec<(Id, Wheel)>,
/// The wheel gesture the split tracks across passes.
gesture: WheelGesture<Id>,
/// The running gesture's gathered scroll in its owner's points, reset when the gesture closes.
#[allow(dead_code)] // P3(pdf-canvas-w4): CV-C29
gathered: Vec2,
/// Whether the owner marked the running gesture moved, reset when the gesture closes.
#[allow(dead_code)] // P3(pdf-canvas-w4): CV-C29
moved: bool,
/// The wheel ease each owner holds.
#[allow(dead_code)] // P3(pdf-canvas-w4): CV-C2
eases: egui::IdMap<craft_behavior::WheelEase>,
}
/// Marks the wheel gesture `id` owns, while it runs, as moved.
pub(crate) fn mark_moved(ctx: &Context, id: Id) {
let _ = (ctx, id);
todo!("CV-C29")
}
/// Feeds `pan` to the wheel ease of `id` and returns this pass's eased step.
pub(crate) fn ease(ctx: &Context, id: Id, pan: Vec2) -> Vec2 {
let _ = (ctx, id, pan);
todo!("CV-C2")
}
/// Drops the wheel ease of `id`.
pub(crate) fn stop_ease(ctx: &Context, id: Id) {
let _ = (ctx, id);
todo!("CV-C2")
}
/// Registers a taker for next pass's split.
@@ -6,6 +6,7 @@ use super::placement::placement_of;
use super::shell::{base_shell, shell_of, window_info};
use super::spec::frame_of;
use super::{Record, shared};
use crate::runtime::egui::access::{AccessTree, Declared, NodeKey};
use crate::runtime::egui::injected::{self, InjectedPointer, Released};
use crate::runtime::egui::input_filter;
use crate::runtime::egui::screenshot::{ScreenshotFacts, ScreenshotSlot};
@@ -207,6 +208,37 @@ impl WindowHost {
injected::inject_ime(&self.ctx, viewport, event);
}
/// Hovers the files over `at` and, with `drop`, drops them in the following injected step, through the same
/// hovered and dropped file input a window's drag session fills.
pub fn inject_files(&self, viewport: ViewportId, at: Option<Pos2>, paths: Vec<std::path::PathBuf>, drop: bool) {
injected::inject_files(&self.ctx, viewport, at, paths, drop);
}
/// Queues one AccessKit action request (click, focus or context menu) on `node` as one injected step behind
/// earlier injected input.
pub fn inject_access(&self, viewport: ViewportId, node: NodeKey, action: Declared) {
injected::inject_access(&self.ctx, viewport, node, action);
}
/// Turns AccessKit output on and, from then on, keeps each viewport's tree from the last presented frame.
pub fn keep_access_tree(&self) {
todo!("SH-C7")
}
/// The kept AccessKit tree of `viewport`: `None` before its first presented frame or without
/// [`keep_access_tree`](Self::keep_access_tree).
pub fn access_tree(&self, viewport: ViewportId) -> Option<AccessTree> {
let _ = viewport;
todo!("SH-C8")
}
/// Changes the open root window's frame to `decision`'s and returns true; a change to or from the inset frame
/// cannot reach an open window, keeps the current decision and returns false.
pub fn set_root_frame(&self, decision: craft_window::policy::Decision) -> bool {
let _ = decision;
todo!("SH-C1")
}
/// Withdraws the injected input of `viewport` (the document changed) at its next input hook: a step whose pass
/// has not run and the queue behind it; what is dropped counts as withdrawn
/// ([`take_injected_withdrawn`](Self::take_injected_withdrawn)). Called from the raw input hook, so every
+12
View File
@@ -234,6 +234,13 @@ impl<'a> StyleCx<'a> {
self.color(craft_theme::ensure_contrast(start, fill, craft_theme::text_contrast_min(self.contrast())))
}
/// The ink of a glyph or label in the data colour `color` on the surface `on`, pushed to the contrast the text
/// needs: the inverse of [`ink_on`](Self::ink_on).
pub fn ink_of(&self, color: DataColor, on: Rgba) -> StyleColor {
let _ = (color, on);
todo!("CH-C9")
}
/// The one builder of the focus ring: the line's focus colour at the medium stroke, on the shape's edge.
pub fn focus_look(&self) -> FocusLook {
FocusLook::new(egui::Stroke::new(self.tokens.stroke.medium, self.color(self.tokens.color.line.focus).egui()), 0.0)
@@ -439,6 +446,11 @@ impl<'a> StyleCx<'a> {
super::paint::state_layer_look(self.tokens)
}
/// The look of the auto-scroll mark.
pub fn auto_scroll_mark(&self) -> crate::primitives::AutoScrollMarkLook {
crate::primitives::auto_scroll_mark_look(self.tokens)
}
/// The look of the reset mark.
pub fn reset_mark(&self) -> ResetMarkLook {
reset_mark_look(self.tokens)
+1
View File
@@ -203,6 +203,7 @@ const COLLECTION: &[Forwarded] = &[
"How tall the rows are: text rows for a read-only display table, control-high rows for a list the user picks from.",
),
("notch", "$ui::contract::Notch", "The distance one wheel notch scrolls the rows."),
("middle_button", "$ui::contract::MiddleButton", "What a middle press does: pan or latched auto-scroll."),
("command_click", "bool", "A Cmd/Ctrl click on an item is a command (`CollectionEvent::CommandClick`), not a pick."),
(
"current",