Escher: Add ESCHER_VIEW_LOGGING

Change-Id: Id0b588069839f9b1d2330eae55a7fd345740cf1b
This commit is contained in:
Romain Goyet
2016-05-27 12:08:00 +02:00
parent 5f2f39d0d9
commit 8f30223aab
14 changed files with 93 additions and 0 deletions

View File

@@ -7,6 +7,10 @@ class SolidColorView : public ChildlessView {
public:
SolidColorView(KDColor color);
void drawRect(KDRect rect) const override;
protected:
#if ESCHER_VIEW_LOGGING
const char * className() const override;
#endif
private:
KDColor m_color;
};

View File

@@ -17,6 +17,9 @@ public:
//TODO: void removeLastTab();
void setActiveIndex(int index);
protected:
#if ESCHER_VIEW_LOGGING
const char * className() const override;
#endif
void storeSubviewAtIndex(View * view, int index) override;
private:
static constexpr uint8_t k_maxNumberOfTabs = 4;

View File

@@ -10,6 +10,10 @@ public:
void drawRect(KDRect rect) const override;
void setName(const char * name);
void setActive(bool active);
protected:
#if ESCHER_VIEW_LOGGING
const char * className() const override;
#endif
private:
bool m_active;
const char * m_name;

View File

@@ -26,6 +26,10 @@ private:
void setActiveView(View * view);
TabView m_tabView;
protected:
#if ESCHER_VIEW_LOGGING
const char * className() const override;
#endif
private:
View * m_activeView;
};

View File

@@ -14,6 +14,10 @@ public:
float verticalAlignment);
void drawRect(KDRect rect) const override;
void setText(const char * text);
protected:
#if ESCHER_VIEW_LOGGING
const char * className() const override;
#endif
private:
const char * m_text;
float m_horizontalAlignment;

View File

@@ -6,6 +6,10 @@ extern "C" {
#include <kandinsky.h>
}
#if ESCHER_VIEW_LOGGING
#include <iostream>
#endif
/* Key concepts
* - A View always clips: you cannot draw outside its frame (TODO!)
* - A View can redraw its whole hierarchy, but a very important optimization is
@@ -28,7 +32,14 @@ public:
void setSubview(View * v, int index);
KDRect bounds() const;
#if ESCHER_VIEW_LOGGING
friend std::ostream &operator<<(std::ostream &os, const View &view);
#endif
protected:
#if ESCHER_VIEW_LOGGING
virtual const char * className() const;
virtual void logAttributes(std::ostream &os) const;
#endif
virtual bool isOnScreen() const;
virtual int numberOfSubviews() const = 0;
virtual const View * subview(int index) const = 0;

View File

@@ -7,6 +7,9 @@ class Window : public View {
public:
Window();
protected:
#if ESCHER_VIEW_LOGGING
const char * className() const override;
#endif
bool isOnScreen() const override;
int numberOfSubviews() const override;
const View * subview(int index) const override;

View File

@@ -9,3 +9,9 @@ SolidColorView::SolidColorView(KDColor color) :
void SolidColorView::drawRect(KDRect rect) const {
KDFillRect(rect, m_color);
}
#if ESCHER_VIEW_LOGGING
const char * SolidColorView::className() const {
return "SolidColorView";
}
#endif

View File

@@ -56,3 +56,9 @@ void TabView::storeSubviewAtIndex(View * view, int index) {
// We're not doing anything here, because we already store all the subviews we ever wanna have
assert(&m_cells[index] == view);
}
#if ESCHER_VIEW_LOGGING
const char * TabView::className() const {
return "TabView";
}
#endif

View File

@@ -23,3 +23,10 @@ void TabViewCell::setActive(bool active) {
void TabViewCell::drawRect(KDRect rect) const {
KDDrawString(m_name, {0,0}, m_active);
}
#if ESCHER_VIEW_LOGGING
const char * TabViewCell::className() const {
return "TabViewCell";
}
#endif

View File

@@ -52,6 +52,12 @@ void TabViewController::ContentView::storeSubviewAtIndex(View * view, int index)
}
}
#if ESCHER_VIEW_LOGGING
const char * TabViewController::ContentView::className() const {
return "TabViewController::ContentView";
}
#endif
TabViewController::TabViewController(ViewController ** children, uint8_t numberOfChildren) :
m_children(children),
m_numberOfChildren(numberOfChildren),

View File

@@ -24,3 +24,9 @@ void TextView::drawRect(KDRect rect) const {
};
KDDrawString(m_text, origin, 0);
}
#if ESCHER_VIEW_LOGGING
const char * TextView::className() const {
return "TextView";
}
#endif

View File

@@ -130,3 +130,26 @@ KDRect View::absoluteDrawingArea() const {
return KDRectIntersection(absoluteFrame, parentDrawingArea);
}
}
#if ESCHER_VIEW_LOGGING
const char * View::className() const {
return "View";
}
void View::logAttributes(std::ostream &os) const {
os << " frame=\"" << m_frame.x << "," << m_frame.y << "," << m_frame.width << "," << m_frame.height << "\"";
//os << " child_count=\"" << numberOfSubviews() << "\"";
}
std::ostream &operator<<(std::ostream &os, const View &view) {
os << "<" << view.className();
view.logAttributes(os);
os << ">";
for (int i=0; i<view.numberOfSubviews(); i++) {
os << *view.subview(i);
}
os << "</" << view.className() << ">";
return os;
}
#endif

View File

@@ -31,3 +31,9 @@ void Window::storeSubviewAtIndex(View * view, int index) {
assert(index == 0);
m_contentView = view;
}
#if ESCHER_VIEW_LOGGING
const char * Window::className() const {
return "Window";
}
#endif