Reference https://eugenkiss.github.io/7guis/tasks#timer
| 2 | |
| 3 | // Reference https://eugenkiss.github.io/7guis/tasks#timer |
| 4 | EE_MAIN_FUNC int main( int, char** ) { |
| 5 | UIApplication app( { 380, 160, "eepp - 7GUIs - Timer" } ); |
| 6 | UIWidget* vbox = app.getUI()->loadLayoutFromString( R"xml( |
| 7 | <vbox layout_width="match_parent" layout_height="match_parent" padding="8dp"> |
| 8 | <hbox layout_width="match_parent" layout_height="wrap_content" marginBottom="8dp"> |
| 9 | <TextView text="Elapsed Time: " marginRight="8dp" /> |
| 10 | <ProgressBar id="progressbar" layout_width="fixed" layout_weight="1" layout_height="match_parent" displayPercent="true" /> |
| 11 | </hbox> |
| 12 | <TextView id="elapsed_time" text="0" marginBottom="8dp" /> |
| 13 | <hbox layout_width="match_parent" layout_height="wrap_content" marginBottom="8dp"> |
| 14 | <TextView text="Duration: " marginRight="8dp" /> |
| 15 | <Slider id="duration_slider" orientation="horizontal" layout_width="fixed" layout_weight="1" |
| 16 | layout_height="wrap_content" value="1" /> |
| 17 | </hbox> |
| 18 | <PushButton id="reset_button" text="Reset" layout_width="match_parent" /> |
| 19 | </vbox> |
| 20 | )xml" ); |
| 21 | Clock clock; |
| 22 | auto progressBar = vbox->find<UIProgressBar>( "progressbar" ); |
| 23 | auto durationSlider = vbox->find<UISlider>( "duration_slider" ); |
| 24 | auto elapsedTimeView = vbox->find<UITextView>( "elapsed_time" ); |
| 25 | auto intervalId = String::hash( "unique_interval_id" ); |
| 26 | const auto update = [&]() { |
| 27 | double totalDurationInSeconds = static_cast<double>( durationSlider->getValue() * 100. ); |
| 28 | elapsedTimeView->setText( clock.getElapsedTime().asSeconds() < totalDurationInSeconds |
| 29 | ? clock.getElapsedTime().toString() |
| 30 | : Seconds( totalDurationInSeconds ).toString() ); |
| 31 | progressBar->setProgress( |
| 32 | std::min( clock.getElapsedTime().asSeconds(), totalDurationInSeconds ) / |
| 33 | totalDurationInSeconds * 100.f ); |
| 34 | if ( clock.getElapsedTime().asSeconds() >= totalDurationInSeconds ) |
| 35 | app.getUI()->removeActionsByTag( intervalId ); |
| 36 | }; |
| 37 | vbox->find<UIPushButton>( "reset_button" )->onClick( [&]( auto ) { |
| 38 | clock.restart(); |
| 39 | app.getUI()->removeActionsByTag( intervalId ); |
| 40 | app.getUI()->setInterval( [&update] { update(); }, Milliseconds( 100 ), intervalId ); |
| 41 | } ); |
| 42 | return app.run(); |
| 43 | } |
nothing calls this directly
no test coverage detected