Skip to content

Commit

Permalink
Add an accent color and use it for progress bars, plots, and histograms
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-edmondson committed Aug 23, 2024
1 parent 82785b6 commit fcd3f99
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
7 changes: 7 additions & 0 deletions ImGuiStyler/Color.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ public static ImColor MultiplySaturation(this ImColor color, float amount)
return FromHSLA(hsla);
}

public static ImColor OffsetHue(this ImColor color, float amount)
{
var hsla = color.ToHSLA();
hsla.X = (1f + (hsla.X + amount)) % 1f;
return FromHSLA(hsla);
}

public static ImColor LightenBy(this ImColor color, float amount)
{
var hsla = color.ToHSLA();
Expand Down
17 changes: 13 additions & 4 deletions ImGuiStyler/Theme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ public static class Theme
{
private static float NormalLuminanceMult { get; set; } = 0.4f;
private static float NormalSaturationMult { get; set; } = 0.5f;
private static float AccentLuminanceMult { get; set; } = 0.7f;
private static float AccentSaturationMult { get; set; } = 0.8f;
private static float AccentHoveredLuminanceMult { get; set; } = 1.0f;
private static float AccentHoveredSaturationMult { get; set; } = 0.9f;
private static float AccentHueOffset { get; set; } = 0.5f;
private static float HeaderLuminanceMult { get; set; } = 0.5f;
private static float HeaderSaturationMult { get; set; } = 0.6f;
private static float ActiveLuminanceMult { get; set; } = .6f;
Expand All @@ -22,6 +27,8 @@ public static class Theme

public static ImColor GetStateColor(ImColor baseColor, bool enabled) => enabled ? baseColor : baseColor.MultiplySaturation(DisabledSaturationMult);
public static ImColor GetNormalColor(ImColor stateColor) => stateColor.MultiplyLuminance(NormalLuminanceMult).MultiplySaturation(NormalSaturationMult);
public static ImColor GetAccentColor(ImColor stateColor) => stateColor.MultiplyLuminance(AccentLuminanceMult).MultiplySaturation(AccentSaturationMult).OffsetHue(AccentHueOffset).WithAlpha(1);
public static ImColor GetAccentHoveredColor(ImColor stateColor) => stateColor.MultiplyLuminance(AccentHoveredLuminanceMult).MultiplySaturation(AccentHoveredSaturationMult).OffsetHue(AccentHueOffset).WithAlpha(1);
public static ImColor GetHeaderColor(ImColor stateColor) => stateColor.MultiplyLuminance(HeaderLuminanceMult).MultiplySaturation(HeaderSaturationMult);
public static ImColor GetActiveColor(ImColor stateColor) => stateColor.MultiplyLuminance(ActiveLuminanceMult).MultiplySaturation(ActiveSaturationMult);
public static ImColor GetHoveredColor(ImColor stateColor) => stateColor.MultiplyLuminance(HoverLuminanceMult).MultiplySaturation(HoverSaturationMult);
Expand Down Expand Up @@ -62,6 +69,8 @@ public static class Palette
public static void Apply(ImColor baseColor)
{
var normalColor = GetNormalColor(baseColor);
var accentColor = GetAccentColor(baseColor);
var accentHoveredColor = GetAccentHoveredColor(baseColor);
var headerColor = GetHeaderColor(baseColor);
var hoveredColor = GetHoveredColor(baseColor);
var activeColor = GetActiveColor(baseColor);
Expand Down Expand Up @@ -101,10 +110,10 @@ public static void Apply(ImColor baseColor)
colors[(int)ImGuiCol.ResizeGrip] = normalColor.Value;
colors[(int)ImGuiCol.ResizeGripActive] = activeColor.Value;
colors[(int)ImGuiCol.ResizeGripHovered] = hoveredColor.Value;
colors[(int)ImGuiCol.PlotLines] = normalColor.Value;
colors[(int)ImGuiCol.PlotLinesHovered] = hoveredColor.Value;
colors[(int)ImGuiCol.PlotHistogram] = normalColor.Value;
colors[(int)ImGuiCol.PlotHistogramHovered] = hoveredColor.Value;
colors[(int)ImGuiCol.PlotLines] = accentColor.Value;
colors[(int)ImGuiCol.PlotLinesHovered] = accentHoveredColor.Value;
colors[(int)ImGuiCol.PlotHistogram] = accentColor.Value;
colors[(int)ImGuiCol.PlotHistogramHovered] = accentHoveredColor.Value;
colors[(int)ImGuiCol.ScrollbarGrab] = normalColor.WithSaturation(0).Value;
colors[(int)ImGuiCol.ScrollbarGrabActive] = activeColor.WithSaturation(0).Value;
colors[(int)ImGuiCol.ScrollbarGrabHovered] = hoveredColor.WithSaturation(0).Value;
Expand Down
1 change: 1 addition & 0 deletions ImGuiStylerDemo/ImGuiStylerDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ private void OnTick(float dt)
ImGui.InputText("InputText", ref valueString, 128);
float valueFloat = 0.0f;
ImGui.SliderFloat("SliderFloat", ref valueFloat, 0.0f, 1.0f);
ImGui.ProgressBar(0.95f, new(300, 0));
ImGui.Text("Text");
ImGui.TextColored(new System.Numerics.Vector4(1.0f, 0.0f, 0.0f, 1.0f), "TextColored");
ImGui.TextDisabled("TextDisabled");
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0-alpha.6
1.0.0-alpha.7

0 comments on commit fcd3f99

Please sign in to comment.