Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ddfcaba
feat(layout): section lines on a map frame (#2863 part 1)
elpidiofilho Nov 24, 2026
7f50ff7
fix(layout): a section line on a frame whose map is missing is said; …
elpidiofilho Nov 24, 2026
83eb3d9
refactor(layout): section lines' Format pane rows move to a part of t…
elpidiofilho Nov 24, 2026
ccd16e2
feat(layout): section lines in the Format pane (#2863 part 1b)
elpidiofilho Nov 24, 2026
2239611
feat(layout): section lines dragged in the layout view (#2863 part 1b)
elpidiofilho Nov 24, 2026
faa1f70
Merge main into feat/2863-layout-section-lines
elpidiofilho Nov 24, 2026
209d5f7
Merge branch 'feat/2863-layout-section-lines' into feat/2863-layout-s…
elpidiofilho Nov 24, 2026
ea5a1c4
fix(layout): layout.addElement refuses what a section doesn't read
elpidiofilho Nov 25, 2026
1ca1415
Merge branch 'feat/2863-layout-section-lines' into feat/2863-layout-s…
elpidiofilho Nov 25, 2026
cb66043
Merge main into feat/2863-layout-section-lines
elpidiofilho Nov 25, 2026
4f94085
Merge feat/2863-layout-section-lines into feat/2863-layout-section-fo…
elpidiofilho Nov 25, 2026
f213416
fix(layout): a removed section line takes no change; a line missing f…
elpidiofilho Nov 25, 2026
e2da7d0
Merge feat/2863-layout-section-lines into feat/2863-layout-section-fo…
elpidiofilho Nov 25, 2026
56facbf
fix(layout): spaces round a section name are not counted as cut
elpidiofilho Nov 25, 2026
2caab1e
Merge feat/2863-layout-section-lines into feat/2863-layout-section-fo…
elpidiofilho Nov 25, 2026
a07a5f5
Merge main into feat/2863-layout-section-lines
elpidiofilho Nov 26, 2026
ff1d9b2
test(capabilities): a sample for layout-section
elpidiofilho Nov 26, 2026
b9183f5
Merge main into feat/2863-layout-section-lines
elpidiofilho Nov 26, 2026
a0e2f86
Merge main into feat/2863-layout-section-lines
elpidiofilho Nov 26, 2026
d06ffe6
fix(layout): a report says the section lines its layout page can't draw
elpidiofilho Nov 27, 2026
985d92d
test(layout): each section test under its own doc comment
elpidiofilho Nov 27, 2026
0ff7ae3
Merge main into feat/2863-layout-section-lines
elpidiofilho Nov 27, 2026
6bdc69e
test(layout): a grid or an extent indicator refuses a section's name
elpidiofilho Nov 27, 2026
6453d3d
Merge main into feat/2863-layout-section-lines
elpidiofilho Nov 27, 2026
e1812b5
fix(layout): section names on short lines, the credit beside them, an…
elpidiofilho Nov 27, 2026
fd9e7db
Merge main into feat/2863-layout-section-lines
elpidiofilho Nov 27, 2026
dc800d2
fix(layout): one report notice for the section lines its layouts leav…
elpidiofilho Nov 27, 2026
d359158
Merge feat/2863-layout-section-lines into feat/2863-layout-section-fo…
elpidiofilho Nov 27, 2026
ca2b8e9
Merge main into feat/2863-layout-section-format
elpidiofilho Nov 27, 2026
acb0565
fix(layout): a section line's drag lets go when a command changes the…
elpidiofilho Nov 27, 2026
a5e8a7b
fix(layout): a section line's drag keeps its name, and a drop off the…
elpidiofilho Nov 27, 2026
39ac5f1
fix(layout): a section line dropped outside a round or polygon frame'…
elpidiofilho Nov 27, 2026
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
8 changes: 8 additions & 0 deletions crates/map/src/layout/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ impl SectionLine {
_ => None,
}
}

/// Its direction's name in commands.
pub fn code(self) -> &'static str {
match self {
SectionLine::Horizontal(_) => "horizontal",
SectionLine::Vertical(_) => "vertical",
}
}
}

