cryptic-clock/src/c/digit_layer.hpp

36 lines
908 B
C++

#pragma once
#include <pebble-cpp/pebble.hpp>
class DigitLayerInner : public Pebble::CustomLayer {
static constexpr int16_t extraDigits = 2;
static constexpr int16_t digitHeight = 56;
int16_t digitCount = 10;
DigitLayerInner() : Pebble::CustomLayer(Pebble::GRect()) {}
static void DrawDigit(const Pebble::GContext& ctx, const Pebble::GRect& bounds, const uint16_t digit);
friend class DigitLayer;
protected:
void OnUpdate(const Pebble::GContext& ctx);
};
class DigitLayer : public Pebble::SimpleLayer {
DigitLayerInner innerLayer;
Pebble::ScrollLayer scrollLayer;
public:
DigitLayer();
void SetDigitCount(uint16_t cnt = 10) {
if (this->innerLayer.digitCount != cnt) {
this->innerLayer.digitCount = cnt;
this->UpdateLayout();
}
}
void UpdateLayout();
void RotateTo(uint16_t digit, bool animate=true);
private:
int16_t ComputeOffset(uint16_t digit);
};