diff --git a/crates/draw/src/ui/brush_settings/panel.rs b/crates/draw/src/ui/brush_settings/panel.rs index b1b55f0cd..c9749777c 100644 --- a/crates/draw/src/ui/brush_settings/panel.rs +++ b/crates/draw/src/ui/brush_settings/panel.rs @@ -54,7 +54,7 @@ impl Outcome for BrushSettingsPanelOutput { } /// Photoshop's Brush Settings panel: the [`BrushSectionList`] at the reading start, a vertical line, the shown -/// section's pane (the app's content) in a scrolling body, a hairline, then the [`BrushStrokeStrip`] with the New, +/// section's pane (the app's content) in a scrolling body, a divider rule, then the [`BrushStrokeStrip`] with the New, /// Reset and Update icon buttons at the reading end. An ordinary dockable panel. /// /// - **Pane.** The `pane` closure (a body closure that also gets the key of the section shown) draws the shown pane section's controls, with the shared rows diff --git a/crates/timeline/src/ui/graph.rs b/crates/timeline/src/ui/graph.rs index 2d347a34c..0f90f62bf 100644 --- a/crates/timeline/src/ui/graph.rs +++ b/crates/timeline/src/ui/graph.rs @@ -16,7 +16,7 @@ use craft_ui::contract::{ Access, Bind, BindMut, Common, Component, Cx, DisabledLook, Edit as _, EditResponse, Focus as _, MeasureCx, Name, Outcome, PaintUi, PartsCx, Pointer as _, Props, Role, Styled as _, WordSetCx as _, }; -use craft_ui::primitives::{Dashes, GridInk, GridLines, IconSpec, PaintShape, RuleKind, StrokeWidth, TextRun, TickRank}; +use craft_ui::primitives::{Dashes, GridInk, GridLines, IconSpec, PaintShape, RectSide, RuleKind, StrokeWidth, TextRun, TickRank}; use craft_ui::runtime::env::Label; use craft_ui::runtime::focus::KeyUse; use craft_ui::style::{ComponentStyle, Flags, FocusLook, Resolve as _, State, StateMix, Stateful, States, StyleColor, StyleCx, TextLook, TypeRole}; @@ -1004,7 +1004,7 @@ impl Component for GraphEditor<'_> { // The bottom bar, over whatever the curves drew past the plot. draw.fill(&PaintShape::Rect(bar, CornerRadius::ZERO), style.bar_fill); - draw.rule(RuleKind::Divider, bar.left_top(), bar.right_top()); + draw.edge_rule(RuleKind::Divider, bar, RectSide::Top); let cells = Self::bar_cells(bar, style); for x in Self::bar_rules(&cells) { draw.rule(RuleKind::Divider, Pos2::new(x, bar.top() + style.gap), Pos2::new(x, bar.bottom() - style.gap)); diff --git a/crates/ui-contract/src/contract/body.rs b/crates/ui-contract/src/contract/body.rs index 7266a54da..632dfc4ae 100644 --- a/crates/ui-contract/src/contract/body.rs +++ b/crates/ui-contract/src/contract/body.rs @@ -69,6 +69,8 @@ pub(super) struct BodyHooks<'b> { end_gap: f32, /// The space between a stacked header and the body (`HeaderRegion::gap`), zero without one. header_gap: f32, + /// The bands the rules between the regions take. + rules: regions::RuleBands, /// The least width of the content, from `ContainerProps::least_width`. least_width: f32, /// How far the widest region wants to exceed the width the room allows, from this pass's measure. @@ -161,6 +163,7 @@ impl<'b> BodyHooks<'b> { region_gap: 0.0, end_gap: 0.0, header_gap: 0.0, + rules: regions::RuleBands::default(), least_width: 0.0, overflow: 0.0, room: Vec2::ZERO, diff --git a/crates/ui-contract/src/contract/body/hooks.rs b/crates/ui-contract/src/contract/body/hooks.rs index 8393137f9..42c59ece8 100644 --- a/crates/ui-contract/src/contract/body/hooks.rs +++ b/crates/ui-contract/src/contract/body/hooks.rs @@ -4,8 +4,8 @@ use super::inherit::{BodyScope, register_instances}; use super::open::open_now; use super::placement::{Placement, measure_layer, overlay_of, shown_placement}; use super::regions::{ - LabelColumns, LabelsFound, RegionFrame, RegionSizes, end_full_height, footer_in_end, gap_of, header_gap_of, label_extra_of, least_of, pad_of, - paint_edge_rule, paint_rules, rect_of, shared_labels, shared_line, + LabelColumns, LabelsFound, RegionFrame, RegionSizes, RuleBands, end_full_height, footer_in_end, footer_rule_under, gap_of, header_gap_of, + label_extra_of, least_of, pad_of, paint_edge_rule, paint_rules, rect_of, shared_labels, shared_line, }; use super::reorder::REORDER_BAND; use super::scroll::{Glide, Jumps, ScrollState, aim_glide, follow_anchor, jump_frame, overflow_inset, scroll_of}; @@ -141,6 +141,7 @@ impl ShapeHooks for BodyHooks<'_> { self.region_gap = gap_of(&env.tokens, Gap::Tight); self.end_gap = gap_of(&env.tokens, props.end.map_or(Gap::Tight, |end| end.gap)); self.header_gap = header_gap_of(props, &env.tokens); + self.rules = RuleBands::of(props, &env.tokens, crate::runtime::egui::scale::pixels_per_point(&ctx)); self.least_width = least_of(&env.tokens, props.least_width); let quiet = stage.is_peek() || crate::runtime::measure::active(&ctx); if !matches!(props.mount, Mount::Inline | Mount::Pane(_)) @@ -323,6 +324,7 @@ impl ShapeHooks for BodyHooks<'_> { self.region_gap = gap_of(&at.env.tokens, Gap::Tight); self.end_gap = gap_of(&at.env.tokens, props.end.map_or(Gap::Tight, |end| end.gap)); self.header_gap = header_gap_of(&props, &at.env.tokens); + self.rules = RuleBands::of(&props, &at.env.tokens, crate::runtime::egui::scale::pixels_per_point(at.ui.ctx())); self.least_width = least_of(&at.env.tokens, props.least_width); self.room = match at.width { Some(width) => Vec2::new(width, props.room_height.unwrap_or(f32::INFINITY)), @@ -997,12 +999,13 @@ impl ShapeHooks for BodyHooks<'_> { // the control. if props.footer.is_some() { let (mut footer_rect, offset) = self.place_footer(&props, &mut regions, inner, body_rect, rtl); - // The region's size counts the gap and the inset (they are part of what the footer took), so the content - // starts below the gap and stays the inset away from the sides and the foot. + // The region's size counts the rule's band, the gap and the inset (they are part of what the footer took), so + // the content starts below the band and the gap and stays the inset away from the sides and the foot. let lead = props.footer.and_then(|footer| footer.gap).map_or(0.0, |gap| gap_of(&env.tokens, gap)); let inset = props.footer.map_or(0.0, |footer| pad_of(&env.tokens, footer.inset)); - footer_rect.min.y += lead; - footer_rect.max.y = (footer_rect.max.y - inset).max(footer_rect.min.y); + let (rule_over, rule_under) = if footer_rule_under(&props) { (0.0, self.rules.footer) } else { (self.rules.footer, 0.0) }; + footer_rect.min.y += rule_over + lead; + footer_rect.max.y = (footer_rect.max.y - inset - rule_under).max(footer_rect.min.y); footer_rect.min.x += inset; footer_rect.max.x = (footer_rect.max.x - inset).max(footer_rect.min.x); let mut bcx = BodyCx::new(body_id, env_view, resolved, footer_rect, &mut *cx.core.memory, &mut open, gate.as_mut()) @@ -1021,6 +1024,7 @@ impl ShapeHooks for BodyHooks<'_> { if took.y > 0.0 { took.y += lead + inset; } + took.y += self.rules.footer; self.footer_size = Some(took); } self.open = open; @@ -1041,7 +1045,7 @@ impl ShapeHooks for BodyHooks<'_> { let radius = CornerRadius { sw: 0, se: 0, ..style.radius }; ui.painter().set(band_slot, Shape::rect_filled(regions.header, radius, band_color(&env.tokens, fill))); } - paint_rules(ui, &props, env, inner, ®ions); + paint_rules(ui, env, ®ions); paint_edge_rule(ui, &props, env, rect); } diff --git a/crates/ui-contract/src/contract/body/regions.rs b/crates/ui-contract/src/contract/body/regions.rs index fe0e9c345..daa9d2db2 100644 --- a/crates/ui-contract/src/contract/body/regions.rs +++ b/crates/ui-contract/src/contract/body/regions.rs @@ -49,6 +49,42 @@ pub fn pad_of(tokens: &UiTokens, pad: Pad) -> f32 { } } +/// The room the rules between a container's regions take, in points: the divider rule's width on the display for each +/// rule the container draws, none for one it doesn't. Each rule lies in a band of its own, so it shares no pixel with +/// a region's content at any scale. +#[derive(Clone, Copy, Debug, Default)] +pub(super) struct RuleBands { + /// Above a header with `HeaderRegion::rule_above`. + pub(super) above: f32, + /// Under a stacked header with `HeaderRegion::rule`, before its gap. + pub(super) under: f32, + /// Between a footer with `FooterRegion::rule` and the content beside it: over the footer, or under it in the end + /// region's top (`footer_rule_under`). + pub(super) footer: f32, + /// Between the body and an end region with `EndRegion::rule`, after the end gap. + pub(super) end: f32, +} + +impl RuleBands { + /// The bands of `props`' rules in `tokens` on a display of `pixels_per_point`. + pub(super) fn of(props: &ContainerProps, tokens: &UiTokens, pixels_per_point: f32) -> Self { + let width = rule_look(tokens, RuleKind::Divider).width.points(pixels_per_point); + let on = |rule: bool| if rule { width } else { 0.0 }; + RuleBands { + above: on(props.header.is_some_and(|header| header.rule_above)), + under: on(props.header.is_some_and(|header| header.rule && !header.inline)), + footer: on(props.footer.is_some_and(|footer| footer.rule)), + end: on(props.end.is_some_and(|end| end.rule)), + } + } +} + +/// Whether a ruled footer's rule lies under it: a footer at the top of the end region separates itself from the end +/// region's content below; every other footer from the content above it. +pub(super) fn footer_rule_under(props: &ContainerProps) -> bool { + props.footer.is_some_and(|footer| footer.place == FooterPlace::EndTop) && footer_in_end(props) +} + /// The space `props`' stacked header leaves before the body: its `HeaderRegion::gap`, none without one. pub(super) fn header_gap_of(props: &ContainerProps, tokens: &UiTokens) -> f32 { props.header.and_then(|header| header.gap).map_or(0.0, |gap| gap_of(tokens, gap)) @@ -95,6 +131,8 @@ pub(super) struct Regions { /// The width the body's line gives the regions beside the body: an inline header and the end region, with their /// gaps. pub(super) beside: f32, + /// The bands of the rules between the regions (`RuleBands`), each with the side its rule runs along. + pub(super) rules: [Option<(Rect, RectSide)>; 4], } /// The sizes of the header, footer and end region that the regions are placed from (zero or `None` for a region the @@ -150,35 +188,12 @@ pub(super) fn paint_edge_rule(ui: &mut Ui, props: &ContainerProps, env: &Env, re ui.painter().extend(Rule::edge(&rule, rect, side, ui.ctx().pixels_per_point())); } -/// The divider rules above and under the header, above the footer and beside the end region. -pub(super) fn paint_rules(ui: &mut Ui, props: &ContainerProps, env: &Env, inner: Rect, regions: &Regions) { +/// The divider rules above and under the header, beside the footer and beside the end region, each in its band. +pub(super) fn paint_rules(ui: &mut Ui, env: &Env, regions: &Regions) { let rule = rule_look(&env.tokens, RuleKind::Divider); let ppp = ui.ctx().pixels_per_point(); - let draw_rule = |from: f32, to: f32, y: f32| ui.painter().extend(Rule::shapes(&rule, Pos2::new(from, y), Pos2::new(to, y), ppp)); - if props.header.is_some_and(|header| header.rule_above) { - draw_rule(inner.min.x, inner.max.x, regions.header.min.y); - } - if props.header.is_some_and(|header| header.rule && !header.inline) { - draw_rule(inner.min.x, inner.max.x, regions.header.max.y); - } - // A footer across the container rules the whole width; one beside or in the end region rules its own. - match props.footer.filter(|footer| footer.rule) { - Some(footer) if footer.place == FooterPlace::EndTop && footer_in_end(props) => { - draw_rule(regions.footer.min.x, regions.footer.max.x, regions.footer.max.y); - } - Some(_) if end_full_height(props) => draw_rule(regions.footer.min.x, regions.footer.max.x, regions.footer.min.y), - Some(_) => draw_rule(inner.min.x, inner.max.x, regions.footer.min.y), - None => {} - } - // The end region's rule runs along its edge toward the body, beside a footer placed in it too. - if props.end.is_some_and(|end| end.rule) && regions.end.width() > 0.0 { - let (top, bottom) = if footer_in_end(props) { - (regions.end.min.y.min(regions.footer.min.y), regions.end.max.y.max(regions.footer.max.y)) - } else { - (regions.end.min.y, regions.end.max.y) - }; - let end = Rect::from_x_y_ranges(regions.end.x_range(), top..=bottom); - ui.painter().extend(Rule::edge(&rule, end, RectSide::start(env.direction.is_rtl()), ppp)); + for (band, side) in regions.rules.iter().flatten() { + ui.painter().extend(Rule::edge(&rule, *band, *side, ppp)); } } @@ -316,9 +331,10 @@ impl<'b> BodyHooks<'b> { bcx.close_requested() } - /// The space under a stacked header `header_h` high: `HeaderRegion::gap` while the body shows, scaled by its presence. + /// The space under a stacked header `header_h` high: the band of the rule under it, then `HeaderRegion::gap` while + /// the body shows, scaled by its presence. pub(super) fn header_space(&self, header_h: f32) -> f32 { - if header_h > 0.0 { self.header_gap * self.presence.t } else { 0.0 } + self.rules.under + if header_h > 0.0 { self.header_gap * self.presence.t } else { 0.0 } } /// The regions inside `inner` (the rect minus padding and the padding tier), placed from `sizes`. A header with a @@ -331,8 +347,9 @@ impl<'b> BodyHooks<'b> { // A footer in the end region takes no band across the container: it stacks with the end region's content. let across_h = if in_end { 0.0 } else { footer_h }; let end_h = sizes.end.map_or(0.0, |end| end.y) + if in_end { footer_h } else { 0.0 }; - // An inline header takes no height of its own: the line is as high as the taller of header and body. - let stacked_h = if inline { 0.0 } else { header_h + self.header_space(header_h) }; + // An inline header takes no height of its own: the line is as high as the taller of header and body. A rule + // above the header takes its band either way. + let stacked_h = self.rules.above + if inline { 0.0 } else { header_h + self.header_space(header_h) }; let top = inner.min.y + stacked_h; // Along an axis the container is not given, its body is offered the room the container was offered and the // container takes what the body took. @@ -372,7 +389,8 @@ impl<'b> BodyHooks<'b> { }; let (left, right) = if rtl { (inner.max.x - width, inner.max.x) } else { (inner.min.x, inner.min.x + width) }; let band = |top: f32, bottom: f32| Rect::from_min_max(Pos2::new(left, top), Pos2::new(right, bottom.max(top))); - let header = band(inner.min.y, if props.header.is_some() { inner.min.y + header_h.max(0.0) } else { inner.min.y }); + let header_top = inner.min.y + self.rules.above; + let header = band(header_top, if props.header.is_some() { header_top + header_h.max(0.0) } else { header_top }); let mut body = band(top, bottom); let header = if inline { // The header keeps the width it measured, none when it measured nothing; before its first measure it @@ -389,6 +407,9 @@ impl<'b> BodyHooks<'b> { } else { header }; + let across = |top: f32, width: f32| (width > 0.0).then(|| (Rect::from_x_y_ranges(inner.x_range(), top..=top + width), RectSide::Top)); + let above = across(inner.min.y, self.rules.above); + let under = if inline { None } else { across(header.max.y, self.rules.under) }; // The end region keeps the width it measured (with a footer in it, the wider of the two) and takes the end // edge; the body takes the rest. Before its first measure it spans the line and the body keeps its width. let measured = props.end.and(sizes.end).map(|end| { @@ -396,7 +417,7 @@ impl<'b> BodyHooks<'b> { end.x.max(footer_w).min(width) }); let taken = measured.unwrap_or(0.0); - let cut = if taken > 0.0 { taken + self.end_gap } else { 0.0 }; + let cut = if taken > 0.0 { taken + self.end_gap + self.rules.end } else { 0.0 }; let end_w = measured.unwrap_or(width); let end_bottom = if full { footer_top + across_h } else { footer_top }; let mut end = if rtl { @@ -429,7 +450,23 @@ impl<'b> BodyHooks<'b> { } else { header }; - Regions { header, body, end, footer, beside: width - body.width() } + let footer_rule = (self.rules.footer > 0.0).then(|| { + // A footer across the container rules the whole width; one beside or in the end region rules its own. + let x = if full { footer.x_range() } else { inner.x_range() }; + let w = self.rules.footer; + if footer_rule_under(props) { + (Rect::from_x_y_ranges(x, footer.max.y - w..=footer.max.y), RectSide::Bottom) + } else { + (Rect::from_x_y_ranges(x, footer.min.y..=footer.min.y + w), RectSide::Top) + } + }); + // The end region's rule runs along its edge toward the body, beside a footer placed in it too. + let end_rule = (self.rules.end > 0.0 && end.width() > 0.0).then(|| { + let (top, bottom) = if in_end { (end.min.y.min(footer.min.y), end.max.y.max(footer.max.y)) } else { (end.min.y, end.max.y) }; + let x = if rtl { end.max.x } else { end.min.x - self.rules.end }; + (Rect::from_x_y_ranges(x..=x + self.rules.end, top..=bottom), RectSide::end(rtl)) + }); + Regions { header, body, end, footer, beside: width - body.width(), rules: [above, under, footer_rule, end_rule] } } } diff --git a/crates/ui-contract/src/contract/body/size.rs b/crates/ui-contract/src/contract/body/size.rs index 7e5a4dd3f..fd2d460b9 100644 --- a/crates/ui-contract/src/contract/body/size.rs +++ b/crates/ui-contract/src/contract/body/size.rs @@ -186,15 +186,21 @@ impl<'b> BodyHooks<'b> { let end = if in_end { Vec2::new(end.x.max(footer.x), end.y + footer.y) } else { end }; let across = if in_end { Vec2::ZERO } else { footer }; let gap = |width: f32, gap: f32| if width > 0.0 { width + gap } else { 0.0 }; + let end_gap = self.end_gap + self.rules.end; let inline = props.header.is_some_and(|header| header.inline); // The line: the body with an inline header before it. let line = if inline { Vec2::new(body.x + gap(header.x, self.region_gap), body.y.max(header.y)) } else { body }; let (width, height) = if end_full_height(props) { - (line.x.max(across.x) + gap(end.x, self.end_gap), (line.y + across.y).max(end.y)) + (line.x.max(across.x) + gap(end.x, end_gap), (line.y + across.y).max(end.y)) } else { - ((line.x + gap(end.x, self.end_gap)).max(across.x), line.y.max(end.y) + across.y) + ((line.x + gap(end.x, end_gap)).max(across.x), line.y.max(end.y) + across.y) }; - if inline { Vec2::new(width, height) } else { Vec2::new(width.max(header.x), height + header.y + self.header_space(header.y)) } + let above = self.rules.above; + if inline { + Vec2::new(width, height + above) + } else { + Vec2::new(width.max(header.x), above + header.y + self.header_space(header.y) + height) + } } /// The width the regions ask for in a content-sized container: what they took together in this pass's measuring run. diff --git a/crates/ui-contract/src/contract/container.rs b/crates/ui-contract/src/contract/container.rs index 98bbf6528..020cabe8f 100644 --- a/crates/ui-contract/src/contract/container.rs +++ b/crates/ui-contract/src/contract/container.rs @@ -284,9 +284,10 @@ pub struct HeaderRegion { /// inline header's move band spans its whole line (header, body and end region), so every free point of the line /// moves the window or layer. pub band: DragBand, - /// Whether a rule separates the header from the body. An inline header has no rule. + /// Whether a rule separates the header from the body, in a band of its own between them. An inline header has no + /// rule. pub rule: bool, - /// Whether a rule runs across the container's width above the header, at its top edge. + /// Whether a rule runs across the container's width above the header, in a band of its own at the top edge. pub rule_above: bool, /// Whether the header shares a line with the body: the header at its measured width, the body in the rest. pub inline: bool, @@ -368,7 +369,8 @@ impl HeaderRegion { #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[non_exhaustive] pub struct FooterRegion { - /// Whether a rule separates the footer from the content beside it: the body, or the end region's content. + /// Whether a rule separates the footer from the content beside it (the body, or the end region's content), in a + /// band of its own. pub rule: bool, /// Where the footer sits. pub place: FooterPlace, @@ -450,7 +452,8 @@ pub struct EndRegion { pub full_height: bool, /// The gap between the body and the region. pub gap: Gap, - /// Whether a rule separates the end region from the body, along the region's edge that faces it. + /// Whether a rule separates the end region from the body, in a band of its own along the region's edge that + /// faces it. pub rule: bool, } diff --git a/crates/ui-contract/src/primitives/scroll_bar.rs b/crates/ui-contract/src/primitives/scroll_bar.rs index 487e8467e..0c6d8cef7 100644 --- a/crates/ui-contract/src/primitives/scroll_bar.rs +++ b/crates/ui-contract/src/primitives/scroll_bar.rs @@ -1,6 +1,6 @@ //! `ScrollBar`: the track and thumb of a scroll part, with state. -use super::rule::Rule; +use super::rule::{RectSide, Rule}; use crate::style::{ScrollBarKind, ScrollBarLook, StateSet}; use craft_behavior::{Axis, ScrollSpan}; use egui::{Color32, CornerRadius, Direction, Rect, Shape, Vec2, pos2}; @@ -91,8 +91,8 @@ impl ScrollBar { }; let mut shapes = vec![Shape::rect_filled(track, track_round, state.resolve(&look.track).egui())]; if let Some(edge) = &look.edge { - let (from, to) = if axis == Axis::X { (track.left_top(), track.right_top()) } else { (track.left_top(), track.left_bottom()) }; - shapes.extend(Rule::shapes(edge, from, to, pixels_per_point)); + let side = if axis == Axis::X { RectSide::Top } else { RectSide::Left }; + shapes.extend(Rule::edge(edge, track, side, pixels_per_point)); } shapes.push(Shape::rect_filled(thumb, round(thumb), state.resolve(&look.thumb).egui())); shapes diff --git a/crates/ui-contract/src/style/paint.rs b/crates/ui-contract/src/style/paint.rs index b2008f722..7edc7d7c3 100644 --- a/crates/ui-contract/src/style/paint.rs +++ b/crates/ui-contract/src/style/paint.rs @@ -55,11 +55,11 @@ impl RuleWidth { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum RuleKind { - /// A separator between neighbours. + /// A separator between neighbours: `line.divider`, `stroke.thin` wide. Divider, - /// The edge of a surface or region. + /// The edge of a surface or region: `line.border`, `stroke.thin` wide. Edge, - /// A grid line. + /// A grid line: `overlay.grid`, one physical pixel wide. Grid, /// The insertion mark of a drop. DropMark, @@ -67,11 +67,12 @@ pub enum RuleKind { pub(crate) fn rule_look(tokens: &UiTokens, kind: RuleKind) -> RuleLook { let c = &tokens.color; - let hairline = RuleWidth::Hairline; + let thin = RuleWidth::Points(tokens.stroke.thin); match kind { - RuleKind::Divider => RuleLook { color: color(c.line.divider), width: hairline }, - RuleKind::Edge => RuleLook { color: color(c.line.border), width: hairline }, - RuleKind::Grid => RuleLook { color: color(c.overlay.grid), width: hairline }, + RuleKind::Divider => RuleLook { color: color(c.line.divider), width: thin }, + RuleKind::Edge => RuleLook { color: color(c.line.border), width: thin }, + // A grid over the document stays finer than the chrome around it. + RuleKind::Grid => RuleLook { color: color(c.overlay.grid), width: RuleWidth::Hairline }, RuleKind::DropMark => RuleLook { color: color(c.accent.solid), width: RuleWidth::Points(tokens.stroke.thick) }, } } diff --git a/crates/ui-panels/src/docking/splitter.rs b/crates/ui-panels/src/docking/splitter.rs index 7bdc995b6..3f9ef1c07 100644 --- a/crates/ui-panels/src/docking/splitter.rs +++ b/crates/ui-panels/src/docking/splitter.rs @@ -6,7 +6,7 @@ use crate::style::{ComponentStyle, Stateful, StyleColor, StyleCx, resize_line_lo use craft_behavior::{Axis, Metrics, Sense}; use egui::{Response, Vec2}; -/// The style of a splitter: a hairline that becomes a thick accent line under the pointer. +/// The style of a splitter: a thin line that becomes a thick accent line under the pointer. #[derive(Clone, Debug, PartialEq, ComponentStyle)] #[non_exhaustive] pub struct SplitterStyle { @@ -16,7 +16,7 @@ pub struct SplitterStyle { /// The line of a column's inner edge: none at rest, as the column's frame already draws that edge, and the accent /// under the pointer. edge_line: Stateful, - /// The line's width: a hairline at rest, thick under the pointer. + /// The line's width: thin at rest, thick under the pointer. width: Stateful, } diff --git a/crates/ui-panels/src/sections/footer.rs b/crates/ui-panels/src/sections/footer.rs index 82939f022..552ae6184 100644 --- a/crates/ui-panels/src/sections/footer.rs +++ b/crates/ui-panels/src/sections/footer.rs @@ -7,7 +7,7 @@ use crate::contract::{ PaintUi, Pointer as _, PopupKind, Props as _, Role, RowAlign, Show as _, ShowContainer as _, Sizing, TooltipSpec, WordSetCx as _, }; use crate::layout_components::Row; -use crate::primitives::IconSpec; +use crate::primitives::{IconSpec, RectSide}; use crate::runtime::access::Name; use crate::runtime::env::{Env, EnvValue, Label}; use crate::runtime::focus; @@ -724,7 +724,7 @@ impl Component for FooterBar { fn paint(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) { if cx.style.rule { - ui.draw().rule(RuleKind::Divider, cx.rect.left_top(), cx.rect.right_top()); + ui.draw().edge_rule(RuleKind::Divider, cx.rect, RectSide::Top); } } diff --git a/crates/ui-shell/src/shell/title_bar/bar.rs b/crates/ui-shell/src/shell/title_bar/bar.rs index e9d88828e..b5a54f490 100644 --- a/crates/ui-shell/src/shell/title_bar/bar.rs +++ b/crates/ui-shell/src/shell/title_bar/bar.rs @@ -78,7 +78,7 @@ pub struct TitleBar<'a> { /// Whether a bar in a native frame shows the title. #[prop(flag)] title_when_native: bool, - /// A hairline along the bar's bottom edge, for a bar whose window draws no edge under it. + /// A divider rule along the bar's bottom edge, for a bar whose window draws no edge under it. #[prop(flag)] separator: bool, /// Glyphs from the desktop's icon theme for the round caption families. diff --git a/crates/ui-shell/src/shell/title_bar/style.rs b/crates/ui-shell/src/shell/title_bar/style.rs index 11f6af586..4e7289bc9 100644 --- a/crates/ui-shell/src/shell/title_bar/style.rs +++ b/crates/ui-shell/src/shell/title_bar/style.rs @@ -1,6 +1,6 @@ //! The style of the title bar. //! -//! The bar paints a chrome surface and a hairline along its bottom edge; its height is its slot's +//! The bar paints a chrome surface and a divider rule along its bottom edge; its height is its slot's //! ([`SlotSize::TitleBar`](crate::shell::SlotSize), `size.bar.title`), the caption buttons carry their own //! family metrics and colours (`caption.*`), and the title is a `Text`. Nothing else of the legacy bar style has a //! token: the corner size belongs to the window's grips, the gaps to the body's row gap. diff --git a/crates/ui-shell/tests/it/body/regions.rs b/crates/ui-shell/tests/it/body/regions.rs index 268a4505e..ba29968a2 100644 --- a/crates/ui-shell/tests/it/body/regions.rs +++ b/crates/ui-shell/tests/it/body/regions.rs @@ -295,3 +295,68 @@ fn an_end_region_with_a_rule_has_a_line_along_its_edge_toward_the_body() { }; assert!(edge_lines(true) > edge_lines(false), "the rule draws a line along the end region's edge toward the body"); } + +/// The rules between the regions (above and under the header, over the footer, before the end region) each take a +/// band of their own: no rule shares a pixel with the header's, body's, footer's or end region's content, at 1x or 2x, +/// and a rule is as wide in points at 2x as at 1x. +#[trial] +fn region_rules_take_their_own_band_at_every_scale() { + use craft_ui::contract::EndRegion; + use egui::Shape; + let rules_at = |pixels_per_point: f32| { + let props = ContainerProps::new() + .sizing(Sizing::Fill) + .header(HeaderRegion::new().rule(true).rule_above(true)) + .footer(FooterRegion::new().rule(true)) + .end(EndRegion::new().full_height(true).rule(true)); + let took = RefCell::new(Took::default()); + let mut frames = Frames::new(); + frames.pixels_per_point(pixels_per_point); + let mut show = |ui: &mut Ui| { + let shown = Regioned { + common: Common::new(), + props: props.clone(), + header: Some(Vec2::new(100.0, 20.0)), + end: Vec2::new(80.0, 40.0), + footer: Vec2::new(70.0, 16.0), + rows: 1, + took: &took, + } + .show_at(ui, AREA, |_, cx| cx.rect); + took.borrow_mut().body = shown.inner; + }; + frames.idle(2, &mut show); + let shapes = frames.frame_shapes(&mut show); + // Each rule's band: the segment's run, as wide across it as its stroke. + let bands: Vec<(Rect, f32)> = shapes + .iter() + .filter_map(|shape| match shape { + Shape::LineSegment { points: [a, b], stroke } => { + let half = stroke.width / 2.0; + let run = Rect::from_two_pos(*a, *b); + let across = if (a.y - b.y).abs() <= (a.x - b.x).abs() { Vec2::new(0.0, half) } else { Vec2::new(half, 0.0) }; + Some((run.expand2(across), stroke.width)) + } + _ => None, + }) + .collect(); + let took = *took.borrow(); + let regions = [("header", took.header), ("body", took.body), ("footer", took.footer), ("end", took.end)]; + for (band, _) in &bands { + for (name, region) in regions { + let region = region.unwrap_or_else(|| panic!("the {name} ran")); + let shared = band.intersect(region); + assert!( + shared.width() <= 1e-3 || shared.height() <= 1e-3, + "at {pixels_per_point}x a rule {band:?} lies over the {name}'s content {region:?}" + ); + } + } + bands + }; + let (one, two) = (rules_at(1.0), rules_at(2.0)); + assert!(one.len() >= 4 && two.len() == one.len(), "the four rules draw at both scales: {} and {}", one.len(), two.len()); + for ((_, at_one), (_, at_two)) in one.iter().zip(&two) { + assert!((at_one - at_two).abs() < 1e-3, "a rule is {at_one} pt wide at 1x and {at_two} pt at 2x"); + } +} diff --git a/crates/ui-widgets/src/buttons/split_button.rs b/crates/ui-widgets/src/buttons/split_button.rs index 9a182b5e6..bf8fdd083 100644 --- a/crates/ui-widgets/src/buttons/split_button.rs +++ b/crates/ui-widgets/src/buttons/split_button.rs @@ -6,7 +6,7 @@ use crate::contract::{ ShowContainer as _, Styled as _, WordSetCx as _, }; use crate::menu::{self, Menu}; -use crate::primitives::{IconSpec, PaintShape}; +use crate::primitives::{IconSpec, PaintShape, RuleKind}; use crate::runtime::env::Label; use crate::style::{ComponentStyle, Corners, FocusLook, IconLook, RuleLook, RuleWidth, Stateful, StyleColor, StyleCx, SurfaceLook, TextLook}; use craft_behavior::{Flow, HitLevel, HitPriority, Metrics, NavMove, PartKey, Sense, Value}; @@ -43,6 +43,7 @@ pub struct SplitButtonStyle { chevron: Stateful, /// The line between the parts, in the variant's edge colour. divider: Stateful, + /// The divider rule's width. divider_width: RuleWidth, /// The divider's gap from the top and bottom edges. divider_inset: f32, @@ -130,7 +131,7 @@ impl Component for SplitButton<'_, T> { part_fill: Stateful::new(clear).off(States::new(clear, fill.hover, fill.pressed, clear)), chevron, divider, - divider_width: RuleWidth::Points(cx.tokens.stroke.thin), + divider_width: cx.rule(RuleKind::Divider).width, divider_inset: cx.tokens.space.gap.inline, radius: parts.radius, } diff --git a/crates/ui-widgets/src/display/divider.rs b/crates/ui-widgets/src/display/divider.rs index a99eebac8..c373f0506 100644 --- a/crates/ui-widgets/src/display/divider.rs +++ b/crates/ui-widgets/src/display/divider.rs @@ -1,4 +1,4 @@ -//! `Divider`: a separator line one physical pixel wide, horizontal or vertical. +//! `Divider`: a separator line as wide as a divider rule, horizontal or vertical. use crate::contract::{Common, Component, Cx, InBar, InMenu, MeasureCx, PaintUi, Role}; use crate::primitives::RuleKind; use crate::style::{ComponentStyle, RuleWidth, StyleCx}; diff --git a/crates/ui-widgets/src/list/row.rs b/crates/ui-widgets/src/list/row.rs index c52467323..491a37ebb 100644 --- a/crates/ui-widgets/src/list/row.rs +++ b/crates/ui-widgets/src/list/row.rs @@ -156,7 +156,7 @@ pub struct ListRow<'a> { /// or thumbnail. #[prop] pub(super) clipped: bool, - /// A hairline along the row's bottom edge, in a plain row too. + /// A divider rule along the row's bottom edge, in a plain row too. #[prop] pub(super) rule: bool, /// The rename editor replaces the label; `state` sets it from the collection's row state. diff --git a/crates/ui-widgets/src/list/row/show.rs b/crates/ui-widgets/src/list/row/show.rs index edf6fa3b2..b94388a02 100644 --- a/crates/ui-widgets/src/list/row/show.rs +++ b/crates/ui-widgets/src/list/row/show.rs @@ -500,8 +500,10 @@ impl Component for ListRow<'_> { draw.edge_rule(RuleKind::Divider, rect, RectSide::Bottom); } if self.layer && style.dividers { - for x in &placed.dividers { - draw.rule(RuleKind::Divider, Pos2::new(*x, rect.top()), Pos2::new(*x, rect.bottom())); + // Each toggle cell's rule lies just past the cell, where a cell's fill never covers it. + for &x in &placed.dividers { + let after = if rtl { rect.left()..=x } else { x..=rect.right() }; + draw.edge_rule(RuleKind::Divider, Rect::from_x_y_ranges(after, rect.y_range()), RectSide::start(rtl)); } } } diff --git a/crates/ui-widgets/src/tile_grid/grid.rs b/crates/ui-widgets/src/tile_grid/grid.rs index 55824045c..d860697b8 100644 --- a/crates/ui-widgets/src/tile_grid/grid.rs +++ b/crates/ui-widgets/src/tile_grid/grid.rs @@ -682,7 +682,7 @@ impl Component for TileGrid<'_, K> for &(at, rect) in &self.placed_tail { let row = &self.tail[at]; if at == 0 { - ui.draw().rule(RuleKind::Divider, rect.left_top(), rect.right_top()); + ui.draw().edge_rule(RuleKind::Divider, rect, RectSide::Top); } let state = RowState { emphasized: lead == Some(Slot::Tail(at)), ..RowState::default() }; ui.face(section_part(&row.key), ListRow::new(row.label.clone()).node(false).state(state));