mirror of
https://github.com/storytold/deckcraft.git
synced 2026-12-01 18:23:52 -06:00
Merge branch 'port/deckcraft/look/app-2' into port/deckcraft/area/app
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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, ¶ms).unwrap().unwrap();
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user