Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions crates/ui-egui/src/layoutview/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,12 +564,28 @@ fn fills_at(e: &Element, (x, y): (f64, f64)) -> impl Iterator<Item = rustgis_eng
/// A row of a layout element's text size in points, within [`LAYOUT_TEXT_SIZE`], labelled `label`
/// (#2581): the size it settles on when it differs from `current`.
pub(super) fn text_size_row(ui: &mut egui::Ui, label: impl Into<egui::WidgetText>, key: egui::Id, current: f64) -> Option<f64> {
points_row(ui, label, key, current, LAYOUT_TEXT_SIZE, None)
}

/// A row of a length in points, within `range`, labelled `label` and with `hover` over its box:
/// the value it settles on when it differs from `current`.
pub(super) fn points_row(
ui: &mut egui::Ui,
label: impl Into<egui::WidgetText>,
key: egui::Id,
current: f64,
range: std::ops::RangeInclusive<f64>,
hover: Option<&str>,
) -> Option<f64> {
let input_label = ui.label(label);
let mut pt = current;
let drag = Dragged::lend(ui, key, &mut pt);
let r = ui
.add(egui::DragValue::new(&mut pt).update_while_editing(false).range(LAYOUT_TEXT_SIZE).speed(0.1).max_decimals(1).suffix(" pt"))
let mut r = ui
.add(egui::DragValue::new(&mut pt).update_while_editing(false).range(range).speed(0.1).max_decimals(1).suffix(" pt"))
.labelled_by(input_label.id);
if let Some(hover) = hover {
r = r.on_hover_text(hover);
}
let settled = drag.settled(ui, &r, &mut pt) && (pt - current).abs() > 1e-6;
ui.end_row();
settled.then_some(pt)
Expand Down
28 changes: 27 additions & 1 deletion crates/ui-egui/src/layoutview/format/legend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use crate::RustGisApp;
use crate::widgets::Dragged;
use egui::{Ui, vec2};
use rustgis_engine::map::Drawn;
use rustgis_engine::map::layout::{Element, ElementKind, Layout, LegendFit, LegendSizes, MAX_LEGEND_COLUMNS};
use rustgis_engine::map::layout::{
Element, ElementKind, LEGEND_PATCH_HEIGHT_RANGE, LEGEND_PATCH_WIDTH_RANGE, Layout, LegendFit, LegendSizes, MAX_LEGEND_COLUMNS,
};
use rustgis_engine::render::layout::{class_row_labels, legend_lists, legend_place};
use serde_json::{Value, json};
use std::collections::HashSet;
Expand All @@ -29,6 +31,8 @@ pub(super) fn legend_property_rows(app: &mut RustGisApp, ui: &mut Ui, li: usize,
show_layer_names,
show_counts,
sizes,
patch_width,
patch_height,
..
} = &e.kind
else {
Expand Down Expand Up @@ -158,6 +162,28 @@ pub(super) fn legend_property_rows(app: &mut RustGisApp, ui: &mut Ui, li: usize,
.labelled_by(input_label.id)
.on_hover_text(tl!("How a point layer's marker sizes are drawn: a row each, or one inside another on a common base"));
ui.end_row();
// The line and polygon patches, in points at the default text size; they follow the text size.
let patch_boxes = [
(
tl!("Patch width"),
"patchWidth",
*patch_width,
LEGEND_PATCH_WIDTH_RANGE,
tl!("How wide the line and polygon patches are, in points at the default text size"),
),
(
tl!("Patch height"),
"patchHeight",
*patch_height,
LEGEND_PATCH_HEIGHT_RANGE,
tl!("How tall the line and polygon patches are, in points at the default text size"),
),
];
for (label, field, current, range, hover) in patch_boxes {
if let Some(pt) = points_row(ui, label, drag_key(field), current, range, Some(hover)) {
update(app, json!({field: pt}));
}
}
// Its names' and labels' points; the title, rows and swatches follow (#2581).
if let Some(pt) = text_size_row(ui, tl!("Text size"), drag_key("textSize"), *text_size) {
update(app, json!({"textSize": pt}));
Expand Down
50 changes: 50 additions & 0 deletions crates/ui-egui/src/layoutview/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4608,3 +4608,53 @@ fn a_legends_column_breaks_are_all_removed_from_the_pane() {
assert!(!h.get_by_role_and_label(Role::SpinButton, "Columns").accesskit_node().is_disabled());
assert!(h.query_by_label("Remove Column Breaks").is_none());
}

/// A legend's patch width and height are typed in the Format pane through layout.update, each one
/// undo step, and a value out of range settles on its limit (#3559).
#[test]
fn a_legend_takes_its_patch_size_in_the_format_pane() {
use egui::accesskit::Role;
use egui_kittest::kittest::Queryable;
use rustgis_engine::map::layout::ElementKind;
let mut app = RustGisApp::with_sample();
app.run("layout.new", json!({"name": "Patched", "template": "map"})).unwrap();
let legend = app.run("layout.addElement", json!({"kind": "legend"})).unwrap()["element"].as_u64().unwrap() as u32;
let li = app.session.active_layout.unwrap();
app.layout.selected = Some(legend);
let mut fonts = false;
let mut h = egui_kittest::Harness::builder().with_size(vec2(1200.0, 900.0)).build_ui_state(
move |ui, app: &mut RustGisApp| {
if !fonts {
crate::theme::install_fonts(ui.ctx(), &[], None);
fonts = true;
return;
}
with_format(app, ui);
},
app,
);
h.run_steps(3);
let patch = |h: &egui_kittest::Harness<'_, RustGisApp>| match &h.state().session.project.layouts[li].element(legend).unwrap().kind {
ElementKind::Legend { patch_width, patch_height, .. } => (*patch_width, *patch_height),
_ => panic!("a legend"),
};
assert_eq!(patch(&h), (16.0, 9.0), "the defaults");
let type_in = |h: &mut egui_kittest::Harness<'_, RustGisApp>, label: &str, text: &str| {
h.get_by_role_and_label(Role::SpinButton, label).focus();
h.run();
h.event(egui::Event::Text(text.into()));
h.run();
h.key_press(egui::Key::Enter);
h.run();
};
let undo = h.state().session.undo_depth();
type_in(&mut h, "Patch width", "32");
assert_eq!(patch(&h), (32.0, 9.0));
assert_eq!(h.state().session.undo_depth(), undo + 1, "one step");
type_in(&mut h, "Patch height", "18");
assert_eq!(patch(&h), (32.0, 18.0));
assert_eq!(h.state().session.undo_depth(), undo + 2, "one step");
type_in(&mut h, "Patch width", "500");
type_in(&mut h, "Patch height", "1");
assert_eq!(patch(&h), (100.0, 3.0), "the limits");
}
3 changes: 2 additions & 1 deletion docs/user-guide/layouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,8 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu
keep the size the map draws them at, and the block is never split between columns. Class rows
stay as rows.
- **Patch size** (`"patchWidth"` 4 to 100 and `"patchHeight"` 3 to 100, in points at the default
text size; 16 and 9 unless set): how wide and how tall the patch of a line or polygon row, or of a classified raster's class, is.
text size; 16 and 9 unless set; **Patch width** and **Patch height** in the Format pane):
how wide and how tall the patch of a line or polygon row, or of a classified raster's class, is.
They grow and shrink with the legend's text size, as its rows do. A taller patch makes the
rows of lines, polygons and raster classes taller (a row is never shorter than the default's), and a wider one
widens the column of patches, so the labels stay lined up. A point symbol keeps the size the
Expand Down
Loading