Wt examples: CountDownWidget Class Reference

Wt examples 4.10.4

Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CountDownWidget Class Reference

A widget which displays a decrementing number. More...

`#include <CountDownWidget.h>`

Inheritance diagram for CountDownWidget:
[legend]

## Public Member Functions
| CountDownWidget (int start, int stop, std::chrono::milliseconds msec)
| Create a new CountDownWidget.
Signal & | done ()
| Signal emitted when the countdown reached stop.
void | cancel ()
| Cancel the count down.

## Private Member Functions
void | timerTick ()
| Process one timer tick.

## Private Attributes
Signal | done_
int | start_
int | stop_
int | current_
std::unique_ptr< WTimer > | timer_

## Detailed Description

A widget which displays a decrementing number.

Definition at line 26 of file CountDownWidget.h.

## Constructor & Destructor Documentation

## ◆ CountDownWidget()

CountDownWidget::CountDownWidget | ( | int | start,
|  | int | stop,
|  | std::chrono::milliseconds | msec )

Create a new CountDownWidget.

The widget will count down from start to stop, decrementing the number every msec milliseconds.

Definition at line 12 of file CountDownWidget.C.

13 : WText(),
14 done_(),
15 start_(start),
16 stop_(stop)
17{
18 stop_ = std::min(start_ - 1, stop_); // stop must be smaller than start
19 current_ = start_;
20
21 timer_ = std::make_unique<WTimer>();
22 timer_->setInterval(msec);
23 timer_->timeout().connect(this, &CountDownWidget::timerTick);
24 timer_->start();
25
26 setText(std::to_string(current_));
27}
CountDownWidget::current_
int current_
Definition CountDownWidget.h:49
CountDownWidget::start_
int start_
Definition CountDownWidget.h:46
CountDownWidget::timer_
std::unique_ptr< WTimer > timer_
Definition CountDownWidget.h:51
CountDownWidget::timerTick
void timerTick()
Process one timer tick.
Definition CountDownWidget.C:34
CountDownWidget::stop_
int stop_
Definition CountDownWidget.h:47
CountDownWidget::done_
Signal done_
Definition CountDownWidget.h:45

## Member Function Documentation

## ◆ cancel()

void CountDownWidget::cancel | ( |  | ) |

Cancel the count down.

Definition at line 29 of file CountDownWidget.C.

30{
31 timer_->stop();
32}

## ◆ done()

Signal & CountDownWidget::done | ( |  | ) |
| inline

Signal emitted when the countdown reached stop.

Definition at line 38 of file CountDownWidget.h.

38{ return done_; }

## ◆ timerTick()

void CountDownWidget::timerTick | ( |  | ) |
| private

Process one timer tick.

Definition at line 34 of file CountDownWidget.C.

35{
36 setText(std::to_string(--current_));
37
38 if (current_ <= stop_) {
39 timer_->stop();
40 done_.emit();
41 }
42}

## Member Data Documentation

## ◆ current_

int CountDownWidget::current_
| private

Definition at line 49 of file CountDownWidget.h.

## ◆ done_

Signal CountDownWidget::done_
| private

Definition at line 45 of file CountDownWidget.h.

## ◆ start_

int CountDownWidget::start_
| private

Definition at line 46 of file CountDownWidget.h.

## ◆ stop_

int CountDownWidget::stop_
| private

Definition at line 47 of file CountDownWidget.h.

## ◆ timer_

std::unique_ptr<WTimer> CountDownWidget::timer_
| private

Definition at line 51 of file CountDownWidget.h.

The documentation for this class was generated from the following files:

- mission/CountDownWidget.h
- mission/CountDownWidget.C