From 7b09ce31c3b6783ecd8dbf2376954dd510207e2b Mon Sep 17 00:00:00 2001 From: Tommi Kabelitz Date: Tue, 18 Nov 2025 11:37:18 +1030 Subject: [PATCH 1/3] Add ability to change tick label color and size for each axis --- egui_plot/src/axis.rs | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/egui_plot/src/axis.rs b/egui_plot/src/axis.rs index 090ea4ef..90ab55a8 100644 --- a/egui_plot/src/axis.rs +++ b/egui_plot/src/axis.rs @@ -107,6 +107,8 @@ pub struct AxisHints<'a> { pub(super) min_thickness: f32, pub(super) placement: Placement, pub(super) label_spacing: Rangef, + pub(super) tick_label_color: Option, + pub(super) tick_label_font: Option, } impl<'a> AxisHints<'a> { @@ -134,6 +136,8 @@ impl<'a> AxisHints<'a> { Axis::X => Rangef::new(60.0, 80.0), // labels can get pretty wide Axis::Y => Rangef::new(20.0, 30.0), // text isn't very high }, + tick_label_color: None, + tick_label_font: None, } } @@ -200,6 +204,27 @@ impl<'a> AxisHints<'a> { self.label_spacing = range.into(); self } + + /// Set the color of the axis tick labels. + /// + /// As labels get close, they will fade in color until they become invisible. See + /// [`Self::label_spacing`]. + /// + /// To change the font of the tick labels see [`Self::tick_label_font`]. + #[inline] + pub fn tick_label_color(mut self, color: egui::Color32) -> Self { + self.tick_label_color = Some(color); + self + } + + /// Set the font of the axis tick labels. + /// + /// To change the color of the tick labels see [`Self::tick_label_color`]. + #[inline] + pub fn tick_label_font(mut self, font: egui::FontId) -> Self { + self.tick_label_font = Some(font); + self + } } #[derive(Clone)] @@ -319,8 +344,19 @@ impl<'a> AxisWidget<'a> { // Fade in labels as they get further apart: let strength = remap_clamp(spacing_in_points, label_spacing, 0.0..=1.0); - let text_color = super::color_from_strength(ui, strength); - let galley = painter.layout_no_wrap(text, font_id.clone(), text_color); + let text_color = if let Some(color) = self.hints.tick_label_color { + color.gamma_multiply(strength.sqrt()) + } else { + super::color_from_strength(ui, strength) + }; + + let label_font_id = self + .hints + .tick_label_font + .clone() + .unwrap_or(font_id.clone()); + + let galley = painter.layout_no_wrap(text, label_font_id, text_color); let galley_size = match axis { Axis::X => galley.size(), Axis::Y => galley.size() + 2.0 * SIDE_MARGIN * Vec2::X, From c2901396568af8d275294e8f5a590da552ed8f00 Mon Sep 17 00:00:00 2001 From: Tommi Kabelitz Date: Thu, 20 Nov 2025 09:41:55 +1030 Subject: [PATCH 2/3] change AxisHints::tick_label_color to take an into rather than a Color32 --- egui_plot/src/axis.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/egui_plot/src/axis.rs b/egui_plot/src/axis.rs index 90ab55a8..73db8996 100644 --- a/egui_plot/src/axis.rs +++ b/egui_plot/src/axis.rs @@ -212,8 +212,8 @@ impl<'a> AxisHints<'a> { /// /// To change the font of the tick labels see [`Self::tick_label_font`]. #[inline] - pub fn tick_label_color(mut self, color: egui::Color32) -> Self { - self.tick_label_color = Some(color); + pub fn tick_label_color(mut self, color: impl Into) -> Self { + self.tick_label_color = Some(color.into()); self } From 7d0ff18420b75d8c6bdf04d35011a996b7e91981 Mon Sep 17 00:00:00 2001 From: Tommi Kabelitz Date: Mon, 24 Nov 2025 13:28:45 +1030 Subject: [PATCH 3/3] import Color32 and FontId directly, clean up method docs --- egui_plot/src/axis.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/egui_plot/src/axis.rs b/egui_plot/src/axis.rs index 73db8996..ef59072f 100644 --- a/egui_plot/src/axis.rs +++ b/egui_plot/src/axis.rs @@ -1,7 +1,8 @@ use std::{fmt::Debug, ops::RangeInclusive, sync::Arc}; use egui::{ - Pos2, Rangef, Rect, Response, Sense, TextStyle, TextWrapMode, Ui, Vec2, WidgetText, + Color32, FontId, Pos2, Rangef, Rect, Response, Sense, TextStyle, TextWrapMode, Ui, Vec2, + WidgetText, emath::{Rot2, remap_clamp}, epaint::TextShape, }; @@ -107,8 +108,8 @@ pub struct AxisHints<'a> { pub(super) min_thickness: f32, pub(super) placement: Placement, pub(super) label_spacing: Rangef, - pub(super) tick_label_color: Option, - pub(super) tick_label_font: Option, + pub(super) tick_label_color: Option, + pub(super) tick_label_font: Option, } impl<'a> AxisHints<'a> { @@ -206,22 +207,15 @@ impl<'a> AxisHints<'a> { } /// Set the color of the axis tick labels. - /// - /// As labels get close, they will fade in color until they become invisible. See - /// [`Self::label_spacing`]. - /// - /// To change the font of the tick labels see [`Self::tick_label_font`]. #[inline] - pub fn tick_label_color(mut self, color: impl Into) -> Self { + pub fn tick_label_color(mut self, color: impl Into) -> Self { self.tick_label_color = Some(color.into()); self } /// Set the font of the axis tick labels. - /// - /// To change the color of the tick labels see [`Self::tick_label_color`]. #[inline] - pub fn tick_label_font(mut self, font: egui::FontId) -> Self { + pub fn tick_label_font(mut self, font: FontId) -> Self { self.tick_label_font = Some(font); self }