Hand-stroked dividers and edges use the rule painter

The split button's divider, the timeline track header's divider and the table
outline and grid header edges paint through Draw::rule and Draw::rule_with, the
one pixel-snapped line, instead of their own strokes.
This commit is contained in:
aiongg
2026-11-12 14:32:41 +00:00
parent a53d901967
commit 5d8b0a94de
7 changed files with 27 additions and 41 deletions
+2 -2
View File
@@ -118,8 +118,8 @@ pub struct CellGridStyle {
pub(crate) background: StyleColor,
pub(crate) header: Stateful<StyleColor>,
pub(crate) header_text: Stateful<StyleColor>,
pub(crate) gridline: StyleColor,
pub(crate) header_line: StyleColor,
/// The line along the frozen panes' edge.
pub(crate) freeze_line: StyleColor,
pub(crate) accent: StyleColor,
pub(crate) preview: StyleColor,
pub(crate) selection: StyleColor,
+5 -6
View File
@@ -3,7 +3,7 @@
use craft_behavior::{CursorIcon, HitLevel, HitPriority, Metrics, PartKey, ScrollPos, Sense, TextPos};
use craft_ui::contract::{Access, Cx, Focus as _, Name, PaintUi, PartsCx, Remember as _, Role, Styled as _};
use craft_ui::primitives::{Dashes, Draw, EditorLine, EditorPurpose, EditorRun, EditorState, HAlign, PaintShape, StrokeWidth, TextRun};
use craft_ui::primitives::{Dashes, Draw, EditorLine, EditorPurpose, EditorRun, EditorState, HAlign, PaintShape, RuleKind, StrokeWidth, TextRun};
use craft_ui::runtime::env::Label;
use craft_ui::runtime::motion::Animate as _;
use craft_ui::style::{Flags, Stateful, StyleCx, TypeRole};
@@ -51,8 +51,7 @@ pub(super) fn style(cx: &StyleCx<'_>, key: CellGridStyleKey) -> CellGridStyle {
background: cx.color(c.surface.background),
header: Stateful::new(cx.color(c.surface.chrome)).when(Flags::SELECTED, cx.color(c.state.selected)),
header_text: Stateful::new(cx.color(c.text.muted)).when(Flags::SELECTED, cx.color(c.text.on_selected)),
gridline: cx.color(c.line.divider),
header_line: cx.color(c.line.border),
freeze_line: cx.color(c.line.border),
accent: cx.color(c.accent.solid),
preview: cx.color(c.text.muted),
selection: cx.color(c.state.text_selection),
@@ -297,13 +296,13 @@ impl CellGrid<'_> {
let (cells, split) = (geometry.cells(), geometry.split());
if frozen_columns > 0 {
let x = geometry.mirror_x(split.x);
draw.stroke(&PaintShape::Path(vec![Pos2::new(x, cells.top()), Pos2::new(x, cells.bottom())]), StrokeWidth::Medium, style.header_line);
draw.stroke(&PaintShape::Path(vec![Pos2::new(x, cells.top()), Pos2::new(x, cells.bottom())]), StrokeWidth::Medium, style.freeze_line);
}
if frozen_rows > 0 {
draw.stroke(
&PaintShape::Path(vec![Pos2::new(cells.left(), split.y), Pos2::new(cells.right(), split.y)]),
StrokeWidth::Medium,
style.header_line,
style.freeze_line,
);
}
if self.headings {
@@ -334,7 +333,7 @@ impl CellGrid<'_> {
}
let marks = Marks::of(selection, geometry.rows().count(), geometry.columns().count());
let rtl = geometry.mirror_x(0.0) > 0.0;
let line = |from: Pos2, to: Pos2| draw.stroke(&PaintShape::Path(vec![from, to]), StrokeWidth::Hairline, style.header_line);
let line = |from: Pos2, to: Pos2| draw.rule(RuleKind::Edge, from, to);
let look = |part: craft_behavior::PartRef| (cx.resolve_part(part, &style.header), cx.resolve_part(part, &style.header_text));
for &column in &frame.columns {
let at = Self::column_header(geometry, column);
+5 -5
View File
@@ -5,7 +5,7 @@ use craft_theme::{Stateful, TypeRole};
use craft_ui::contract::{
Access, Common, Component, Cx, MeasureCx, Name, NoValue, Outcome, PaintUi, PartsCx, Props as _, Role, Styled as _, WordSetCx as _,
};
use craft_ui::primitives::{PaintShape, StrokeWidth, TextRun};
use craft_ui::primitives::{PaintShape, RuleKind, StrokeWidth, TextRun};
use craft_ui::runtime::env::Label;
use craft_ui::style::{ComponentStyle, FocusLook, StyleColor, StyleCx, TextLook};
use egui::{CornerRadius, Pos2, Rect, Response, Vec2, pos2, vec2};
@@ -180,7 +180,6 @@ pub struct OutlineBandStyle {
hit: f32,
radius: CornerRadius,
background: StyleColor,
edge: StyleColor,
button: StyleColor,
ink: StyleColor,
}
@@ -274,7 +273,6 @@ impl Component for OutlineBand<'_> {
hit: size.hit.slop,
radius: CornerRadius::same(tokens.shape.radius.sm.round() as u8),
background: cx.color(colors.surface.background),
edge: cx.color(colors.line.border),
button: cx.color(colors.surface.chrome),
ink,
}
@@ -345,13 +343,15 @@ impl Component for OutlineBand<'_> {
draw.fill(&PaintShape::Rect(geometry.mirror_rect(band), CornerRadius::ZERO), style.background);
}
}
let half = draw.rule_width(RuleKind::Edge) / 2.0;
let edge = |a: Pos2, b: Pos2| draw.rule(RuleKind::Edge, geometry.mirror_pos(a), geometry.mirror_pos(b));
if frame.row_band.width() > 0.0 {
let band = frame.row_band;
draw.stroke(&line(pos2(band.right(), band.top()), pos2(band.right(), band.bottom())), StrokeWidth::Hairline, style.edge);
edge(pos2(band.right() - half, band.top()), pos2(band.right() - half, band.bottom()));
}
if frame.column_band.height() > 0.0 {
let band = frame.column_band;
draw.stroke(&line(pos2(band.left(), band.bottom()), pos2(band.right(), band.bottom())), StrokeWidth::Hairline, style.edge);
edge(pos2(band.left(), band.bottom() - half), pos2(band.right(), band.bottom() - half));
}
for bracket in &self.laid.brackets {
draw.stroke(&line(bracket.line[0], bracket.line[1]), StrokeWidth::Thin, style.ink);