UI utilities - Toolbar buttons can be used as toggles

This commit is contained in:
Emmanuel BENOîT 2017-11-30 09:28:20 +01:00
parent 382138e5d2
commit b284c2ecc2
2 changed files with 15 additions and 2 deletions

View file

@ -38,12 +38,24 @@ bool ImGui::ToolbarButton(
char const* const string , char const* const string ,
ImVec2 const& size , ImVec2 const& size ,
char const* const tooltip , char const* const tooltip ,
bool enabled ) noexcept bool enabled ,
bool toggled ) noexcept
{ {
if ( !enabled ) { if ( !enabled ) {
PushDisabled( ); PushDisabled( );
} }
if ( toggled ) {
PushStyleColor( ImGuiCol_Border , 0x7fffffff );
PushStyleColor( ImGuiCol_BorderShadow , 0 );
PushStyleVar( ImGuiStyleVar_FrameBorderSize , 1 );
}
const bool rv{ Button( string , size ) }; const bool rv{ Button( string , size ) };
if ( toggled ) {
PopStyleVar( );
PopStyleColor( 2 );
}
if ( !enabled ) { if ( !enabled ) {
PopDisabled( ); PopDisabled( );
} else if ( tooltip && IsItemHovered( ) ) { } else if ( tooltip && IsItemHovered( ) ) {

View file

@ -28,7 +28,8 @@ namespace ImGui {
char const* const string , char const* const string ,
ImVec2 const& size , ImVec2 const& size ,
char const* const tooltip = nullptr , char const* const tooltip = nullptr ,
bool enabled = true ) noexcept; bool enabled = true ,
bool toggled = false ) noexcept;
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/