diff --git a/bin/assets/ui/breeze.css b/bin/assets/ui/breeze.css index 44e086765..7cb8c2e1d 100644 --- a/bin/assets/ui/breeze.css +++ b/bin/assets/ui/breeze.css @@ -186,7 +186,8 @@ SelectButton:selected:pressed { pushbutton:disabled, selectbutton:disabled, -textinput:disabled { +textinput:disabled, +textedit:disabled { color: var(--disabled-color); border-color: var(--disabled-border); } diff --git a/premake4.lua b/premake4.lua index 5e4b5a910..553a9f828 100644 --- a/premake4.lua +++ b/premake4.lua @@ -1363,6 +1363,12 @@ solution "eepp" files { "src/examples/7guis/flight_booker/*.cpp" } build_link_configuration( "eepp-7guis-flight-booker", true ) + project "eepp-7guis-timer" + set_kind() + language "C++" + files { "src/examples/7guis/timer/*.cpp" } + build_link_configuration( "eepp-7guis-timer", true ) + -- Tools project "eepp-textureatlaseditor" set_kind() diff --git a/premake5.lua b/premake5.lua index 3ca9876d8..7030c0c74 100644 --- a/premake5.lua +++ b/premake5.lua @@ -1100,13 +1100,13 @@ workspace "eepp" kind "ConsoleApp" language "C++" files { "src/examples/http_request/*.cpp" } + incdirs { "src/thirdparty" } build_link_configuration( "eepp-http-request", true ) project "eepp-ui-hello-world" set_kind() language "C++" files { "src/examples/ui_hello_world/*.cpp" } - incdirs { "src/thirdparty" } build_link_configuration( "eepp-ui-hello-world", true ) project "eepp-7guis-counter" @@ -1127,6 +1127,12 @@ workspace "eepp" files { "src/examples/7guis/flight_booker/*.cpp" } build_link_configuration( "eepp-7guis-flight-booker", true ) + project "eepp-7guis-timer" + set_kind() + language "C++" + files { "src/examples/7guis/timer/*.cpp" } + build_link_configuration( "eepp-7guis-timer", true ) + -- Tools project "eepp-textureatlaseditor" set_kind() diff --git a/projects/linux/ee.files b/projects/linux/ee.files index 74c1e7f83..ad6880e8a 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -1130,6 +1130,9 @@ ../../src/eepp/window/keycodes.cpp ../../src/eepp/window/platformhelper.hpp ../../src/eepp/window/window.cpp +../../src/examples/7guis/counter/counter.cpp +../../src/examples/7guis/flight_booker/flight_booker.cpp +../../src/examples/7guis/temperature_converter/temperature_converter.cpp ../../src/examples/empty_window/empty_window.cpp ../../src/examples/external_shader/external_shader.cpp ../../src/examples/fonts/fonts.cpp diff --git a/src/eepp/ui/uiprogressbar.cpp b/src/eepp/ui/uiprogressbar.cpp index 602de3204..563103ae8 100644 --- a/src/eepp/ui/uiprogressbar.cpp +++ b/src/eepp/ui/uiprogressbar.cpp @@ -146,6 +146,10 @@ void UIProgressBar::onSizeChange() { Sizef fSize( ( ( mSize.getWidth() - mPaddingPx.Left - mPaddingPx.Right ) * getProgress() ) / getTotalSteps(), mSize.getHeight() - mPaddingPx.Top - mPaddingPx.Bottom ); + if ( std::isnan( fSize.x ) ) + fSize.x = 0; + if ( std::isnan( fSize.y ) ) + fSize.y = 0; mFiller->setPixelsSize( fSize ); mFiller->setPixelsPosition( mPaddingPx.Left, mPaddingPx.Top ); updateTextBox(); @@ -157,7 +161,7 @@ void UIProgressBar::onPaddingChange() { } void UIProgressBar::setProgress( Float Val ) { - mProgress = Val; + mProgress = eeclamp( Val, 0.f, mTotalSteps ); onValueChange(); updateTextBox(); @@ -210,7 +214,10 @@ const bool& UIProgressBar::getDisplayPercent() const { void UIProgressBar::updateTextBox() { mTextBox->setVisible( mStyleConfig.DisplayPercent ); - mTextBox->setText( String::toString( (Int32)( ( mProgress / mTotalSteps ) * 100.f ) ) + "%" ); + Float clamped = eefloor( eeclamp( ( mProgress / mTotalSteps ) * 100.f, 0.f, 100.f ) ); + if ( std::isnan( clamped ) ) + clamped = 0; + mTextBox->setText( String::fromFloat( clamped ) + "%" ); mTextBox->center(); } diff --git a/src/examples/7guis/counter/counter.cpp b/src/examples/7guis/counter/counter.cpp index d3e510c51..01e9fc8cf 100644 --- a/src/examples/7guis/counter/counter.cpp +++ b/src/examples/7guis/counter/counter.cpp @@ -1,5 +1,6 @@ #include +// Reference https://eugenkiss.github.io/7guis/tasks#counter EE_MAIN_FUNC int main( int, char** ) { UIApplication app( { 380, 64, "eepp - 7GUIs - Counter" } ); UIWidget* hbox = app.getUI()->loadLayoutFromString( R"xml( diff --git a/src/examples/7guis/flight_booker/flight_booker.cpp b/src/examples/7guis/flight_booker/flight_booker.cpp index 4b632c6ce..255cb1121 100644 --- a/src/examples/7guis/flight_booker/flight_booker.cpp +++ b/src/examples/7guis/flight_booker/flight_booker.cpp @@ -1,6 +1,7 @@ #include #include +// Reference https://eugenkiss.github.io/7guis/tasks#flight EE_MAIN_FUNC int main( int, char** ) { UIApplication app( { 440, 240, "eepp - 7GUIs - Flight Booker" } ); UIWidget* hbox = app.getUI()->loadLayoutFromString( R"xml( diff --git a/src/examples/7guis/temperature_converter/temperature_converter.cpp b/src/examples/7guis/temperature_converter/temperature_converter.cpp index c38bbc591..a3d8dd0b4 100644 --- a/src/examples/7guis/temperature_converter/temperature_converter.cpp +++ b/src/examples/7guis/temperature_converter/temperature_converter.cpp @@ -1,5 +1,6 @@ #include +// Reference https://eugenkiss.github.io/7guis/tasks#temp EE_MAIN_FUNC int main( int, char** ) { UIApplication app( { 490, 64, "eepp - 7GUIs - Temperature Converter" } ); UIWidget* hbox = app.getUI()->loadLayoutFromString( R"xml( diff --git a/src/examples/7guis/timer/timer.cpp b/src/examples/7guis/timer/timer.cpp new file mode 100644 index 000000000..897317de7 --- /dev/null +++ b/src/examples/7guis/timer/timer.cpp @@ -0,0 +1,43 @@ +#include + +// Reference https://eugenkiss.github.io/7guis/tasks#timer +EE_MAIN_FUNC int main( int, char** ) { + UIApplication app( { 380, 160, "eepp - 7GUIs - Timer" } ); + UIWidget* hbox = app.getUI()->loadLayoutFromString( R"xml( + + + + + + + + + + + + + )xml" ); + Clock clock; + auto progressBar = hbox->find( "progressbar" ); + auto durationSlider = hbox->find( "duration_slider" ); + auto elapsedTimeView = hbox->find( "elapsed_time" ); + auto intervalId = String::hash( "unique_interval_id" ); + const auto update = [&]() { + double totalDurationInSeconds = static_cast( durationSlider->getValue() * 100. ); + elapsedTimeView->setText( clock.getElapsedTime().asSeconds() < totalDurationInSeconds + ? clock.getElapsedTime().toString() + : Seconds( totalDurationInSeconds ).toString() ); + progressBar->setProgress( + std::min( clock.getElapsedTime().asSeconds(), totalDurationInSeconds ) / + totalDurationInSeconds * 100.f ); + if ( clock.getElapsedTime().asSeconds() >= totalDurationInSeconds ) + app.getUI()->removeActionsByTag( intervalId ); + }; + hbox->find( "reset_button" )->onClick( [&]( auto ) { + clock.restart(); + app.getUI()->removeActionsByTag( intervalId ); + app.getUI()->setInterval( [&update] { update(); }, Milliseconds( 100 ), intervalId ); + } ); + return app.run(); +}