impl Section {
Expand Down
81 changes: 65 additions & 16 deletions crates/render/src/layout/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,69 @@ use super::*;
/// A section line's ends in its frame's points, from its left or top.
pub type SectionEnds = [(f64, f64); 2];

/// The globe a frame `w` × `h` points shows, if its map is on one.
fn section_globe(map: &Map, cam: &rustgis_map::Camera, (w, h): (f64, f64)) -> Option<rustgis_map::globe::Globe> {
map.projection.is_globe().then(|| rustgis_map::globe::Globe::new(cam, w, h))
}

/// Where the place `at` is on a frame `w` × `h` points, in its points; on a map whose world
/// repeats, the copy nearest the frame's middle. `None` where the frame's map can't show it.
fn section_px(
map: &Map,
cam: &rustgis_map::Camera,
globe: Option<&rustgis_map::globe::Globe>,
(w, h): (f64, f64),
mut at: Coord,
) -> Option<(f64, f64)> {
if let Some(mid) = map.to_lonlat(cam.center).filter(|c| c.x.is_finite()) {
at.x += 360.0 * ((mid.x - at.x) / 360.0).round();
}
match globe {
Some(g) => g.forward(at),
// A projection that holds a place to its reach (Web Mercator past 85.05°) gives another
// place, back: that one isn't the frame's to show.
None => {
map.to_map(at).filter(|&m| map.to_lonlat(m).is_none_or(|back| same_place(back, at))).and_then(|m| cam.try_to_screen(m, w, h))
}
}
.filter(|(x, y)| x.is_finite() && y.is_finite())
}

/// `line` moved `by` points across itself (down, or right for a vertical one) on a frame drawn as
/// for [`section_ends`], and its ends there. Its place keeps where it is along the line; where that
/// isn't in the frame's shape there, it goes to `along` points from the frame's left (or top).
/// `None` where the frame would not draw the line there.
pub fn section_moved(
map: &Map,
cam: &rustgis_map::Camera,
(w, h): (f64, f64),
shape: &FrameShape,
line: SectionLine,
by: f64,
along: f64,
) -> Option<(SectionLine, SectionEnds)> {
let globe = section_globe(map, cam, (w, h));
let vertical = matches!(line, SectionLine::Vertical(_));
let swap = |(x, y): (f64, f64)| if vertical { (y, x) } else { (x, y) };
let (own, across) = swap(section_px(map, cam, globe.as_ref(), (w, h), line.at())?);
let to = across + by;
[own, along].into_iter().find_map(|along| {
let (x, y) = swap((along, to));
let at = match &globe {
Some(g) => g.inverse(x, y),
None => cam.try_to_map(x, y, w, h).and_then(|m| map.to_lonlat(m)),
}?;
let at = Coord::new((at.x + 180.0).rem_euclid(360.0) - 180.0, at.y);
if !at.x.is_finite() || !(-90.0..=90.0).contains(&at.y) {
return None;
}
let moved = line.through(at);
let ends = section_ends(map, cam, (w, h), shape, moved).ok()?;
// Where the projection has no such place, its inverse can give one that is drawn elsewhere.
((swap(ends[0]).1 - to).abs() < 0.5).then_some((moved, ends))
})
}

/// Where `line` is drawn on a frame `w` × `h` points showing `map` through `cam`, within its
/// `shape`: its ends, the outermost of where it meets the shape's outline (#2863). It is straight
/// on the page whatever the frame's projection or bearing. On a tilted frame or the globe it runs
Expand All @@ -21,22 +84,8 @@ pub fn section_ends(
line: SectionLine,
) -> Result<SectionEnds, &'static str> {
const NOT_SHOWN: &str = "its place isn't one the frame's map shows";
let globe = map.projection.is_globe().then(|| rustgis_map::globe::Globe::new(cam, w, h));
let mut at = line.at();
// On a map whose world repeats, the copy of the place nearest the frame's middle.
if let Some(mid) = map.to_lonlat(cam.center).filter(|c| c.x.is_finite()) {
at.x += 360.0 * ((mid.x - at.x) / 360.0).round();
}
let (px, py) = match &globe {
Some(g) => g.forward(at),
// A projection that holds a place to its reach (Web Mercator past 85.05°) gives another
// place, back: that one isn't the frame's to show.
None => {
map.to_map(at).filter(|&m| map.to_lonlat(m).is_none_or(|back| same_place(back, at))).and_then(|m| cam.try_to_screen(m, w, h))
}
}
.filter(|(x, y)| x.is_finite() && y.is_finite())
.ok_or(NOT_SHOWN)?;
let globe = section_globe(map, cam, (w, h));
let (px, py) = section_px(map, cam, globe.as_ref(), (w, h), line.at()).ok_or(NOT_SHOWN)?;
// Along the line and across it: a vertical line is worked out with the axes swapped.
let vertical = matches!(line, SectionLine::Vertical(_));
let swap = |(x, y): (f64, f64)| if vertical { (y, x) } else { (x, y) };
Expand Down
54 changes: 54 additions & 0 deletions crates/render/src/layout/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7993,6 +7993,60 @@ fn a_section_line_past_mercators_reach_is_not_drawn() {
assert!(end(85.0).is_ok(), "{:?}", end(85.0));
}

/// A section line moved across itself is drawn where it was moved to, its place kept along it
/// whatever the frame's projection or bearing; in a round frame its place goes where the pointer
/// is when the shape leaves it out. Off the frame, its ground or its projection, it isn't moved.
#[test]
fn a_section_line_moves_across_its_frame() {
use rustgis_map::Projection;
let (w, h) = (400.0, 200.0);
let at = Coord::new(-44.66, -22.38);
let moved = |map: &Map, (c, scale, bearing, pitch): (Coord, f64, f64, f64), shape: &FrameShape, line, by, along| {
section_moved(map, &frame_camera(map, c, scale, bearing, pitch), (w, h), shape, line, by, along)
};
let rect = FrameShape::Rectangle;
let mut albers = Map::new("albers");
albers.projection = Projection::Custom("EPSG:10857".into());
for (map, bearing) in [(Map::new("m"), 0.0), (Map::new("m"), 40.0), (albers, -30.0)] {
let view = (Coord::new(at.x - 0.1, at.y + 0.05), 1e6, bearing, 0.0);
let cam = frame_camera(&map, view.0, view.1, view.2, view.3);
let px = |at: Coord| cam.try_to_screen(map.to_map(at).unwrap(), w, h).unwrap();
let (x, y) = px(at);
let near = |a: (f64, f64), b: (f64, f64)| (a.0 - b.0).abs() < 0.01 && (a.1 - b.1).abs() < 0.01;
let (line, ends) = moved(&map, view, &rect, SectionLine::Horizontal(at), -20.0, 7.0).unwrap();
assert!(near(px(line.at()), (x, y - 20.0)) && matches!(line, SectionLine::Horizontal(_)), "{line:?}");
assert!(near(ends[0], (0.0, y - 20.0)) && near(ends[1], (w, y - 20.0)), "{ends:?}");
let (line, ends) = moved(&map, view, &rect, SectionLine::Vertical(at), 25.0, 7.0).unwrap();
assert!(near(px(line.at()), (x + 25.0, y)) && matches!(line, SectionLine::Vertical(_)), "{line:?}");
assert!(near(ends[0], (x + 25.0, 0.0)) && near(ends[1], (x + 25.0, h)), "{ends:?}");
assert_eq!(moved(&map, view, &rect, SectionLine::Horizontal(at), h, 7.0), None, "below the frame");
assert_eq!(moved(&map, view, &rect, SectionLine::Vertical(at), -w, 7.0), None, "left of the frame");
}
// A place by a round frame's edge, moved up: the shape is narrower there, so it goes to the
// pointer, and there is no line where the pointer is off the shape too.
let map = Map::new("m");
let here = (at, 1e6, 0.0, 0.0);
let cam = frame_camera(&map, at, 1e6, 0.0, 0.0);
let edge = SectionLine::Horizontal(map.to_lonlat(cam.to_map(110.0, h / 2.0, w, h)).unwrap());
let (line, _) = moved(&map, here, &FrameShape::Circle, edge, -80.0, 210.0).unwrap();
let (x, y) = cam.try_to_screen(map.to_map(line.at()).unwrap(), w, h).unwrap();
assert!((x - 210.0).abs() < 0.01 && (y - 20.0).abs() < 0.01, "{x} {y}");
assert_eq!(moved(&map, here, &FrameShape::Circle, edge, -80.0, 110.0), None);
// Across 180°, the place keeps within the longitudes a command takes.
let line = SectionLine::Vertical(Coord::new(179.5, 0.0));
let (line, _) = moved(&map, (Coord::new(179.5, 0.0), 1e7, 0.0, 0.0), &rect, line, 60.0, 100.0).unwrap();
assert!((-180.0..-175.0).contains(&line.at().x), "{line:?}");
// Not over the horizon, nor off the globe.
let tilted = (at, 5e4, 0.0, 80.0);
assert!(moved(&map, tilted, &rect, SectionLine::Horizontal(at), 20.0, 200.0).is_some());
assert_eq!(moved(&map, tilted, &rect, SectionLine::Horizontal(at), -99.0, 200.0), None);
let mut globe = Map::new("g");
globe.projection = Projection::Globe;
let whole = (at, 5e8, 0.0, 0.0);
assert!(moved(&globe, whole, &rect, SectionLine::Vertical(at), 20.0, 100.0).is_some());
assert_eq!(moved(&globe, whole, &rect, SectionLine::Vertical(at), 190.0, 100.0), None);
}

/// A frame's section lines are drawn over its map in their colour, dashed, with their names at
/// both ends, clipped to its shape, as pixels and as vectors in a layer of their own; a frame
/// without one draws the same page as before.
Expand Down
10 changes: 10 additions & 0 deletions crates/ui-egui/src/layoutview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mod actions;
mod format;
mod handles;
mod interact;
mod section;
mod snap;
#[cfg(test)]
mod tests;
Expand All @@ -25,6 +26,7 @@ pub use format::format;
use format::*;
use handles::*;
use interact::*;
use section::*;
use snap::*;

/// Width of the rulers along the view's top and left edges (points).
Expand Down Expand Up @@ -569,6 +571,14 @@ pub fn show(app: &mut RustGisApp, ui: &mut Ui) {
let top = [rt, rb, lb].into_iter().fold(lt, |a, p| if p.y < a.y - 0.5 { p } else { a });
painter.text(top + vec2(0.0, -4.0), Align2::LEFT_BOTTOM, &e.name, regular(11.0), accent);
}
// A section line being dragged: where it will be, and its place.
if let (Some(Drag::Section(id, i, line, start)), Some(p)) = (app.layout.drag, pointer)
&& let Some((e, name, at, ends)) = section_landing(app, &layout, (id, i, line, start), to_mm(page, s, p))
{
painter.line_segment(section_on_screen(e, page, s, ends), Stroke::new(2.0, accent));
let label = format!("{name}: {:.4}°, {:.4}°", at.x, at.y);
painter.text(p + vec2(12.0, 12.0), Align2::LEFT_TOP, label, semibold(12.0), accent);
}
// A line being turned: where it will point, and its angle.
if let (Some(Drag::Rotate(id, a0, from)), Some(p)) = (app.layout.drag, pointer)
&& let Some(e) = layout.element(id)
Expand Down
112 changes: 110 additions & 2 deletions crates/ui-egui/src/layoutview/format/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,108 @@ use crate::RustGisApp;
use crate::widgets::Dragged;
use egui::{Ui, vec2};
use rustgis_engine::map::layout::{
CoordFormat, Element, ElementKind, Grid, GridKind, GridStyle, Layout, MAX_FRAME_SCALE, MAX_GRID_WIDTH, MAX_TICK_MM, MIN_FRAME_SCALE,
Orientation,
CoordFormat, Element, ElementKind, Grid, GridKind, GridStyle, Layout, MAX_FRAME_SCALE, MAX_GRID_WIDTH, MAX_SECTIONS, MAX_TICK_MM,
MIN_FRAME_SCALE, Orientation, Section, SectionLine,
};
use serde_json::{Value, json};

/// A map frame's section lines (#2863), each with its name, direction, place and look, why it isn't
/// drawn when it isn't, and Remove; below them, the buttons that add one, whose direction is given
/// back when one is clicked. `update` sends a change.
fn section_rows(
app: &mut RustGisApp,
ui: &mut Ui,
layout: &Layout,
id: u32,
sections: &[Section],
update: &dyn Fn(&mut RustGisApp, Value),
) -> Option<&'static str> {
let gaps = rustgis_engine::render::layout::sections_not_drawn(layout, &app.session.project.maps);
Comment thread
elpidioassinaturas marked this conversation as resolved.
Resolved
for (i, s) in sections.iter().enumerate() {
let set = |app: &mut RustGisApp, mut p: Value| {
p["section"]["name"] = json!(s.name);
update(app, p);
};
ui.push_id(("section", id, i), |ui| {
egui::Grid::new("section_place").num_columns(2).spacing(vec2(8.0, 6.0)).show(ui, |ui| {
let label = ui.label(tl!("Name"));
// Typing is kept with the view until the field is left.
let key = egui::Id::unique(("section_name", id, i));
let mut name = ui.data_mut(|d| d.get_temp::<String>(key)).unwrap_or_else(|| s.name.clone());
let r = ui.add(egui::TextEdit::singleline(&mut name).desired_width(60.0)).labelled_by(label.id);
if r.has_focus() {
ui.data_mut(|d| d.insert_temp(key, name));
} else {
ui.data_mut(|d| d.remove::<String>(key));
if r.lost_focus() && name.trim() != s.name {
set(app, json!({"section": {"newName": name}}));
Comment thread
elpidioassinaturas marked this conversation as resolved.
Resolved
}
}
ui.end_row();
let label = ui.label(tl!("Direction"));
let shown = |line: SectionLine| match line {
SectionLine::Horizontal(_) => tl!("Horizontal"),
SectionLine::Vertical(_) => tl!("Vertical"),
};
let at = s.line.at();
let items = [SectionLine::Horizontal(at), SectionLine::Vertical(at)]
.map(|l| (shown(l).to_string(), l == s.line, json!({"section": {"direction": l.code()}})));
if let Some(p) = choice(ui, ("section_direction", id), label.id, shown(s.line), &items) {
set(app, p);
}
ui.end_row();
for (text, axis, current, most) in [("Longitude", 0, at.x, 180.0), ("Latitude", 1, at.y, 90.0)] {
let label = ui.label(tl!(text));
let mut v = current;
let drag = Dragged::lend(ui, egui::Id::unique(("section_drag", id, i, text)), &mut v);
let field = egui::DragValue::new(&mut v).update_while_editing(false).range(-most..=most).speed(0.01).max_decimals(5);
let r = ui.add(field.suffix("°")).labelled_by(label.id);
if drag.settled(ui, &r, &mut v) && (v - current).abs() > 1e-9 {
let mut to = [at.x, at.y];
to[axis] = v;
set(app, json!({"section": {"at": to}}));
}
ui.end_row();
}
let label = ui.label(tl!("Dash"));
if let Some(dash) = dash_picked(ui, ("section_dash", id), s.dash, s.width, label.id) {
set(app, json!({"section": {"dash": dash}}));
}
ui.end_row();
});
let (least, most) = rustgis_engine::map::layout::SECTION_WIDTHS;
let line = Outline {
key: "section",
drag: egui::Id::unique(("section_drag", id, i, "width")),
color: s.color,
width: s.width,
range: least..=most,
};
outline_rows(app, ui, "section_look", line, None, &set);
if let Some(gap) = gaps.iter().find(|g| g.frame == id && g.section == s.name) {
let why = crate::i18n::fmt("Not drawn: {why}", &[("why", tl_raw!(gap.why))]);
ui.label(egui::RichText::new(why).size(11.5).color(ui.visuals().warn_fg_color));
}
if ui.button(tl!("Remove Section Line")).clicked() {
set(app, json!({"section": {"remove": true}}));
}
});
ui.separator();
}
let mut add = None;
ui.add_enabled_ui(sections.len() < MAX_SECTIONS, |ui| {
ui.horizontal_wrapped(|ui| {
for (text, direction) in [("Add Horizontal", "horizontal"), ("Add Vertical", "vertical")] {
let hint = tl!("A line across the frame through its centre's place, named at both ends.");
if ui.button(tl!(text)).on_hover_text(hint).clicked() {
add = Some(direction);
}
}
});
});
add
}

