diff --git a/escher/Makefile b/escher/Makefile index de048714f..b167eda82 100644 --- a/escher/Makefile +++ b/escher/Makefile @@ -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\ diff --git a/escher/include/escher/scroll_view.h b/escher/include/escher/scroll_view.h new file mode 100644 index 000000000..ef217b77b --- /dev/null +++ b/escher/include/escher/scroll_view.h @@ -0,0 +1,27 @@ +#ifndef ESCHER_SCROLL_VIEW_H +#define ESCHER_SCROLL_VIEW_H + +#include + +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 diff --git a/escher/src/scroll_view.cpp b/escher/src/scroll_view.cpp new file mode 100644 index 000000000..cdacbd6ba --- /dev/null +++ b/escher/src/scroll_view.cpp @@ -0,0 +1,46 @@ +#include +extern "C" { +#include +} + +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