7GUIs circle drawer WIP.

UILoader rendering glitch fix.
Git create branch fix checkout in subrepos.
UIMessageBox don't focus on any disabled input by default.
This commit is contained in:
Martín Lucas Golini
2024-02-08 22:25:18 -03:00
parent 4bc250515c
commit 2541dccfc9
12 changed files with 144 additions and 15 deletions

View File

@@ -59,9 +59,9 @@ class EE_API UINode : public Node {
virtual Node* setPosition( const Float& x, const Float& y );
void setPixelsPosition( const Vector2f& position );
Node* setPixelsPosition( const Vector2f& position );
void setPixelsPosition( const Float& x, const Float& y );
Node* setPixelsPosition( const Float& x, const Float& y );
const Vector2f& getPosition() const;

View File

@@ -461,8 +461,8 @@ class EE_API Window {
/** Runs the main loop function passed as parameter
** @param func The main loop function
** @param fps The desired FPS ( 0 = infinite ) */
void runMainLoop( std::function<void()> func, int fps = 0 );
** @param fps The desired FPS ( 0 = infinite, < 0 keep current setting ) */
void runMainLoop( std::function<void()> func, int fps = -1 );
/** @return The current display index. */
virtual int getCurrentDisplayIndex();

View File

@@ -1374,6 +1374,12 @@ solution "eepp"
files { "src/examples/7guis/crud/*.cpp" }
build_link_configuration( "eepp-7guis-crud", true )
project "eepp-7guis-circle-drawer"
set_kind()
language "C++"
files { "src/examples/7guis/circle_drawer/*.cpp" }
build_link_configuration( "eepp-7guis-circle-drawer", true )
-- Tools
project "eepp-textureatlaseditor"
set_kind()

View File

@@ -1139,6 +1139,12 @@ workspace "eepp"
files { "src/examples/7guis/crud/*.cpp" }
build_link_configuration( "eepp-7guis-crud", true )
project "eepp-7guis-circle-drawer"
set_kind()
language "C++"
files { "src/examples/7guis/circle_drawer/*.cpp" }
build_link_configuration( "eepp-7guis-circle-drawer", true )
-- Tools
project "eepp-textureatlaseditor"
set_kind()

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 12.0.1, 2024-02-07T13:02:10. -->
<!-- Written by QtCreator 12.0.1, 2024-02-08T17:31:05. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
@@ -1328,6 +1328,27 @@
<value type="bool" key="RunConfiguration.UseTerminal">false</value>
<value type="QString" key="RunConfiguration.WorkingDirectory">%{buildDir}/../../bin</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.26">
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
<value type="qlonglong" key="Analyzer.QmlProfiler.FlushInterval">0</value>
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
<valuelist type="QVariantList" key="CustomOutputParsers"/>
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Executable">%{buildDir}/../../bin/eepp-7guis-circle-drawer-debug</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">eepp-7guis-circle-drawer</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">true</value>
<value type="int" key="RunConfiguration.UseCppDebugger">0</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">false</value>
<value type="int" key="RunConfiguration.UseQmlDebugger">1</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">false</value>
<value type="bool" key="RunConfiguration.UseTerminal">false</value>
<value type="QString" key="RunConfiguration.WorkingDirectory">%{buildDir}/../../bin</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.3">
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
<value type="qlonglong" key="Analyzer.QmlProfiler.FlushInterval">0</value>
@@ -1470,7 +1491,7 @@
<value type="bool" key="RunConfiguration.UseTerminal">false</value>
<value type="QString" key="RunConfiguration.WorkingDirectory">%{buildDir}../../../bin/</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">26</value>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">27</value>
</valuemap>
</data>
<data>

View File

@@ -1130,6 +1130,7 @@
../../src/eepp/window/keycodes.cpp
../../src/eepp/window/platformhelper.hpp
../../src/eepp/window/window.cpp
../../src/examples/7guis/circle_drawer/circle_drawer.cpp
../../src/examples/7guis/counter/counter.cpp
../../src/examples/7guis/crud/crud.cpp
../../src/examples/7guis/flight_booker/flight_booker.cpp

View File

@@ -62,6 +62,9 @@ void UILoader::draw() {
}
void UILoader::scheduledUpdate( const Time& time ) {
if ( !mVisible )
return;
if ( mVisible && isMeOrParentTreeVisible() && mAnimationSpeed != 0.f )
invalidateDraw();
@@ -77,6 +80,9 @@ void UILoader::scheduledUpdate( const Time& time ) {
mArcAngle = 20;
}
if ( mArcStartAngle > 360 )
mArcStartAngle = fmod( mArcStartAngle, 360 );
mArc.setArcAngle( mArcAngle );
mArc.setArcStartAngle( mArcStartAngle );
} else {

View File

@@ -176,11 +176,11 @@ Uint32 UIMessageBox::onKeyUp( const KeyEvent& event ) {
bool UIMessageBox::show() {
bool b = UIWindow::show();
if ( NULL != mTextInput ) {
if ( NULL != mTextInput && mTextInput->isEnabled() ) {
mTextInput->setFocus();
} else if ( NULL != mTextEdit ) {
} else if ( NULL != mTextEdit && mTextEdit->isEnabled() ) {
mTextEdit->setFocus();
} else {
} else if ( mButtonOK->isEnabled() ) {
mButtonOK->setFocus();
}
return b;

View File

@@ -114,17 +114,19 @@ Node* UINode::setPosition( const Float& x, const Float& y ) {
return this;
}
void UINode::setPixelsPosition( const Vector2f& Pos ) {
Node* UINode::setPixelsPosition( const Vector2f& Pos ) {
if ( mPosition != Pos ) {
mDpPos = PixelDensity::pxToDp( Pos );
Transformable::setPosition( Pos );
setDirty();
onPositionChange();
}
return this;
}
void UINode::setPixelsPosition( const Float& x, const Float& y ) {
Node* UINode::setPixelsPosition( const Float& x, const Float& y ) {
setPixelsPosition( Vector2f( x, y ) );
return this;
}
const Vector2f& UINode::getPosition() const {

View File

@@ -602,12 +602,14 @@ static void eepp_mainloop() {
#endif
void Window::runMainLoop( std::function<void()> func, int fps ) {
mMainLoop = std::move(func);
mMainLoop = std::move( func );
#if EE_PLATFORM == EE_PLATFORM_EMSCRIPTEN
emscripten_set_main_loop( eepp_mainloop, fps, 1 );
emscripten_set_main_loop( eepp_mainloop, std::max( mFrameData.FPS.Limit, std::max( 0, fps ) ),
1 );
#else
setFrameRateLimit( fps );
if ( fps >= 0 )
setFrameRateLimit( fps );
while ( isRunning() ) {
mMainLoop();

View File

@@ -0,0 +1,85 @@
#include <eepp/ee.hpp>
// Reference https://eugenkiss.github.io/7guis/tasks#circle
// This is a work in progress, undo redo stack is pending
EE_MAIN_FUNC int main( int, char** ) {
UIApplication app( { 800, 600, "eepp - 7GUIs - Circle Drawer" } );
UIWidget* cont = app.getUI()->loadLayoutFromString( R"xml(
<style>
#canvas {
background-color: var(--list-back);
margin: 0dp 8dp 8dp 8dp;
clip: true;
}
.circle {
background-color: transparent;
border: 1dp solid var(--primary);
transition: all 0.1s;
}
.circle:hover {
background-color: var(--primary);
}
</style>
<vbox layout_width="match_parent" layout_height="match_parent">
<hbox padding="4dp" layout_gravity="center">
<PushButton id="undo" text="Undo" marginRight="8dp" />
<PushButton id="redo" text="Redo" marginLeft="8dp" />
</hbox>
<Widget id="canvas" layout_width="match_parent" layout_height="0" layout_weight="1" />
</vbox>
)xml" );
UIWidget* canvas = cont->find<UIWidget>( "canvas" );
canvas->onClick( [&]( const MouseEvent* event ) {
Float size = Math::randi( 20, 80 );
Vector2f mousePos( event->getPosition().asFloat() - size / 2 );
canvas->worldToNodeTranslation( mousePos );
UIWidget* circle = UIWidget::New();
circle->addClass( "circle" )->setParent( canvas );
circle->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::Fixed )
->setPixelsSize( { size, size } )
->setBorderRadius( size / 2 )
->setPixelsPosition( mousePos );
// undoRedoStack->insert( circle );
circle->onClick(
[circle]( auto ) {
auto adjustMsgBox = UIMessageBox::New( UIMessageBox::OK, "Adjust diameter..." );
adjustMsgBox->on( Event::OnConfirm, [circle]( auto ) {
auto pos( circle->getPixelsPosition().asInt() );
auto msgBox = UIMessageBox::New(
UIMessageBox::OK,
String::format( "Adjust diameter of circle at (%d, %d)", pos.x, pos.y ) );
msgBox->getButtonOK()->setVisible( false )->setEnabled( false );
auto slider = UISlider::NewHorizontal();
slider->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::WrapContent )
->setLayoutMargin( Rectf( 8, 8, 8, 8 ) )
->setParent( msgBox->getLayoutCont()->getFirstChild() )
->setFocus()
->toPosition( 1 );
slider->setMinValue( 20 );
slider->setMaxValue( 80 );
slider->setValue( circle->getPixelsSize().x );
slider->on( Event::OnValueChange, [slider, circle]( auto ) {
Float size = std::floor( slider->getValue() );
Sizef newSize = { size, size };
circle->setPixelsPosition(
( circle->getPixelsPosition() + ( circle->getPixelsSize() / 2.f ) ) -
newSize / 2.f );
circle->setPixelsSize( newSize )->setBorderRadius( size / 2 );
} );
msgBox->on( Event::OnWindowClose, [/*circle*/]( auto ) {
// undoRedoStack->changeSize( circle );
} );
msgBox->showWhenReady();
} );
adjustMsgBox->showWhenReady();
},
MouseButton::EE_BUTTON_RIGHT );
} );
cont->find( "undo" )->onClick( []( auto ) {
// undoRedoStack->undo();
} );
cont->find( "redo" )->onClick( []( auto ) {
// undoRedoStack->redo();
} );
return app.run();
}

View File

@@ -250,7 +250,7 @@ Git::Result Git::createBranch( const std::string& branchName, bool _checkout,
const std::string& projectDir ) {
auto res = gitSimple( String::format( "branch --no-track %s", branchName ), projectDir );
if ( _checkout )
checkout( branchName );
checkout( branchName, projectDir );
return res;
}