refactor(UI): button helper functions#2228
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughRefactors and expands the UI button styling API: removes Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
No actionable suggestions for changed features. |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/Utils/UI.h (1)
224-240: ClarifyResetownership between warning vs destructive helper docs.
Resetis 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.
kHoverBrightenandkActiveBrightenare now local knobs. Moving them toThemeManager::Constantswould 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
📒 Files selected for processing (7)
src/Features/InverseSquareLighting/LightEditor.cppsrc/Menu/SettingsTabRenderer.cppsrc/Utils/UI.cppsrc/Utils/UI.hsrc/WeatherEditor/EditorWindow.cppsrc/WeatherEditor/InteriorOnlyPanel.cppsrc/WeatherEditor/Widget.cpp
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/Utils/UI.h (1)
250-261: Add a brief note thatidmust be unique forErrorImageButton.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, andWarningButtonshare 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
📒 Files selected for processing (3)
src/Menu/ThemeManager.hsrc/Utils/UI.cppsrc/Utils/UI.h
✅ Files skipped from review due to trivial changes (1)
- src/Menu/ThemeManager.h
|
✅ A pre-release build is available for this PR: |
(cherry picked from commit a82afac)
closes: #1879
Summary by CodeRabbit
Refactor
New Features