Skip to content

refactor(UI): button helper functions#2228

Merged
alandtse merged 5 commits into
community-shaders:devfrom
SkrubbySkrubInAShrub:centralize-and-reuse-error-button
Apr 29, 2026
Merged

refactor(UI): button helper functions#2228
alandtse merged 5 commits into
community-shaders:devfrom
SkrubbySkrubInAShrub:centralize-and-reuse-error-button

Conversation

@SkrubbySkrubInAShrub
Copy link
Copy Markdown
Collaborator

@SkrubbySkrubInAShrub SkrubbySkrubInAShrub commented Apr 28, 2026

closes: #1879

Summary by CodeRabbit

  • Refactor

    • Unified button styling to use theme-driven status colors with improved hover/active visuals for more consistent UI appearance.
    • Replaced ad-hoc button color handling with semantic action buttons (success, warning, destructive) across the app for clearer affordances.
  • New Features

    • Destructive actions now use dedicated styled icon/text controls and include brief flash feedback on activation.
    • New theme parameters fine-tune button color clamping and status-text alpha for better contrast.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: dbe41c4f-9412-433c-9a43-7f245f96e545

📥 Commits

Reviewing files that changed from the base of the PR and between d73b43e and d9a7293.

📒 Files selected for processing (3)
  • src/Menu/ThemeManager.h
  • src/Utils/UI.cpp
  • src/Utils/UI.h
✅ Files skipped from review due to trivial changes (1)
  • src/Menu/ThemeManager.h
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Utils/UI.cpp

📝 Walkthrough

Walkthrough

Refactors and expands the UI button styling API: removes ErrorButtonStyle() and adds generic status/destructive/text style factories plus convenience button helpers; updates call sites to use the new helpers and adds ThemeManager constants for button hover/active adjustments.

Changes

Cohort / File(s) Summary
UI util API
src/Utils/UI.h, src/Utils/UI.cpp
Removed ErrorButtonStyle(); added StatusButtonStyle, DestructiveButtonStyle, StatusTextButtonStyle, SuccessButtonStyle, WarningButtonStyle, ErrorButtonWithFlash, ErrorButton, SuccessButton, WarningButton, ErrorTextButton, ErrorImageButton and internal helper logic for hover/active color computation and flashable buttons.
Theme constants
src/Menu/ThemeManager.h
Added new ThemeManager::Constants for button color clamping and hover/active brighten/alpha values (BUTTON_MIN_COLOR_CHANNEL, BUTTON_MAX_COLOR_CHANNEL, BUTTON_HOVER_BRIGHTEN, BUTTON_ACTIVE_BRIGHTEN, BUTTON_STATUS_TEXT_HOVER_ALPHA, BUTTON_STATUS_TEXT_ACTIVE_ALPHA).
Settings UI
src/Menu/SettingsTabRenderer.cpp
Replaced scoped style + ButtonWithFlash pattern with direct Util::ErrorButtonWithFlash(...) call for theme delete control.
WeatherEditor: EditorWindow
src/WeatherEditor/EditorWindow.cpp
Swapped raw ImageButton/Button usages for Util::ErrorImageButton / Util::ErrorButton and removed now-unnecessary scoped style temporaries.
WeatherEditor: Widget
src/WeatherEditor/Widget.cpp
Replaced palette-based styled text button lambda and manual style scopes with Util::SuccessButton, Util::WarningButton, Util::ErrorTextButton, and Util::ErrorImageButton invocations for apply/revert/delete controls.
WeatherEditor: InteriorOnlyPanel
src/WeatherEditor/InteriorOnlyPanel.cpp
Replaced manual ErrorButtonStyle() + ImGui::Button("X",...) with Util::ErrorButton("X",...), preserving existing delete confirmation/removal flow.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • davo0411
  • alandtse

Poem

🐰
I hopped through styles with nimble paws,
Grouped all the danger, success, and flaws,
Buttons now sparkle, tidy and bright,
One helper for wrongs and one for right,
A carrot-cheer for UI delight! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.70% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main refactoring effort: centralizing and reusing button helper functions across the UI codebase.
Linked Issues check ✅ Passed The PR successfully addresses all coding requirements from #1879: centralizes error-styled buttons with new helper functions, adds complementary helpers (Success, Warning, Status), removes duplicated style logic across multiple files, maintains consistent hover/active behavior, and ensures no behavioral regressions.
Out of Scope Changes check ✅ Passed All changes directly support the refactoring objectives. UI constant additions to ThemeManager support parameterization, new helper functions replace duplicated styling code, and updates across five files migrate from manual styling to the new centralized helpers.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

No actionable suggestions for changed features.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
src/Utils/UI.h (1)

224-240: Clarify Reset ownership between warning vs destructive helper docs.

