diff --git a/escher/include/escher/view.h b/escher/include/escher/view.h index 063e56a44..707750bce 100644 --- a/escher/include/escher/view.h +++ b/escher/include/escher/view.h @@ -11,13 +11,12 @@ extern "C" { #endif /* Key concepts - * - A View always clips: you cannot draw outside its frame (TODO!) + * - A View always clips: you cannot draw outside its frame * - A View can redraw its whole hierarchy, but a very important optimization is * for it not to do this all the time. So a View will try to track which parts * of it really need to be redrawn. * - A view can be offscreen. Until it's attached to the screen, it shouldn't - * send any display command. - */ + * send any display command. */ class Window; @@ -27,51 +26,36 @@ class View { public: View(); - virtual void drawRect(KDRect rect) const; // To be implemented. Draw ourself. + /* The drawRect method should be implemented by each View subclass. In a + * typical drawRect implementation, a subclass will make drawing calls to the + * Kandinsky library. */ + virtual void drawRect(KDRect rect) const; - //void addSubview(View * subview); - //void removeFromSuperview(); void setFrame(KDRect frame); - void markAsNeedingRedraw(); - /* - void markAsDirty() const; - void redraw() const; - */ - - //void setSubview(View * v, int index); --> Remove this, it's annoying - // Also this allows us to remove storeSubviewAtIndex - //void layoutSubviews should not be purely virtual. - - KDRect bounds() const; - View * subview(int index); #if ESCHER_VIEW_LOGGING friend std::ostream &operator<<(std::ostream &os, View &view); #endif protected: + void markAsNeedingRedraw(); #if ESCHER_VIEW_LOGGING virtual const char * className() const; virtual void logAttributes(std::ostream &os) const; #endif - virtual const Window * window() const; - virtual int numberOfSubviews() const = 0; - virtual void layoutSubviews() = 0; KDRect m_frame; private: + virtual int numberOfSubviews() const = 0; virtual View * subviewAtIndex(int index) = 0; + virtual void layoutSubviews() = 0; + virtual const Window * window() const; void redraw(KDRect rect); KDPoint absoluteOrigin() const; KDRect absoluteVisibleFrame() const; View * m_superview; bool m_needsRedraw; - //TODO: We may want a dynamic size at some point - /* - static constexpr uint8_t k_maxNumberOfSubviews = 4; - View * m_subviews[k_maxNumberOfSubviews]; - */ }; #endif diff --git a/escher/include/escher/window.h b/escher/include/escher/window.h index 89ea44a1a..5434717c9 100644 --- a/escher/include/escher/window.h +++ b/escher/include/escher/window.h @@ -12,10 +12,10 @@ protected: #if ESCHER_VIEW_LOGGING const char * className() const override; #endif - const Window * window() const override; int numberOfSubviews() const override; void layoutSubviews() override; private: + const Window * window() const override; View * subviewAtIndex(int index) override; View * m_contentView; }; diff --git a/escher/src/tab_view_controller.cpp b/escher/src/tab_view_controller.cpp index 1b190bfc5..9d2ed1226 100644 --- a/escher/src/tab_view_controller.cpp +++ b/escher/src/tab_view_controller.cpp @@ -13,7 +13,7 @@ TabViewController::ContentView::ContentView() : void TabViewController::ContentView::setActiveView(View * view) { m_activeView = view; layoutSubviews(); - view->markAsNeedingRedraw(); + markAsNeedingRedraw(); } void TabViewController::ContentView::layoutSubviews() { diff --git a/escher/src/view.cpp b/escher/src/view.cpp index c703f210e..714f7328d 100644 --- a/escher/src/view.cpp +++ b/escher/src/view.cpp @@ -86,49 +86,6 @@ View * View::subview(int index) { return subview; } -/* - void View::setSubview(View * view, int index) { - view->m_superview = this; - storeSubviewAtIndex(view, index); - assert(subview(index) == view); - view->markAsNeedingRedraw(); -} -*/ - -/* -void View::addSubview(View * subview) { - // Let's find a spot for that subview - uint8_t i = 0; - while (m_subviews[i] != nullptr) { - i++; - assert(im_superview = this; - m_subviews[i] = subview; - - // That subview needs to be drawn - subview->redraw(); -} -*/ - -/* -void View::removeFromSuperview() { - assert(m_superview != nullptr); - // First, remove the view from its parent hierarchy - for (int i=0; inumberOfSubviews(); i++) { - if (m_superview->subview(i) == this) { - m_superview->storeSubviewAtIndex(nullptr, i); - break; - } - } - // Then, redraw the parent - m_superview->redraw(m_frame); - // Eventually clear the superview ivar - m_superview = nullptr; -} -*/ - void View::setFrame(KDRect frame) { // TODO: Return if frame is equal to m_frame m_frame = frame;