28 #ifndef _LCDGFX_SLIDER_H_ 29 #define _LCDGFX_SLIDER_H_ 69 LcdGfxSlider(
const NanoRect &rect, int16_t minValue, int16_t maxValue, int16_t value, int16_t step = 1,
77 template <
typename D>
void show(D &d)
79 uint16_t color = d.getColor();
80 if ( m_orientation == LcdGfxSliderOrientation::Horizontal )
87 lcdint_t bandTop = (m_rect.p1.y + kPage) & ~(kPage - 1);
88 lcdint_t bandBot = (m_rect.p2.y & ~(kPage - 1)) - 1;
89 if ( bandBot < bandTop || bandBot >= m_rect.p2.y )
91 bandTop = m_rect.p1.y + 1;
92 bandBot = m_rect.p2.y - 1;
94 lcdint_t innerLeft = m_rect.p1.x + 1;
95 lcdint_t innerRight = m_rect.p2.x - 1;
96 lcdint_t innerW = innerRight - innerLeft - 2;
97 if ( innerW < 1 ) innerW = 1;
99 lcdint_t knobX = innerLeft + 1 + (span > 0 ? (
lcdint_t)(((int32_t)(m_value - m_min) * innerW) / span) : 0);
100 lcdint_t knobW = bandBot - bandTop + 1;
103 if ( knobL < innerLeft ) { knobL = innerLeft; knobR = knobL + knobW - 1; }
104 if ( knobR > innerRight ) { knobR = innerRight; knobL = knobR - knobW + 1;
if ( knobL < innerLeft ) knobL = innerLeft; }
107 if ( knobL > innerLeft )
109 d.fillRect(innerLeft, bandTop, knobL - 1, bandBot);
111 if ( knobR < innerRight )
113 d.fillRect(knobR + 1, bandTop, innerRight, bandBot);
116 d.fillRect(knobL, bandTop, knobR, bandBot);
120 lcdint_t innerLeft = m_rect.p1.x + 1;
121 lcdint_t innerRight = m_rect.p2.x - 1;
122 lcdint_t innerTop = m_rect.p1.y + 1;
123 lcdint_t innerBot = m_rect.p2.y - 1;
124 lcdint_t innerH = innerBot - innerTop - 2;
125 if ( innerH < 1 ) innerH = 1;
127 lcdint_t knobY = innerTop + 1 + (span > 0 ? (
lcdint_t)(((int32_t)(m_value - m_min) * innerH) / span) : 0);
128 lcdint_t knobW = innerRight - innerLeft + 1;
130 if ( knobH < 4 ) knobH = 4;
133 if ( knobT < innerTop ) { knobT = innerTop; knobB = knobT + knobH - 1; }
134 if ( knobB > innerBot ) { knobB = innerBot; knobT = knobB - knobH + 1;
if ( knobT < innerTop ) knobT = innerTop; }
137 if ( knobT > innerTop )
139 d.fillRect(innerLeft, innerTop, innerRight, knobT - 1);
141 if ( knobB < innerBot )
143 d.fillRect(innerLeft, knobB + 1, innerRight, innerBot);
146 d.fillRect(innerLeft, knobT, innerRight, knobB);
164 void setValue(int16_t value);
int16_t minValue() const
Returns the configured minimum.
void show(D &d)
Renders the slider on the display.
NanoRect structure describes rectangle area.
const NanoRect & getRect() const
Returns the rectangle area used by the slider.
int8_t lcdint_t
internal int type, used by the library.
Basic structures of nano gfx library.
int16_t value() const
Returns the current value.
int16_t maxValue() const
Returns the configured maximum.
LcdGfxSliderOrientation
Orientation of the slider track.
Class implements a value slider widget for lcdgfx library.