Merge branch 'pdf-port/sync-fw-menu-misc' into pdf-port/sync

This commit is contained in:
Dylan M. Taylor
2026-11-22 23:05:15 -05:00
29 changed files with 220 additions and 565 deletions
Generated
-16
View File
@@ -2059,13 +2059,9 @@ version = "0.1.0"
name = "craft-automation"
version = "0.1.0"
dependencies = [
<<<<<<< HEAD
"base64 0.23.1",
"craft-ai-agents",
"craft-atomic",
=======
"base64 0.22.1",
>>>>>>> origin/next
"craft-behavior",
"craft-control",
"craft-host",
@@ -3731,11 +3727,7 @@ name = "craft-print"
version = "0.1.0"
dependencies = [
"craft-behavior",
<<<<<<< HEAD
"craft-theme",
=======
"craft-host",
>>>>>>> origin/next
"craft-ui",
"craft-winprint-gdi",
"egui",
@@ -3938,10 +3930,6 @@ dependencies = [
"tempfile",
"toml",
"toml_edit",
<<<<<<< HEAD
=======
"wasm-bindgen-test",
>>>>>>> origin/next
"web-sys",
"web-time",
]
@@ -4364,11 +4352,7 @@ dependencies = [
"smallvec",
"syn 2.0.119",
"toml",
<<<<<<< HEAD
"wasm-bindgen-futures",
=======
"typeid",
>>>>>>> origin/next
"web-time",
]
+3 -20
View File
@@ -34,13 +34,11 @@ agents = ["craft-control/agents", "dep:craft-host"]
# The screenshot reply's PNG and its inline base64 (the control channel builds on every target with `ui`).
base64 = "0.23"
craft-behavior = { workspace = true, optional = true }
<<<<<<< HEAD
craft-host = { workspace = true, optional = true }
=======
# The agents code without a UI toolkit (settings, the launcher's switch, the connection file, the
# CLI's live client), re-exported by `agents` so every app shares one copy.
craft-control = { workspace = true }
>>>>>>> origin/next
# The recorded actions' file picks (`ui`) go through the host on every target.
craft-host = { workspace = true, optional = true }
craft-keymap = { workspace = true, optional = true }
craft-theme = { workspace = true }
craft-ui = { workspace = true, optional = true }
@@ -48,27 +46,12 @@ egui = { workspace = true, optional = true }
png = "0.17"
serde = { workspace = true }
serde_json = { workspace = true }
<<<<<<< HEAD
# `std::time::Instant` panics on wasm; this is the same type on native.
web-time = "1.1"
# The server and client, the token files, the profiler and the trace.
# The server, client, token files, profiler and trace.
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
craft-platform = { workspace = true }
craft-ai-agents = { workspace = true, optional = true }
craft-atomic = { workspace = true, optional = true }
craft-flags = { workspace = true, optional = true }
=======
web-time = "1.1"
# The screenshot queue encodes and inlines PNGs on every target the control channel builds for.
base64 = "0.22"
png = "0.17"
# The server, client, profiler and trace.
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
craft-platform = { workspace = true }
craft-host = { workspace = true, optional = true }
>>>>>>> origin/next
getrandom = "0.3"
hmac = "0.12"
log = "0.4"
+5 -21
View File
@@ -14,10 +14,6 @@
//! two happened, once, between the UI thread and the transport.
use std::sync::mpsc::{Receiver, Sender};
<<<<<<< HEAD
=======
use web_time::Instant;
>>>>>>> origin/next
use craft_ui::runtime::motion;
use craft_ui::runtime::windows::WindowHost;
@@ -140,22 +136,15 @@ pub enum Reply {
}
impl Reply {
<<<<<<< HEAD
/// A `ui.screenshot` reply for `token` of `viewport` with what [`ScreenshotParams::from_params`] read: the PNG
/// goes to `params.path` or is inlined when `None`, and shows `params.region` or the whole window.
pub fn screenshot(token: u64, params: ScreenshotParams, viewport: egui::ViewportId) -> Self {
Self::Screenshot { token, path: params.path, region: params.region, viewport }
=======
/// A `ui.accessTree` reply: held until the window's settled access tree is available.
pub fn access_tree() -> Reply {
Reply::AccessTree
}
/// A `ui.screenshot` reply for `token` of `viewport`, writing the PNG to `path` or inlining it
/// when `None`.
pub fn screenshot(token: u64, path: Option<String>, viewport: egui::ViewportId) -> Self {
Self::Screenshot { token, path, viewport }
>>>>>>> origin/next
/// A `ui.screenshot` reply for `token` of `viewport` with what [`ScreenshotParams::from_params`] read: the PNG
/// goes to `params.path` or is inlined when `None`, and shows `params.region` or the whole window.
pub fn screenshot(token: u64, params: ScreenshotParams, viewport: egui::ViewportId) -> Self {
Self::Screenshot { token, path: params.path, region: params.region, viewport }
}
/// `Done` with the [`result_reply`] of a method's result.
@@ -220,15 +209,10 @@ impl ControlChannel {
}
Reply::AfterInput => self.input_waiters.push(reply),
Reply::AfterJob(job) => self.job_waiters.push((job, reply)),
<<<<<<< HEAD
Reply::AccessTree => self.tree_waiters.push(reply),
Reply::Screenshot { token, path, region, viewport } => {
let request = ScreenshotRequest { token, path, region, viewport, reply, document, settle_ms };
if let Err((reply, e)) = self.captures.admit(request, motion::now()) {
=======
Reply::AccessTree => self.tree_waiters.push(reply),
Reply::Screenshot { token, path, viewport } => {
if let Err((reply, e)) = self.captures.admit(ScreenshotRequest { token, path, viewport, reply, document, settle_ms }, motion::now()) {
>>>>>>> origin/next
let _ = reply.send(json!({"ok": false, "error": e}));
}
}
-5
View File
@@ -38,11 +38,6 @@ pub mod dock;
pub mod files;
#[cfg(not(target_arch = "wasm32"))]
pub mod profiler;
<<<<<<< HEAD
// The native client reads `REPLY_DEADLINE` without `ui`; the control channel reads the validators on every target.
#[cfg(any(feature = "ui", not(target_arch = "wasm32")))]
=======
>>>>>>> origin/next
pub mod protocol;
#[cfg(feature = "ui")]
pub mod screenshot;
-4
View File
@@ -19,11 +19,7 @@
use std::collections::HashMap;
use std::sync::Arc;
use std::sync::mpsc::Sender;
<<<<<<< HEAD
use std::time::Duration;
=======
use web_time::{Duration, Instant};
>>>>>>> origin/next
use base64::Engine as _;
use craft_ui::runtime::windows::{ScreenshotFacts, ScreenshotSlot, WindowHost};
+1 -6
View File
@@ -92,13 +92,8 @@ impl At {
fn in_space(p: &Params<'_>, pos: Pos2) -> Result<Self, String> {
Ok(match p.choice("coordinates", "coordinates", &["screen", "document"])?.unwrap_or("screen") {
<<<<<<< HEAD
"document" => Self::Document(pos),
"document" => Self::Document(pos, p.uint_field("page")?.map_or(0, |page| usize::try_from(page).unwrap_or(usize::MAX))),
_ => Self::Screen(pos),
=======
"document" => Self::Document(pos2(x, y), p.uint_field("page")?.map_or(0, |page| usize::try_from(page).unwrap_or(usize::MAX))),
_ => Self::Screen(pos2(x, y)),
>>>>>>> origin/next
})
}
+2 -3
View File
@@ -123,7 +123,6 @@ fn an_unauthenticated_connection_is_closed_at_the_deadline_whatever_it_sends() {
assert!(rx.try_recv().is_err(), "nothing was dispatched");
}
<<<<<<< HEAD
/// Whether the server closed the connection: the next read is the end of the stream, not a timeout or an error.
fn is_closed(reader: &mut impl BufRead) -> bool {
let mut line = String::new();
@@ -186,7 +185,8 @@ fn a_refused_first_frame_closes_the_connection() {
assert!(is_closed(&mut reader), "{first}: the connection is closed, the second guess unanswered");
}
assert!(rx.try_recv().is_err(), "nothing was dispatched");
=======
}
/// A web page can reach loopback: a browser `POST` whose body is a valid `auth` line is refused at its request line
/// and the connection closed, so neither the body's `auth` nor a request after it reaches the app.
#[trial]
@@ -212,7 +212,6 @@ fn a_browser_post_never_reaches_the_app() {
};
assert!(closed, "the connection closes after the refusal, answering nothing more: {rest:?}");
assert!(rx.recv_timeout(Duration::from_millis(300)).is_err(), "nothing reached the app");
>>>>>>> origin/next
}
/// A request line over `MAX_REQUEST_BYTES` without a newline gets an error reply and the connection is closed.
+3 -12
View File
@@ -2,21 +2,12 @@
// Unwrapping, expecting and panicking on failure is fine in tests, unlike in shipped code.
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
<<<<<<< HEAD
mod access;
mod actions;
mod agents;
mod control;
mod dialogs;
mod dock;
mod files;
mod screenshot;
mod synthetic;
=======
pub(crate) mod access;
pub(crate) mod actions;
pub(crate) mod agents;
pub(crate) mod control;
pub(crate) mod dialogs;
pub(crate) mod dock;
pub(crate) mod files;
pub(crate) mod screenshot;
pub(crate) mod synthetic;
>>>>>>> origin/next
+3 -3
View File
@@ -419,7 +419,6 @@ mod tests {
}
#[test]
<<<<<<< HEAD
fn stacked_parts_of_one_priority_rank_by_their_order_before_the_nearest_centre() {
let at = pos2(50.0, 50.0);
let owner = |shapes: &[Shape<u8>]| resolve(shapes, at, ResolveFor::Press).map(|w| w.owner);
@@ -428,7 +427,9 @@ mod tests {
assert_eq!(owner(&[far(), near()]), Some(1), "unstacked, the nearer centre wins");
assert_eq!(owner(&[far().stacking(1), near()]), Some(2), "the higher stacking order wins though the press is nearer the other's centre");
assert_eq!(owner(&[near().stacking(1), far().stacking(1)]), Some(1), "one order: the nearest centre decides");
=======
}
#[test]
fn a_polyline_hits_within_its_own_reach_and_a_bad_reach_is_a_lines() {
let points = vec![pos2(0.0, 0.0), pos2(100.0, 0.0)];
let line = HitShape::polyline(points.clone(), false);
@@ -440,6 +441,5 @@ mod tests {
for bad in [f32::NAN, f32::INFINITY, -1.0] {
assert_eq!(HitShape::polyline_within(points.clone(), false, bad), line);
}
>>>>>>> origin/next
}
}
+1 -5
View File
@@ -19,11 +19,7 @@ pub enum ReorderKeys {
}
/// What the focused stop is, as far as the table's rows differ.
<<<<<<< HEAD
#[derive(Clone, Copy, Debug)]
=======
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
>>>>>>> origin/next
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct KeyRole {
/// A value control with a reset value and no text part: Delete resets it.
+3 -3
View File
@@ -291,7 +291,6 @@ mod tests {
}
#[test]
<<<<<<< HEAD
fn an_overlay_with_no_room_on_its_side_opens_on_the_other() {
let size = Vec2::new(200.0, 80.0);
let low = rect(300.0, 540.0, 100.0, 30.0);
@@ -303,7 +302,9 @@ mod tests {
let placed = place(&PlaceRequest::new(high, size, BOUNDS).side(Side::Below).gap(4.0));
assert_eq!(placed.side, Side::Below, "room below: {placed:?}");
assert!(placed.rect.top() >= high.bottom(), "below the anchor: {placed:?}");
=======
}
#[test]
fn a_menu_that_covers_its_anchor_and_fits_neither_side_keeps_its_height_and_slides_over_the_anchor() {
let point = rect(300.0, 400.0, 0.0, 0.0);
let request = PlaceRequest::new(point, Vec2::new(200.0, 450.0), BOUNDS).covers_anchor(true);
@@ -315,7 +316,6 @@ mod tests {
assert!(above.side == Side::Above && above.rect.bottom() == point.top(), "fits above: opens above the point: {above:?}");
let without = place(&request.covers_anchor(false));
assert!(without.side == Side::Above && without.rect.height() < 450.0, "without it: capped to the larger side: {without:?}");
>>>>>>> origin/next
}
#[test]
+2 -23
View File
@@ -525,7 +525,6 @@ struct Open<T> {
dragging: bool,
/// Moved past slop on a target that senses no drag: the click is gone and nothing starts.
abandoned: bool,
<<<<<<< HEAD
/// Moved past slop in this pass on a target that clicks and passes its drag (`Sense::PASSES_DRAG`), with the
/// pointer at the pass's end: no click and no drag until [`PressMachine::hand_over`] gives the press its new
/// target. The next pass abandons a press no shape took.
@@ -533,13 +532,11 @@ struct Open<T> {
/// A press passed to this target ([`PressPick::passed`]) whose drag has not started: it reports nothing, and a
/// release or cancel ends it unreported. Its move past slop starts the drag with `DragStart`, as a hand-over does.
silent: bool,
=======
/// The pointer left the window ([`PointerEvent::Gone`]): the click is gone, but a target that senses a drag still
/// starts it from the moves that follow. The button is still down and the window keeps getting the pointer's moves
/// and release while it is outside, so a press near a window edge (a window's resize grip) that leaves the window
/// before it passes slop still drags.
left: bool,
>>>>>>> origin/next
/// A pass reported the press: later passes within slop report `Held`, not `Down`.
reported: bool,
/// A pass reported the drag's start: later passes report `Drag`.
@@ -558,11 +555,7 @@ impl<T> Open<T> {
/// A release now is a click.
fn clicks(&self) -> bool {
<<<<<<< HEAD
!self.dragging && !self.abandoned && self.passing.is_none() && self.sense.contains(Sense::CLICK)
=======
!self.dragging && !self.abandoned && !self.left && self.sense.contains(Sense::CLICK)
>>>>>>> origin/next
!self.dragging && !self.abandoned && !self.left && self.passing.is_none() && self.sense.contains(Sense::CLICK)
}
}
@@ -700,7 +693,6 @@ impl<T: Copy> PressMachine<T> {
let sense = if capture_only && !clicks { pick.sense - Sense::CLICK } else { pick.sense };
(pick, sense, clicks)
})
<<<<<<< HEAD
.filter(|(_, sense, clicks)| match button {
PointerButton::Primary => true,
PointerButton::Middle => *clicks || sense.contains(Sense::DRAG),
@@ -715,26 +707,13 @@ impl<T: Copy> PressMachine<T> {
start: PressStart::new(at, button, time, clicks),
dragging: false,
abandoned: false,
left: false,
passing: None,
silent,
reported: silent,
drag_reported: false,
released_at: None,
}
=======
.filter(|(_, sense, clicks)| !capture_only || *clicks || sense.contains(Sense::DRAG))
.map(|(target, sense, _)| (target, sense))
.map(|(target, sense)| Open {
target,
sense,
start: PressStart::new(at, button, time, clicks),
dragging: false,
abandoned: false,
left: false,
reported: false,
drag_reported: false,
released_at: None,
>>>>>>> origin/next
});
}
PointerEvent::Released { button, pos: at } => {
-5
View File
@@ -469,12 +469,7 @@ impl Component for PaintChip<'_> {
let solid = cx.memory::<LastSolid>().0.unwrap_or(self.fallback);
let current = FillKind::of(&paint);
let sampled = self.sampled;
<<<<<<< HEAD
let swatch_words = cx.words::<SwatchesWords>();
let recent = self.recent;
=======
let recent_cells: Vec<(Label, Srgba)> = self.recent.iter().map(|color| (Label::from(color.to_hex()), *color)).collect();
>>>>>>> origin/next
let full_picker = self.full_picker;
let cmyk = self.cmyk.unwrap_or_else(|| CmykConverter::coated());
let solid_now = if let Paint::Solid(color) = &paint { Some(*color) } else { None };
+28 -50
View File
@@ -18,19 +18,12 @@ use craft_host::Section;
use craft_theme::variant::Tone;
use craft_ui::buttons::{ControlPlace, IconButton};
use craft_ui::contract::{
<<<<<<< HEAD
Access, Bind, Common, Component, Cx, Edit as _, EditResponse, Focus as _, Input, MeasureCx, Outcome, OverlayUi, Overlays as _, PaintUi, PartsCx,
Pointer as _, Props as _, Remember as _, Role, WordSetCx as _,
};
use craft_ui::fonts::FontRef;
use craft_ui::list::{ThumbSize, TrailingPart};
=======
Bind, Common, Component, Cx, Edit as _, EditResponse, Focus as _, Input, MeasureCx, Outcome, OverlayUi, Overlays as _, PaintUi, PartsCx,
Pointer as _, Props as _, Remember as _, Role, Styled as _, WordSetCx as _,
};
use craft_ui::controls::disclosure::DisclosureGlyph;
use craft_ui::fonts::FontRef;
use craft_ui::list::{ListRow, ThumbSize};
>>>>>>> origin/next
use craft_ui::primitives::{IconSpec, TextKey, TextOptions, TextRun};
use craft_ui::runtime::env::{EnvView, Label};
use craft_ui::runtime::memory::StageAccess;
@@ -416,13 +409,10 @@ pub struct FontPickerOutput {
/// of the open list (Photoshop previews on hover). It ends when the pointer leaves the rows, the list closes
/// (Escape, a press outside) or a row is picked. The field's value and text stay.
pub preview: Preview<String>,
<<<<<<< HEAD
/// The key of the host face or action row run in this pass; a host pick does not write the `family` binding.
pub host_picked: Option<String>,
=======
/// The index of the action row picked, in the `actions` the host gave.
pub action: Option<usize>,
>>>>>>> origin/next
/// The key of the host face or action row run in this pass; a host pick does not write the `family` binding.
pub host_picked: Option<String>,
}
impl Outcome for FontPickerOutput {
@@ -461,13 +451,10 @@ fn text_key() -> TextKey<String> {
struct FamilyCodec {
infos: Arc<FamilyInfos>,
language: String,
<<<<<<< HEAD
/// The name of the host row shown as the field's value, which stands in for the family's name.
host: Option<String>,
=======
/// A typed name that is no installed family is a value too (Word's font box applies it as typed).
free: bool,
>>>>>>> origin/next
/// The name of the host row shown as the field's value, which stands in for the family's name.
host: Option<String>,
}
impl FamilyCodec {
@@ -611,15 +598,6 @@ pub struct FontPicker<'a> {
/// Families the host can fetch but that are not installed, listed with the served mark.
#[prop]
served: &'a [String],
<<<<<<< HEAD
/// Host groups listed above the catalogue families, in order, with a separator between groups.
#[prop]
host: &'a [HostFontGroup<'a>],
/// The key of the host row shown as the field's value.
#[prop]
current_host: Option<String>,
host_picked: Option<String>,
=======
/// How the list is laid out: the library picker, or Word's plain font box.
#[prop]
kind: FontPickerKind,
@@ -633,7 +611,13 @@ pub struct FontPicker<'a> {
#[prop]
advice: MissingAdvice,
action: Option<usize>,
>>>>>>> origin/next
/// Host groups listed above the catalogue families, in order, with a separator between groups.
#[prop]
host: &'a [HostFontGroup<'a>],
/// The key of the host row shown as the field's value.
#[prop]
current_host: Option<String>,
host_picked: Option<String>,
}
impl<'a> FontPicker<'a> {
@@ -651,17 +635,14 @@ impl<'a> FontPicker<'a> {
preview: Preview::Unchanged,
preview_text: None,
served: &[],
<<<<<<< HEAD
host: &[],
current_host: None,
host_picked: None,
=======
kind: FontPickerKind::default(),
actions: &[],
shown_as: None,
advice: MissingAdvice::default(),
action: None,
>>>>>>> origin/next
host: &[],
current_host: None,
host_picked: None,
}
.label(label)
.enabled(catalog.is_ready())
@@ -678,14 +659,11 @@ impl<'a> FontPicker<'a> {
all
}
<<<<<<< HEAD
fn codec(&self, env: &EnvView<'_>) -> FamilyCodec {
FamilyCodec { infos: infos(self.catalog), language: ui_language(env), host: self.host_name() }
=======
/// The note for `family` when it is shown in another face because the catalog lacks it, by the rule the Missing
/// Fonts dialog uses: the missing-font sentence, then the advice the host chose.
/// Fonts dialog uses: the missing-font sentence, then the advice the host chose. A host row shown as the value
/// has none.
fn missing_note(&self, family: &str, words: &MissingFontsWords) -> Option<Label> {
let face = self.shown_as.filter(|_| self.catalog.is_ready())?;
let face = self.shown_as.filter(|_| self.catalog.is_ready() && self.host_name().is_none())?;
let status = document_fonts(self.catalog, &[DocumentFont::new(family, "", None)]).into_iter().next()?.status;
if status != FontStatus::Missing {
return None;
@@ -699,8 +677,7 @@ impl<'a> FontPicker<'a> {
}
fn codec(&self, infos: Arc<FamilyInfos>, env: &EnvView<'_>) -> FamilyCodec {
FamilyCodec { infos, language: ui_language(env), free: self.kind == FontPickerKind::Plain }
>>>>>>> origin/next
FamilyCodec { infos, language: ui_language(env), free: self.kind == FontPickerKind::Plain, host: self.host_name() }
}
/// The name of the host row `current_host` names, which the field shows in place of the family.
@@ -840,12 +817,10 @@ impl Component for FontPicker<'_> {
}
let mut options = TextOptions::new();
options.select_on_focus = true;
<<<<<<< HEAD
options.mixed = cx.value().is_none();
if options.mixed {
options.placeholder = Some(cx.words::<FontPickerWords>().mixed.clone());
}
=======
if !self.catalog.is_ready() {
// The first scan runs on a background thread; the field asks again until it ends.
self.catalog.scan_in_background();
@@ -855,7 +830,6 @@ impl Component for FontPicker<'_> {
return;
}
let codec = self.codec(infos_of(cx.ui.ctx(), cx.id, self.catalog), &cx.env);
>>>>>>> origin/next
cx.text(text_key(), placed.text, &codec, &family, &options);
}
@@ -968,10 +942,14 @@ impl Component for FontPicker<'_> {
settings.note_recent(family);
write(&mut bind, &mut cx, settings, "Recent font");
}
<<<<<<< HEAD
FontPickerOutput { edit, picked, preview: self.preview, picked_style: self.picked_style, rested: self.rested, host_picked }
=======
FontPickerOutput { edit, picked, preview: self.preview, picked_style: self.picked_style, rested: self.rested, action: self.action }
>>>>>>> origin/next
FontPickerOutput {
edit,
picked,
preview: self.preview,
picked_style: self.picked_style,
rested: self.rested,
action: self.action,
host_picked,
}
}
}
-29
View File
@@ -366,7 +366,6 @@ pub(super) fn list(
}
(rows, comparable)
}
<<<<<<< HEAD
/// The host rows the list shows for `query`, as (group, row) in group order: every row for an empty query, else the
/// face and action rows whose name matches as a family name would. A notice speaks of its group as a whole, so it
@@ -383,31 +382,3 @@ pub(super) fn host_rows(groups: &[HostFontGroup<'_>], query: &str, folder: &Fold
.map(|(group, at, _)| (group, at))
.collect()
}
#[cfg(test)]
mod tests {
use craft_ui::testing::trial;
use super::{ARABIC_CORE, has_arabic_sample};
const LATIN: &str = "AaBbCc";
/// "أبجد هوز".
const ARABIC: &str = "\u{623}\u{628}\u{62C}\u{62F} \u{647}\u{648}\u{632}";
fn maps(chars: &str) -> impl Fn(&str) -> bool + '_ {
move |text| text.chars().filter(|c| !c.is_whitespace()).all(|c| chars.contains(c))
}
#[trial]
fn an_arabic_sample_needs_the_latin_sample_and_every_arabic_test_letter() {
let all = format!("{LATIN}{ARABIC_CORE}{ARABIC}");
assert!(has_arabic_sample(&maps(&all), LATIN, ARABIC));
assert!(!has_arabic_sample(&maps(LATIN), LATIN, ARABIC), "a Latin-only face");
for missing in LATIN.chars().chain(ARABIC_CORE.chars()).chain(ARABIC.chars().filter(|c| !c.is_whitespace())) {
let partial: String = all.chars().filter(|c| *c != missing).collect();
assert!(!has_arabic_sample(&maps(&partial), LATIN, ARABIC), "without U+{:04X}", missing as u32);
}
}
}
=======
>>>>>>> origin/next
+79 -164
View File
@@ -1,11 +1,6 @@
<<<<<<< HEAD
//! The picker's popup: the preview banner, the filter toggles, the class column and the list of the host's rows and
//! the family rows with the styles of the families opened in it.
=======
//! The picker's popup: the preview banner, the filter toggles, the class column and the list of family rows with the
//! styles of the families opened in it. A family row reads, in reading order: its star, the disclosure of its styles
//! the family rows with the styles of the families opened in it. A family row reads, in reading order: its star, the disclosure of its styles
//! (or the empty disclosure column), the name, the format badge and the sample in the family's face.
>>>>>>> origin/next
use std::borrow::Cow;
use std::collections::hash_map::DefaultHasher;
@@ -25,18 +20,11 @@ use craft_ui::layout_components::{Row, Stack};
use craft_ui::list::{List, ListRow, ThumbSize, ToggleCell, ToggleFace, ToggleState, TreeLeaves};
use craft_ui::runtime::env::Label;
<<<<<<< HEAD
use super::rank::{Infos, Language, Listing, host_rows, list, shown_name};
use super::{
FamilyRow, FontClass, FontFilters, FontFormat, FontPicker, FontPickerSettings, FontPickerWords, HostFontGroup, HostFontKind, HostFontRow, POPUP,
STAR, Typing, infos, read, ui_language, write,
=======
use super::banner::FontPreviewBanner;
use super::rank::{FamilyInfos, Language, Listing, list, shown_name};
use super::rank::{FamilyInfos, Language, Listing, host_rows, list, shown_name};
use super::{
FamilyRow, FontClass, FontFilters, FontFormat, FontPicker, FontPickerKind, FontPickerSettings, FontPickerWords, POPUP, SAMPLE_EM, Typing,
infos_of, read, ui_language, write,
>>>>>>> origin/next
FamilyRow, FontClass, FontFilters, FontFormat, FontPicker, FontPickerKind, FontPickerSettings, FontPickerWords, HostFontGroup, HostFontKind,
HostFontRow, POPUP, SAMPLE_EM, Typing, infos_of, read, ui_language, write,
};
use crate::panel::faces::Owner;
use crate::panel::specimen::{FontSample, SampleFace};
@@ -51,7 +39,13 @@ const NAME: ColumnKey = ColumnKey::new("name");
/// The column of the sample in the family's face.
const SAMPLE: ColumnKey = ColumnKey::new("sample");
<<<<<<< HEAD
/// The headings of the `Plain` list.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
enum Heading {
Recent,
All,
}
/// Which gap a gap slot is: the one after a host group (before the next group or the families), or the one between
/// the recents and the other families.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
@@ -61,27 +55,13 @@ enum Gap {
}
/// One position of the list: a host group's heading, a host row (`at` in group `group`), a family, one style of an
/// open family, or a gap.
=======
/// The headings of the `Plain` list.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
enum Heading {
Recent,
All,
}
/// One position of the list: a family, one style of an open family, the gap between the recents and the other
/// families, a heading of the `Plain` list, or one of the host's action rows.
>>>>>>> origin/next
/// open family, a gap, a heading of the `Plain` list, or one of the host's action rows.
enum Slot {
Heading { group: usize, name: Label },
HostHeading { group: usize, name: Label },
Host { group: usize, at: usize, row: HostFontRow },
Family { row: FamilyRow, open: bool },
Style { family: String, style: String },
<<<<<<< HEAD
Gap(Gap),
=======
Gap,
Heading(Heading),
Action(usize),
}
@@ -92,22 +72,17 @@ struct Layout {
sections: bool,
/// How many action rows follow the families.
actions: usize,
>>>>>>> origin/next
}
/// What names a slot across passes. A family opening shifts the positions after it, so the list keys its rows by what
/// they are and the lead stays on its row.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
enum SlotKey {
<<<<<<< HEAD
Gap(Gap),
Heading(usize),
Host { group: usize, at: usize },
=======
Gap,
Heading(Heading),
HostHeading(usize),
Host { group: usize, at: usize },
Action(usize),
>>>>>>> origin/next
Family { family: String, recent: bool },
Style { family: String, style: String },
}
@@ -115,17 +90,13 @@ enum SlotKey {
impl Slot {
fn key(&self) -> SlotKey {
match self {
Slot::Heading { group, .. } => SlotKey::Heading(*group),
Slot::HostHeading { group, .. } => SlotKey::HostHeading(*group),
Slot::Host { group, at, .. } => SlotKey::Host { group: *group, at: *at },
Slot::Family { row, .. } => SlotKey::Family { family: row.family.clone(), recent: row.recent },
Slot::Style { family, style } => SlotKey::Style { family: family.clone(), style: style.clone() },
<<<<<<< HEAD
Slot::Gap(gap) => SlotKey::Gap(*gap),
=======
Slot::Gap => SlotKey::Gap,
Slot::Heading(heading) => SlotKey::Heading(*heading),
Slot::Action(at) => SlotKey::Action(*at),
>>>>>>> origin/next
}
}
@@ -135,11 +106,7 @@ impl Slot {
match self {
Slot::Family { row, .. } => Some(&row.family),
Slot::Style { family, .. } => Some(family),
<<<<<<< HEAD
Slot::Heading { .. } | Slot::Host { .. } | Slot::Gap(_) => None,
=======
Slot::Gap | Slot::Heading(_) | Slot::Action(_) => None,
>>>>>>> origin/next
Slot::HostHeading { .. } | Slot::Host { .. } | Slot::Gap(_) | Slot::Heading(_) | Slot::Action(_) => None,
}
}
@@ -148,11 +115,7 @@ impl Slot {
match self {
Slot::Family { row, .. } => Some((&row.family, None)),
Slot::Style { family, style } => Some((family, Some(style))),
<<<<<<< HEAD
Slot::Heading { .. } | Slot::Host { .. } | Slot::Gap(_) => None,
=======
Slot::Gap | Slot::Heading(_) | Slot::Action(_) => None,
>>>>>>> origin/next
Slot::HostHeading { .. } | Slot::Host { .. } | Slot::Gap(_) | Slot::Heading(_) | Slot::Action(_) => None,
}
}
}
@@ -195,51 +158,53 @@ impl DisplayOrder<SlotKey> for Slots<'_> {
}
fn is_section(&self, at: usize) -> bool {
<<<<<<< HEAD
matches!(self.0[at], Slot::Gap(_) | Slot::Heading { .. })
matches!(self.slots[at], Slot::Gap(_) | Slot::Heading(_) | Slot::HostHeading { .. })
}
/// A notice is text, which neither the keys nor a click take.
fn enabled(&self, at: usize) -> bool {
!matches!(&self.0[at], Slot::Host { row, .. } if matches!(row.kind, HostFontKind::Notice))
}
fn text(&self, at: usize) -> Option<Cow<'_, str>> {
match &self.0[at] {
Slot::Heading { name, .. } => Some(Cow::Borrowed(name.as_str())),
Slot::Host { row, .. } => Some(Cow::Borrowed(row.name.as_str())),
Slot::Family { row, .. } => Some(Cow::Borrowed(row.shown.as_str())),
Slot::Style { style, .. } => Some(Cow::Borrowed(style.as_str())),
Slot::Gap(_) => None,
=======
matches!(self.slots[at], Slot::Gap | Slot::Heading(_))
!matches!(&self.slots[at], Slot::Host { row, .. } if matches!(row.kind, HostFontKind::Notice))
}
fn text(&self, at: usize) -> Option<Cow<'_, str>> {
match &self.slots[at] {
Slot::HostHeading { name, .. } => Some(Cow::Borrowed(name.as_str())),
Slot::Host { row, .. } => Some(Cow::Borrowed(row.name.as_str())),
Slot::Family { row, .. } => Some(Cow::Borrowed(row.shown.as_str())),
Slot::Style { style, .. } => Some(Cow::Borrowed(style.as_str())),
Slot::Gap | Slot::Heading(_) | Slot::Action(_) => None,
>>>>>>> origin/next
Slot::Gap(_) | Slot::Heading(_) | Slot::Action(_) => None,
}
}
}
impl ItemSource<SlotKey> for Slots<'_> {
fn size_hint(&self, at: usize) -> SizeHint {
match self.slots[at] {
match &self.slots[at] {
Slot::Family { .. } => SizeHint::Height(self.row),
Slot::Host { row, .. } if matches!(row.kind, HostFontKind::Face(_)) => SizeHint::Height(self.row),
_ => SizeHint::Auto,
}
}
<<<<<<< HEAD
fn toggled(&self, at: usize, column: &ColumnKey) -> bool {
*column == STAR && matches!(&self.slots[at], Slot::Family { row, .. } if row.starred)
}
}
/// The `shown` host rows (as `host_rows` lists them) by group, each under its group's heading, with a gap after each
/// group that has rows; then the family rows with a gap after the recents and the styles of each expanded family
/// under its row.
fn slots(catalog: &Catalog, host: &[HostFontGroup<'_>], shown: &[(usize, usize)], rows: Vec<FamilyRow>, expanded: &[String]) -> Vec<Slot> {
/// group that has rows; then the family rows with a gap after the recents (headings over the recents and the
/// families under `layout.sections`), the styles of each expanded family under its row, and the action rows at the
/// end.
fn slots(
catalog: &Catalog,
host: &[HostFontGroup<'_>],
shown: &[(usize, usize)],
rows: Vec<FamilyRow>,
expanded: &[String],
layout: &Layout,
) -> Vec<Slot> {
let recents = rows.iter().take_while(|row| row.recent).count();
let mut slots: Vec<Slot> = Vec::with_capacity(shown.len() + rows.len() + 1);
let mut slots: Vec<Slot> = Vec::with_capacity(shown.len() + rows.len() + 2);
let mut last_group: Option<usize> = None;
for &(group, at) in shown {
let Some(of) = host.get(group) else { continue };
@@ -249,7 +214,7 @@ fn slots(catalog: &Catalog, host: &[HostFontGroup<'_>], shown: &[(usize, usize)]
slots.push(Slot::Gap(Gap::Host(last)));
}
if let Some(name) = &of.heading {
slots.push(Slot::Heading { group, name: name.clone() });
slots.push(Slot::HostHeading { group, name: name.clone() });
}
last_group = Some(group);
}
@@ -260,20 +225,6 @@ fn slots(catalog: &Catalog, host: &[HostFontGroup<'_>], shown: &[(usize, usize)]
{
slots.push(Slot::Gap(Gap::Host(last)));
}
for (at, row) in rows.into_iter().enumerate() {
if at == recents && recents > 0 {
slots.push(Slot::Gap(Gap::Recents));
=======
fn toggled(&self, at: usize, column: &ColumnKey) -> bool {
*column == STAR && matches!(&self.slots[at], Slot::Family { row, .. } if row.starred)
}
}
/// The rows with a gap after the recents (headings over the recents and the families under `layout.sections`), the
/// styles of each expanded family under its row, and the action rows at the end.
fn slots(catalog: &Catalog, rows: Vec<FamilyRow>, expanded: &[String], layout: &Layout) -> Vec<Slot> {
let recents = rows.iter().take_while(|row| row.recent).count();
let mut slots: Vec<Slot> = Vec::with_capacity(rows.len() + 2);
for (at, row) in rows.into_iter().enumerate() {
if layout.sections {
@@ -284,8 +235,7 @@ fn slots(catalog: &Catalog, rows: Vec<FamilyRow>, expanded: &[String], layout: &
slots.push(Slot::Heading(Heading::All));
}
} else if at == recents && recents > 0 {
slots.push(Slot::Gap);
>>>>>>> origin/next
slots.push(Slot::Gap(Gap::Recents));
}
let open = !row.recent && row.styles > 1 && expanded.contains(&row.family);
let family = row.family.clone();
@@ -366,36 +316,6 @@ impl DisplayOrder<u8> for Classes<'_> {
}
}
<<<<<<< HEAD
/// The line of a host row: a face with its name painted in its own face at the preview size, an action, or a notice
/// that takes no activation.
fn host_line<'r>(row: &HostFontRow, checked: bool, size: ThumbSize) -> ListRow<'r> {
match &row.kind {
HostFontKind::Notice => ListRow::new(row.name.clone()).depth(0).enabled(false),
HostFontKind::Action => ListRow::new(row.name.clone()).option().depth(0),
HostFontKind::Face(face) => {
let line = ListRow::new(row.name.clone()).option().depth(0).check(checked);
match face.clone().filter(|_| size != ThumbSize::None) {
Some(font) => {
let text = row.name.as_str().to_owned();
let aspect = ThumbAspect::new(SAMPLE_ASPECT.0, SAMPLE_ASPECT.1);
line.thumb_aspect(size, aspect, move |cx, rect| {
let ink = DataColor::new(cx.ink());
paint_sample(cx, rect, &font, &text, rect.height() * SAMPLE_EM, ink);
})
}
None => line,
}
}
}
}
/// The banner: `text` in the face of `family`, on one line cut at the end, in a picture as high as the large thumbnail.
fn banner(ui: &mut egui::Ui, catalog: &Arc<Catalog>, infos: &Infos, family: &str, shown_name: &str, text: &str) {
Picture::painter(shown_name.to_owned(), ThumbAspect::new(BANNER_ASPECT.0, BANNER_ASPECT.1), face_thumb(catalog, infos, family, text.to_owned()))
.extent(PictureSize::Thumb(ThumbSize::Large))
.show(ui);
=======
impl ItemSource<u8> for Classes<'_> {}
/// The class column: All Classes and the eight classes as a list of options, the chosen one selected.
@@ -418,7 +338,26 @@ fn sample<'a>(catalog: &'a Catalog, infos: &'a FamilyInfos, family: &str, shown:
let face =
infos.families.get(family).map_or(SampleFace::Missing, |info| SampleFace::Face { catalog, owner: Owner::Installed, face: &info.regular });
FontSample::new(format!("{shown}: {text}"), text, face, points)
>>>>>>> origin/next
}
/// The line of a host row: a face with its name as the sample in its own face, an action, or a notice that takes no
/// activation. A face row lays out in the list's columns as a family row does.
fn host_line<'r>(row: &'r HostFontRow, checked: bool, cells: &[(ColumnKey, egui::Rect)], size: ThumbSize, points: f32) -> ListRow<'r> {
match &row.kind {
HostFontKind::Notice => ListRow::new(row.name.clone()).depth(0).enabled(false),
HostFontKind::Action => ListRow::new(row.name.clone()).option().depth(0),
HostFontKind::Face(face) => {
let line = ListRow::new(row.name.clone()).cells(cells).option().depth(0).check(checked);
match face.as_ref().filter(|_| size != ThumbSize::None) {
Some(font) => {
let text = row.name.as_str();
let sample = FontSample::new(format!("{text}: {text}"), text, SampleFace::Font(font), points);
line.cell_field(SAMPLE, sample, |_| {})
}
None => line,
}
}
}
}
/// The name the banner shows for `family`: its row's shown name when the list holds one, else its name in the
@@ -497,18 +436,13 @@ pub(super) fn popup<'a>(picker: &mut FontPicker<'a>, ui: &mut OverlayUi<'_>, cx:
served: picker.served,
};
let (found, comparable) = list(catalog, &infos, &listing, &Language { folder: &folder, collator: &collator }, true);
<<<<<<< HEAD
let layout = Layout { sections: plain && query.trim().is_empty(), actions: actions.len() };
let shown_host = host_rows(picker.host, &query, &folder);
let slots = slots(catalog, picker.host, &shown_host, found, &expanded);
let slots = slots(catalog, picker.host, &shown_host, found, &expanded, &layout);
let current = match picker.current_host.as_deref() {
Some(key) => slots.iter().position(|slot| matches!(slot, Slot::Host { row, .. } if row.key == key)),
None => slots.iter().position(|slot| matches!(slot, Slot::Family { row, .. } if row.family == family)),
};
=======
let layout = Layout { sections: plain && query.trim().is_empty(), actions: actions.len() };
let slots = slots(catalog, found, &expanded, &layout);
let current = slots.iter().position(|slot| matches!(slot, Slot::Family { row, .. } if row.family == family));
>>>>>>> origin/next
let size = settings.as_ref().map_or(ThumbSize::None, |s| s.preview.thumb());
let sample_size = cx.style.sample(size);
let points = sample_size.side * SAMPLE_EM;
@@ -589,20 +523,15 @@ pub(super) fn popup<'a>(picker: &mut FontPicker<'a>, ui: &mut OverlayUi<'_>, cx:
.selection(Bind::given(selection))
.rows_stamp(stamp.finish())
.show_items(ui, &source, &mut |_, item| match &slots[item.at] {
<<<<<<< HEAD
Slot::Gap(_) => ListRow::spacer(),
Slot::Heading { name, .. } => ListRow::new(name.clone()).heading(),
Slot::Host { row, .. } => host_line(row, current == Some(item.at), size),
Slot::Style { style, .. } => ListRow::new(style.clone()).option().depth(1),
=======
Slot::Gap => ListRow::separator(),
Slot::Gap(_) => ListRow::separator(),
Slot::HostHeading { name, .. } => ListRow::new(name.clone()).heading(),
Slot::Host { row, .. } => host_line(row, current == Some(item.at), item.cells(), size, points),
Slot::Heading(Heading::Recent) => ListRow::new(words.recently_used.clone()).section_heading(),
Slot::Heading(Heading::All) => ListRow::new(words.all_fonts.clone()).section_heading(),
Slot::Action(at) => ListRow::new(actions[*at].clone()).option().depth(0),
Slot::Style { style, .. } => {
ListRow::new(style.clone()).cells(item.cells()).in_label_column().option().depth(1).check(false)
}
>>>>>>> origin/next
Slot::Family { row, open } => {
let mut line = ListRow::new(row.shown.clone()).cells(item.cells()).option().depth(0).check(current == Some(item.at));
if !plain {
@@ -702,34 +631,21 @@ pub(super) fn popup<'a>(picker: &mut FontPicker<'a>, ui: &mut OverlayUi<'_>, cx:
{
write(&mut picker.filters, cx, filters, "Font filters");
}
<<<<<<< HEAD
match picked.and_then(|key| slot_of(&slots, &key)) {
Some(Slot::Host { row, .. }) if !matches!(row.kind, HostFontKind::Notice) => {
picker.host_picked = Some(row.key.clone());
end_preview(picker, cx);
// A host pick writes no family, so a typed query goes back to the field's text.
if drafting {
cx.set_draft(None);
}
popup.close(cx);
}
Some(slot) => {
if let Some((family, style)) = slot.pick() {
picker.picked = Some(family.to_owned());
picker.picked_style = style.map(str::to_owned);
end_preview(picker, cx);
cx.propose(family.to_owned());
cx.commit();
popup.close(cx);
}
}
None => {}
=======
let chosen = picked.and_then(|key| slot_of(&slots, &key));
if let Some(Slot::Action(at)) = chosen {
picker.action = Some(*at);
end_preview(picker, cx);
popup.close(cx);
} else if let Some(Slot::Host { row, .. }) = chosen
&& !matches!(row.kind, HostFontKind::Notice)
{
picker.host_picked = Some(row.key.clone());
end_preview(picker, cx);
// A host pick writes no family, so a typed query goes back to the field's text.
if drafting {
cx.set_draft(None);
}
popup.close(cx);
} else if let Some((family, style)) = chosen.and_then(Slot::pick) {
picker.picked = Some(family.to_owned());
picker.picked_style = style.map(str::to_owned);
@@ -737,6 +653,5 @@ pub(super) fn popup<'a>(picker: &mut FontPicker<'a>, ui: &mut OverlayUi<'_>, cx:
cx.propose(family.to_owned());
cx.commit();
popup.close(cx);
>>>>>>> origin/next
}
}
+7 -30
View File
@@ -1,33 +1,19 @@
<<<<<<< HEAD
//! Stories of `FontPicker`: the closed field, the list open with recents and a typed query, the list open with the
//! class column and a filter on, and the list open with host rows above the families. They draw from the two faces
//! egui ships in an in-memory catalog.
=======
//! Stories of `FontPicker`: the closed field, the list open with recents and a typed query, and the list open with
//! the class column and a filter on. They draw from the two faces egui ships in an in-memory catalog, with Inter where a
//! story needs a family of two styles and Noto Sans Arabic, from the craft fonts set when the build has
//! `CRAFT_FONTS_DIR`, for the Arabic sample.
>>>>>>> origin/next
//! egui ships in an in-memory catalog, with Inter where a story needs a family of two styles and Noto Sans Arabic,
//! from the craft fonts set when the build has `CRAFT_FONTS_DIR`, for the Arabic sample.
use std::sync::{Arc, OnceLock};
use craft_behavior::Mixed;
use craft_ui::contract::{Bind, Show as _, Validity};
<<<<<<< HEAD
use craft_ui::fonts::FontRef;
=======
use craft_ui::fonts::EmbeddedFace;
>>>>>>> origin/next
use craft_ui::fonts::{EmbeddedFace, FontRef};
use craft_ui::runtime::env::{Label, Message};
use craft_ui::testing::focus::AccessActionKind;
use craft_ui::testing::{Drive, Fixture, StoryData, StoryOutput, story};
use egui::{Key, Modifiers, Ui};
<<<<<<< HEAD
use super::{FontFilters, FontPicker, FontPickerSettings, HostFontGroup, HostFontRow};
=======
use super::{FontFilters, FontPicker, FontPickerKind, FontPickerSettings, MissingAdvice};
>>>>>>> origin/next
use super::{FontFilters, FontPicker, FontPickerKind, FontPickerSettings, HostFontGroup, HostFontRow, MissingAdvice};
use crate::Catalog;
use crate::craft_font_catalog::{Limits, Source};
use crate::panel::fixtures::story_catalog;
@@ -85,14 +71,11 @@ fn arabic_catalog() -> Arc<Catalog> {
struct Extras<'a> {
served: &'a [String],
banner: Option<&'a str>,
<<<<<<< HEAD
host: &'a [HostFontGroup<'a>],
=======
kind: FontPickerKind,
actions: &'a [Label],
shown_as: Option<&'a str>,
advice: MissingAdvice,
>>>>>>> origin/next
host: &'a [HostFontGroup<'a>],
}
fn show_with(ui: &mut Ui, data: &mut StoryData, init: Demo, catalog: &Arc<Catalog>, extras: &Extras<'_>) -> StoryOutput {
@@ -101,16 +84,13 @@ fn show_with(ui: &mut Ui, data: &mut StoryData, init: Demo, catalog: &Arc<Catalo
.settings(Bind::bound(settings))
.filters(Bind::bound(filters))
.served(extras.served)
<<<<<<< HEAD
.host(extras.host);
=======
.kind(extras.kind)
.actions(extras.actions)
.advice(extras.advice);
.advice(extras.advice)
.host(extras.host);
if let Some(face) = extras.shown_as {
picker = picker.shown_as(face);
}
>>>>>>> origin/next
if let Some(text) = extras.banner {
picker = picker.preview_text(text);
}
@@ -195,7 +175,6 @@ fn font_picker_served(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
&catalog(),
&Extras { served: &served, ..Extras::default() },
)
<<<<<<< HEAD
}
/// A host group above the families: a face with its sample, an action and a notice, under the group's heading.
@@ -210,8 +189,6 @@ fn font_picker_host_groups(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let host = [HostFontGroup::new(Some(Label::from("Document fonts")), &rows)];
let extras = Extras { host: &host, ..Extras::default() };
show_with(ui, data, demo("Ubuntu", FontPickerSettings::default(), FontFilters::default()), &catalog(), &extras)
=======
>>>>>>> origin/next
}
/// The preview banner above the filters.
+4 -10
View File
@@ -7,14 +7,11 @@ use std::sync::Arc;
use craft_behavior::{PartKey, Preview};
use craft_font_manager::craft_font_catalog::{Limits, Os, Source};
<<<<<<< HEAD
use craft_font_manager::picker::{FontFilters, FontPicker, FontPickerSettings, HostFontGroup, HostFontRow, SIMILAR_COUNT, family_rows};
=======
use craft_font_manager::missing::MissingFontsWords;
use craft_font_manager::picker::{
FamilyInfos, FontClass, FontFilters, FontPicker, FontPickerKind, FontPickerSettings, FontPickerWords, MissingAdvice, SIMILAR_COUNT, family_rows,
FamilyInfos, FontClass, FontFilters, FontPicker, FontPickerKind, FontPickerSettings, FontPickerWords, HostFontGroup, HostFontRow, MissingAdvice,
SIMILAR_COUNT, family_rows,
};
>>>>>>> origin/next
use craft_font_manager::{Catalog, FontEnv};
use craft_ui::buttons::ControlPlace;
use craft_ui::contract::tooltip::DELAY;
@@ -44,14 +41,11 @@ struct Seen {
rested: Vec<String>,
/// The family the open list proposes as a live preview, as the last pass reported it.
preview: Option<String>,
<<<<<<< HEAD
/// The keys of the host rows picked, in order.
host_picks: Vec<String>,
=======
actions: Vec<usize>,
/// The id of the shown picker, as the last pass reported it.
id: Option<egui::Id>,
>>>>>>> origin/next
/// The keys of the host rows picked, in order.
host_picks: Vec<String>,
}
fn rig(catalog: Arc<Catalog>, served: Vec<String>) -> (Fixture, Rc<RefCell<Seen>>) {
+6 -19
View File
@@ -83,13 +83,6 @@ pub struct MenuBarUi<'a> {
compact: bool,
}
<<<<<<< HEAD
impl<'a> MenuBarUi<'a> {
/// The bar for `bar`, already laid out ([`crate::layout`]), on [`Target::current`].
pub fn new(bar: &'a MenuBar) -> MenuBarUi<'a> {
MenuBarUi { bar, target: Target::current(), english: None, preferred: &[], keyboard: None, help_search: false, icons: true, compact: false }
}
=======
/// Every input of the bar's view.
#[derive(MemoProps)]
struct BarProps<'a> {
@@ -99,13 +92,14 @@ struct BarProps<'a> {
keyboard: bool,
help: Option<usize>,
label: Label,
icons: bool,
compact: bool,
}
>>>>>>> origin/next
impl<'a> MenuBarUi<'a> {
/// The bar for `bar`, already laid out ([`crate::layout`]), on the shell's platform ([`Target::of_shell`]).
pub fn new(bar: &'a Tracked<MenuBar>) -> MenuBarUi<'a> {
MenuBarUi { bar, target: None, preferred: &[], keyboard: None, help_search: false }
MenuBarUi { bar, target: None, preferred: &[], keyboard: None, help_search: false, icons: true, compact: false }
}
}
@@ -158,16 +152,7 @@ impl<'a> MenuBarUi<'a> {
/// the root window instead.
pub fn show(self, ui: &mut Ui) -> MenuBarOutput {
let env = Env::of(ui);
<<<<<<< HEAD
let rows = Rows::new(self.target).english(self.english).preferred(self.preferred).icons(self.icons).compact(self.compact);
let labels =
rows.labels(&self.bar.menus, |menu| menu.title.as_str(), |menu| menu.title.as_str(), |menu| rows.english_of(Labeled::Title(&menu.title)));
let shared = &rows;
let titles: Vec<MenuTitle<'_>> =
self.bar.menus.iter().zip(labels).map(|(menu, label)| MenuTitle::new(label, move |ui| shared.show(ui, &menu.children))).collect();
=======
let target = self.target.unwrap_or_else(|| Target::of_shell(env.view().shell()));
>>>>>>> origin/next
let help = self.help_search.then(|| self.bar.menus.iter().position(|menu| menu.role == MenuRole::Help)).flatten();
let props = BarProps {
bar: self.bar,
@@ -176,6 +161,8 @@ impl<'a> MenuBarUi<'a> {
keyboard: self.keyboard.unwrap_or(target != Target::Mac),
help,
label: env.words::<BarWords>().label.clone(),
icons: self.icons,
compact: self.compact,
};
MemoView::new("menu-bar", props, show_bar).show(ui).unwrap_or(MenuBarOutput { titles: Rect::NOTHING })
}
@@ -183,7 +170,7 @@ impl<'a> MenuBarUi<'a> {
/// The bar's view: the titles through [`craft_ui::menu::MenuBar`], each menu's rows as command rows.
fn show_bar(props: &mut BarProps<'_>, ui: &mut Ui) -> MenuBarOutput {
let rows = Rows::new(props.target).preferred(props.preferred);
let rows = Rows::new(props.target).preferred(props.preferred).icons(props.icons).compact(props.compact);
let env = Env::of(ui);
let os = env.view().shell().os;
// The text of every menu is worked out once for these inputs and kept: a pass that shows an open menu again writes none of it.
+1 -10
View File
@@ -67,8 +67,7 @@ pub(crate) struct Rows<'a> {
impl<'a> Rows<'a> {
pub(crate) fn new(target: Target) -> Self {
<<<<<<< HEAD
Rows { target, english: None, preferred: &[], icons: true, compact: false }
Rows { target, preferred: &[], icons: true, compact: false }
}
pub(crate) fn icons(mut self, on: bool) -> Self {
@@ -81,14 +80,6 @@ impl<'a> Rows<'a> {
self
}
pub(crate) fn english(mut self, english: Option<&'a EnglishHook<'a>>) -> Self {
self.english = english;
self
=======
Rows { target, preferred: &[] }
>>>>>>> origin/next
}
pub(crate) fn preferred(mut self, preferred: &'a [(&'a str, char)]) -> Self {
self.preferred = preferred;
self
+5 -26
View File
@@ -367,13 +367,8 @@ fn desktop_bar(bar: &MenuBar, target: Target, quit: Option<&'static str>, option
it.english = Some("Preferences…".to_owned());
Node::Item(it)
}
<<<<<<< HEAD
Node::Submenu { children, role, platforms, enabled, .. } => {
Node::Submenu { label: options.text("Preferences"), children, role, platforms, enabled }
=======
Node::Submenu { children, role, platforms, .. } => {
Node::Submenu { label: options.text("Preferences"), english: Some("Preferences".to_owned()), children, role, platforms }
>>>>>>> origin/next
Node::Submenu { label: options.text("Preferences"), english: Some("Preferences".to_owned()), children, role, platforms, enabled }
}
other => other,
};
@@ -401,21 +396,13 @@ fn shown_on(bar: &MenuBar, target: Target) -> MenuBar {
let shown = nodes.iter().filter_map(|n| match n {
Node::Item(it) if !it.platforms.contains(on) => None,
Node::Submenu { platforms, .. } if !platforms.contains(on) => None,
<<<<<<< HEAD
Node::Submenu { label, children, role, platforms, enabled } => Some(Node::Submenu {
label: label.clone(),
children: keep(children, on, appkit),
role: *role,
platforms: *platforms,
enabled: *enabled,
=======
Node::Submenu { label, english, children, role, platforms } => Some(Node::Submenu {
Node::Submenu { label, english, children, role, platforms, enabled } => Some(Node::Submenu {
label: label.clone(),
english: english.clone(),
children: keep(children, on, appkit),
role: *role,
platforms: *platforms,
>>>>>>> origin/next
enabled: *enabled,
}),
Node::Standard { .. } if !appkit => None,
other => Some(other.clone()),
@@ -489,11 +476,7 @@ fn settings_node(node: Node, comma_taken: Option<CommandRef>, options: &LayoutOp
if let Some(Node::Item(first)) = children.iter_mut().find(|n| matches!(n, Node::Item(i) if i.enabled)) {
give(first);
}
<<<<<<< HEAD
Node::Submenu { label: options.text("Settings"), children, role, platforms, enabled }
=======
Node::Submenu { label: options.text("Settings"), english: Some("Settings".to_owned()), children, role, platforms }
>>>>>>> origin/next
Node::Submenu { label: options.text("Settings"), english: Some("Settings".to_owned()), children, role, platforms, enabled }
}
other => other,
}
@@ -514,11 +497,7 @@ fn appearance_node(bar: &mut MenuBar, options: &LayoutOptions) -> Vec<Node> {
children.push(Node::Separator);
children.extend(items);
}
<<<<<<< HEAD
vec![Node::Submenu { label: options.text("Appearance"), children, role, platforms, enabled }]
=======
vec![Node::Submenu { label: options.text("Appearance"), english: Some("Appearance".to_owned()), children, role, platforms }]
>>>>>>> origin/next
vec![Node::Submenu { label: options.text("Appearance"), english: Some("Appearance".to_owned()), children, role, platforms, enabled }]
}
_ => items,
}
+11 -25
View File
@@ -453,8 +453,17 @@ impl Node {
/// An enabled submenu shown on every platform.
pub fn submenu(label: impl Into<String>, children: Vec<Node>) -> Node {
<<<<<<< HEAD
Node::Submenu { label: label.into(), children, role: None, platforms: Platforms::ALL, enabled: true }
Node::Submenu { label: label.into(), english: None, children, role: None, platforms: Platforms::ALL, enabled: true }
}
/// Set the English name of an item's label or a submenu's title.
pub fn english(mut self, english: impl Into<String>) -> Node {
match &mut self {
Node::Item(it) => it.english = Some(english.into()),
Node::Submenu { english: e, .. } => *e = Some(english.into()),
Node::Separator | Node::Standard { .. } => {}
}
self
}
/// Set whether an item can be chosen or a submenu opened:
@@ -463,16 +472,6 @@ impl Node {
match &mut self {
Node::Item(it) => it.enabled = on,
Node::Submenu { enabled, .. } => *enabled = on,
=======
Node::Submenu { label: label.into(), english: None, children, role: None, platforms: Platforms::ALL }
}
/// Set the English name of an item's label or a submenu's title.
pub fn english(mut self, english: impl Into<String>) -> Node {
match &mut self {
Node::Item(it) => it.english = Some(english.into()),
Node::Submenu { english: e, .. } => *e = Some(english.into()),
>>>>>>> origin/next
Node::Separator | Node::Standard { .. } => {}
}
self
@@ -765,18 +764,6 @@ pub fn from_items(tops: &[&str], rows: &[Row]) -> MenuBar {
/// Drop separators at the start or end of a level and collapse runs of them, and drop empty
/// submenus, at every depth, in place. A submenu holding only a disabled placeholder (`No Recent Files`)
/// stays.
<<<<<<< HEAD
pub fn tidy(nodes: Vec<Node>) -> Vec<Node> {
let mut out: Vec<Node> = Vec::with_capacity(nodes.len());
for n in nodes {
let n = match n {
Node::Submenu { label, children, role, platforms, enabled } => {
let children = tidy(children);
if children.is_empty() {
continue;
}
Node::Submenu { label, children, role, platforms, enabled }
=======
pub fn tidy(nodes: &mut Vec<Node>) {
let mut previous_separator = true;
nodes.retain_mut(|node| {
@@ -784,7 +771,6 @@ pub fn tidy(nodes: &mut Vec<Node>) {
tidy(children);
if children.is_empty() {
return false;
>>>>>>> origin/next
}
}
let separator = matches!(node, Node::Separator);
+3 -2
View File
@@ -1,19 +1,20 @@
//! The in-window bar's own rules over the model.
use craft_menu::{Item, Menu, MenuBar, MenuBarUi, Node};
use craft_ui::contract::Tracked;
use craft_ui::testing::{Fixture, trial};
/// A submenu the app disables stays greyed and never opens, though its rows could be chosen
/// (Open Recent with a placeholder row while the app keeps no recent files).
#[trial]
fn a_disabled_submenu_is_greyed_and_does_not_open() {
let bar = MenuBar::new(vec![Menu::new(
let bar = Tracked::new(MenuBar::new(vec![Menu::new(
"File",
vec![
Node::submenu("Open Recent", vec![Item::new("file.recent.a", "notes.txt").into()]).enabled(false),
Node::submenu("Export", vec![Item::new("file.export.pdf", "PDF").into()]),
],
)]);
)]));
let mut fixture = Fixture::new(move |ui| {
MenuBarUi::new(&bar).show(ui);
});
+1 -7
View File
@@ -1,13 +1,8 @@
//! The integration binary of craft-menu: every test is a registered trial.
<<<<<<< HEAD
mod bar;
mod layout;
mod mnemonic;
mod native;
=======
#[cfg(target_os = "macos")]
mod appkit;
pub(crate) mod bar;
pub(crate) mod from_items;
pub(crate) mod keytips;
pub(crate) mod layout;
@@ -16,7 +11,6 @@ pub(crate) mod mnemonic;
pub(crate) mod native;
pub(crate) mod ribbon;
pub(crate) mod ribbon_gallery;
>>>>>>> origin/next
mod sample;
pub(crate) mod shortcuts;
pub(crate) mod title_bar;
+6 -13
View File
@@ -1,10 +1,11 @@
//! The Keyboard Shortcuts dialog, driven pass by pass through `craft_ui::testing::Fixture`.
mod fixture;
<<<<<<< HEAD
mod import_offer;
mod recorder;
mod rows;
mod sets;
pub(crate) mod import_offer;
pub(crate) mod lists;
pub(crate) mod recorder;
pub(crate) mod rows;
pub(crate) mod sets;
pub(crate) mod tabs;
use craft_keymap::Platform;
use craft_ui::testing::trial;
@@ -19,11 +20,3 @@ fn a_read_only_dialog_opens_at_a_moderate_height() {
let close = rig.fixture.by_label("Close").expect("the close button");
assert!(close.rect.bottom() < 560.0, "the dialog's footer sits within a moderate height, not the 700-point window: {:?}", close.rect);
}
=======
pub(crate) mod import_offer;
pub(crate) mod lists;
pub(crate) mod recorder;
pub(crate) mod rows;
pub(crate) mod sets;
pub(crate) mod tabs;
>>>>>>> origin/next
+9 -6
View File
@@ -326,13 +326,8 @@ impl ColorTokens {
inverse: c,
shadow: c,
},
<<<<<<< HEAD
text: TextColors { normal: c, muted: c, faint: c, disabled: c, on_accent: c, on_strong: c, on_status: c, on_selected: c, on_inverse: c },
line: LineColors { divider: c, border: c, control_edge: c, knob_edge: c, frame: c, mark: c, focus: c },
=======
text: TextColors { normal: c, muted: c, faint: c, disabled: c, on_accent: c, on_strong: c, on_status: c, on_selected: c },
line: LineColors { divider: c, border: c, control_edge: c, knob_edge: c, frame: c, mark: c, grip: c, focus: c },
>>>>>>> origin/next
accent: AccentColors {
solid: c,
hover: c,
@@ -657,7 +652,15 @@ impl ColorToken {
};
matches!(
self,
SurfaceBackground | SurfaceCanvas | SurfaceCanvasPattern | SurfaceChrome | SurfacePanel | SurfaceRaised | SurfaceSunken | SurfaceKnob | SurfaceInverse
SurfaceBackground
| SurfaceCanvas
| SurfaceCanvasPattern
| SurfaceChrome
| SurfacePanel
| SurfaceRaised
| SurfaceSunken
| SurfaceKnob
| SurfaceInverse
)
}
}
+36 -37
View File
@@ -61,42 +61,6 @@
"text.on_accent": "#ffffff"
},
"apps": {
<<<<<<< HEAD
"pdfcraft": {
"light": {
"accent.soft": "#e3ecfd",
"accent.solid": "#1b63e0",
"accent.text": "#1755c4",
"line.border": "#dadade",
"line.divider": "#e8e8eb",
"state.hover": "#f0f0f3",
"state.pressed": "#e4e4e9",
"state.selected": "#e6eefd",
"surface.background": "#e9e9eb",
"surface.canvas": "#f1f1f3",
"surface.chrome": "#ffffff",
"surface.panel": "#ffffff",
"surface.raised": "#ffffff",
"surface.sunken": "#ffffff",
"text.faint": "#6b6b73",
"text.muted": "#5e5e66",
"text.normal": "#222226"
},
"dark": {
"accent.solid": "#4b8bf5",
"accent.text": "#8cb6fa",
"line.border": "#3c3c43",
"line.divider": "#333339",
"surface.background": "#1b1b1e",
"surface.canvas": "#19191c",
"surface.chrome": "#26262a",
"surface.panel": "#26262a",
"surface.raised": "#2e2e33",
"surface.sunken": "#1e1e22",
"text.faint": "#97979e",
"text.muted": "#aeaeb6",
"text.normal": "#ececef"
=======
"wordcraft": {
"shape": {
"button_radius": 4
@@ -138,7 +102,42 @@
"text.muted": "#c8c8c8",
"text.normal": "#eeeeee",
"text.on_accent": "#11162e"
>>>>>>> origin/next
}
},
"pdfcraft": {
"light": {
"accent.soft": "#e3ecfd",
"accent.solid": "#1b63e0",
"accent.text": "#1755c4",
"line.border": "#dadade",
"line.divider": "#e8e8eb",
"state.hover": "#f0f0f3",
"state.pressed": "#e4e4e9",
"state.selected": "#e6eefd",
"surface.background": "#e9e9eb",
"surface.canvas": "#f1f1f3",
"surface.chrome": "#ffffff",
"surface.panel": "#ffffff",
"surface.raised": "#ffffff",
"surface.sunken": "#ffffff",
"text.faint": "#6b6b73",
"text.muted": "#5e5e66",
"text.normal": "#222226"
},
"dark": {
"accent.solid": "#4b8bf5",
"accent.text": "#8cb6fa",
"line.border": "#3c3c43",
"line.divider": "#333339",
"surface.background": "#1b1b1e",
"surface.canvas": "#19191c",
"surface.chrome": "#26262a",
"surface.panel": "#26262a",
"surface.raised": "#2e2e33",
"surface.sunken": "#1e1e22",
"text.faint": "#97979e",
"text.muted": "#aeaeb6",
"text.normal": "#ececef"
}
}
}
+1 -5
View File
@@ -189,14 +189,10 @@ channel.finish_captures(finished, &mut |path, bytes| self.write_automation_file(
let settle = settle_ms(ctx.global_style().animation_time);
while let Some(req) = channel.next_request() {
let reply = match req.method.as_str() {
<<<<<<< HEAD
"ui.screenshot" => match ScreenshotParams::from_params(&req.params) {
Ok(params) => Reply::screenshot(self.next_capture_token(), params, ViewportId::ROOT),
Ok(params) => Reply::screenshot(self.next_capture_token(), params, viewport),
Err(e) => Reply::from_result(Err(e)),
},
=======
"ui.screenshot" => Reply::screenshot(self.next_capture_token(), path_param(&req.params), viewport),
>>>>>>> origin/next
"ui.resize" => { /* send ViewportCommand::InnerSize */ Reply::from_result(Ok(json!(null))) }
"ui.set" => Reply::from_result(self.ui_set(&req.params)),
other => Reply::from_result(Err(format!("unknown method {other}"))),
-6
View File
@@ -431,17 +431,11 @@ mod tests {
parse_segment_header(&mut Reader::new(&data)).unwrap_err()
};
<<<<<<< HEAD
let mut reader = Reader::new(&data);
let error = parse_segment_header(&mut reader).unwrap_err();
assert!(matches!(error, DecodeError::Segment(SegmentError::InvalidReferredCount)));
=======
// The 29-bit maximum, 536,870,911, would reserve about 2 GiB.
for count in [0x1FFF_FFFF, MAX_REFERRED_TO_SEGMENTS + 1] {
assert!(matches!(header(count), DecodeError::Segment(SegmentError::InvalidReferredCount)));
}
// At the cap the header is read on and ends at its missing retention bytes.
assert!(matches!(header(MAX_REFERRED_TO_SEGMENTS), DecodeError::Parse(ParseError::UnexpectedEof)));
>>>>>>> origin/next
}
}