1313OvUI::Widgets::Buttons::Button::Button (const std::string& p_label, const OvMaths::FVector2& p_size, bool p_disabled) :
1414 label(p_label), size(p_size), disabled(p_disabled)
1515{
16- auto & style = ImGui::GetStyle ();
17-
18- idleBackgroundColor = Internal::Converter::ToColor (style.Colors [ImGuiCol_Button]);
19- hoveredBackgroundColor = Internal::Converter::ToColor (style.Colors [ImGuiCol_ButtonHovered]);
20- clickedBackgroundColor = Internal::Converter::ToColor (style.Colors [ImGuiCol_ButtonActive]);
21- textColor = Internal::Converter::ToColor (style.Colors [ImGuiCol_Text]);
2216}
2317
2418void OvUI::Widgets::Buttons::Button::_Draw_Impl ()
2519{
26- auto & style = ImGui::GetStyle () ;
20+ using namespace OvUI ::Internal ;
2721
28- auto defaultIdleColor = style.Colors [ImGuiCol_Button];
29- auto defaultHoveredColor = style.Colors [ImGuiCol_ButtonHovered];
30- auto defaultClickedColor = style.Colors [ImGuiCol_ButtonActive];
31- auto defaultTextColor = style.Colors [ImGuiCol_Text];
22+ uint32_t styleOverrides = 0 ;
3223
33- style.Colors [ImGuiCol_Button] = OvUI::Internal::Converter::ToImVec4 (idleBackgroundColor);
34- style.Colors [ImGuiCol_ButtonHovered] = OvUI::Internal::Converter::ToImVec4 (hoveredBackgroundColor);
35- style.Colors [ImGuiCol_ButtonActive] = OvUI::Internal::Converter::ToImVec4 (clickedBackgroundColor);
36- style.Colors [ImGuiCol_Text] = OvUI::Internal::Converter::ToImVec4 (textColor);
24+ if (idleBackgroundColor.has_value ())
25+ {
26+ ImGui::PushStyleColor (ImGuiCol_Button, Converter::ToImVec4 (idleBackgroundColor.value ()));
27+ ++styleOverrides;
28+ }
29+
30+ if (hoveredBackgroundColor.has_value ())
31+ {
32+ ImGui::PushStyleColor (ImGuiCol_ButtonHovered, Converter::ToImVec4 (hoveredBackgroundColor.value ()));
33+ ++styleOverrides;
34+ }
35+
36+ if (clickedBackgroundColor.has_value ())
37+ {
38+ ImGui::PushStyleColor (ImGuiCol_ButtonActive, Converter::ToImVec4 (clickedBackgroundColor.value ()));
39+ ++styleOverrides;
40+ }
41+
42+ if (textColor.has_value ())
43+ {
44+ ImGui::PushStyleColor (ImGuiCol_Text, Converter::ToImVec4 (textColor.value ()));
45+ ++styleOverrides;
46+ }
3747
3848 // Instead of using disabled directly, as its value can change if some
3949 // callback is bound to the ClickedEvent.
@@ -54,8 +64,6 @@ void OvUI::Widgets::Buttons::Button::_Draw_Impl()
5464 ImGui::EndDisabled ();
5565 }
5666
57- style.Colors [ImGuiCol_Button] = defaultIdleColor;
58- style.Colors [ImGuiCol_ButtonHovered] = defaultHoveredColor;
59- style.Colors [ImGuiCol_ButtonActive] = defaultClickedColor;
60- style.Colors [ImGuiCol_Text] = defaultTextColor;
67+ ImGui::PopStyleColor (styleOverrides);
6168}
69+
0 commit comments