Wt examples  4.10.4
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. More...
 
Signaldone ()
 Signal emitted when the countdown reached stop. More...
 
void cancel ()
 Cancel the count down. More...
 
- Public Member Functions inherited from Wt::WText
 WText ()
 
 WText (const WString &text)
 
 WText (const WString &text, TextFormat textFormat)
 
 ~WText ()
 
const WStringtext () const
 
bool setText (const WString &text)
 
bool setTextFormat (TextFormat format)
 
TextFormat textFormat () const
 
void setWordWrap (bool wordWrap)
 
bool wordWrap () const
 
void setTextAlignment (AlignmentFlag textAlignment)
 
AlignmentFlag textAlignment () const
 
void setPadding (const WLength &padding, WFlags< Side > sides=Side::Left|Side::Right)
 
WLength padding (Side side) const
 
void setInternalPathEncoding (bool enabled)
 
bool hasInternalPathEncoding () const
 
virtual void refresh () override
 
- Public Member Functions inherited from Wt::WInteractWidget
 WInteractWidget ()
 
EventSignal< WKeyEvent > & keyWentDown ()
 
EventSignal< WKeyEvent > & keyPressed ()
 
EventSignal< WKeyEvent > & keyWentUp ()
 
EventSignalenterPressed ()
 
EventSignalescapePressed ()
 
EventSignal< WMouseEvent > & clicked ()
 
EventSignal< WMouseEvent > & doubleClicked ()
 
EventSignal< WMouseEvent > & mouseWentDown ()
 
EventSignal< WMouseEvent > & mouseWentUp ()
 
EventSignal< WMouseEvent > & mouseWentOut ()
 
EventSignal< WMouseEvent > & mouseWentOver ()
 
EventSignal< WMouseEvent > & mouseMoved ()
 
EventSignal< WMouseEvent > & mouseDragged ()
 
EventSignal< WMouseEvent > & mouseWheel ()
 
EventSignal< WTouchEvent > & touchStarted ()
 
EventSignal< WTouchEvent > & touchEnded ()
 
EventSignal< WTouchEvent > & touchMoved ()
 
EventSignal< WGestureEvent > & gestureStarted ()
 
EventSignal< WGestureEvent > & gestureChanged ()
 
EventSignal< WGestureEvent > & gestureEnded ()
 
void setDraggable (const std::string &mimeType, WWidget *dragWidget=nullptr, bool isDragWidgetOnly=false, WObject *sourceWidget=nullptr)
 
void unsetDraggable ()
 
void setMouseOverDelay (int delay)
 
int mouseOverDelay () const
 
virtual void setPopup (bool popup) override
 
virtual void load () override
 
virtual bool isEnabled () const override
 
- Public Member Functions inherited from Wt::WWebWidget
 WWebWidget ()
 
virtual std::vector< WWidget * > children () const override
 
SignalchildrenChanged ()
 
virtual void setPositionScheme (PositionScheme scheme) override
 
virtual PositionScheme positionScheme () const override
 
virtual void setOffsets (const WLength &offset, WFlags< Side > sides=AllSides) override
 
virtual WLength offset (Side s) const override
 
virtual void resize (const WLength &width, const WLength &height) override
 
virtual WLength width () const override
 
virtual WLength height () const override
 
virtual void setMinimumSize (const WLength &width, const WLength &height) override
 
virtual WLength minimumWidth () const override
 
virtual WLength minimumHeight () const override
 
virtual void setMaximumSize (const WLength &width, const WLength &height) override
 
virtual WLength maximumWidth () const override
 
virtual WLength maximumHeight () const override
 
virtual void setLineHeight (const WLength &height) override
 
virtual WLength lineHeight () const override
 
virtual void setFloatSide (Side s) override
 
virtual Side floatSide () const override
 
virtual void setClearSides (WFlags< Side > sides) override
 
virtual WFlags< SideclearSides () const override
 
virtual void setMargin (const WLength &margin, WFlags< Side > sides=AllSides) override
 
virtual WLength margin (Side side) const override
 
virtual void setHiddenKeepsGeometry (bool enabled) override
 
virtual bool hiddenKeepsGeometry () const override
 
virtual void setHidden (bool hidden, const WAnimation &animation=WAnimation()) override
 
virtual bool isHidden () const override
 
virtual bool isVisible () const override
 
virtual void setDisabled (bool disabled) override
 
virtual bool isDisabled () const override
 
virtual bool isPopup () const override
 
virtual void setInline (bool isInline) override
 
virtual bool isInline () const override
 
virtual void setDecorationStyle (const WCssDecorationStyle &style) override
 
virtual WCssDecorationStyledecorationStyle () override
 
virtual void setStyleClass (const WString &styleClass) override
 
virtual WString styleClass () const override
 
virtual void addStyleClass (const WString &styleClass, bool force=false) override
 
virtual void removeStyleClass (const WString &styleClass, bool force=false) override
 
virtual bool hasStyleClass (const WString &styleClass) const override
 
virtual void setVerticalAlignment (AlignmentFlag alignment, const WLength &length=WLength()) override
 
virtual AlignmentFlag verticalAlignment () const override
 
virtual WLength verticalAlignmentLength () const override
 
virtual void setToolTip (const WString &text, TextFormat textFormat=TextFormat::Plain) override
 
virtual void setDeferredToolTip (bool enable, TextFormat textFormat=TextFormat::Plain) override
 
virtual WString toolTip () const override
 
virtual void setAttributeValue (const std::string &name, const WString &value) override
 
