🐛 Fix guides not clipping (#10423)

This commit is contained in:
Belén Albeza 2026-06-25 11:50:58 +02:00 committed by GitHub
parent a668702982
commit d323aa9693
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 4 deletions

View File

@ -13,7 +13,7 @@ use super::fonts::FontStore;
use crate::state::RulerState;
use crate::view::Viewbox;
const RULER_AREA_SIZE: f32 = 22.0;
pub const RULER_AREA_SIZE: f32 = 22.0;
const RULER_TICK_OFFSET: f32 = 15.0;
const RULER_TICK_LEN: f32 = 4.0;
const RULER_TICK_GAP: f32 = 2.0;

View File

@ -65,13 +65,19 @@ pub fn render(render_state: &mut RenderState, shapes: ShapesPoolRef) {
let viewbox = render_state.viewbox;
let ruler_state = render_state.rulers;
rulers::render(canvas, viewbox, &render_state.fonts, &ruler_state);
// TODO: pass guides data here
// Width of the ruler bars in document coordinates.
// Note that when rulers are hidden, guides are not shown either, so we
// can use a fixed value here.
let ruler_width = rulers::RULER_AREA_SIZE / viewbox.zoom;
let (horizontal, vertical) = get_ui_state().guides();
guides::render(
canvas,
zoom,
render_state.options.dpr,
viewbox.area,
ruler_width,
horizontal,
vertical,
);

View File

@ -3,22 +3,43 @@ use skia_safe::{self as skia};
use crate::math::Rect;
use crate::ui::{Guide, GuideKind};
/// Renders the ruler guides overlay using the guides provided by the host
/// (ClojureScript) and stored in the render state.
/// Renders the ruler guides, clipped out of the ruler bars.
pub fn render(
canvas: &skia::Canvas,
zoom: f32,
dpr: f32,
area: Rect,
ruler_width: f32,
horizontal: &[Guide],
vertical: &[Guide],
) {
// Horizontal guides: clip out the top strip (horizontal ruler)
canvas.save();
canvas.clip_rect(
Rect::from_ltrb(area.left, area.top + ruler_width, area.right, area.bottom),
None,
false,
);
for guide in horizontal {
render_guide(canvas, zoom, dpr, area, *guide);
}
canvas.restore();
// Vertical guides: clip out the left strip (vertical ruler)
canvas.save();
canvas.clip_rect(
Rect::from_ltrb(area.left + ruler_width, area.top, area.right, area.bottom),
None,
false,
);
for guide in vertical {
render_guide(canvas, zoom, dpr, area, *guide);
}
canvas.restore();
}
pub fn render_guide(canvas: &skia::Canvas, zoom: f32, dpr: f32, area: Rect, guide: Guide) {