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
21 changes: 20 additions & 1 deletion crates/render/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3076,7 +3076,9 @@ fn stacked_swatch(
view: &view,
ppp: ppp * k,
wireframe: false,
cull: Extent::EMPTY,
// (The swatch's own view: the stroke and fill paths don't cull today, and one that does
// still keeps the swatch, where an empty extent would drop it.)
cull: crate::cull_extent(&view, crate::CULL_MARGIN),
globe: None,
sprites: Default::default(),
bursts: Default::default(),
Expand Down Expand Up @@ -7649,6 +7651,23 @@ Elaboração: RustGIS",
assert!(inked(&pm, 7..21, 34..41, red) > 50, "its symbol's fill");
}

/// A polygon's outline is drawn over its stacked fills, as on the map (#2490).
#[test]
fn a_legend_draws_a_polygons_outline_over_its_fills() {
let (blue, green) = (Rgba::rgb(0, 0, 255), Rgba::rgb(0, 200, 0));
let s = rustgis_map::Symbol { stroke: blue, stroke_width: 2.0, ..rustgis_map::Symbol::default_for(GeometryType::Polygon, 0) };
let solid = rustgis_map::fills::FillLayer { color: Some(green), pattern: rustgis_map::fills::FillPattern::Solid };
let map = shape_legend_map(GeometryType::Polygon, |l| {
l.renderer = rustgis_map::Renderer::Single(s);
l.fill_layers = vec![solid];
});
let pm = point_legend(&map);
// The box's top edge, 3 points down, under the 2-point outline; its inside, the fill.
assert!(inked(&pm, 1..15, 3..4, blue) > 10, "the outline");
assert_eq!(inked(&pm, 1..15, 3..4, green), 0, "no fill over it");
assert!(inked(&pm, 2..14, 5..10, green) > 50, "the fill inside");
}

/// A diagram's categories keep their own colour on a layer with stacked strokes or fills.
#[test]
fn a_diagrams_rows_keep_their_colour_on_lines_and_polygons() {
Expand Down
12 changes: 6 additions & 6 deletions crates/ui-egui/src/fill_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ pub(crate) fn fills_editor(app: &mut RustGisApp, ui: &mut Ui, l: &Layer, t: &Tok
let (r, _) = ui.allocate_exact_size(vec2(ui.available_width(), 44.0), Sense::hover());
ui.painter().rect_filled(r, CornerRadius::same(4), t.ribbon);
let swatch = Rect::from_center_size(r.center(), vec2(r.width().min(120.0) - 8.0, r.height() - 10.0));
preview(ui, swatch, &fills, &base);
preview(ui.painter(), swatch, &fills, &base);
if borrowed {
ui.label(
egui::RichText::new(tl!("This class is drawn with the layer's fills. Changing them here gives it its own."))
Expand Down Expand Up @@ -469,8 +469,8 @@ pub(crate) fn fills_editor(app: &mut RustGisApp, ui: &mut Ui, l: &Layer, t: &Tok
/// The stacked `fills` on `r`, bottom first: a colour fills it, hatch lines cross it at their
/// angle and spacing, markers sit on their grid (as circles, images as themselves), a gradient or
/// shapeburst shades it (in cells), each in its colour or `base`'s.
fn preview(ui: &Ui, r: Rect, fills: &[FillLayer], base: &Symbol) {
let p = ui.painter().with_clip_rect(r);
pub(crate) fn preview(p: &egui::Painter, r: Rect, fills: &[FillLayer], base: &Symbol) {
let p = p.with_clip_rect(r);
let one = [FillLayer::default()];
let shown = if fills.is_empty() { &one[..] } else { fills };
// (Only what the map draws: a hatch of no width, a marker of no size, no colour to show.)
Expand All @@ -495,7 +495,7 @@ fn preview(ui: &Ui, r: Rect, fills: &[FillLayer], base: &Symbol) {
}
FillPattern::Dots { marker, size, spacing, displacement, .. } => {
// An image, looked up once for all its dots.
let image = crate::markerimages::image(ui.ctx(), marker);
let image = crate::markerimages::image(p.ctx(), marker);
// (No finer than 4 points in the swatch: it is a picture, not every dot.)
let [dx, dy] = spacing.map(|s| s.max(4.0));
// (Shifts widened with the spacing, so a half shift stays a half.)
Expand Down Expand Up @@ -611,11 +611,11 @@ mod tests {
let r = Rect::from_min_size(pos2(0.0, 0.0), vec2(40.0, 20.0));
let textured =
|c: &egui::epaint::ClippedShape| matches!(&c.shape, egui::Shape::Mesh(m) if m.texture_id != egui::TextureId::default());
let mut out = ctx.run_ui(egui::RawInput::default(), |ui| preview(ui, r, &[dots(Marker::Picture(pic))], &base));
let mut out = ctx.run_ui(egui::RawInput::default(), |ui| preview(ui.painter(), r, &[dots(Marker::Picture(pic))], &base));
assert!(!out.shapes.is_empty() && out.shapes.iter().all(textured));
out.textures_delta.clear();
// A shape is still circles.
let shapes = ctx.run_ui(egui::RawInput::default(), |ui| preview(ui, r, &[dots(Marker::Circle)], &base)).shapes;
let shapes = ctx.run_ui(egui::RawInput::default(), |ui| preview(ui.painter(), r, &[dots(Marker::Circle)], &base)).shapes;
assert!(shapes.iter().all(|c| matches!(c.shape, egui::Shape::Circle(_))));
}

Expand Down
Loading
Loading