diff --git a/demo.cc b/demo.cc index f381bea..4c4c691 100644 --- a/demo.cc +++ b/demo.cc @@ -8,9 +8,6 @@ #include #include -#warning remove this later -#include "syncoverrides.hh" - bool T_Demo::initialise( const uint32_t w , diff --git a/sync.cc b/sync.cc index fe81d1f..7ea84dd 100644 --- a/sync.cc +++ b/sync.cc @@ -389,8 +389,19 @@ void A_SyncOverride::setup( ) noexcept } } +char const* A_SyncOverride::buildLabel( + uint32_t& counter , + T_StringBuilder& sb ) noexcept +{ + sb.clear( ) << "temp label " << counter << '\0'; + counter ++; + return sb.data( ); +} -void A_SyncOverride::makeUI( ) noexcept + +void A_SyncOverride::makeUI( + uint32_t& counter , + T_StringBuilder& sb ) noexcept { using namespace ImGui; @@ -403,7 +414,7 @@ void A_SyncOverride::makeUI( ) noexcept } Indent( ); PushItemWidth( -1 ); - makeEditWidgets( ); + makeEditWidgets( counter , sb ); PopItemWidth( ); Unindent( ); if ( !enabled_ ) { @@ -433,6 +444,8 @@ void T_SyncOverrideSection::merge( } void T_SyncOverrideSection::makeUI( + uint32_t& counter , + T_StringBuilder& tempSb , const bool topLevel ) noexcept { const bool display( topLevel @@ -443,13 +456,13 @@ void T_SyncOverrideSection::makeUI( } for ( auto& os : subsections ) { - os->makeUI( false ); + os->makeUI( counter , tempSb ); } if ( subsections.size( ) && overrides.size( ) ) { ImGui::Separator( ); } for ( auto& ov : overrides ) { - ov->makeUI( ); + ov->makeUI( counter , tempSb ); } if ( !topLevel ) { @@ -683,8 +696,10 @@ void T_SyncManager::makeOverridesWindow( ) if ( soRoot_.subsections.empty( ) ) { ImGui::Text( "No overrides have been defined." ); } else { + T_StringBuilder temp; + uint32_t counter{ 0 }; for ( auto& section : soRoot_.subsections ) { - section->makeUI( true ); + section->makeUI( counter , temp , true ); } } diff --git a/sync.hh b/sync.hh index 83e6c6d..4415af3 100644 --- a/sync.hh +++ b/sync.hh @@ -183,8 +183,17 @@ class A_SyncOverride A_SyncOverride( char const* type , T_String const& title ) noexcept; + // Build a temporary label for use with ImGui. The label is valid + // until the next call to buildLabel(), as it is in fact stored + // in the string builder. + char const* buildLabel( + uint32_t& counter , + T_StringBuilder& sb ) noexcept; + // Draw the UI for that specific override. - virtual void makeEditWidgets( ) noexcept = 0; + virtual void makeEditWidgets( + uint32_t& counter , + T_StringBuilder& sb ) noexcept = 0; public: A_SyncOverride( ) = delete; @@ -208,8 +217,11 @@ class A_SyncOverride // the inputs have been added. virtual void setup( ) noexcept; - // Draw the title, enable button and editor. - virtual void makeUI( ) noexcept; + // Draw the title, enable button and editor. The counter and temporary + // string builder are used to generate "fake" labels for ImGui. + virtual void makeUI( + uint32_t& counter , + T_StringBuilder& sb ) noexcept; }; // Overrides section @@ -228,7 +240,12 @@ struct T_SyncOverrideSection explicit T_SyncOverrideSection( T_String title ) noexcept; void merge( T_SyncOverrideSection& other ) noexcept; - void makeUI( bool topLevel ) noexcept; + + // Generate the UI. A counter and temporary string builder are passed + // to help generating "fake" labels for use with ImGui. + void makeUI( uint32_t& counter , + T_StringBuilder& sb , + bool topLevel = false ) noexcept; T_SyncOverrideSection& section( T_String const& name ) noexcept; diff --git a/syncoverrides.cc b/syncoverrides.cc index 8e1ccdd..0378f09 100644 --- a/syncoverrides.cc +++ b/syncoverrides.cc @@ -185,7 +185,9 @@ ebcl::T_SRDParserConfig sov::GetParserConfig( ) << OnExit( ExitSection_ ) ) ; defs.context( "section" ) - << ( Rule() << "section" << Text( ) << EnterContext( "section" ) ) + << ( Rule() << "section" << Text( ) << EnterContext( "section" ) + << OnEnter( EnterSection_ ) + << OnExit( ExitSection_ ) ) // Floating point controls << ( Rule() << "float" << Text( ) << Word( ) << EnterContext( "float" ) @@ -285,16 +287,19 @@ T_Float::T_Float( inputs_.add( input ); } -void T_Float::makeEditWidgets( ) noexcept +void T_Float::makeEditWidgets( + uint32_t& counter , + T_StringBuilder& sb ) noexcept { using namespace ImGui; float v[ 1 ] = { Globals::Sync( ).inputs( )[ inputPos_[ 0 ] ] }; + char const* const label( buildLabel( counter , sb ) ); const bool changed( slider( ) - ? SliderFloat( "" , v , min( ) , max( ) , decimals( ) , power( ) ) - : DragFloat( "" , v , step( ) , min( ) , max( ) , decimals( ) , power( ) ) ); + ? SliderFloat( label , v , min( ) , max( ) , decimals( ) , power( ) ) + : DragFloat( label , v , step( ) , min( ) , max( ) , decimals( ) , power( ) ) ); if ( changed ) { Globals::Sync( ).inputs( )[ inputPos_[ 0 ] ] = v[ 0 ]; } @@ -313,7 +318,9 @@ T_Float2::T_Float2( inputs_.add( input1 ); } -void T_Float2::makeEditWidgets( ) noexcept +void T_Float2::makeEditWidgets( + uint32_t& counter , + T_StringBuilder& sb ) noexcept { using namespace ImGui; auto& sinp( Globals::Sync( ).inputs( ) ); @@ -322,9 +329,10 @@ void T_Float2::makeEditWidgets( ) noexcept v[ i ] = sinp[ inputPos_[ i ] ]; } + char const* const label( buildLabel( counter , sb ) ); const bool changed( slider( ) - ? SliderFloat2( "" , v , min( ) , max( ) , decimals( ) , power( ) ) - : DragFloat2( "" , v , step( ) , min( ) , max( ) , decimals( ) , power( ) ) ); + ? SliderFloat2( label , v , min( ) , max( ) , decimals( ) , power( ) ) + : DragFloat2( label , v , step( ) , min( ) , max( ) , decimals( ) , power( ) ) ); if ( changed ) { for ( auto i = 0 ; i < 2 ; i ++ ) { sinp[ inputPos_[ i ] ] = v[ i ]; @@ -347,7 +355,9 @@ T_Float3::T_Float3( inputs_.add( input2 ); } -void T_Float3::makeEditWidgets( ) noexcept +void T_Float3::makeEditWidgets( + uint32_t& counter , + T_StringBuilder& sb ) noexcept { using namespace ImGui; auto& sinp( Globals::Sync( ).inputs( ) ); @@ -356,9 +366,10 @@ void T_Float3::makeEditWidgets( ) noexcept v[ i ] = sinp[ inputPos_[ i ] ]; } + char const* const label( buildLabel( counter , sb ) ); const bool changed( slider( ) - ? SliderFloat3( "" , v , min( ) , max( ) , decimals( ) , power( ) ) - : DragFloat3( "" , v , step( ) , min( ) , max( ) , decimals( ) , power( ) ) ); + ? SliderFloat3( label , v , min( ) , max( ) , decimals( ) , power( ) ) + : DragFloat3( label , v , step( ) , min( ) , max( ) , decimals( ) , power( ) ) ); if ( changed ) { for ( auto i = 0 ; i < 3 ; i ++ ) { sinp[ inputPos_[ i ] ] = v[ i ]; @@ -383,7 +394,9 @@ T_Float4::T_Float4( inputs_.add( input3 ); } -void T_Float4::makeEditWidgets( ) noexcept +void T_Float4::makeEditWidgets( + uint32_t& counter , + T_StringBuilder& sb ) noexcept { using namespace ImGui; auto& sinp( Globals::Sync( ).inputs( ) ); @@ -392,9 +405,10 @@ void T_Float4::makeEditWidgets( ) noexcept v[ i ] = sinp[ inputPos_[ i ] ]; } + char const* const label( buildLabel( counter , sb ) ); const bool changed( slider( ) - ? SliderFloat4( "" , v , min( ) , max( ) , decimals( ) , power( ) ) - : DragFloat4( "" , v , step( ) , min( ) , max( ) , decimals( ) , power( ) ) ); + ? SliderFloat4( label , v , min( ) , max( ) , decimals( ) , power( ) ) + : DragFloat4( label , v , step( ) , min( ) , max( ) , decimals( ) , power( ) ) ); if ( changed ) { for ( auto i = 0 ; i < 4 ; i ++ ) { sinp[ inputPos_[ i ] ] = v[ i ]; diff --git a/syncoverrides.hh b/syncoverrides.hh index b977e7d..dc4c1dd 100644 --- a/syncoverrides.hh +++ b/syncoverrides.hh @@ -45,7 +45,9 @@ class A_Float : public A_SyncOverride class T_Float : public A_Float { protected: - void makeEditWidgets( ) noexcept override; + void makeEditWidgets( + uint32_t& counter , + T_StringBuilder& sb ) noexcept override; public: T_Float( T_String const& input , T_String const& title ) noexcept; @@ -55,7 +57,9 @@ class T_Float : public A_Float class T_Float2 : public A_Float { protected: - void makeEditWidgets( ) noexcept override; + void makeEditWidgets( + uint32_t& counter , + T_StringBuilder& sb ) noexcept override; public: T_Float2( T_String const& input0 , T_String const& input1 , @@ -66,7 +70,9 @@ class T_Float2 : public A_Float class T_Float3 : public A_Float { protected: - void makeEditWidgets( ) noexcept override; + void makeEditWidgets( + uint32_t& counter , + T_StringBuilder& sb ) noexcept override; public: T_Float3( T_String const& input0 , T_String const& input1 , @@ -78,7 +84,9 @@ class T_Float3 : public A_Float class T_Float4 : public A_Float { protected: - void makeEditWidgets( ) noexcept override; + void makeEditWidgets( + uint32_t& counter , + T_StringBuilder& sb ) noexcept override; public: T_Float4( T_String const& input0 , T_String const& input1 ,