Overrides - Fixed two bugs
* Sub-sections were ignored in the definitions * Using the same label for all ImGui controlled caused problems.
This commit is contained in:
parent
0796847b5e
commit
8cd6231206
5 changed files with 80 additions and 29 deletions
3
demo.cc
3
demo.cc
|
@ -8,9 +8,6 @@
|
||||||
#include <ebcl/Files.hh>
|
#include <ebcl/Files.hh>
|
||||||
#include <ebcl/SRDText.hh>
|
#include <ebcl/SRDText.hh>
|
||||||
|
|
||||||
#warning remove this later
|
|
||||||
#include "syncoverrides.hh"
|
|
||||||
|
|
||||||
|
|
||||||
bool T_Demo::initialise(
|
bool T_Demo::initialise(
|
||||||
const uint32_t w ,
|
const uint32_t w ,
|
||||||
|
|
25
sync.cc
25
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;
|
using namespace ImGui;
|
||||||
|
|
||||||
|
@ -403,7 +414,7 @@ void A_SyncOverride::makeUI( ) noexcept
|
||||||
}
|
}
|
||||||
Indent( );
|
Indent( );
|
||||||
PushItemWidth( -1 );
|
PushItemWidth( -1 );
|
||||||
makeEditWidgets( );
|
makeEditWidgets( counter , sb );
|
||||||
PopItemWidth( );
|
PopItemWidth( );
|
||||||
Unindent( );
|
Unindent( );
|
||||||
if ( !enabled_ ) {
|
if ( !enabled_ ) {
|
||||||
|
@ -433,6 +444,8 @@ void T_SyncOverrideSection::merge(
|
||||||
}
|
}
|
||||||
|
|
||||||
void T_SyncOverrideSection::makeUI(
|
void T_SyncOverrideSection::makeUI(
|
||||||
|
uint32_t& counter ,
|
||||||
|
T_StringBuilder& tempSb ,
|
||||||
const bool topLevel ) noexcept
|
const bool topLevel ) noexcept
|
||||||
{
|
{
|
||||||
const bool display( topLevel
|
const bool display( topLevel
|
||||||
|
@ -443,13 +456,13 @@ void T_SyncOverrideSection::makeUI(
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( auto& os : subsections ) {
|
for ( auto& os : subsections ) {
|
||||||
os->makeUI( false );
|
os->makeUI( counter , tempSb );
|
||||||
}
|
}
|
||||||
if ( subsections.size( ) && overrides.size( ) ) {
|
if ( subsections.size( ) && overrides.size( ) ) {
|
||||||
ImGui::Separator( );
|
ImGui::Separator( );
|
||||||
}
|
}
|
||||||
for ( auto& ov : overrides ) {
|
for ( auto& ov : overrides ) {
|
||||||
ov->makeUI( );
|
ov->makeUI( counter , tempSb );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !topLevel ) {
|
if ( !topLevel ) {
|
||||||
|
@ -683,8 +696,10 @@ void T_SyncManager::makeOverridesWindow( )
|
||||||
if ( soRoot_.subsections.empty( ) ) {
|
if ( soRoot_.subsections.empty( ) ) {
|
||||||
ImGui::Text( "No overrides have been defined." );
|
ImGui::Text( "No overrides have been defined." );
|
||||||
} else {
|
} else {
|
||||||
|
T_StringBuilder temp;
|
||||||
|
uint32_t counter{ 0 };
|
||||||
for ( auto& section : soRoot_.subsections ) {
|
for ( auto& section : soRoot_.subsections ) {
|
||||||
section->makeUI( true );
|
section->makeUI( counter , temp , true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
25
sync.hh
25
sync.hh
|
@ -183,8 +183,17 @@ class A_SyncOverride
|
||||||
A_SyncOverride( char const* type ,
|
A_SyncOverride( char const* type ,
|
||||||
T_String const& title ) noexcept;
|
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.
|
// Draw the UI for that specific override.
|
||||||
virtual void makeEditWidgets( ) noexcept = 0;
|
virtual void makeEditWidgets(
|
||||||
|
uint32_t& counter ,
|
||||||
|
T_StringBuilder& sb ) noexcept = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
A_SyncOverride( ) = delete;
|
A_SyncOverride( ) = delete;
|
||||||
|
@ -208,8 +217,11 @@ class A_SyncOverride
|
||||||
// the inputs have been added.
|
// the inputs have been added.
|
||||||
virtual void setup( ) noexcept;
|
virtual void setup( ) noexcept;
|
||||||
|
|
||||||
// Draw the title, enable button and editor.
|
// Draw the title, enable button and editor. The counter and temporary
|
||||||
virtual void makeUI( ) noexcept;
|
// string builder are used to generate "fake" labels for ImGui.
|
||||||
|
virtual void makeUI(
|
||||||
|
uint32_t& counter ,
|
||||||
|
T_StringBuilder& sb ) noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Overrides section
|
// Overrides section
|
||||||
|
@ -228,7 +240,12 @@ struct T_SyncOverrideSection
|
||||||
explicit T_SyncOverrideSection( T_String title ) noexcept;
|
explicit T_SyncOverrideSection( T_String title ) noexcept;
|
||||||
|
|
||||||
void merge( T_SyncOverrideSection& other ) 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_SyncOverrideSection& section(
|
||||||
T_String const& name ) noexcept;
|
T_String const& name ) noexcept;
|
||||||
|
|
|
@ -185,7 +185,9 @@ ebcl::T_SRDParserConfig sov::GetParserConfig( )
|
||||||
<< OnExit( ExitSection_ ) )
|
<< OnExit( ExitSection_ ) )
|
||||||
;
|
;
|
||||||
defs.context( "section" )
|
defs.context( "section" )
|
||||||
<< ( Rule() << "section" << Text( ) << EnterContext( "section" ) )
|
<< ( Rule() << "section" << Text( ) << EnterContext( "section" )
|
||||||
|
<< OnEnter( EnterSection_ )
|
||||||
|
<< OnExit( ExitSection_ ) )
|
||||||
// Floating point controls
|
// Floating point controls
|
||||||
<< ( Rule() << "float" << Text( ) << Word( )
|
<< ( Rule() << "float" << Text( ) << Word( )
|
||||||
<< EnterContext( "float" )
|
<< EnterContext( "float" )
|
||||||
|
@ -285,16 +287,19 @@ T_Float::T_Float(
|
||||||
inputs_.add( input );
|
inputs_.add( input );
|
||||||
}
|
}
|
||||||
|
|
||||||
void T_Float::makeEditWidgets( ) noexcept
|
void T_Float::makeEditWidgets(
|
||||||
|
uint32_t& counter ,
|
||||||
|
T_StringBuilder& sb ) noexcept
|
||||||
{
|
{
|
||||||
using namespace ImGui;
|
using namespace ImGui;
|
||||||
float v[ 1 ] = {
|
float v[ 1 ] = {
|
||||||
Globals::Sync( ).inputs( )[ inputPos_[ 0 ] ]
|
Globals::Sync( ).inputs( )[ inputPos_[ 0 ] ]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
char const* const label( buildLabel( counter , sb ) );
|
||||||
const bool changed( slider( )
|
const bool changed( slider( )
|
||||||
? SliderFloat( "" , v , min( ) , max( ) , decimals( ) , power( ) )
|
? SliderFloat( label , v , min( ) , max( ) , decimals( ) , power( ) )
|
||||||
: DragFloat( "" , v , step( ) , min( ) , max( ) , decimals( ) , power( ) ) );
|
: DragFloat( label , v , step( ) , min( ) , max( ) , decimals( ) , power( ) ) );
|
||||||
if ( changed ) {
|
if ( changed ) {
|
||||||
Globals::Sync( ).inputs( )[ inputPos_[ 0 ] ] = v[ 0 ];
|
Globals::Sync( ).inputs( )[ inputPos_[ 0 ] ] = v[ 0 ];
|
||||||
}
|
}
|
||||||
|
@ -313,7 +318,9 @@ T_Float2::T_Float2(
|
||||||
inputs_.add( input1 );
|
inputs_.add( input1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void T_Float2::makeEditWidgets( ) noexcept
|
void T_Float2::makeEditWidgets(
|
||||||
|
uint32_t& counter ,
|
||||||
|
T_StringBuilder& sb ) noexcept
|
||||||
{
|
{
|
||||||
using namespace ImGui;
|
using namespace ImGui;
|
||||||
auto& sinp( Globals::Sync( ).inputs( ) );
|
auto& sinp( Globals::Sync( ).inputs( ) );
|
||||||
|
@ -322,9 +329,10 @@ void T_Float2::makeEditWidgets( ) noexcept
|
||||||
v[ i ] = sinp[ inputPos_[ i ] ];
|
v[ i ] = sinp[ inputPos_[ i ] ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char const* const label( buildLabel( counter , sb ) );
|
||||||
const bool changed( slider( )
|
const bool changed( slider( )
|
||||||
? SliderFloat2( "" , v , min( ) , max( ) , decimals( ) , power( ) )
|
? SliderFloat2( label , v , min( ) , max( ) , decimals( ) , power( ) )
|
||||||
: DragFloat2( "" , v , step( ) , min( ) , max( ) , decimals( ) , power( ) ) );
|
: DragFloat2( label , v , step( ) , min( ) , max( ) , decimals( ) , power( ) ) );
|
||||||
if ( changed ) {
|
if ( changed ) {
|
||||||
for ( auto i = 0 ; i < 2 ; i ++ ) {
|
for ( auto i = 0 ; i < 2 ; i ++ ) {
|
||||||
sinp[ inputPos_[ i ] ] = v[ i ];
|
sinp[ inputPos_[ i ] ] = v[ i ];
|
||||||
|
@ -347,7 +355,9 @@ T_Float3::T_Float3(
|
||||||
inputs_.add( input2 );
|
inputs_.add( input2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void T_Float3::makeEditWidgets( ) noexcept
|
void T_Float3::makeEditWidgets(
|
||||||
|
uint32_t& counter ,
|
||||||
|
T_StringBuilder& sb ) noexcept
|
||||||
{
|
{
|
||||||
using namespace ImGui;
|
using namespace ImGui;
|
||||||
auto& sinp( Globals::Sync( ).inputs( ) );
|
auto& sinp( Globals::Sync( ).inputs( ) );
|
||||||
|
@ -356,9 +366,10 @@ void T_Float3::makeEditWidgets( ) noexcept
|
||||||
v[ i ] = sinp[ inputPos_[ i ] ];
|
v[ i ] = sinp[ inputPos_[ i ] ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char const* const label( buildLabel( counter , sb ) );
|
||||||
const bool changed( slider( )
|
const bool changed( slider( )
|
||||||
? SliderFloat3( "" , v , min( ) , max( ) , decimals( ) , power( ) )
|
? SliderFloat3( label , v , min( ) , max( ) , decimals( ) , power( ) )
|
||||||
: DragFloat3( "" , v , step( ) , min( ) , max( ) , decimals( ) , power( ) ) );
|
: DragFloat3( label , v , step( ) , min( ) , max( ) , decimals( ) , power( ) ) );
|
||||||
if ( changed ) {
|
if ( changed ) {
|
||||||
for ( auto i = 0 ; i < 3 ; i ++ ) {
|
for ( auto i = 0 ; i < 3 ; i ++ ) {
|
||||||
sinp[ inputPos_[ i ] ] = v[ i ];
|
sinp[ inputPos_[ i ] ] = v[ i ];
|
||||||
|
@ -383,7 +394,9 @@ T_Float4::T_Float4(
|
||||||
inputs_.add( input3 );
|
inputs_.add( input3 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void T_Float4::makeEditWidgets( ) noexcept
|
void T_Float4::makeEditWidgets(
|
||||||
|
uint32_t& counter ,
|
||||||
|
T_StringBuilder& sb ) noexcept
|
||||||
{
|
{
|
||||||
using namespace ImGui;
|
using namespace ImGui;
|
||||||
auto& sinp( Globals::Sync( ).inputs( ) );
|
auto& sinp( Globals::Sync( ).inputs( ) );
|
||||||
|
@ -392,9 +405,10 @@ void T_Float4::makeEditWidgets( ) noexcept
|
||||||
v[ i ] = sinp[ inputPos_[ i ] ];
|
v[ i ] = sinp[ inputPos_[ i ] ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char const* const label( buildLabel( counter , sb ) );
|
||||||
const bool changed( slider( )
|
const bool changed( slider( )
|
||||||
? SliderFloat4( "" , v , min( ) , max( ) , decimals( ) , power( ) )
|
? SliderFloat4( label , v , min( ) , max( ) , decimals( ) , power( ) )
|
||||||
: DragFloat4( "" , v , step( ) , min( ) , max( ) , decimals( ) , power( ) ) );
|
: DragFloat4( label , v , step( ) , min( ) , max( ) , decimals( ) , power( ) ) );
|
||||||
if ( changed ) {
|
if ( changed ) {
|
||||||
for ( auto i = 0 ; i < 4 ; i ++ ) {
|
for ( auto i = 0 ; i < 4 ; i ++ ) {
|
||||||
sinp[ inputPos_[ i ] ] = v[ i ];
|
sinp[ inputPos_[ i ] ] = v[ i ];
|
||||||
|
|
|
@ -45,7 +45,9 @@ class A_Float : public A_SyncOverride
|
||||||
class T_Float : public A_Float
|
class T_Float : public A_Float
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
void makeEditWidgets( ) noexcept override;
|
void makeEditWidgets(
|
||||||
|
uint32_t& counter ,
|
||||||
|
T_StringBuilder& sb ) noexcept override;
|
||||||
public:
|
public:
|
||||||
T_Float( T_String const& input ,
|
T_Float( T_String const& input ,
|
||||||
T_String const& title ) noexcept;
|
T_String const& title ) noexcept;
|
||||||
|
@ -55,7 +57,9 @@ class T_Float : public A_Float
|
||||||
class T_Float2 : public A_Float
|
class T_Float2 : public A_Float
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
void makeEditWidgets( ) noexcept override;
|
void makeEditWidgets(
|
||||||
|
uint32_t& counter ,
|
||||||
|
T_StringBuilder& sb ) noexcept override;
|
||||||
public:
|
public:
|
||||||
T_Float2( T_String const& input0 ,
|
T_Float2( T_String const& input0 ,
|
||||||
T_String const& input1 ,
|
T_String const& input1 ,
|
||||||
|
@ -66,7 +70,9 @@ class T_Float2 : public A_Float
|
||||||
class T_Float3 : public A_Float
|
class T_Float3 : public A_Float
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
void makeEditWidgets( ) noexcept override;
|
void makeEditWidgets(
|
||||||
|
uint32_t& counter ,
|
||||||
|
T_StringBuilder& sb ) noexcept override;
|
||||||
public:
|
public:
|
||||||
T_Float3( T_String const& input0 ,
|
T_Float3( T_String const& input0 ,
|
||||||
T_String const& input1 ,
|
T_String const& input1 ,
|
||||||
|
@ -78,7 +84,9 @@ class T_Float3 : public A_Float
|
||||||
class T_Float4 : public A_Float
|
class T_Float4 : public A_Float
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
void makeEditWidgets( ) noexcept override;
|
void makeEditWidgets(
|
||||||
|
uint32_t& counter ,
|
||||||
|
T_StringBuilder& sb ) noexcept override;
|
||||||
public:
|
public:
|
||||||
T_Float4( T_String const& input0 ,
|
T_Float4( T_String const& input0 ,
|
||||||
T_String const& input1 ,
|
T_String const& input1 ,
|
||||||
|
|
Loading…
Reference in a new issue