Merge branch 'lookfix/r8app' into area/app-1

This commit is contained in:
Dylan M. Taylor committed 2026-11-22 12:19:41 -05:00
commit ce7ef972fb
4 files changed
+145 -97

No files matched your search

+7 -7
View File
@@ -8,12 +8,11 @@ use craft::pages::{PageRange, PageScope};
use craft::ui::buttons::Button;
use craft::ui::contract::{Bind, Show as _};
use craft::ui::dialog::dialog_id;
use craft::ui::display::Picture;
use craft::ui::list::ThumbAspect;
use craft::ui::display::{Picture, PictureSize};
use craft::ui::list::{ThumbAspect, ThumbSize};
use craft::ui::patterns::form_dialogs::{DialogFields, HostedParamDialog, NumberUnit, Param, ParamDialog, ParamKind};
use craft::ui::primitives::StrokeWidth;
use craft::ui::runtime::env::UnitKind;
use craft::ui::style::{Corners, SurfaceKind};
use egui::{CornerRadius, Rect, Stroke, pos2, vec2};
use pdfcraft_engine::{BoxSpec, Edit, PageBox};
@@ -101,12 +100,13 @@ fn paint_preview(cx: &craft::ui::primitives::ContentPainterCx<'_>, rect: Rect, m
let (w, h) = ((media[2] - media[0]).max(1.0), (media[3] - media[1]).max(1.0));
let s = (rect.width() / w as f32).min(rect.height() / h as f32);
let page = Rect::from_center_size(rect.center(), vec2(w as f32 * s, h as f32 * s));
cx.with_draw(|draw| draw.surface(page, SurfaceKind::Well, Corners::None));
cx.painter.rect_stroke(page, CornerRadius::ZERO, Stroke::new(cx.stroke_width(StrokeWidth::Thin), cx.ink()), egui::StrokeKind::Outside);
// The page is paper: white, whatever the theme.
cx.painter.rect_filled(page, CornerRadius::ZERO, egui::Color32::WHITE);
cx.painter.rect_stroke(page, CornerRadius::ZERO, Stroke::new(cx.stroke_width(StrokeWidth::Thin), egui::Color32::from_gray(120)), egui::StrokeKind::Outside);
let [l, bo, ri, to] = margins.map(|v| v as f32 * s);
let inner = Rect::from_min_max(pos2(page.left() + l, page.top() + to), pos2(page.right() - ri, page.bottom() - bo));
if inner.is_positive() {
cx.painter.rect_stroke(inner, CornerRadius::ZERO, Stroke::new(cx.stroke_width(StrokeWidth::Medium), cx.ink()), egui::StrokeKind::Middle);
cx.painter.rect_stroke(inner, CornerRadius::ZERO, Stroke::new(cx.stroke_width(StrokeWidth::Medium), egui::Color32::from_rgb(38, 115, 230)), egui::StrokeKind::Middle);
}
}
@@ -144,7 +144,7 @@ fn params(count: usize, current: usize, media: Option<[f64; 4]>) -> Vec<Param> {
rows.push(
Param::custom("preview", "", move |ui, fields, _| {
let margins = margins_of(fields);
Picture::painter(label.clone(), aspect, move |cx, rect| paint_preview(cx, rect, media, margins)).show(ui)
Picture::painter(label.clone(), aspect, move |cx, rect| paint_preview(cx, rect, media, margins)).extent(PictureSize::Sample(ThumbSize::Large)).show(ui)
})
.full_width(),
);
+29 -12
View File
@@ -10,8 +10,8 @@ use craft::ui::{
buttons::Button,
canvas::{CanvasTool, ToolAction, ToolClaims, ToolContext, ToolKey, ToolPath, ToolPointer},
choice::{Checkbox, Segmented},
contract::{Bind, CollectionEvent, Entry, Props as _, SelectMode, Show as _, ShowCollection as _},
form::SliderField,
contract::{Bind, CollectionEvent, Entry, Props as _, SelectMode, Show as _, ShowCollection as _, ShowContainer as _},
form::{Field, SliderField},
list::{List, ListRow},
notices::Notice,
pickers::{Select, UnitSelect},
@@ -643,7 +643,9 @@ pub(crate) fn panel(app: &mut PdfCraftApp, ui: &mut egui::Ui) {
} else {
Notice::new(Tone::Neutral, tl!("Click the first point to begin.")).show(ui);
}
TextField::new(tl!("Label"), Bind::bound(&mut state.label)).show(ui);
Field::new(tl!("Label")).id_salt("measure-label").show(ui, |ui, _| {
TextField::new(tl!("Label"), Bind::bound(&mut state.label)).show(ui);
});
Checkbox::new(Bind::bound(&mut state.snap_enabled)).label(tl!("Snap to drawing")).show(ui);
if state.snap_enabled {
Checkbox::new(Bind::bound(&mut state.snaps.endpoints)).label(tl!("Endpoints")).show(ui);
@@ -656,17 +658,22 @@ pub(crate) fn panel(app: &mut PdfCraftApp, ui: &mut egui::Ui) {
let mut chosen = None;
let fields = scale_fields(state);
let before = state.ratio_text.clone();
let typed = TextField::new(tl!("Scale"), Bind::bound(&mut state.ratio_text)).submits().show(ui);
let ratio_text = &mut state.ratio_text;
let typed = Field::new(tl!("Drawing scale")).id_salt("measure-ratio").show(ui, |ui, _| {
TextField::new(tl!("Scale"), Bind::bound(ratio_text)).submits().show(ui)
});
state.ratio_dirty |= state.ratio_text != before;
if (typed.submitted || typed.response.lost_focus()) && std::mem::take(&mut state.ratio_dirty) {
if typed.inner.as_ref().is_some_and(|t| t.submitted || t.response.lost_focus()) && std::mem::take(&mut state.ratio_dirty) {
match parse_ratio(&state.ratio_text) {
Some(n) => chosen = Some(n),
None => state.error = Some(tl!("Enter a scale such as 1:50.").into()),
}
}
let ratios: Vec<Entry<String>> = RATIOS.iter().map(|&n| Entry::new(format_ratio(n), format_ratio(n))).collect();
let common = Select::new(tl!("Common scales"), Bind::given(state.ratio_text.clone()), &ratios).show(ui);
if let Some(text) = common.value()
let common = Field::new(tl!("Common scales")).id_salt("measure-common").show(ui, |ui, _| {
Select::new(tl!("Common scales"), Bind::given(state.ratio_text.clone()), &ratios).show(ui)
});
if let Some(text) = common.inner.as_ref().and_then(|c| c.value())
&& let Some(n) = parse_ratio(text)
&& *text != state.ratio_text
{
@@ -676,17 +683,25 @@ pub(crate) fn panel(app: &mut PdfCraftApp, ui: &mut egui::Ui) {
let unit_entries: Vec<Entry<UnitKind>> = PageUnit::ALL.iter().map(|&u| Entry::new(unit_kind(u), u.label())).collect();
let mut drawing = Some(state.drawing_points);
let mut picked_unit = unit_kind(page_unit);
UnitSelect::new(tl!("Page length"), Bind::bound(&mut drawing), Bind::bound(&mut picked_unit), &unit_entries).range(0.000001..=1e9).show(ui);
Field::new(tl!("Page length")).id_salt("measure-page-length").show(ui, |ui, _| {
UnitSelect::new(tl!("Page length"), Bind::bound(&mut drawing), Bind::bound(&mut picked_unit), &unit_entries).range(0.000001..=1e9).show(ui);
});
state.drawing_points = drawing.unwrap_or(state.drawing_points);
if picked_unit != unit_kind(page_unit) {
state.page_unit = page_unit_of_kind(picked_unit);
}
let mut real = Some(state.real_distance);
NumberField::new(tl!("Real distance"), Bind::bound(&mut real)).range(0.000001..=1e9).show(ui);
Field::new(tl!("Real distance")).id_salt("measure-real").show(ui, |ui, _| {
NumberField::new(tl!("Real distance"), Bind::bound(&mut real)).range(0.000001..=1e9).show(ui);
});
state.real_distance = real.unwrap_or(state.real_distance);
TextField::new(tl!("Unit"), Bind::bound(&mut state.unit)).show(ui);
Field::new(tl!("Unit")).id_salt("measure-unit").show(ui, |ui, _| {
TextField::new(tl!("Unit"), Bind::bound(&mut state.unit)).show(ui);
});
let mut precision = Some(f64::from(state.precision));
NumberField::new(tl!("Decimals"), Bind::bound(&mut precision)).range(0.0..=6.0).step(1.0).show(ui);
Field::new(tl!("Decimals")).id_salt("measure-decimals").show(ui, |ui, _| {
NumberField::new(tl!("Decimals"), Bind::bound(&mut precision)).range(0.0..=6.0).step(1.0).show(ui);
});
state.precision = precision.map_or(state.precision, |p| p.round().clamp(0.0, 6.0) as u8);
// A hand edit of the fields leaves the 1:N field showing the old ratio: say the new one.
if scale_fields(state) != fields {
@@ -706,7 +721,9 @@ pub(crate) fn panel(app: &mut PdfCraftApp, ui: &mut egui::Ui) {
}
}
}
TextField::new(tl!("Viewport"), Bind::bound(&mut state.name)).show(ui);
Field::new(tl!("Viewport")).id_salt("measure-viewport").show(ui, |ui, _| {
TextField::new(tl!("Viewport"), Bind::bound(&mut state.name)).show(ui);
});
let apply = Button::new(tl!("Apply scale")).enabled(doc.allows_annotation()).show(ui).clicked();
if let Some(error) = &state.error {
Notice::new(Tone::Bad, error.clone()).show(ui);
+106 -75
View File
@@ -218,83 +218,114 @@ fn options_bar(app: &mut PdfCraftApp, ui: &mut Ui, n: &mut Intents) {
let mut verified = page_done;
let engine_before = d.engine;
Stack::new().label(tl!("OCR options")).fill_width().show(ui, |ui, _| {
// Row 1: the settings (each written back into the persisted draft).
Row::new().wrap(true).show(ui, |ui, _| {
Select::new(tl!("Language"), Bind::bound(&mut d.language), &languages).show(ui);
Select::new(tl!("Engine"), Bind::bound(&mut d.engine), &engines).show(ui);
Select::new(tl!("Strategy"), Bind::bound(&mut d.strategy), &strategies).show(ui);
Select::new(tl!("Output"), Bind::bound(&mut d.output_mode), &outputs).show(ui);
for (flag, label, why) in [
(&mut d.auto_rotate, tl!("Auto-rotate"), tl!("Turns pages scanned sideways or upside down upright before reading")),
(&mut d.deskew, tl!("Deskew"), tl!("Straightens skewed text lines before reading")),
(&mut d.denoise, tl!("Denoise"), tl!("A 3×3 median filter against scan speckle")),
(&mut d.binarize, tl!("Binarize"), tl!("Sauvola binarization: ink to black, paper to white")),
] {
Checkbox::new(Bind::bound(flag)).label(label).tooltip(format!("{label} \u{2014} {why}")).show(ui);
}
});
// Row 2: scope and actions.
Row::new().wrap(true).show(ui, |ui, _| {
RadioGroup::new(tl!("Pages to read"), Bind::bound(&mut d.pages)).show(ui, |ui, _| {
Row::new().show(ui, |ui, _| {
Radio::new(OcrPages::All).label(tl!("All pages")).show(ui);
Radio::new(OcrPages::Current).label(tl!("Current page")).show(ui);
Radio::new(OcrPages::Range).label(tl!("From")).show(ui);
});
// Production's bar is one wide row pair; in a narrower centre column (the side panels stay) the same controls
// are grouped into rows that each fit, so nothing runs out of the screen.
let wide = ui.available_width() >= 1000.0;
let mut language = |ui: &mut Ui| {
Select::new(tl!("Language"), Bind::bound(&mut d.language), &languages).show(ui);
Select::new(tl!("Engine"), Bind::bound(&mut d.engine), &engines).show(ui);
};
let mut reading = |ui: &mut Ui| {
Select::new(tl!("Strategy"), Bind::bound(&mut d.strategy), &strategies).show(ui);
Select::new(tl!("Output"), Bind::bound(&mut d.output_mode), &outputs).show(ui);
};
let mut prep = |ui: &mut Ui| {
for (flag, label, why) in [
(&mut d.auto_rotate, tl!("Auto-rotate"), tl!("Turns pages scanned sideways or upside down upright before reading")),
(&mut d.deskew, tl!("Deskew"), tl!("Straightens skewed text lines before reading")),
(&mut d.denoise, tl!("Denoise"), tl!("A 3×3 median filter against scan speckle")),
(&mut d.binarize, tl!("Binarize"), tl!("Sauvola binarization: ink to black, paper to white")),
] {
Checkbox::new(Bind::bound(flag)).label(label).tooltip(format!("{label} \u{2014} {why}")).show(ui);
}
};
let mut scope = |ui: &mut Ui| {
RadioGroup::new(tl!("Pages to read"), Bind::bound(&mut d.pages)).show(ui, |ui, _| {
Row::new().show(ui, |ui, _| {
Radio::new(OcrPages::All).label(tl!("All pages")).show(ui);
Radio::new(OcrPages::Current).label(tl!("Current page")).show(ui);
Radio::new(OcrPages::Range).label(tl!("From")).show(ui);
});
let ranged = d.pages == OcrPages::Range;
NumberField::new(tl!("From page"), Bind::bound(&mut from)).range(1.0..=9999.0).enabled(ranged).show(ui);
Text::new(tl!("to")).shade(Shade::Muted).show(ui);
NumberField::new(tl!("To page"), Bind::bound(&mut to)).range(1.0..=9999.0).enabled(ranged).show(ui);
Divider::vertical().show(ui);
if Button::new(tl!("Run OCR")).variant(Variant::PRIMARY).enabled(run_enabled).show(ui).clicked() {
n.run = true;
}
if running && Button::new(tl!("Cancel")).variant(Variant::SECONDARY).show(ui).clicked() {
n.cancel = true;
}
if rereading && Button::new(tl!("Cancel re-read")).variant(Variant::SECONDARY).show(ui).clicked() {
n.cancel_reread = true;
}
if Button::new(tl!("Accept")).variant(Variant::SECONDARY).enabled(accept_enabled).show(ui).clicked() {
n.accept = true;
}
if Button::new(tl!("Reject")).variant(Variant::SECONDARY).enabled(can_reject).show(ui).clicked() {
n.reject = true;
}
Divider::vertical().show(ui);
Checkbox::new(Bind::bound(&mut verified))
.label(tl!("Page verified"))
.tooltip(tl!("Mark this page as reviewed (Ctrl+T)"))
.enabled(review)
.show(ui);
if Button::new(tl!("Next uncertain"))
.variant(Variant::GHOST)
.icon(craft::behavior::IconId::new("chevron_right"))
.tooltip(tl!("F8: next word to review; Shift+F8 goes back"))
.enabled(review)
.show(ui)
.clicked()
{
n.next_uncertain = true;
}
if Button::new(tl!("Previous uncertain"))
.variant(Variant::GHOST)
.icon(craft::behavior::IconId::new("chevron_left"))
.tooltip(tl!("Shift+F8: the previous word to review"))
.enabled(review)
.show(ui)
.clicked()
{
n.prev_uncertain = true;
}
if Button::new(tl!("Exit")).variant(Variant::GHOST).icon(craft::behavior::IconId::new("close")).show(ui).clicked() {
n.exit = true;
}
});
let ranged = d.pages == OcrPages::Range;
NumberField::new(tl!("From page"), Bind::bound(&mut from)).range(1.0..=9999.0).enabled(ranged).show(ui);
Text::new(tl!("to")).shade(Shade::Muted).show(ui);
NumberField::new(tl!("To page"), Bind::bound(&mut to)).range(1.0..=9999.0).enabled(ranged).show(ui);
};
let mut actions = |ui: &mut Ui, n: &mut Intents| {
if wide {
Divider::vertical().show(ui);
}
if Button::new(tl!("Run OCR")).variant(Variant::PRIMARY).enabled(run_enabled).show(ui).clicked() {
n.run = true;
}
if running && Button::new(tl!("Cancel")).variant(Variant::SECONDARY).show(ui).clicked() {
n.cancel = true;
}
if rereading && Button::new(tl!("Cancel re-read")).variant(Variant::SECONDARY).show(ui).clicked() {
n.cancel_reread = true;
}
if Button::new(tl!("Accept")).variant(Variant::SECONDARY).enabled(accept_enabled).show(ui).clicked() {
n.accept = true;
}
if Button::new(tl!("Reject")).variant(Variant::SECONDARY).enabled(can_reject).show(ui).clicked() {
n.reject = true;
}
};
let mut review_bar = |ui: &mut Ui, n: &mut Intents| {
if wide {
Divider::vertical().show(ui);
}
Checkbox::new(Bind::bound(&mut verified))
.label(tl!("Page verified"))
.tooltip(tl!("Mark this page as reviewed (Ctrl+T)"))
.enabled(review)
.show(ui);
if Button::new(tl!("Next uncertain"))
.variant(Variant::GHOST)
.icon(craft::behavior::IconId::new("chevron_right"))
.tooltip(tl!("F8: next word to review; Shift+F8 goes back"))
.enabled(review)
.show(ui)
.clicked()
{
n.next_uncertain = true;
}
if Button::new(tl!("Previous uncertain"))
.variant(Variant::GHOST)
.icon(craft::behavior::IconId::new("chevron_left"))
.tooltip(tl!("Shift+F8: the previous word to review"))
.enabled(review)
.show(ui)
.clicked()
{
n.prev_uncertain = true;
}
if Button::new(tl!("Exit")).variant(Variant::GHOST).icon(craft::behavior::IconId::new("close")).show(ui).clicked() {
n.exit = true;
}
};
Stack::new().label(tl!("OCR options")).fill_width().show(ui, |ui, _| {
if wide {
Row::new().wrap(true).show(ui, |ui, _| {
language(ui);
reading(ui);
prep(ui);
});
Row::new().wrap(true).show(ui, |ui, _| {
scope(ui);
actions(ui, n);
review_bar(ui, n);
});
} else {
Row::new().show(ui, |ui, _| language(ui));
Row::new().show(ui, |ui, _| reading(ui));
Row::new().show(ui, |ui, _| prep(ui));
Row::new().show(ui, |ui, _| scope(ui));
Row::new().show(ui, |ui, _| actions(ui, n));
Row::new().show(ui, |ui, _| review_bar(ui, n));
}
});
if let Some(from) = from {
+3 -3
View File
@@ -1286,7 +1286,7 @@ fn measurement_tools_draw_live_calibrate_save_and_export() {
h.state_mut().views[0].session.measure.page_unit = Some(pdfcraft_engine::measure::PageUnit::Pt);
h.state_mut().views[0].session.measure.real_distance = 1.0;
h.state_mut().views[0].session.measure.unit = "m".into();
h.get_by_label("Apply scale").click();
h.get_by_label("Apply scale").click_accesskit();
h.run_steps(3);
let scale = h.state().session.get(doc).unwrap().measurement_scale(0, [20.0, 20.0]).unwrap();
assert!((scale.x - 0.1).abs() < 1e-10);
@@ -1345,7 +1345,7 @@ fn a_1_to_50_scale_in_millimetres_measures_a_10_mm_line_as_500_mm() {
h.run_steps(3);
let m = &mut h.state_mut().views[0].session.measure;
(m.drawing_points, m.real_distance, m.unit) = (1.0, 50.0, "mm".into());
h.get_by_label("Apply scale").click();
h.get_by_label("Apply scale").click_accesskit();
h.run_steps(3);
let mm = 72.0 / 25.4;
let line = [[20.0, 30.0], [20.0 + 10.0 * mm, 30.0]];
@@ -1399,7 +1399,7 @@ fn a_plan_scale_picked_or_typed_applies_at_once() {
assert_eq!(read(&h), ("12.00 m".to_string(), "1 mm = 0.2 m".to_string()));
// Typed, in the other notations; leaving the field applies.
fn field<'a>(h: &'a Harness<'static, PdfCraftApp>) -> egui_kittest::Node<'a> {
h.get_by_role_and_label(egui::accesskit::Role::TextInput, "Scale")
h.get_by_role_and_label(egui::accesskit::Role::TextInput, "Drawing scale")
}
for (typed, label) in [("1/50", "3.00 m"), ("1:100", "6.00 m")] {
field(&h).click();