KiCad PCB EDA Suite
Loading...
Searching...
No Matches
WX_DEBOUNCED_ACTION Class Reference

Debounces an action: runs it only after a quiet period following the last trigger. More...

#include <wx_debounced_action.h>

Inheritance diagram for WX_DEBOUNCED_ACTION:

Public Types

using ACTION_FN = std::function<void()>
 

Public Member Functions

 WX_DEBOUNCED_ACTION (ACTION_FN aAction, int aDelayMs)
 
void Restart ()
 (Re)start the delay: the action runs by the delay after the call, unless another one is made within the delay period.
 
void Cancel ()
 Stop the timer.
 

Static Public Attributes

static constexpr int TEXT_INPUT_DEBOUNCE_MS = 200
 A typical debounce period for text input events, in milliseconds.
 
static constexpr int HOVER_PREVIEW_DEBOUNCE_MS = 400
 A typical debounce period for hover preview events, in milliseconds.
 

Protected Member Functions

void Notify () override
 

Private Attributes

ACTION_FN m_action
 
int m_delayMs
 

Detailed Description

Debounces an action: runs it only after a quiet period following the last trigger.

Call Restart() to trigger the debounce timer, and on every (potential) trigger. Call Cancel() to drop a pending action.

Definition at line 33 of file wx_debounced_action.h.

Member Typedef Documentation

◆ ACTION_FN

using WX_DEBOUNCED_ACTION::ACTION_FN = std::function<void()>

Definition at line 36 of file wx_debounced_action.h.

Constructor & Destructor Documentation

◆ WX_DEBOUNCED_ACTION()

WX_DEBOUNCED_ACTION::WX_DEBOUNCED_ACTION ( ACTION_FN aAction,
int aDelayMs )
Parameters
aActionthe action to run when the delay elapses.
aDelayMsthe period after a trigger when the action runs

Definition at line 25 of file wx_debounced_action.cpp.

References m_action, m_delayMs, and move.

Member Function Documentation

◆ Cancel()

void WX_DEBOUNCED_ACTION::Cancel ( )

Stop the timer.

Any pending action will be canceled.

Does nothing when none is pending. You must do this if the object the action callback will use is about to be destroyed.

Definition at line 41 of file wx_debounced_action.cpp.

◆ Notify()

void WX_DEBOUNCED_ACTION::Notify ( )
overrideprotected

Definition at line 47 of file wx_debounced_action.cpp.

References m_action.

◆ Restart()

void WX_DEBOUNCED_ACTION::Restart ( )

(Re)start the delay: the action runs by the delay after the call, unless another one is made within the delay period.

Definition at line 33 of file wx_debounced_action.cpp.

References m_delayMs.

Member Data Documentation

◆ HOVER_PREVIEW_DEBOUNCE_MS

int WX_DEBOUNCED_ACTION::HOVER_PREVIEW_DEBOUNCE_MS = 400
staticconstexpr

A typical debounce period for hover preview events, in milliseconds.

Definition at line 57 of file wx_debounced_action.h.

◆ m_action

ACTION_FN WX_DEBOUNCED_ACTION::m_action
private

Definition at line 63 of file wx_debounced_action.h.

Referenced by Notify(), and WX_DEBOUNCED_ACTION().

◆ m_delayMs

int WX_DEBOUNCED_ACTION::m_delayMs
private

Definition at line 64 of file wx_debounced_action.h.

Referenced by Restart(), and WX_DEBOUNCED_ACTION().

◆ TEXT_INPUT_DEBOUNCE_MS

int WX_DEBOUNCED_ACTION::TEXT_INPUT_DEBOUNCE_MS = 200
staticconstexpr

A typical debounce period for text input events, in milliseconds.

Definition at line 55 of file wx_debounced_action.h.


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