View don't explicitely store their subviews

Change-Id: I54c1d60982d51d6fb35517fabde4d7b6056f4ea3
This commit is contained in:
Romain Goyet
2016-05-24 14:25:31 +02:00
parent 0b6382620d
commit da93ac6dfb
4 changed files with 31 additions and 10 deletions

View File

@@ -0,0 +1,12 @@
#ifndef ESCHER_CHILDLESS_VIEW_H
#define ESCHER_CHILDLESS_VIEW_H
#include <escher/view.h>
class ChildlessView : public View {
protected:
int numberOfSubviews() override;
View * subview(int index) override;
};
#endif

View File

@@ -1,7 +1,7 @@
#ifndef ESCHER_TEXT_VIEW_H
#define ESCHER_TEXT_VIEW_H
#include <escher/view.h>
#include <escher/childless_view.h>
class TextView : public View {
public:

View File

@@ -22,20 +22,25 @@ public:
virtual void drawRect(KDRect rect); // To be implemented. Draw ourself.
void addSubview(View * subview);
void removeFromSuperview();
//void addSubview(View * subview);
//void removeFromSuperview();
void setFrame(KDRect frame);
protected:
KDRect bounds();
virtual int numberOfSubviews() = 0;
virtual View * subview(int index) = 0;
private:
void redraw();
void redraw(KDRect rect);
KDRect absoluteDrawingArea();
//TODO: We may want a dynamic size at some point
static constexpr uint8_t k_maxNumberOfSubviews = 4;
KDRect m_frame;
View * m_superview;
KDRect m_frame;
//TODO: We may want a dynamic size at some point
/*
static constexpr uint8_t k_maxNumberOfSubviews = 4;
View * m_subviews[k_maxNumberOfSubviews];
*/
};
#endif

View File

@@ -4,12 +4,14 @@ extern "C" {
#include <escher/view.h>
View::View(KDRect frame) :
m_frame(frame),
m_superview(nullptr)
m_superview(nullptr),
m_frame(frame)
{
/*
for (uint8_t i=0; i<k_maxNumberOfSubviews; i++) {
m_subviews[i] = nullptr;
}
*/
}
View::~View() {
@@ -29,8 +31,8 @@ void View::redraw(KDRect rect) {
KDSetDrawingArea(absoluteDrawingArea());
this->drawRect(rect);
// Then, let's recursively draw our children over ourself
for (uint8_t i=0; i<k_maxNumberOfSubviews; i++) {
View * subview = m_subviews[i];
for (uint8_t i=0; i<numberOfSubviews(); i++) {
View * subview = this->subview(i);
if (subview == nullptr) {
continue;
}
@@ -44,6 +46,7 @@ void View::redraw(KDRect rect) {
}
}
/*
void View::addSubview(View * subview) {
// Let's find a spot for that subview
uint8_t i = 0;
@@ -66,6 +69,7 @@ void View::removeFromSuperview() {
// Then, redraw the parent
m_superview->redraw(m_frame);
}
*/
void View::setFrame(KDRect frame) {
// TODO: Return if frame is equal to m_frame