Reset is listed under both destructive (DestructiveButtonStyle) and warning (WarningButtonStyle) guidance. That overlap can reintroduce inconsistent button selection across call sites.

Suggested doc-only adjustment
- /** Use for cautionary or reversible actions such as Revert, Reset, or Undo. */
+ /** Use for cautionary or reversible actions such as Revert, Retry, or Undo. */
  StyledButtonWrapper WarningButtonStyle();
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Utils/UI.h` around lines 224 - 240, The docs currently list "Reset" under
both DestructiveButtonStyle and WarningButtonStyle causing ambiguity; update the
comment blocks so "Reset" appears only under the appropriate helper: move
"Reset" to DestructiveButtonStyle if it is irreversible, or keep it under
WarningButtonStyle if it is reversible/cautionary, and adjust the phrasing to
state "Reset (reversible)" or "Reset (irreversible)" accordingly; update the doc
strings for DestructiveButtonStyle and WarningButtonStyle to clearly distinguish
irreversible actions (DestructiveButtonStyle) from reversible/cautionary actions
(WarningButtonStyle) and reference the function names DestructiveButtonStyle and
WarningButtonStyle when making the change.
src/Utils/UI.cpp (1)

516-518: Consider centralizing hover/active brighten amounts in theme constants.

kHoverBrighten and kActiveBrighten are now local knobs. Moving them to ThemeManager::Constants would keep status-button behavior as a single source of truth with other UI tuning values.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Utils/UI.cpp` around lines 516 - 518, Replace the local constexpr knobs
kHoverBrighten and kActiveBrighten with centralized theme constants: add
corresponding entries (e.g., hoverBrighten and activeBrighten) to
ThemeManager::Constants and then use those constants where kHoverBrighten and
kActiveBrighten are referenced in UI.cpp (e.g., in status-button hover/active
color calculations). Ensure you remove the local constexpr lines in UI.cpp and
update any call sites to reference ThemeManager::Constants::hoverBrighten and
ThemeManager::Constants::activeBrighten (or the chosen names) so the brighten
values are a single source of truth.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/Utils/UI.cpp`:
- Around line 516-518: Replace the local constexpr knobs kHoverBrighten and
kActiveBrighten with centralized theme constants: add corresponding entries
(e.g., hoverBrighten and activeBrighten) to ThemeManager::Constants and then use
those constants where kHoverBrighten and kActiveBrighten are referenced in
UI.cpp (e.g., in status-button hover/active color calculations). Ensure you
remove the local constexpr lines in UI.cpp and update any call sites to
reference ThemeManager::Constants::hoverBrighten and
ThemeManager::Constants::activeBrighten (or the chosen names) so the brighten
values are a single source of truth.

In `@src/Utils/UI.h`:
- Around line 224-240: The docs currently list "Reset" under both
DestructiveButtonStyle and WarningButtonStyle causing ambiguity; update the
comment blocks so "Reset" appears only under the appropriate helper: move
"Reset" to DestructiveButtonStyle if it is irreversible, or keep it under
WarningButtonStyle if it is reversible/cautionary, and adjust the phrasing to
state "Reset (reversible)" or "Reset (irreversible)" accordingly; update the doc
strings for DestructiveButtonStyle and WarningButtonStyle to clearly distinguish
irreversible actions (DestructiveButtonStyle) from reversible/cautionary actions
(WarningButtonStyle) and reference the function names DestructiveButtonStyle and
WarningButtonStyle when making the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: fcfc81a9-3436-45d2-9895-02c96fbebf53

📥 Commits

Reviewing files that changed from the base of the PR and between efb7317 and 928e4d7.

📒 Files selected for processing (7)
  • src/Features/InverseSquareLighting/LightEditor.cpp
  • src/Menu/SettingsTabRenderer.cpp
  • src/Utils/UI.cpp
  • src/Utils/UI.h
  • src/WeatherEditor/EditorWindow.cpp
  • src/WeatherEditor/InteriorOnlyPanel.cpp
  • src/WeatherEditor/Widget.cpp

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
src/Utils/UI.h (1)

250-261: Add a brief note that id must be unique for ErrorImageButton.

A one-line contract in the comment helps prevent accidental ImGui ID collisions at call sites.

📝 Optional doc tweak
 	template <class TextureID>
 	bool ErrorImageButton(
-		const char* id,
+		const char* id,  // Must be unique per item (use ##suffix where needed)
 		TextureID textureId,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Utils/UI.h` around lines 250 - 261, Add a one-line comment above the
