tabs: the Tabs dialog shows lengths in the document's unit

The dialog showed points; production shows inches, the default document
unit. It now takes the unit the ruler that opens it shows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dylan M. Taylor
2026-11-28 11:03:56 +00:00
co-authored by Claude Opus 5.5
parent dc2545d33c
commit b9185dec4c
4 changed files with 32 additions and 2 deletions
+2
View File
@@ -26,6 +26,8 @@ mod rulers;
pub(crate) mod text_host;
pub(crate) mod tool;
pub(crate) use rulers::doc_unit;
fn navigation() -> NavigationOptions {
let mut navigation = NavigationOptions::default();
navigation.wheel = WheelScheme::Document;
+6 -1
View File
@@ -22,6 +22,11 @@ pub(super) fn ruler_text(unit: Unit) -> RulerText {
RulerText::new(RulerUnits::new(1.0 / unit.points_per_unit(), Ticks::decimal(unit == Unit::Pixels)), kind)
}
/// The document's unit as the text controls take it: the ruler's, and the Tabs dialog it opens.
pub(crate) fn doc_unit(unit: Unit) -> DocUnit {
DocUnit::new(ruler_text(unit).kind, UnitKind::POINTS_PER_INCH / Unit::Pixels.points_per_unit())
}
/// Builds display-only rulers whose origin stays at the slide origin.
pub(crate) fn rulers(app: &SlideApp) -> Option<Rulers<'static>> {
app.ui.ruler.then(|| Rulers::new("Rulers", Bind::given(Point::ZERO)).origin_locked(true).interactive(false))
@@ -59,7 +64,7 @@ pub(crate) fn show_text_ruler(app: &mut SlideApp, ui: &mut egui::Ui, space: &Can
.corner(corner)
.scale(space.view.zoom as f32)
.origin(space.view.to_screen(Point::new(number("x"), 0.0)).x)
.unit(DocUnit::new(ruler_text(unit).kind, UnitKind::POINTS_PER_INCH / Unit::Pixels.points_per_unit()))
.unit(doc_unit(unit))
.kind(app.ruler_tab_kind)
.show_at(ui, top.union(corner));
ui.set_clip_rect(body_clip);
@@ -103,6 +103,21 @@ fn tabs_from_paragraph_applies_a_stop_and_returns() {
assert_eq!(align_of(&h), before, "cancelling Paragraph leaves the document's alignment");
}
/// The Tabs dialog shows its lengths in the document's unit, as the ruler that opens it does.
#[test]
fn tabs_shows_lengths_in_the_document_unit() {
use deckcraft_geom::Unit;
for unit in [Unit::Inches, Unit::Centimeters] {
let mut h = harness();
h.state_mut().session.prefs.units = unit;
h.state_mut().open_dialog("tabs", json!({"tabs": [], "defaultTab": 72.0}));
h.run_steps(4);
let shown = h.get_by_label("Default tab stops:").value().unwrap_or_default();
let number: f64 = shown.trim_matches(|c: char| !c.is_ascii_digit() && c != '.').parse().unwrap_or(f64::NAN);
assert!((number * unit.points_per_unit() - 72.0).abs() < 0.5, "{unit:?}: the default spacing {shown:?} is 72 pt in the unit");
}
}
fn dialog(h: &mut Harness<'_, SlideApp>, method: &str, params: serde_json::Value) {
let ctx = h.ctx.clone();
super::control(h.state_mut(), &ctx, method, &params).unwrap().unwrap();
+9 -1
View File
@@ -32,7 +32,15 @@ pub(crate) fn open(app: &mut SlideApp, _ctx: &Context, host: &mut DialogHost, pa
})
.collect();
let default_tab = params["defaultTab"].as_f64().unwrap_or(72.0) as f32;
Ok(Some(host.open(TabStopsDialog::new(stops, default_tab).key("tabs".to_owned()).parts(TabStopsParts::Basic).held_ok())))
Ok(Some(
host.open(
TabStopsDialog::new(stops, default_tab)
.unit(crate::canvas::doc_unit(app.session.prefs.units))
.key("tabs".to_owned())
.parts(TabStopsParts::Basic)
.held_ok(),
),
))
}
/// Keeps Paragraph's unapplied format while the engine supplies the Tabs seed.