From b284c2ecc2ba88e3dcaab2a6cc9fdc93995bca8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Thu, 30 Nov 2017 09:28:20 +0100 Subject: [PATCH] UI utilities - Toolbar buttons can be used as toggles --- ui-utilities.cc | 14 +++++++++++++- ui-utilities.hh | 3 ++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/ui-utilities.cc b/ui-utilities.cc index 3b65ffa..2d5f97d 100644 --- a/ui-utilities.cc +++ b/ui-utilities.cc @@ -38,12 +38,24 @@ bool ImGui::ToolbarButton( char const* const string , ImVec2 const& size , char const* const tooltip , - bool enabled ) noexcept + bool enabled , + bool toggled ) noexcept { if ( !enabled ) { PushDisabled( ); } + + if ( toggled ) { + PushStyleColor( ImGuiCol_Border , 0x7fffffff ); + PushStyleColor( ImGuiCol_BorderShadow , 0 ); + PushStyleVar( ImGuiStyleVar_FrameBorderSize , 1 ); + } const bool rv{ Button( string , size ) }; + if ( toggled ) { + PopStyleVar( ); + PopStyleColor( 2 ); + } + if ( !enabled ) { PopDisabled( ); } else if ( tooltip && IsItemHovered( ) ) { diff --git a/ui-utilities.hh b/ui-utilities.hh index 23e3c22..409f357 100644 --- a/ui-utilities.hh +++ b/ui-utilities.hh @@ -28,7 +28,8 @@ namespace ImGui { char const* const string , ImVec2 const& size , char const* const tooltip = nullptr , - bool enabled = true ) noexcept; + bool enabled = true , + bool toggled = false ) noexcept; /*--------------------------------------------------------------------*/