mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-08-13 04:42:12 +03:00
Added 7GUIs Timer.
Fixes in UIProgressBar. Fix build.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <eepp/ee.hpp>
|
||||
|
||||
// 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(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <eepp/ee.hpp>
|
||||
#include <iomanip>
|
||||
|
||||
// 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(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <eepp/ee.hpp>
|
||||
|
||||
// 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(
|
||||
|
||||
43
src/examples/7guis/timer/timer.cpp
Normal file
43
src/examples/7guis/timer/timer.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <eepp/ee.hpp>
|
||||
|
||||
// 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(
|
||||
<vbox layout_width="match_parent" layout_height="match_parent" padding="8dp">
|
||||
<hbox layout_width="match_parent" layout_height="wrap_content" marginBottom="8dp">
|
||||
<TextView text="Elapsed Time: " marginRight="8dp" />
|
||||
<ProgressBar id="progressbar" layout_width="fixed" layout_weight="1" layout_height="match_parent" displayPercent="true" />
|
||||
</hbox>
|
||||
<TextView id="elapsed_time" text="0" marginBottom="8dp" />
|
||||
<hbox layout_width="match_parent" layout_height="wrap_content" marginBottom="8dp">
|
||||
<TextView text="Duration: " marginRight="8dp" />
|
||||
<Slider id="duration_slider" orientation="horizontal" layout_width="fixed" layout_weight="1"
|
||||
layout_height="wrap_content" value="1" />
|
||||
</hbox>
|
||||
<PushButton id="reset_button" text="Reset" layout_width="match_parent" />
|
||||
</vbox>
|
||||
)xml" );
|
||||
Clock clock;
|
||||
auto progressBar = hbox->find<UIProgressBar>( "progressbar" );
|
||||
auto durationSlider = hbox->find<UISlider>( "duration_slider" );
|
||||
auto elapsedTimeView = hbox->find<UITextView>( "elapsed_time" );
|
||||
auto intervalId = String::hash( "unique_interval_id" );
|
||||
const auto update = [&]() {
|
||||
double totalDurationInSeconds = static_cast<double>( 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<UIPushButton>( "reset_button" )->onClick( [&]( auto ) {
|
||||
clock.restart();
|
||||
app.getUI()->removeActionsByTag( intervalId );
|
||||
app.getUI()->setInterval( [&update] { update(); }, Milliseconds( 100 ), intervalId );
|
||||
} );
|
||||
return app.run();
|
||||
}
|
||||
Reference in New Issue
Block a user