CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
cdc::ui::ColorPickerView Class Reference

Monochrome RGB color picker. More...

#include <ColorPickerView.h>

Inheritance diagram for cdc::ui::ColorPickerView:
cdc::ui::ViewBase cdc::ui::IView

Public Types

using SaveCallback = void(*)(uint8_t r, uint8_t g, uint8_t b)
 Save callback. Values are pre-multiplied with brightness.
using CancelCallback = void(*)()
 Cancel callback. The view pops itself before this fires.

Public Member Functions

void init (uint8_t r, uint8_t g, uint8_t b)
 Initialize the picker with a starting color.
void setOnSave (SaveCallback cb)
 Register a save callback (fired on Y).
void setOnCancel (CancelCallback cb)
 Register a cancel callback (fired when dismissed with N).
void currentColor (uint8_t &r, uint8_t &g, uint8_t &b) const
 Read the currently chosen color (post brightness scaling).
void render (bool partial) override
InputResult onKey (char key) override
void onTick (uint32_t nowMs) override
const char * getName () const override
const char * getFooterHint () const override
Public Member Functions inherited from cdc::ui::ViewBase
virtual ~ViewBase ()=default
void onEnter (void *context) override
void onExit () override
void onResume () override
void onPause () override
void setLifecycleHooks (void(*onHide)(void *), void(*onShow)(void *), void *userData) override
bool needsRender () const override
void markDirty () override
void clearDirty () override
void setFooterHint (const char *hint) override
const char * getFooterHint () const override
Public Member Functions inherited from cdc::ui::IView
virtual ~IView ()=default
virtual bool prefersLightRefresh () const
virtual InputResult onLongPress (char key)

Additional Inherited Members

Protected Member Functions inherited from cdc::ui::ViewBase
void setTitle (const char *title)
const char * getTitle () const
Protected Attributes inherited from cdc::ui::ViewBase
bool dirty_ = true
const char * title_ = nullptr
const char * customFooter_ = nullptr
void(* onHide_ )(void *) = nullptr
void(* onShow_ )(void *) = nullptr
void * lifecycleUserData_ = nullptr

Detailed Description

Monochrome RGB color picker.

Pick an RGB color via barycentric coordinates inside an R/G/B triangle. A separate brightness slider scales the value. The chosen color is previewed as a Bayer-4-dithered box reflecting perceived luminance (Y = 0.299 R + 0.587 G + 0.114 B).

Keys: 2 / 4 / 6 / 8 move cursor inside triangle 7 / 9 brightness -/+ Y save (fires callback with chosen 0..255 R/G/B) N cancel (REQUEST_POP)

Definition at line 24 of file ColorPickerView.h.

Member Typedef Documentation

◆ CancelCallback

Cancel callback. The view pops itself before this fires.

Definition at line 30 of file ColorPickerView.h.

◆ SaveCallback

using cdc::ui::ColorPickerView::SaveCallback = void(*)(uint8_t r, uint8_t g, uint8_t b)

Save callback. Values are pre-multiplied with brightness.

Definition at line 27 of file ColorPickerView.h.

Member Function Documentation

◆ currentColor()

void cdc::ui::ColorPickerView::currentColor ( uint8_t & r,
uint8_t & g,
uint8_t & b ) const

Read the currently chosen color (post brightness scaling).

Definition at line 195 of file ColorPickerView.cpp.

Referenced by onKey(), and render().

◆ getFooterHint()

const char * cdc::ui::ColorPickerView::getFooterHint ( ) const
overridevirtual

Get footer hint text (e.g., "[Y] OK [N] Back") Return nullptr for no footer

Reimplemented from cdc::ui::IView.

Definition at line 275 of file ColorPickerView.cpp.

References cdc::ui::ViewBase::customFooter_.

Referenced by render().

◆ getName()

const char * cdc::ui::ColorPickerView::getName ( ) const
inlineoverridevirtual

Get view name for debugging

Implements cdc::ui::IView.

Definition at line 53 of file ColorPickerView.h.

◆ init()

void cdc::ui::ColorPickerView::init ( uint8_t r,
uint8_t g,
uint8_t b )

Initialize the picker with a starting color.

Parameters
rInitial red value (0..255).
gInitial green value (0..255).
bInitial blue value (0..255).

Definition at line 94 of file ColorPickerView.cpp.

References cdc::ui::ViewBase::dirty_.

◆ onKey()

InputResult cdc::ui::ColorPickerView::onKey ( char key)
overridevirtual

Handle key press

Parameters
keyKey character ('0'-'9', 'Y', 'N', etc.)
Returns
Input result

Implements cdc::ui::IView.

Definition at line 221 of file ColorPickerView.cpp.

References cdc::ui::CONSUMED, currentColor(), cdc::ui::IGNORED, cdc::ui::ViewStack::instance(), cdc::ui::KEY_NO, cdc::ui::KEY_YES, and cdc::ui::ViewStack::pop().

◆ onTick()

void cdc::ui::ColorPickerView::onTick ( uint32_t nowMs)
overridevirtual

Called periodically for animations/timers

Parameters
nowMsCurrent time in milliseconds

Reimplemented from cdc::ui::IView.

Definition at line 249 of file ColorPickerView.cpp.

References cdc::hal::getKeypadInstance(), REPEAT_INITIAL_MS, and REPEAT_PERIOD_MS.

◆ render()

void cdc::ui::ColorPickerView::render ( bool partial)
overridevirtual

Render view content to display buffer

Parameters
partialTrue for partial update, false for full refresh

Implements cdc::ui::IView.

Definition at line 280 of file ColorPickerView.cpp.

References currentColor(), cdc::ui::ViewBase::dirty_, cdc::ui::display, cdc::ui::render::drawFooterBar(), cdc::ui::layout::FOOTER_HEIGHT, cdc::hal::getDisplayInstance(), getFooterHint(), name, NAME_Y, cdc::ui::render::printText(), and cdc::ui::TEXT_Y.

◆ setOnCancel()

void cdc::ui::ColorPickerView::setOnCancel ( CancelCallback cb)
inline

Register a cancel callback (fired when dismissed with N).

Definition at line 44 of file ColorPickerView.h.

◆ setOnSave()

void cdc::ui::ColorPickerView::setOnSave ( SaveCallback cb)
inline

Register a save callback (fired on Y).

Definition at line 41 of file ColorPickerView.h.


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