virtual WString attributeValue (const std::string &name) const override
 
virtual void setJavaScriptMember (const std::string &name, const std::string &value) override
 
virtual std::string javaScriptMember (const std::string &name) const override
 
virtual void callJavaScriptMember (const std::string &name, const std::string &args) override
 
virtual bool loaded () const override
 
virtual void setId (const std::string &id) override
 
virtual WWidgetfind (const std::string &name) override
 
virtual WWidgetfindById (const std::string &id) override
 
virtual void setSelectable (bool selectable) override
 
virtual void doJavaScript (const std::string &javascript) override
 
virtual const std::string id () const override
 
void setLoadLaterWhenInvisible (bool)
 
std::string htmlTagName () const
 
void setHtmlTagName (const std::string &tag)
 
virtual void setCanReceiveFocus (bool enabled) override
 
virtual bool canReceiveFocus () const override
 
virtual bool setFirstFocus () override
 
virtual void setFocus (bool focus) override
 
virtual bool hasFocus () const override
 
virtual void setTabIndex (int index) override
 
virtual int tabIndex () const override
 
EventSignalblurred ()
 
EventSignalfocussed ()
 
virtual bool scrollVisibilityEnabled () const final override
 
virtual void setScrollVisibilityEnabled (bool enabled) final override
 
virtual int scrollVisibilityMargin () const final override
 
virtual void setScrollVisibilityMargin (int margin) final override
 
virtual Signal< bool > & scrollVisibilityChanged () final override
 
virtual bool isScrollVisible () const final override
 
virtual void setThemeStyleEnabled (bool enabled) final override
 
virtual bool isThemeStyleEnabled () const final override
 
virtual void setObjectName (const std::string &name) override
 
void setFocus ()
 
virtual void setFocus (bool focus)=0
 
- Public Member Functions inherited from Wt::WWidget
virtual ~WWidget ()
 
WWidgetparent () const
 
virtual std::unique_ptr< WWidgetremoveWidget (WWidget *widget)
 
std::unique_ptr< Widget > removeWidget (Widget *widget)
 
std::unique_ptr< WWidgetremoveFromParent ()
 
void setWidth (const WLength &width)
 
void setHeight (const WLength &height)
 
virtual void positionAt (const WWidget *widget, Orientation orientation=Orientation::Vertical)
 
virtual void toggleStyleClass (const WString &styleClass, bool add, bool force=false)
 
std::string jsRef () const
 
void setFocus ()
 
virtual void acceptDrops (const std::string &mimeType, const WString &hoverStyleClass=WString())
 
virtual void stopAcceptDrops (const std::string &mimeType)
 
virtual void htmlText (std::ostream &out)
 
bool isRendered () const
 
void hide ()
 
void animateHide (const WAnimation &animation)
 
void show ()
 
void animateShow (const WAnimation &animation)
 
void enable ()
 
void disable ()
 
bool layoutSizeAware () const
 
- Public Member Functions inherited from Wt::WObject
void addChild (std::unique_ptr< WObject > child)
 
Child * addChild (std::unique_ptr< Child > child)
 
std::unique_ptr< WObjectremoveChild (WObject *child)
 
std::unique_ptr< Child > removeChild (Child *child)
 
virtual std::string objectName () const
 
void resetLearnedSlots ()
 
void resetLearnedSlot (void(T::*method)())
 
WStatelessSlot * implementStateless (void(T::*method)())
 
WStatelessSlot * implementStateless (void(T::*method)(), void(T::*undoMethod)())
 
void isNotStateless ()
 
WStatelessSlot * implementJavaScript (void(T::*method)(), const std::string &jsCode)
 
- Public Member Functions inherited from Wt::Core::observable
 observable () noexcept
 
virtual ~observable ()
 
auto bindSafe (void(C::*method)(Args...)) noexcept
 
auto bindSafe (void(C::*method)(Args...) const) const noexcept
 
auto bindSafe (const Function &function) noexcept
 

Private Member Functions

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

Private Attributes

Signal done_
 
int start_
 
int stop_
 
int current_
 
std::unique_ptr< WTimertimer_
 

Additional Inherited Members

- Public Types inherited from Wt::WObject
typedef void(WObject::* Method) ()
 
- Static Public Member Functions inherited from Wt::WWebWidget
static std::string jsStringLiteral (const std::string &v, char delimiter='\'')
 
- Static Public Member Functions inherited from Wt::WWidget
static WString tr (const char *key)
 
- Protected Member Functions inherited from Wt::WText
virtual void render (WFlags< RenderFlag > flags) override
 
- Protected Member Functions inherited from Wt::WInteractWidget
virtual void propagateSetEnabled (bool enabled) override
 
- Protected Member Functions inherited from Wt::WWebWidget
virtual void enableAjax () override
 
virtual WStatelessSlot * getStateless (Method method) override
 
- Protected Member Functions inherited from Wt::WWidget
void setLayoutSizeAware (bool sizeAware)
 
virtual void layoutSizeChanged (int width, int height)
 
 WWidget ()
 
virtual void dropEvent (WDropEvent dropEvent)
 
virtual int boxPadding (Orientation orientation) const
 
virtual int boxBorder (Orientation orientation) const
 
void scheduleRender (WFlags< RepaintFlag > flags=None)
 

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 }
std::unique_ptr< WTimer > timer_
void timerTick()
Process one timer tick.
bool setText(const WString &text)

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 }
void emit(A... args) const

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: