refactor(editor): hoist relative-alpha + over helpers into util

6 git_panel modules each duplicated fn alpha (RELATIVE: multiplies c.a*factor) and git_panel_empty duplicated over(). Hoisted to util::alpha / util::over (single source); locals now delegate. NOTE: align_toolbar::alpha SETS absolute alpha (Color{a,..}) — a different op (= Color::with_alpha), deliberately left separate. Part of atomic-sink Phase 0.4.
This commit is contained in:
Kayshen-X 2026-06-20 00:11:58 +08:00
parent f5c1ef555f
commit eb02c293d2
7 changed files with 30 additions and 31 deletions

View file

@ -82,6 +82,29 @@ pub fn color_to_hex_with_alpha(c: Color) -> String {
}
}
/// A colour at `factor` of its current alpha — the Rust analogue of a Tailwind
/// `/NN` opacity modifier (e.g. `bg-muted/60`). RELATIVE: it MULTIPLIES the
/// existing alpha. For an absolute set, use `Color::with_alpha` instead.
pub fn alpha(c: Color, factor: f32) -> Color {
Color {
a: c.a * factor,
..c
}
}
/// `top` (a translucent colour) composited over the opaque `base`, yielding an
/// opaque colour — so a `bg-accent/30`-over-`bg-card` hover fill paints in a
/// single pass.
pub fn over(base: Color, top: Color) -> Color {
let a = top.a;
Color {
r: base.r * (1.0 - a) + top.r * a,
g: base.g * (1.0 - a) + top.g * a,
b: base.b * (1.0 - a) + top.b * a,
a: base.a,
}
}
/// Format a numeric property value for a panel input: drop a trailing `.0`
/// for whole numbers, otherwise show two decimals.
pub fn format_panel_number(value: f32) -> String {

View file

@ -245,8 +245,5 @@ impl GitPanel<'_> {
/// A colour at `factor` of its current alpha (Tailwind `/NN`).
fn alpha(c: Color, factor: f32) -> Color {
Color {
a: c.a * factor,
..c
}
crate::util::alpha(c, factor)
}

View file

@ -347,21 +347,12 @@ impl GitPanel<'_> {
/// A colour at `factor` of its current alpha — the Rust analogue of a
/// Tailwind `/NN` opacity modifier (e.g. `bg-muted/60`).
fn alpha(c: Color, factor: f32) -> Color {
Color {
a: c.a * factor,
..c
}
crate::util::alpha(c, factor)
}
/// `top` (a translucent colour) composited over the opaque `base`,
/// yielding an opaque colour — so a `bg-accent/30`-over-`bg-card` hover
/// fill paints in a single pass.
fn over(base: Color, top: Color) -> Color {
let a = top.a;
Color {
r: base.r * (1.0 - a) + top.r * a,
g: base.g * (1.0 - a) + top.g * a,
b: base.b * (1.0 - a) + top.b * a,
a: base.a,
}
crate::util::over(base, top)
}

View file

@ -898,10 +898,7 @@ impl GitPanel<'_> {
/// A colour at `factor` of its current alpha (Tailwind `/NN`).
fn alpha(c: Color, factor: f32) -> Color {
Color {
a: c.a * factor,
..c
}
crate::util::alpha(c, factor)
}
/// Rough rendered width of a 12px label without a backend — CJK glyphs

View file

@ -963,10 +963,7 @@ impl GitPanel<'_> {
/// A colour at `factor` of its current alpha (Tailwind `/NN`).
fn alpha(c: Color, factor: f32) -> Color {
Color {
a: c.a * factor,
..c
}
crate::util::alpha(c, factor)
}
/// The first whitespace-delimited token of an author name — TS

View file

@ -174,8 +174,5 @@ impl GitPanel<'_> {
/// A colour at `factor` of its current alpha (Tailwind `/NN`).
fn alpha(c: Color, factor: f32) -> Color {
Color {
a: c.a * factor,
..c
}
crate::util::alpha(c, factor)
}

View file

@ -385,8 +385,5 @@ fn popup_anchor(popup: Rect) -> Rect {
/// A colour at `factor` of its current alpha (Tailwind `/NN`).
fn alpha(c: Color, factor: f32) -> Color {
Color {
a: c.a * factor,
..c
}
crate::util::alpha(c, factor)
}