/// A map frame's grid options; `set` sends the changed ones (`false` removes the grid).
fn grid_properties(app: &mut RustGisApp, ui: &mut Ui, grid: Option<&Grid>, id: u32, set: &dyn Fn(&mut RustGisApp, Value)) {
let mut on = grid.is_some();
Expand Down Expand Up @@ -327,6 +424,17 @@ pub(super) fn frame_sections(
grid_properties(app, ui, grid.as_ref(), id, &|app, g| update(app, json!({"grid": g})));
});
}
if let ElementKind::MapFrame { sections, .. } = &e.kind {
ui.add_space(4.0);
egui::CollapsingHeader::new(tl!("Section Lines")).id_salt(("frame_sections", id)).default_open(!sections.is_empty()).show(
ui,
|ui| {
if let Some(direction) = section_rows(app, ui, layout, id, sections, &update) {
let _ = app.run("layout.addElement", json!({"layout": li, "kind": "section", "frame": id, "direction": direction}));
}
},
);
}
// The extent indicator this frame draws (another frame's extent): its colour and width.
if let ElementKind::MapFrame { extent_of: Some(of), extent_color, extent_width, .. } = &e.kind {
let other = layout.element(*of).map_or_else(|| of.to_string(), |o| o.name.clone());
Expand Down
Loading
Loading