Skip to content

Add grid_color and grid_fade API#235

Merged
emilk merged 2 commits intoemilk:mainfrom
gavrelina:katya/grid-color-api
Mar 17, 2026
Merged

Add grid_color and grid_fade API#235
emilk merged 2 commits intoemilk:mainfrom
gavrelina:katya/grid-color-api

Conversation

@gavrelina
Copy link
Contributor

Summary

  • grid_color(Color32) — sets the base color for grid lines independently of text_color(), while preserving the strength-based fading.
  • grid_fade(f32) — controls the contrast between dense and sparse grid lines. 0.0 = uniform (all lines same opacity), 0.5 = default (sqrt), 1.0 = maximum fade. The zoom-based density logic is always preserved.

Motivation

When embedding egui_plot in an application with its own design system, the grid color needs to be independent of text color. The current behavior derives grid color from ui.visuals().text_color(), which couples grid styling to text styling.

Similarly, the strength curve (hardcoded sqrt) may not suit all visual designs — some applications want less contrast between grid levels, or uniform grid lines.

Changes

Single file change in plot.rs:

  • Added grid_color: Option<Color32> field with .grid_color() builder method
  • Added grid_strength_exponent: f32 field (default 0.5) with .grid_fade() builder method
  • paint_grid_direction uses the custom base color and exponent when set, falls back to existing behavior otherwise

@github-actions
Copy link

View snapshot changes at kitdiff

@emilk emilk added enhancement New feature or request include in changelog This change will be included in the changelog labels Mar 17, 2026
@emilk emilk changed the title Add grid_color and grid_fade API Add grid_color and grid_fade API Mar 17, 2026
@emilk emilk merged commit 965ea9c into emilk:main Mar 17, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request include in changelog This change will be included in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants