15#include <goodisplay/gdey029T94.h>
22static const char*
TAG =
"SliderView";
46 uint16_t initial, uint16_t step,
const char* unit) {
50 value_ = std::clamp(initial, minVal, maxVal);
51 step_ = step > 0 ? step : 1;
65 value = std::clamp(value, minValue_, maxValue_);
66 if (value_ != value) {
77void SliderView::adjust(
bool increase) {
78 uint16_t newValue = value_;
81 uint16_t currentStep = stepCallback_ ? stepCallback_(value_, increase) : step_;
84 uint16_t next = value_ + currentStep;
85 newValue = (next > maxValue_) ? maxValue_ : next;
87 newValue = (value_ > currentStep) ? value_ - currentStep : minValue_;
90 if (newValue != value_) {
93 LOG_D(
TAG,
"Slider adjusted to %d (step=%d)", value_, currentStep);
145 if (!keyLeft && !keyRight) {
150 if (repeatStartMs_ == 0) {
151 repeatStartMs_ = nowMs;
152 lastRepeatMs_ = nowMs;
159 lastRepeatMs_ = nowMs;
168 return ui::tr(
"core.hint_brightness");
180 auto* gfx =
static_cast<Gdey029T94*
>(
display->getNativeHandle());
183 const uint16_t width =
display->getWidth();
184 const uint16_t height =
display->getHeight();
187 gfx->fillScreen(EPD_WHITE);
190 gfx->setTextColor(EPD_BLACK);
200 int16_t displayValue =
static_cast<int16_t
>(value_) + displayOffset_;
202 if (value_ == 0 && zeroLabel_) {
204 snprintf(valueStr,
sizeof(valueStr),
"%s", zeroLabel_);
206 snprintf(valueStr,
sizeof(valueStr),
"%d %s", displayValue, unit_);
208 snprintf(valueStr,
sizeof(valueStr),
"%d", displayValue);
214 gfx->getTextBounds(valueStr, 0, 0, &x1, &y1, &w, &h);
215 gfx->fillRect(0,
VALUE_Y - 5, width, h + 10, EPD_WHITE);
216 gfx->setCursor((width - w) / 2,
VALUE_Y);
217 gfx->print(valueStr);
223 if (maxValue_ > minValue_) {
224 fillWidth = (value_ - minValue_) * (barWidth - 4) / (maxValue_ - minValue_);
245 barRight + 15, arrowY,
246 barRight + 5, arrowY - 5,
247 barRight + 5, arrowY + 5,
278 uint16_t initial, uint16_t step,
const char* unit,
static constexpr uint32_t REPEAT_PERIOD_MS
static constexpr uint32_t REPEAT_INITIAL_MS
Internationalization with English fallbacks in code and overlay translations loaded at runtime from a...
static constexpr int TITLE_Y
Display layout constants.
static constexpr int VALUE_Y
static constexpr int BAR_HEIGHT
static constexpr int BAR_Y
static constexpr int BAR_MARGIN
CDC Log: logging over TinyUSB CDC and UART.
#define LOG_D(tag, fmt,...)
const char * getFooterHint() const override
Returns localized footer hint text.
InputResult onKey(char key) override
Handles key input for slider adjustment and confirmation.
void onTick(uint32_t nowMs) override
void setValue(uint16_t value)
Sets slider value with range clamping.
void(*)(uint16_t value) ChangeCallback
void init(const char *title, uint16_t minVal, uint16_t maxVal, uint16_t initial, uint16_t step, const char *unit=nullptr)
Initializes slider bounds, value, and display options.
void render(bool partial) override
Renders slider title, value text, progress bar, and footer.
void(*)(uint16_t value) SaveCallback
static ViewStack & instance()
Returns singleton view-stack instance.
void push(IView *view, void *context=nullptr)
IDisplay * getDisplayInstance()
Returns lazily created singleton display instance.
IKeypad * getKeypadInstance()
Returns the singleton keypad service instance.
void drawFooterBar(Gdey029T94 *gfx, uint16_t width, uint16_t height, const char *prefix, const char *hint, bool force=false)
Draws footer bar with optional prefix and hint text.
void drawHeaderCentered(Gdey029T94 *gfx, const char *title, int y, uint16_t width)
Draws a centered header title.
Centralized key-code constants for cdc_views.
const char * tr(const char *key)
Look up a translation by string key.
static constexpr char KEY_NO
Cancel / Back / Backspace.
static constexpr int TITLE_Y
Layout constants mirror the ones used by T9InputView.
static SliderView s_sharedSlider
Convenience factory/helper function.
SliderView * showSlider(const char *title, uint16_t minVal, uint16_t maxVal, uint16_t initial, uint16_t step, const char *unit, SliderView::SaveCallback onSave, SliderView::ChangeCallback onChange=nullptr)
Shows a shared slider view instance.
static constexpr char KEY_YES
Confirm / OK / Save.