mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-24 19:31:51 +01:00
Merge branch 'lookfix/edit' into area/app-1
# Conflicts: # crates/ui-egui/src/tools/prepare/tool.rs
This commit is contained in:
commit
0e85fbc488
6 files changed
+82
-53
No files matched your search
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
Reference in new issue
Block a user