mirror of
https://github.com/storytold/designcraft.git
synced 2026-11-17 15:46:58 +00:00
Apply review fixes
- crates/ui-egui/src/panels/pages.rs
This commit is contained in:
1 parent
a60cb72826
commit
1f75a8d8f0
1 file changed
+12
-4
@@ -293,11 +293,16 @@ const LAYOUT_COL_MIN: f32 = 96.0;
|
||||
/// A spread's label under its thumbnails, as InDesign's: one name for a single page, "2–3" for
|
||||
/// pages numbered on in one section (an en dash), and the names apart ("2, 1", "8, A") when a section starts
|
||||
/// inside the spread.
|
||||
/// The names read left to right as the thumbnails are drawn, so a spread bound right to left
|
||||
/// lists its second page first.
|
||||
pub(crate) fn spread_label(app: &DesignApp, doc: &designcraft_doc::Document, first: usize, n: usize) -> String {
|
||||
let mut names: Vec<String> = (first..first + n).map(|abs| app.session.page_label(abs)).collect();
|
||||
if doc.settings.right_to_left_binding {
|
||||
names.reverse();
|
||||
let mut order: Vec<usize> = (first..first + n).collect();
|
||||
// In the order the thumbnails are drawn: by each page's x (a right-to-left pair shows its second page on the left).
|
||||
if let Some(sp) = doc.page_loc(first).and_then(|(si, _)| doc.spreads.get(si)) {
|
||||
let x = |abs: usize| sp.pages.get(abs.saturating_sub(first)).map_or(0.0, |p| p.x);
|
||||
order.sort_by(|&a, &b| x(a).total_cmp(&x(b)));
|
||||
}
|
||||
let names: Vec<String> = order.into_iter().map(|abs| app.session.page_label(abs)).collect();
|
||||
let starts = |abs: usize| abs == 0 || doc.sections.iter().any(|s| s.start == abs);
|
||||
match (names.first(), names.last()) {
|
||||
(Some(a), Some(b)) if names.len() > 1 => {
|
||||
@@ -1311,7 +1316,8 @@ mod spread_label_tests {
|
||||
|
||||
/// Bound right to left, a spread's label follows the document's reading order: the left
|
||||
/// page first ("3–2", not "2–3"), and a section inside a spread lists its pages left to
|
||||
/// right. Left-to-right labels are unchanged.
|
||||
/// right. Left-to-right labels are unchanged. A spread of more pages, drawn in document
|
||||
/// order, keeps its label in that order.
|
||||
#[test]
|
||||
fn rtl_binding_labels_spreads_in_visual_left_to_right_order() {
|
||||
let mut app = app();
|
||||
@@ -1322,6 +1328,8 @@ mod spread_label_tests {
|
||||
let got = labels(&app);
|
||||
assert_eq!(got[1], "1, 2");
|
||||
assert_eq!(got[2], "3–2");
|
||||
app.run("layout.pages.toSpread", json!({"page": 4, "spread": 1})).unwrap();
|
||||
assert_eq!(labels(&app)[1], "2–4");
|
||||
}
|
||||
|
||||
/// Labels navigate to document spreads, including when parent editing was active.
|
||||
|
||||
Reference in new issue
Block a user