mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
Escher: Add a ScrollViewIndicator
Change-Id: Ie619c16c9f784c3456a33de3ce21e25fae952ffc
This commit is contained in:
@@ -5,6 +5,7 @@ objs += $(addprefix escher/src/,\
|
||||
childless_view.o\
|
||||
responder.o\
|
||||
scroll_view.o\
|
||||
scroll_view_indicator.o\
|
||||
solid_color_view.o\
|
||||
tab_view.o\
|
||||
tab_view_cell.o\
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <escher/app.h>
|
||||
#include <escher/responder.h>
|
||||
#include <escher/scroll_view_indicator.h>
|
||||
#include <escher/solid_color_view.h>
|
||||
#include <escher/text_view.h>
|
||||
#include <escher/tab_view_controller.h>
|
||||
|
||||
28
escher/include/escher/scroll_view_indicator.h
Normal file
28
escher/include/escher/scroll_view_indicator.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef ESCHER_SCROLL_VIEW_INDICATOR_H
|
||||
#define ESCHER_SCROLL_VIEW_INDICATOR_H
|
||||
|
||||
#include <escher/childless_view.h>
|
||||
|
||||
class ScrollViewIndicator : public ChildlessView {
|
||||
public:
|
||||
enum class Direction {
|
||||
Horizontal,
|
||||
Vertical
|
||||
};
|
||||
ScrollViewIndicator(Direction direction);
|
||||
void drawRect(KDRect rect) const override;
|
||||
|
||||
void setStart(float start);
|
||||
void setEnd(float end);
|
||||
protected:
|
||||
#if ESCHER_VIEW_LOGGING
|
||||
virtual const char * className() const override;
|
||||
virtual void logAttributes(std::ostream &os) const override;
|
||||
#endif
|
||||
private:
|
||||
Direction m_direction;
|
||||
float m_start;
|
||||
float m_end;
|
||||
};
|
||||
|
||||
#endif
|
||||
55
escher/src/scroll_view_indicator.cpp
Normal file
55
escher/src/scroll_view_indicator.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <escher/scroll_view_indicator.h>
|
||||
extern "C" {
|
||||
#include <assert.h>
|
||||
}
|
||||
|
||||
constexpr KDColor k_backgroundColor = 0x00;
|
||||
constexpr KDColor k_indicatorColor = 0x30;
|
||||
|
||||
ScrollViewIndicator::ScrollViewIndicator(ScrollViewIndicator::Direction direction) :
|
||||
ChildlessView(),
|
||||
m_direction(direction),
|
||||
m_start(0),
|
||||
m_end(0)
|
||||
{
|
||||
}
|
||||
|
||||
void ScrollViewIndicator::drawRect(KDRect rect) const {
|
||||
KDFillRect(bounds(), k_backgroundColor);
|
||||
KDRect indicatorFrame;
|
||||
if (m_direction == Direction::Horizontal) {
|
||||
indicatorFrame.x = m_start*bounds().width;
|
||||
indicatorFrame.y = 0;
|
||||
indicatorFrame.width = (m_end-m_start)*bounds().width;
|
||||
indicatorFrame.height = bounds().height;
|
||||
} else {
|
||||
assert(m_direction == Direction::Vertical);
|
||||
indicatorFrame.x = 0;
|
||||
indicatorFrame.y = m_start*bounds().height;
|
||||
indicatorFrame.width = bounds().width;
|
||||
indicatorFrame.height = (m_end-m_start)*bounds().height;
|
||||
}
|
||||
KDFillRect(indicatorFrame, k_indicatorColor);
|
||||
}
|
||||
|
||||
void ScrollViewIndicator::setStart(float start) {
|
||||
m_start = start;
|
||||
redraw();
|
||||
}
|
||||
|
||||
void ScrollViewIndicator::setEnd(float end) {
|
||||
m_end = end;
|
||||
redraw();
|
||||
}
|
||||
|
||||
#if ESCHER_VIEW_LOGGING
|
||||
const char * ScrollViewIndicator::className() const {
|
||||
return "ScrollViewIndicator";
|
||||
}
|
||||
|
||||
void ScrollViewIndicator::logAttributes(std::ostream &os) const {
|
||||
View::logAttributes(os);
|
||||
os << " start=\"" << m_start << "\"";
|
||||
os << " end=\"" << m_end << "\"";
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user