ErrorImageButton(...) function stating that the id parameter must be unique to
avoid ImGui ID collisions at call sites; keep it brief (e.g., "id must be unique
per ImGui element to prevent ID collisions") and place it directly above the
ErrorImageButton declaration so callers and reviewers see the contract; no code
changes to the function body or behavior (DestructiveButtonStyle and
ImGui::ImageButton remain unchanged).
src/Utils/UI.cpp (1)

543-580: Consider a tiny helper to remove repeated style+button boilerplate.

ErrorButton, SuccessButton, and WarningButton share the same pattern and can be collapsed for easier future extension.

♻️ Optional refactor
+	namespace
+	{
+		template <class TFactory>
+		bool DrawStyledButton(const char* label, const ImVec2& size, TFactory&& factory)
+		{
+			auto _style = factory();
+			return ImGui::Button(label, size);
+		}
+	}
+
 	bool ErrorButton(const char* label, const ImVec2& size)
 	{
-		auto _style = DestructiveButtonStyle();
-		return ImGui::Button(label, size);
+		return DrawStyledButton(label, size, [] { return DestructiveButtonStyle(); });
 	}
@@
 	bool SuccessButton(const char* label, const ImVec2& size)
 	{
-		auto _style = SuccessButtonStyle();
-		return ImGui::Button(label, size);
+		return DrawStyledButton(label, size, [] { return SuccessButtonStyle(); });
 	}
@@
 	bool WarningButton(const char* label, const ImVec2& size)
 	{
-		auto _style = WarningButtonStyle();
-		return ImGui::Button(label, size);
+		return DrawStyledButton(label, size, [] { return WarningButtonStyle(); });
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Utils/UI.cpp` around lines 543 - 580, The three button functions
(ErrorButton, SuccessButton, WarningButton) and ErrorButtonWithFlash repeat the
pattern of creating a style RAII (DestructiveButtonStyle, SuccessButtonStyle,
WarningButtonStyle) then calling ImGui::Button or ButtonWithFlash; factor this
by adding a small helper (e.g., ApplyStyledButton or MakeStyledButton) that
accepts a StyledButtonWrapper (or a callable style-provider like
DestructiveButtonStyle/SuccessButtonStyle/WarningButtonStyle) plus a callable to
invoke the button (ImGui::Button or ButtonWithFlash) and the label/size/optional
flashDuration, then returns the button result; replace ErrorButton,
ErrorButtonWithFlash, SuccessButton, WarningButton to call that helper,
preserving use of DestructiveButtonStyle, ButtonWithFlash,
StatusTextButtonStyle/SuccessButtonStyle/WarningButtonStyle and return values
exactly as before.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/Utils/UI.cpp`:
- Around line 543-580: The three button functions (ErrorButton, SuccessButton,
WarningButton) and ErrorButtonWithFlash repeat the pattern of creating a style
RAII (DestructiveButtonStyle, SuccessButtonStyle, WarningButtonStyle) then
calling ImGui::Button or ButtonWithFlash; factor this by adding a small helper
(e.g., ApplyStyledButton or MakeStyledButton) that accepts a StyledButtonWrapper
(or a callable style-provider like
DestructiveButtonStyle/SuccessButtonStyle/WarningButtonStyle) plus a callable to
invoke the button (ImGui::Button or ButtonWithFlash) and the label/size/optional
flashDuration, then returns the button result; replace ErrorButton,
ErrorButtonWithFlash, SuccessButton, WarningButton to call that helper,
preserving use of DestructiveButtonStyle, ButtonWithFlash,
StatusTextButtonStyle/SuccessButtonStyle/WarningButtonStyle and return values
exactly as before.

In `@src/Utils/UI.h`:
- Around line 250-261: Add a one-line comment above the ErrorImageButton(...)
function stating that the id parameter must be unique to avoid ImGui ID
collisions at call sites; keep it brief (e.g., "id must be unique per ImGui
element to prevent ID collisions") and place it directly above the
ErrorImageButton declaration so callers and reviewers see the contract; no code
changes to the function body or behavior (DestructiveButtonStyle and
ImGui::ImageButton remain unchanged).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8c43546f-903f-475a-b28e-994bd7051e72

📥 Commits

Reviewing files that changed from the base of the PR and between 928e4d7 and 16b75f5.

📒 Files selected for processing (3)
  • src/Menu/ThemeManager.h
  • src/Utils/UI.cpp
  • src/Utils/UI.h
✅ Files skipped from review due to trivial changes (1)
  • src/Menu/ThemeManager.h

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 28, 2026

✅ A pre-release build is available for this PR:
Download

Comment thread src/Utils/UI.cpp
Comment thread src/Utils/UI.cpp Outdated
Comment thread src/Menu/ThemeManager.h
@alandtse alandtse merged commit a82afac into community-shaders:dev Apr 29, 2026
14 checks passed
ParticleTroned pushed a commit to ParticleTroned/skyrim-community-shaders that referenced this pull request May 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(ui): centralize and reuse error-styled button helper

3 participants