Escher: Add a ScrollViewIndicator

Change-Id: Ie619c16c9f784c3456a33de3ce21e25fae952ffc
This commit is contained in:
Romain Goyet
2016-06-01 09:54:46 +02:00
parent fb529fc98f
commit 8d8824cb69
4 changed files with 85 additions and 0 deletions

View File

@@ -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\

View File

@@ -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>

View 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

View 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