Escher: Use a scrollview

Change-Id: I24c754a7ea860b79d1d660adfbf143ed0e42c8a5
This commit is contained in:
Romain Goyet
2016-05-30 18:28:18 +02:00
parent 4ed72f60df
commit eb3273d785
3 changed files with 74 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ objs += $(addprefix escher/src/,\
app.o\
childless_view.o\
responder.o\
scroll_view.o\
solid_color_view.o\
tab_view.o\
tab_view_cell.o\

View File

@@ -0,0 +1,27 @@
#ifndef ESCHER_SCROLL_VIEW_H
#define ESCHER_SCROLL_VIEW_H
#include <escher/view.h>
class ScrollView : public View {
public:
ScrollView(View * contentView);
int numberOfSubviews() const override;
const View * subview(int index) const override;
void storeSubviewAtIndex(View * view, int index) override;
void layoutSubviews() override;
void setContentOffset(KDPoint offset);
protected:
#if ESCHER_VIEW_LOGGING
virtual const char * className() const;
virtual void logAttributes(std::ostream &os) const;
#endif
private:
KDPoint m_offset;
View * m_contentView;
//ScollIndicator m_verticalScrollIndicator;
};
#endif

View File

@@ -0,0 +1,46 @@
#include <escher/scroll_view.h>
extern "C" {
#include <assert.h>
}
ScrollView::ScrollView(View * contentView) :
View(),
m_offset(KDPointZero),
m_contentView(contentView)
{
setSubview(m_contentView, 0);
//setSubview(&m_verticalScrollIndicator, 1);
}
int ScrollView::numberOfSubviews() const {
return 1;
}
const View * ScrollView::subview(int index) const {
assert(index == 0);
return m_contentView;
}
void ScrollView::storeSubviewAtIndex(View * view, int index) {
assert(index == 0);
m_contentView = view;
}
void ScrollView::layoutSubviews() {
// Layout indicators
// TODO
// Layout contentview
// FIXME: Use KDCoordinateMax
m_contentView->setFrame({m_offset.x, m_offset.y, (KDCoordinate)9999, (KDCoordinate)9999});
}
#if ESCHER_VIEW_LOGGING
const char * ScrollView::className() const {
return "ScrollView";
}
void ScrollView::logAttributes(std::ostream &os) const {
View::logAttributes(os);
os << " offset=\"" << (int)m_offset.x << "," << (int)m_offset.y << "\"";
}
#endif