Edit look: field overlays and marquee as production tints them, stamp strips and panel title, accent outlines, Auto line spacing, menu arrows, View more link

This commit is contained in:
Dylan M. Taylor committed 2026-11-22 04:39:20 -05:00
1 parent e40d0cfc23
commit 4fe96abbec
7 files changed
+98 -58

No files matched your search

+59 -42
View File
@@ -148,7 +148,9 @@ fn tool_row(ui: &mut egui::Ui, icon: &'static str, label: &str, availability: Av
Availability::Provider => row.ink(RowInk::Dimmed).tooltip(tl!("Optional: needs an AI provider you configure").to_string()),
};
if menu {
row = row.row_menu();
// The disclosure arrow production shows at the end of Header and footer and Watermark; the whole row
// opens the menu.
row = row.trailing_named("\u{25BE}".to_owned(), tl!("Options").to_owned());
}
row.show(ui).response
}
@@ -170,53 +172,68 @@ impl craft::behavior::DisplayOrder<usize> for Stamps {
}
}
impl craft::behavior::ItemSource<usize> for Stamps {}
impl craft::behavior::ItemSource<usize> for Stamps {
/// Every stamp is a wide strip, as production draws them: six parts wide to one high.
fn size_hint(&self, _at: usize) -> craft::behavior::SizeHint {
craft::behavior::SizeHint::Aspect(6.0)
}
}
/// Add a stamp: Dynamic, Sign Here and Standard Business stamps; click one, then click on the
/// page to place it.
pub(super) fn stamp_palette(app: &mut PdfCraftApp, ui: &mut egui::Ui) {
use pdfcraft_engine::{StampGroup, StampKind};
Stack::new().scroll(Scroll::vertical()).show(ui, |ui, _| {
Text::new(tl!("Choose a stamp, then click on the page to place it.").to_string()).shade(Shade::Faint).show(ui);
let titles = [
(StampGroup::Dynamic, tl!("Dynamic")),
(StampGroup::SignHere, tl!("Sign Here")),
(StampGroup::StandardBusiness, tl!("Standard Business")),
];
// The kinds in group order, and the headers' keys after every tile's.
let mut kinds: Vec<(StampGroup, StampKind)> = Vec::new();
let mut groups = Vec::new();
for (n, (group, title)) in titles.iter().enumerate() {
let start = kinds.len();
kinds.extend(StampKind::ALL.into_iter().filter(|k| k.group() == *group).map(|k| (*group, k)));
groups.push(TileGroup::new(1_000_000 + n, start, kinds.len() - start, title.to_string()));
}
let mut selection = match app.quick_tool {
crate::QuickTool::Stamp(current) => kinds.iter().position(|(_, kind)| *kind == current).map(Selection::single).unwrap_or_default(),
_ => Selection::default(),
};
let before = selection.clone();
let _ = TileGrid::<usize>::new(tl!("Stamps").to_string())
.natural_height(true)
.caption(CaptionPlace::None)
.select(SelectMode::Single)
.selection(Bind::bound(&mut selection))
.groups(&groups)
.show_items(ui, &Stamps(kinds.len()), &mut |key, _| {
let Some((group, kind)) = kinds.get(*key).copied() else { return Tile::new(String::new()) };
let [r, g, b] = kind.color().map(|v| (v * 255.0) as u8);
let color = egui::Color32::from_rgb(r, g, b);
let (label, by) = (kind.label().to_string(), tl!("By name at time, date").to_string());
Tile::new(label.clone()).thumb(ThumbAspect::new(6, 1), move |cx, rect| paint_chip(cx, rect, group, &label, &by, color))
});
if selection != before
&& let Some(&at) = selection.items.first()
&& let Some((_, kind)) = kinds.get(at)
{
app.quick_tool = crate::QuickTool::Stamp(*kind);
}
crate::stamps_ui::palette_section(app, ui);
// Titled as production's panel is: Back to All tools, the name and Close.
let commands = vec![HeaderCommand::new(IconId::new("chevron-left"), "tools.all")];
let shown = Panel::new(tl!("Add a stamp").to_string()).titled().commands(commands).actions([HeaderAction::Close]).show(ui, |ui, _| {
Stack::new().scroll(Scroll::vertical()).show(ui, |ui, _| {
Text::new(tl!("Choose a stamp, then click on the page to place it.").to_string()).shade(Shade::Faint).show(ui);
let titles = [
(StampGroup::Dynamic, tl!("Dynamic")),
(StampGroup::SignHere, tl!("Sign Here")),
(StampGroup::StandardBusiness, tl!("Standard Business")),
];
// The kinds in group order, and the headers' keys after every tile's.
let mut kinds: Vec<(StampGroup, StampKind)> = Vec::new();
let mut groups = Vec::new();
for (n, (group, title)) in titles.iter().enumerate() {
let start = kinds.len();
kinds.extend(StampKind::ALL.into_iter().filter(|k| k.group() == *group).map(|k| (*group, k)));
groups.push(TileGroup::new(1_000_000 + n, start, kinds.len() - start, title.to_string()));
}
let mut selection = match app.quick_tool {
crate::QuickTool::Stamp(current) => kinds.iter().position(|(_, kind)| *kind == current).map(Selection::single).unwrap_or_default(),
_ => Selection::default(),
};
let before = selection.clone();
let _ = TileGrid::<usize>::new(tl!("Stamps").to_string())
.natural_height(true)
.justified()
// Pictures this high keep every strip, the last of a group included, at one size across the panel.
.zoom(craft::ui::tile_grid::GridZoom::Fixed(0.22))
.caption(CaptionPlace::None)
.select(SelectMode::Single)
.selection(Bind::bound(&mut selection))
.groups(&groups)
.show_items(ui, &Stamps(kinds.len()), &mut |key, _| {
let Some((group, kind)) = kinds.get(*key).copied() else { return Tile::new(String::new()) };
let [r, g, b] = kind.color().map(|v| (v * 255.0) as u8);
let color = egui::Color32::from_rgb(r, g, b);
let (label, by) = (kind.label().to_string(), tl!("By name at time, date").to_string());
Tile::new(label.clone()).thumb(ThumbAspect::new(6, 1), move |cx, rect| paint_chip(cx, rect, group, &label, &by, color))
});
if selection != before
&& let Some(&at) = selection.items.first()
&& let Some((_, kind)) = kinds.get(at)
{
app.quick_tool = crate::QuickTool::Stamp(*kind);
}
crate::stamps_ui::palette_section(app, ui);
});
});
if shown.output.closed.is_some() || shown.output.action == Some(HeaderAction::Close) {
app.set_left_open(false);
}
}
/// A stamp's chip: its colour as a tinted frame (Sign Here as a pentagon pointing left, with the label
+2 -3
View File
@@ -468,9 +468,8 @@ fn show(
.char_spacing_presets(&char_spacings)
.char_spacing_range(range(&CHAR_SPACING_RANGE))
.unsupported(&unsupported);
if let Some(line_spacing) = v.line_spacing {
text = text.line_spacing(line_spacing);
}
// With nothing to set it on the row still reads Auto, as production's does, not Mixed.
text = text.line_spacing(v.line_spacing.unwrap_or(LineSpacing::Auto));
#[cfg(not(target_arch = "wasm32"))]
if matches!(target, Target::Paragraph(_))
&& let Some(installed) = installed
+9 -3
View File
@@ -1,9 +1,14 @@
use craft::behavior::{DisplayOrder, IconId, ItemSource, Selection};
use craft::theme::{
Variant,
variant::{Emphasis, Tone},
};
use craft::ui::buttons::Button;
use craft::ui::choice::{Checkbox, Segmented};
use craft::ui::contract::{ActivateOn, Bind, CollectionEvent, Entry, Props as _, SelectMode, Show as _, ShowCollection as _, Sizing};
use craft::ui::contract::{
ActivateOn, Bind, CollectionEvent, Entry, Outcome as _, Props as _, SelectMode, Show as _, ShowCollection as _, Sizing, clicked,
};
use craft::ui::display::Badge;
use craft::theme::{Variant, variant::{Emphasis, Tone}};
use craft::ui::list::{HueTarget, List, ListRow, RowEvent, RowInk, TrailingFace, TrailingPart};
use craft::ui::primitives::IconSpec;
use craft::ui::style::DataColor;
@@ -99,6 +104,7 @@ fn all_tools(app: &mut PdfCraftApp, ui: &mut egui::Ui) {
let shown = if app.all_tools_expanded { TOOL_GROUPS.len() } else { COLLAPSED_TOOLS.min(TOOL_GROUPS.len()) };
let pins: Vec<bool> = TOOL_GROUPS[..shown].iter().map(|g| app.is_tool_pinned(g.id)).collect();
let out = List::<usize>::new(tl!("All tools").to_owned())
.natural_height(true)
.select(SelectMode::Single)
.activate(ActivateOn::Click)
.selection(Bind::given(Selection::default()))
@@ -122,7 +128,7 @@ fn all_tools(app: &mut PdfCraftApp, ui: &mut egui::Ui) {
}
}
let more = if app.all_tools_expanded { "View less" } else { "View more" };
if Button::new(tl!(more).to_owned()).show(ui).clicked() {
if clicked(craft::ui::buttons::Link::new(tl!(more).to_owned()).show(ui).response()) {
app.all_tools_expanded = !app.all_tools_expanded;
}
}
+2 -2
View File
@@ -138,8 +138,8 @@ impl CanvasTool for EditTextTool<'_> {
}
fn paint(&self, draw: &Draw<'_>, cx: &ToolContext<'_>) {
let (Some(rect), Some(style)) = (object_ui::marquee_rect(&self.press.phase), cx.style()) else { return };
draw.stroke(&PaintShape::Rect(rect, egui::CornerRadius::ZERO), StrokeWidth::Thin, style.color(style.tokens.color.accent.solid));
let Some(rect) = object_ui::marquee_rect(&self.press.phase) else { return };
crate::prepare::tool::marquee_fill(draw, cx, rect);
}
fn command_form(&self) -> ToolPath {
+1 -1
View File
@@ -985,7 +985,7 @@ fn outline_closed(ui: &mut egui::Ui, body: &PageBody<'_>, session: &PageSession,
let paths: Vec<BezPath> =
boxes.iter().enumerate().filter(|(i, _)| Some(*i) != open).take(MAX_OUTLINES).map(|(_, b)| rect_path(doc_rect(&body.view, *b))).collect();
if !paths.is_empty() {
let _ = SelectionOutline::faint(tl!("Edit text & images").to_string(), &paths).show_at(ui, clip);
let _ = SelectionOutline::faint(tl!("Edit text & images").to_string(), &paths).color(crate::object_ui::accent_ink(ui, 0.9)).show_at(ui, clip);
}
}
+9 -2
View File
@@ -426,11 +426,11 @@ pub(crate) fn object_controls(
.unwrap_or(Vec2::ZERO);
let rects: Vec<Rect> = s.selected.iter().map(|o| screen(&xf, info, page, o)).collect();
let shown: Vec<BezPath> = rects.iter().map(|r| outline_path(body, r.translate(offset))).collect();
SelectionOutline::solid(tl!("Selected object"), &shown).show(ui);
SelectionOutline::solid(tl!("Selected object"), &shown).color(accent_ink(ui, 1.0)).show(ui);
if rects.len() > 1 {
let union = rects.iter().fold(Rect::NOTHING, |u, r| u.union(*r)).translate(offset).expand(4.0);
let group = [outline_path(body, union)];
SelectionOutline::faint(tl!("Selected objects"), &group).show(ui);
SelectionOutline::faint(tl!("Selected objects"), &group).color(accent_ink(ui, 1.0)).show(ui);
}
}
None
@@ -594,3 +594,10 @@ mod tests {
assert!(Edit::delete_objects(0, Vec::new()).is_none());
}
}
/// The accent as outline ink: production outlines the selection and the editable paragraphs in blue, not in
/// the overlay grey the outline component defaults to.
pub(crate) fn accent_ink(ui: &egui::Ui, share: f32) -> craft::ui::style::DataColor {
let [r, g, b, a] = craft::ui::runtime::env::Env::of(ui).tokens.color.accent.solid.0;
craft::ui::style::DataColor::new(egui::Color32::from_rgba_unmultiplied(r, g, b, a).gamma_multiply(share))
}
+16 -5
View File
@@ -318,7 +318,7 @@ impl CanvasTool for PrepareTool<'_> {
Gesture::Draw { drag, .. } => drag.paint(cx),
Gesture::Marquee { marquee, .. } => {
let r = marquee.rect();
cx.marching_ants(&[r.left_top(), r.right_top(), r.right_bottom(), r.left_bottom()], true);
marquee_fill(_draw, cx, r);
}
Gesture::Move { .. } | Gesture::Idle => {}
}
@@ -504,11 +504,13 @@ impl Component for PrepareOverlay {
let colors = &cx.tokens.color;
PrepareOverlayStyle {
metrics: Metrics::new(),
fill: cx.color(colors.accent.soft),
// Production tints a field over the page with the accent at about a third, not the soft surface (dark navy).
fill: cx.color(colors.accent.solid),
outline: cx.color(colors.line.control_edge),
selected: cx.color(colors.accent.solid),
tag: cx.color(colors.text.normal),
tag_text: cx.color(colors.surface.sunken),
// Production's name tag: light text on a dark plate, over the light page.
tag: cx.color(colors.surface.sunken),
tag_text: cx.color(colors.text.normal),
selected_tag: cx.color(colors.accent.solid),
selected_tag_text: cx.color(colors.text.on_strong),
badge: cx.color(colors.accent.solid),
@@ -524,7 +526,7 @@ impl Component for PrepareOverlay {
let draw = ui.draw();
for field in &self.fields {
let r = field.rect;
draw.fill(&PaintShape::Rect(r, CornerRadius::ZERO), style.fill);
draw.faded(89.0 / 255.0, |draw| draw.fill(&PaintShape::Rect(r, CornerRadius::ZERO), style.fill));
if !field.selected {
draw.stroke(&PaintShape::Rect(r, CornerRadius::ZERO), StrokeWidth::Thin, style.outline);
}
@@ -559,3 +561,12 @@ impl Component for PrepareOverlay {
cx.response.clone()
}
}
/// A marquee as production draws it: the accent over the page at about a quarter, with a solid accent edge.
pub(crate) fn marquee_fill(draw: &Draw<'_>, cx: &ToolContext<'_>, r: Rect) {
let Some(style) = cx.style() else { return };
let shape = PaintShape::Rect(r, CornerRadius::ZERO);
let accent = style.color(style.tokens.color.accent.solid);
draw.faded(0.3, |draw| draw.fill(&shape, accent));
draw.stroke(&shape, StrokeWidth::Thin, accent);
}