Wt examples  4.0.3
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:
Inheritance graph
[legend]

Public Member Functions

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

Private Member Functions

void timerTick ()
 Process one timer tick. More...
 

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_ = cpp14::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 }
std::unique_ptr< WTimer > timer_
void timerTick()
Process one timer tick.

Member Function Documentation

◆ cancel()

void CountDownWidget::cancel ( )

Cancel the count down.

Definition at line 29 of file CountDownWidget.C.

30 {
31  timer_->stop();
32 }
std::unique_ptr< WTimer > timer_

◆ 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 }
std::unique_ptr< WTimer > timer_

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:

Generated on Tue Aug 21 2018 for the C++ Web Toolkit (Wt) by doxygen 1.8.14