From 1ca3168b02dbc2555ce828723bcff98213344d9e Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Wed, 18 Nov 2026 17:25:02 +0000 Subject: [PATCH] platform-w3: net change of 2 commits - platform-w3: written from its sheet - platform-w3: review fixes (review-1) --- .../src/runtime/commands/clipboard.rs | 79 +++++---- .../ui-contract/src/runtime/egui/clipboard.rs | 154 +++++++++++++++--- crates/ui-contract/src/runtime/frame.rs | 10 +- crates/ui-contract/src/runtime/install.rs | 9 +- crates/ui-contract/src/runtime/pass_state.rs | 1 + .../ui-contract/tests/it/runtime/clipboard.rs | 79 ++++++++- docs/contract-api.md | 20 ++- 7 files changed, 284 insertions(+), 68 deletions(-) diff --git a/crates/ui-contract/src/runtime/commands/clipboard.rs b/crates/ui-contract/src/runtime/commands/clipboard.rs index d74cecff2..1b70aebe6 100644 --- a/crates/ui-contract/src/runtime/commands/clipboard.rs +++ b/crates/ui-contract/src/runtime/commands/clipboard.rs @@ -1,9 +1,9 @@ -//! The clipboard handle `Commands::clipboard` returns, over `runtime::egui::clipboard`. +//! The clipboard handle `Commands::clipboard` returns, over the clipboard `runtime::egui::clipboard` keeps installed. use crate::runtime::egui::clipboard; use crate::runtime::keys; use crate::runtime::pending::Pending; -use craft_platform::clipboard::{ClipboardError, ClipboardImage, Flavor, Written}; +use craft_platform::clipboard::{ClipboardError, ClipboardImage, Flavor, HTML, MATHML, RTF, Written}; use egui::{ColorImage, Context, Id}; use std::path::PathBuf; use std::sync::Arc; @@ -35,8 +35,25 @@ pub enum ClipItem { impl ClipItem { /// An item of an app-defined type: `bytes` under the MIME type `mime`. pub fn custom(mime: impl Into>, bytes: impl Into>) -> ClipItem { - let _ = (mime.into(), bytes.into()); - todo!("pf.C-R3") + ClipItem::Custom { mime: mime.into(), bytes: bytes.into() } + } + + /// The flavour the clipboard carries this item as; an image goes as straight-alpha `RGBA8`. + fn flavor(&self) -> Result { + Ok(match self { + ClipItem::Text(text) => Flavor::text(text), + ClipItem::Html(html) => Flavor::new(HTML, html.as_bytes().to_vec()), + ClipItem::Rtf(rtf) => Flavor::new(RTF, rtf.as_bytes().to_vec()), + ClipItem::MathMl(mathml) => Flavor::new(MATHML, mathml.as_bytes().to_vec()), + ClipItem::Custom { mime, bytes } => Flavor::new(mime.to_string(), bytes.to_vec()), + ClipItem::Image(image) => { + let image = clipboard::clipboard_image(image); + if !image.is_whole() { + return Err(ClipboardError::BadImage); + } + Flavor::rgba8(&image) + } + }) } } @@ -53,8 +70,8 @@ pub struct ClipContent { #[non_exhaustive] pub struct ClipError(pub String); -/// The component's paste slot over the system clipboard. egui carries text and images, so `Html` and `Custom` -/// items are not written. +/// The component's paste slot over the installed clipboard (the host's, else egui's). Every call goes to the +/// clipboard installed in the context; the handle holds nothing else. pub struct ClipboardHandle { ctx: Context, slot: Pending, @@ -69,73 +86,65 @@ impl ClipboardHandle { ClipboardHandle { ctx: ctx.clone(), slot } } - /// The clipboard handle of `ctx`, over the installed clipboard. + /// The clipboard handle of `ctx`, over the installed clipboard, for code outside a component; its paste slot + /// stays loading, as no component takes the paste. pub fn of(ctx: &Context) -> ClipboardHandle { - let _ = ctx; - todo!("pf.C-R3") + ClipboardHandle::new(ctx, None) } - /// Offers `items` in the caller's order, as one offer, and says which flavour the clipboard kept. + /// Offers `items` in the caller's order, as one offer, and says which flavour the clipboard kept. A measuring run + /// writes nothing and answers `Written::Fenced`. pub fn offer(&self, items: &[ClipItem]) -> Result { - let _ = items; - todo!("pf.C-R3") + if !crate::runtime::measure::effect(&self.ctx, "clipboard::offer") { + return Ok(Written::Fenced); + } + let flavors = items.iter().map(ClipItem::flavor).collect::, _>>()?; + clipboard::with(&self.ctx, |clipboard| clipboard.write(&flavors)) } /// The first of `mimes` the installed clipboard holds. pub fn read(&self, mimes: &[&str]) -> Result, ClipboardError> { - let _ = mimes; - todo!("pf.C-R3") + clipboard::with(&self.ctx, |clipboard| clipboard.read(mimes)) } /// The clipboard's text. pub fn read_text(&self) -> Result, ClipboardError> { - todo!("pf.C-R3") + clipboard::with(&self.ctx, |clipboard| clipboard.read_text()) } - /// The clipboard's image as straight-alpha RGBA8 pixels. + /// The clipboard's image as straight-alpha RGBA8 pixels; `ColorImage::from_rgba_unmultiplied` turns them back. pub fn read_image(&self) -> Result, ClipboardError> { - todo!("pf.C-R3") + clipboard::with(&self.ctx, |clipboard| clipboard.read_image()) } /// The files the clipboard holds. pub fn read_files(&self) -> Result>, ClipboardError> { - todo!("pf.C-R3") + clipboard::with(&self.ctx, |clipboard| clipboard.read_files()) } /// Whether the clipboard holds one of `mimes`. pub fn has(&self, mimes: &[&str]) -> bool { - let _ = mimes; - todo!("pf.C-R3") + clipboard::with(&self.ctx, |clipboard| clipboard.has(mimes)) } /// Whether the clipboard still holds what this app last offered. pub fn holds_ours(&self) -> bool { - todo!("pf.C-R3") + clipboard::with(&self.ctx, |clipboard| clipboard.holds_ours()) } /// The MIME names of the formats on the clipboard. pub fn formats(&self) -> Vec { - todo!("pf.C-R3") + clipboard::with(&self.ctx, |clipboard| clipboard.formats()) } /// Whether a late paste offer arrived this frame; true in every pass of that frame. pub fn arrived(&self) -> bool { - todo!("pf.C-R3") + clipboard::arrived(&self.ctx) } - /// Writes every flavour of `items` that the clipboard carries. + /// Offers `items` as one offer ([`offer`](Self::offer)), for a caller that does not ask what was kept. pub fn put(&self, items: &[ClipItem]) { - if !crate::runtime::measure::effect(&self.ctx, "clipboard::put") { - return; - } - for item in items { - match item { - ClipItem::Text(text) => clipboard::copy_text(&self.ctx, text.to_string()), - ClipItem::Image(image) => clipboard::copy_image(&self.ctx, (**image).clone()), - // P3(platform-w3): pf.C-R3: the new items are written through `offer`. - ClipItem::Html(_) | ClipItem::Rtf(_) | ClipItem::MathMl(_) | ClipItem::Custom { .. } => {} - } - } + let _ = self.offer(items); } /// The pasted content: ready in the pass that delivers the paste to the focused component that lists Paste. diff --git a/crates/ui-contract/src/runtime/egui/clipboard.rs b/crates/ui-contract/src/runtime/egui/clipboard.rs index 25a762c33..456d3b363 100644 --- a/crates/ui-contract/src/runtime/egui/clipboard.rs +++ b/crates/ui-contract/src/runtime/egui/clipboard.rs @@ -1,17 +1,60 @@ -//! Clipboard output commands. +//! The installed clipboard, its egui backend, and the once-per-frame late paste flag. -use craft_platform::clipboard::{Clipboard, ClipboardBackend, ClipboardError, ClipboardImage, Flavor}; +use crate::runtime::pass_state; +use craft_platform::clipboard::{Clipboard, ClipboardBackend, ClipboardError, ClipboardImage, Flavor, RGBA8, TEXT}; use egui::{ColorImage, Context}; use std::path::PathBuf; +use std::sync::{Arc, Mutex, PoisonError}; -/// The backend the runtime installs when the host gives no clipboard: egui's own copy and paste commands. -#[allow(dead_code)] // P3(platform-w3): pf.C-R2 -pub(crate) struct EguiClipboard; +/// The backend the runtime installs when the host gives no clipboard: egui's own copy and paste commands. egui +/// carries one value of text or of an image, and the last copy command of a frame wins, so a write acts on the first +/// flavour egui carries and skips the rest. It holds no `Context` (the context owns the clipboard, so a clone would +/// be a cycle): a write is left in a slot that `with` hands to the context's output. +pub(crate) struct EguiClipboard { + copies: Copies, +} + +/// The copy command an `EguiClipboard` write leaves for `with`. +enum EguiCopy { + Text(String), + Image(ColorImage), +} + +/// Where an `EguiClipboard` leaves its write until `with` sends it to egui. +type Copies = Arc>>; + +impl EguiClipboard { + /// The backend that leaves its writes in `copies`. + fn new(copies: Copies) -> Self { + EguiClipboard { copies } + } + + fn leave(&self, copy: EguiCopy) { + *self.copies.lock().unwrap_or_else(PoisonError::into_inner) = Some(copy); + } +} impl ClipboardBackend for EguiClipboard { fn write(&mut self, flavors: &[Flavor]) -> Result { - let _ = flavors; - todo!("pf.C-R2") + if flavors.is_empty() { + self.leave(EguiCopy::Text(String::new())); + return Ok(0); + } + for (at, flavor) in flavors.iter().enumerate() { + if flavor.mime == TEXT + && let Ok(text) = std::str::from_utf8(&flavor.data) + { + self.leave(EguiCopy::Text(text.to_owned())); + return Ok(at); + } + if flavor.mime == RGBA8 + && let Some(image) = flavor.rgba8_image().and_then(|image| color_image(&image)) + { + self.leave(EguiCopy::Image(image)); + return Ok(at); + } + } + Err(ClipboardError::NoFormat) } /// egui delivers pasted text only as an input event, so a read finds nothing. @@ -20,44 +63,111 @@ impl ClipboardBackend for EguiClipboard { Ok(None) } + /// egui has no clipboard read. fn read_image(&mut self, limit: u64) -> Result, ClipboardError> { let _ = limit; - todo!("pf.C-R2") + Ok(None) } + /// egui has no clipboard read. fn read_files(&mut self, limit: usize) -> Result>, ClipboardError> { let _ = limit; - todo!("pf.C-R2") + Ok(None) } + /// egui cannot look at the clipboard, so it holds nothing it could name. fn has(&mut self, mimes: &[&str]) -> bool { let _ = mimes; - todo!("pf.C-R2") + false } } -/// Runs `f` on the clipboard installed in `ctx`'s runtime memory. -#[allow(dead_code)] // P3(platform-w3): pf.C-R2 +/// The clipboard of a context and whether a late paste arrived this frame. The clipboard is an install-time handle, +/// shared so `with` can lend it after the pass-state borrow ends. +#[derive(Default)] +pub(crate) struct Installed { + clipboard: Option>>, + /// What the egui backend wrote, until `with` sends it to the context. + copies: Copies, + /// Assigned once per frame by `begin_frame`, so it is a fact of that frame alone. + arrived: bool, +} + +/// Keeps `clipboard` as the context's clipboard; `None` leaves the choice to `with`, which builds egui's. +pub(crate) fn install(ctx: &Context, clipboard: Option) { + pass_state::with::(ctx, |installed| { + installed.clipboard = clipboard.map(|clipboard| Arc::new(Mutex::new(clipboard))); + installed.arrived = false; + }); +} + +/// Runs `f` on the clipboard installed in `ctx`'s runtime memory: the host's, else egui's, built here once. pub(crate) fn with(ctx: &Context, f: impl FnOnce(&mut Clipboard) -> R) -> R { - let _ = (ctx, f); - todo!("pf.C-R2") + let (shared, copies) = pass_state::with::(ctx, |installed| { + let copies = Arc::clone(&installed.copies); + let clipboard = installed + .clipboard + .get_or_insert_with(|| Arc::new(Mutex::new(Clipboard::new(EguiClipboard::new(Arc::clone(&copies)))))); + (Arc::clone(clipboard), copies) + }); + let result = { + let mut clipboard = shared.lock().unwrap_or_else(PoisonError::into_inner); + f(&mut clipboard) + }; + let copy = copies.lock().unwrap_or_else(PoisonError::into_inner).take(); + match copy { + Some(EguiCopy::Text(text)) => ctx.copy_text(text), + Some(EguiCopy::Image(image)) => ctx.copy_image(image), + None => {} + } + result } -/// Once per frame, in the pass that receives input: takes a late paste offer for this frame. -#[allow(dead_code)] // P3(platform-w3): pf.C-R2 +/// Once per frame, from `set_input`: takes a late paste offer for this frame. The flag is assigned, never or-ed, so it +/// holds in every pass of this frame (passes a frame reruns do not call `set_input`) and goes with the next frame. pub(crate) fn begin_frame(ctx: &Context) { - let _ = ctx; - todo!("pf.C-R2") + let arrived = with(ctx, Clipboard::take_arrived_paste); + pass_state::with::(ctx, |installed| installed.arrived = arrived); } -/// Puts `text` on the system clipboard. +/// Whether a late paste offer arrived this frame. +pub(crate) fn arrived(ctx: &Context) -> bool { + pass_state::with::(ctx, |installed| installed.arrived) +} + +/// `image` as straight-alpha RGBA8 pixels, the form every clipboard flavour of a bitmap carries. A side too long for +/// a `u32` gives an image that is not whole, which a write refuses. +pub(crate) fn clipboard_image(image: &ColorImage) -> ClipboardImage { + let [width, height] = image.size; + ClipboardImage { + width: u32::try_from(width).unwrap_or(0), + height: u32::try_from(height).unwrap_or(0), + rgba: image.pixels.iter().flat_map(|pixel| pixel.to_srgba_unmultiplied()).collect(), + } +} + +/// The pixels of `image` for egui, `None` when its pixels do not match its size. +fn color_image(image: &ClipboardImage) -> Option { + if !image.is_whole() { + return None; + } + let size = [usize::try_from(image.width).ok()?, usize::try_from(image.height).ok()?]; + Some(ColorImage::from_rgba_unmultiplied(size, &image.rgba)) +} + + +/// Puts `text` on the installed clipboard. pub(crate) fn copy_text(ctx: &Context, text: String) { - ctx.copy_text(text); + with(ctx, |clipboard| { + let _ = clipboard.write_text(&text); + }); } -/// Puts `image` on the system clipboard. +/// Puts `image` on the installed clipboard. pub(crate) fn copy_image(ctx: &Context, image: ColorImage) { - ctx.copy_image(image); + with(ctx, |clipboard| { + let _ = clipboard.write_image(&clipboard_image(&image)); + }); } /// Asks the platform for the clipboard text, which arrives as a paste event. diff --git a/crates/ui-contract/src/runtime/frame.rs b/crates/ui-contract/src/runtime/frame.rs index 96b17bd3d..133fde603 100644 --- a/crates/ui-contract/src/runtime/frame.rs +++ b/crates/ui-contract/src/runtime/frame.rs @@ -3,8 +3,8 @@ use crate::runtime::commands::{self, CommandInput, CommandSet as _, Fired}; use crate::runtime::egui::input::{self as raw_input, Arrived, HeldInput, RawInput}; use crate::runtime::egui::memory as store; -use crate::runtime::egui::{pass, scale, style}; -use crate::runtime::env::{Env, RootEnv, WindowKey}; +use crate::runtime::egui::{clipboard, pass, scale, style}; +use crate::runtime::env::{AltCodePages, Env, RootEnv, WheelSpeed, WindowKey}; use crate::runtime::pass_state; use crate::runtime::{access, cursor, drag, focus, ime, keys, layout_memory, measure, memory, motion, overlay, pointer, toast, wheel, windows}; use craft_behavior::{DocKey, GestureId}; @@ -305,6 +305,7 @@ pub fn set_input(ctx: &Context, input: FrameInput) { ran }); commands::set_input(ctx, &commands); + clipboard::begin_frame(ctx); windows::set_input(ctx); debug_assert!(hooks_ran, "the runtime plugin's hooks did not run for the previous pass: drive frames with `Context::run_ui` or `run_pass`"); scale::set_interface_scale(ctx, scale.0); @@ -341,6 +342,11 @@ fn frame_hit(ctx: &Context) -> HitSizes { pass_state::with::(ctx, |state| state.hit.as_ref().map(|(_, hit)| *hit)).unwrap_or_else(|| resolved_hit(&AppSizes::default())) } +/// The wheel speed and Alt-code pages of the frame's root values; the defaults before the app sets any input. +pub(crate) fn root_input(ctx: &Context) -> (WheelSpeed, AltCodePages) { + pass_state::with::(ctx, |state| state.input.as_ref().map(|input| (input.root.wheel, input.root.alt_codes))).unwrap_or_default() +} + /// How far a press may move and still be a click, in points: the app's hit tolerances (`HitSizes::slop`). egui's own /// click options stay the app's. pub(crate) fn slop(ctx: &Context) -> f32 { diff --git a/crates/ui-contract/src/runtime/install.rs b/crates/ui-contract/src/runtime/install.rs index 354100a78..42268e916 100644 --- a/crates/ui-contract/src/runtime/install.rs +++ b/crates/ui-contract/src/runtime/install.rs @@ -1,6 +1,6 @@ //! `runtime::install`: adds the runtime plugin once and sets the egui options the runtime owns. -use crate::runtime::egui::{input, plugin}; +use crate::runtime::egui::{clipboard, input, plugin}; use crate::runtime::env::{SystemReader, system}; use crate::runtime::pen::PenSource; use crate::runtime::{commands, frame, pen, windows}; @@ -90,9 +90,9 @@ impl InstallSpec { } /// Installs the host's clipboard (system, browser event, memory) in place of the runtime's own. - pub fn clipboard(self, clipboard: craft_platform::clipboard::Clipboard) -> Self { - let _ = clipboard; - todo!("pf.C-R1") + pub fn clipboard(mut self, clipboard: craft_platform::clipboard::Clipboard) -> Self { + self.clipboard = Some(clipboard); + self } /// Loads the stories' command sets too, for an install that shows stories. @@ -211,6 +211,7 @@ pub fn install(ctx: &Context, spec: InstallSpec) -> Result<(), InstallError> { input::set_wheel_modifiers(ctx, spec.wheel.zoom, spec.wheel.sideways); system::install(ctx, spec.system); pen::install(ctx, spec.pen); + clipboard::install(ctx, spec.clipboard); windows::install(ctx, with_browser_caps(spec.shell_info), spec.window_system, spec.placement, spec.frame, spec.app_id); frame::set_frame_layers(ctx, spec.frame_layers); frame::seed_hooked_passes(ctx); diff --git a/crates/ui-contract/src/runtime/pass_state.rs b/crates/ui-contract/src/runtime/pass_state.rs index 9839be283..0990f2103 100644 --- a/crates/ui-contract/src/runtime/pass_state.rs +++ b/crates/ui-contract/src/runtime/pass_state.rs @@ -107,6 +107,7 @@ pass_state! { inspect: crate::runtime::inspect::Log, recorder: crate::runtime::replay::Recorder, pen: crate::runtime::pen::InstalledPen, + clipboard: crate::runtime::egui::clipboard::Installed, #[cfg(feature = "testing")] noted: crate::runtime::egui::widgets::noted::Noted, #[cfg(feature = "testing")] diff --git a/crates/ui-contract/tests/it/runtime/clipboard.rs b/crates/ui-contract/tests/it/runtime/clipboard.rs index 71a65a804..1489a1bf8 100644 --- a/crates/ui-contract/tests/it/runtime/clipboard.rs +++ b/crates/ui-contract/tests/it/runtime/clipboard.rs @@ -1 +1,78 @@ -//! Clipboard trials (owed by platform-w3: this placeholder lets shell-w1's `mod clipboard;` line compile; platform-w3 writes the trials). +//! The clipboard handle: a write is one offer of every flavour, and a late paste reads only in the frame it arrived in. + +use craft_platform::clipboard::{Clipboard, EventClipboard, Flavor, HTML, MemoryClipboard, RTF, TEXT}; +use craft_ui::runtime::commands::{ClipItem, ClipboardHandle}; +use craft_ui::runtime::frame; +use craft_ui::testing::{Frames, install_spec, trial}; +use std::sync::Arc; +use std::sync::atomic::{AtomicU64, Ordering}; + +/// The text of the clipboard's `mime` flavour. +fn text_of(handle: &ClipboardHandle, mime: &str) -> Option { + handle.read(&[mime]).expect("the clipboard reads").map(|flavor| String::from_utf8(flavor.data).expect("the flavour is UTF-8")) +} + +/// One frame that puts `items` (once, in its first pass) and reads every text flavour back in each pass. +fn put_frame(frames: &mut Frames, items: Vec) -> Vec<[Option; 3]> { + let mut items = Some(items); + let mut seen = Vec::new(); + frames.frame(Vec::new(), |ui| { + let handle = ClipboardHandle::of(ui.ctx()); + if let Some(items) = items.take() { + handle.put(&items); + } + seen.push([TEXT, HTML, RTF].map(|mime| text_of(&handle, mime))); + }); + seen +} + +/// One frame, counted as the host counts frames (once per `set_input`), and what each of its passes saw: whether a +/// late paste arrived and the clipboard's text. With `rerun` the frame reruns its first pass. +fn paste_frame(frames: &mut Frames, frame_nr: &AtomicU64, rerun: bool) -> Vec<(bool, Option)> { + frame_nr.fetch_add(1, Ordering::SeqCst); + let mut passes = Vec::new(); + let mut reran = false; + frames.frame(Vec::new(), |ui| { + let handle = ClipboardHandle::of(ui.ctx()); + passes.push((handle.arrived(), handle.read_text().expect("the clipboard reads"))); + if rerun && !reran && frame::discardable(ui.ctx()) { + reran = true; + frame::discard_pass(ui.ctx(), "clipboard trial: a rerun pass"); + } + }); + passes +} + +#[trial] +fn a_clipboard_handle_writes_one_offer_and_a_late_paste_reads_only_in_its_frame() { + let mut frames = Frames::uninstalled(); + craft_ui::install(&frames.ctx, install_spec().clipboard(Clipboard::new(MemoryClipboard::default()))).expect("the runtime installs once"); + let rich = [ClipItem::Text("plain".into()), ClipItem::Html("rich".into()), ClipItem::Rtf("{\\rtf1 rich}".into())]; + let seen = put_frame(&mut frames, rich.to_vec()); + let all = [Some("plain".to_owned()), Some("rich".to_owned()), Some("{\\rtf1 rich}".to_owned())]; + assert_eq!(seen.last(), Some(&all), "one put offers text, HTML and RTF together"); + let handle = ClipboardHandle::of(&frames.ctx); + assert!(handle.has(&[RTF]), "the clipboard holds the RTF flavour of the offer"); + assert!(handle.holds_ours(), "the clipboard holds what the app offered"); + + let seen = put_frame(&mut frames, vec![ClipItem::Text("again".into())]); + assert_eq!(seen.last(), Some(&[Some("again".to_owned()), None, None]), "a later put replaces every flavour of the earlier one"); + + let frame_nr = Arc::new(AtomicU64::new(0)); + let counter = Arc::clone(&frame_nr); + let event = EventClipboard::new(move || counter.load(Ordering::SeqCst), |_: &[Flavor]| Ok(0)); + let late = event.late_offers(); + let mut frames = Frames::uninstalled(); + craft_ui::install(&frames.ctx, install_spec().clipboard(Clipboard::new(event))).expect("the runtime installs once"); + assert_eq!(paste_frame(&mut frames, &frame_nr, false), [(false, None)], "nothing arrived before the offer"); + + late.offer(vec![Flavor::text("late"), Flavor::new(HTML, b"late".to_vec())]); + let passes = paste_frame(&mut frames, &frame_nr, true); + assert_eq!(passes.len(), 2, "the frame reran its pass"); + assert!( + passes.iter().all(|pass| *pass == (true, Some("late".to_owned()))), + "the late paste arrived and reads in every pass of its frame, the rerun one included: {passes:?}" + ); + + assert_eq!(paste_frame(&mut frames, &frame_nr, false), [(false, None)], "the arrival and its flavours stay with the frame it came in"); +} diff --git a/docs/contract-api.md b/docs/contract-api.md index 08caf938b..ab24d020d 100644 --- a/docs/contract-api.md +++ b/docs/contract-api.md @@ -3144,9 +3144,20 @@ The command board: the registry and typed sets, per-frame state, the queue, firi - `pub const fn toggle(self) -> ChromeToggle`. The toggle the command writes to the output. - `craft_ui::runtime::commands::ClipContent`: `pub struct ClipContent { pub text: Option> }`. What a paste delivers. - `craft_ui::runtime::commands::ClipError`: `pub struct ClipError(pub String)`. Why a paste has no content. -- `craft_ui::runtime::commands::ClipItem`: `pub enum ClipItem { Text(Arc), Html(Arc), Image(Arc), Custom { mime: Arc, bytes: Arc<[u8]> } }`. One clipboard item. -- `craft_ui::runtime::commands::ClipboardHandle`: `pub struct ClipboardHandle`. The component's paste slot over the system clipboard. egui carries text and images, so `Html` and `Custom` - - `pub fn put(&self, items: &[ClipItem])`. Writes every flavour of `items` that the clipboard carries. +- `craft_ui::runtime::commands::ClipItem`: `pub enum ClipItem { Text(Arc), Html(Arc), Image(Arc), Rtf(Arc), MathMl(Arc), Custom { mime: Arc, bytes: Arc<[u8]> } }`. One clipboard item. + - `pub fn custom(mime: impl Into>, bytes: impl Into>) -> ClipItem`. An item of an app-defined type: `bytes` under the MIME type `mime`. +- `craft_ui::runtime::commands::ClipboardHandle`: `pub struct ClipboardHandle`. The component's paste slot over the installed clipboard (the host's, else egui's). Every call goes to the + - `pub fn of(ctx: &Context) -> ClipboardHandle`. The clipboard handle of `ctx`, over the installed clipboard, for code outside a component; its paste slot + - `pub fn offer(&self, items: &[ClipItem]) -> Result`. Offers `items` in the caller's order, as one offer, and says which flavour the clipboard kept. A measuring run + - `pub fn read(&self, mimes: &[&str]) -> Result, ClipboardError>`. The first of `mimes` the installed clipboard holds. + - `pub fn read_text(&self) -> Result, ClipboardError>`. The clipboard's text. + - `pub fn read_image(&self) -> Result, ClipboardError>`. The clipboard's image as straight-alpha RGBA8 pixels; `ColorImage::from_rgba_unmultiplied` turns them back. + - `pub fn read_files(&self) -> Result>, ClipboardError>`. The files the clipboard holds. + - `pub fn has(&self, mimes: &[&str]) -> bool`. Whether the clipboard holds one of `mimes`. + - `pub fn holds_ours(&self) -> bool`. Whether the clipboard still holds what this app last offered. + - `pub fn formats(&self) -> Vec`. The MIME names of the formats on the clipboard. + - `pub fn arrived(&self) -> bool`. Whether a late paste offer arrived this frame; true in every pass of that frame. + - `pub fn put(&self, items: &[ClipItem])`. Offers `items` as one offer ([`offer`](Self::offer)), for a caller that does not ask what was kept. - `pub fn paste(&self) -> &Pending`. The pasted content: ready in the pass that delivers the paste to the focused component that lists Paste. - `craft_ui::runtime::commands::CommandDef`: re-export of `craft_keymap::CommandDef` (outside these crates). - `craft_ui::runtime::commands::CommandDefError`: `pub enum CommandDefError { Binding { command: &'static str, error: BindingError }, Scope { command: &'static str }, Duplicate { command: String } }`. Why a command definition is unusable. @@ -3570,13 +3581,14 @@ Decision records and findings: what each pipeline step did, kept in frames a tes `runtime::install`: adds the runtime plugin once and sets the egui options the runtime owns. - `craft_ui::runtime::install::InstallError`: `pub enum InstallError { AlreadyInstalled, DuplicateStyle(DuplicateStyle), Commands(commands::CommandDefError) }`. Why `install` refused a spec. -- `craft_ui::runtime::install::InstallSpec`: `pub struct InstallSpec { pub shell_info: ShellInfo, pub window_system: Arc, pub placement: Option>>, pub frame_layers: Option, pub looks: StyleReplacements, pub frame: Option, pub system: SystemReader }`. What `install` takes. +- `craft_ui::runtime::install::InstallSpec`: `pub struct InstallSpec { pub shell_info: ShellInfo, pub window_system: Arc, pub placement: Option>>, pub frame_layers: Option, pub looks: StyleReplacements, pub frame: Option, pub system: SystemReader, pub clipboard: Option }`. What `install` takes. - `pub fn new(shell_info: ShellInfo, window_system: Arc) -> Self`. A spec for `shell_info` and `window_system`, with no ghost-layer painter. - `pub fn placement(mut self, store: Arc>) -> Self`. Sets the store viewport mounts save their window placement in. - `pub fn looks(mut self, looks: impl Into) -> Self`. Sets the app's style replacements. - `pub fn system(mut self, reader: SystemReader) -> Self`. Sets the reader of the OS's appearance; the host starts it (`SystemReader::start`) with a wake that repaints. - `pub fn frame(mut self, decision: Decision) -> Self`. Sets the root window's decided frame (`craft_window::policy::decide_for`). - `pub fn frame_layers(mut self, painter: Option) -> Self`. Sets the end hook's ghost-layer painter. + - `pub fn clipboard(mut self, clipboard: craft_platform::clipboard::Clipboard) -> Self`. Installs the host's clipboard (system, browser event, memory) in place of the runtime's own. - `craft_ui::runtime::install::install`: `pub fn install(ctx: &Context, spec: InstallSpec) -> Result<(), InstallError>`. Adds the runtime plugin to `ctx` and sets the egui options the runtime owns: interface scale is a command, and ## `craft_ui::runtime::keys`