mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-19 05:40:38 +01:00
Escher: View cleanup
Change-Id: I9143c3d979515c742f99a7f169fbf04bf9d5e731
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -13,7 +13,7 @@ TabViewController::ContentView::ContentView() :
|
||||
void TabViewController::ContentView::setActiveView(View * view) {
|
||||
m_activeView = view;
|
||||
layoutSubviews();
|
||||
view->markAsNeedingRedraw();
|
||||
markAsNeedingRedraw();
|
||||
}
|
||||
|
||||
void TabViewController::ContentView::layoutSubviews() {
|
||||
|
||||
@@ -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(i<k_maxNumberOfSubviews); // No room left!
|
||||
}
|
||||
|
||||
subview->m_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; i<m_superview->numberOfSubviews(); 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;
|
||||
|
||||
Reference in New Issue
Block a user