mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-30 12:10:03 +02:00
Escher: const-correctness for View
Change-Id: I78efaeff9911413716e669b92affa7ae4f388776
This commit is contained in:
@@ -6,8 +6,8 @@
|
||||
class ChildlessView : public View {
|
||||
using View::View;
|
||||
protected:
|
||||
int numberOfSubviews() override;
|
||||
View * subview(int index) override;
|
||||
int numberOfSubviews() const override;
|
||||
const View * subview(int index) const override;
|
||||
void storeSubviewAtIndex(View * v, int index) override;
|
||||
void layoutSubviews() override;
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
class SolidColorView : public ChildlessView {
|
||||
public:
|
||||
SolidColorView(KDColor color);
|
||||
void drawRect(KDRect rect) override;
|
||||
void drawRect(KDRect rect) const override;
|
||||
private:
|
||||
KDColor m_color;
|
||||
};
|
||||
|
||||
@@ -9,8 +9,8 @@ class TabViewController;
|
||||
class TabView : public View {
|
||||
public:
|
||||
TabView();
|
||||
int numberOfSubviews() override;
|
||||
View * subview(int index) override;
|
||||
int numberOfSubviews() const override;
|
||||
const View * subview(int index) const override;
|
||||
void layoutSubviews() override;
|
||||
|
||||
void addTabNamed(const char * name);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
class TabViewCell : public ChildlessView {
|
||||
public:
|
||||
TabViewCell();
|
||||
void drawRect(KDRect rect) override;
|
||||
void drawRect(KDRect rect) const override;
|
||||
void setName(const char * name);
|
||||
void setActive(bool active);
|
||||
private:
|
||||
|
||||
@@ -19,8 +19,8 @@ private:
|
||||
public:
|
||||
ContentView();
|
||||
|
||||
int numberOfSubviews() override;
|
||||
View * subview(int index) override;
|
||||
int numberOfSubviews() const override;
|
||||
const View * subview(int index) const override;
|
||||
void storeSubviewAtIndex(View * view, int index) override;
|
||||
void layoutSubviews() override;
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
TextView(const char * text,
|
||||
float horizontalAlignment,
|
||||
float verticalAlignment);
|
||||
void drawRect(KDRect rect) override;
|
||||
void drawRect(KDRect rect) const override;
|
||||
void setText(const char * text);
|
||||
private:
|
||||
const char * m_text;
|
||||
|
||||
@@ -19,24 +19,24 @@ class View {
|
||||
public:
|
||||
View();
|
||||
|
||||
virtual void drawRect(KDRect rect); // To be implemented. Draw ourself.
|
||||
virtual void drawRect(KDRect rect) const; // To be implemented. Draw ourself.
|
||||
|
||||
//void addSubview(View * subview);
|
||||
//void removeFromSuperview();
|
||||
void setFrame(KDRect frame);
|
||||
void redraw();
|
||||
void redraw() const;
|
||||
|
||||
void setSubview(View * v, int index);
|
||||
KDRect bounds();
|
||||
KDRect bounds() const;
|
||||
protected:
|
||||
virtual bool isOnScreen();
|
||||
virtual int numberOfSubviews() = 0;
|
||||
virtual View * subview(int index) = 0;
|
||||
virtual bool isOnScreen() const;
|
||||
virtual int numberOfSubviews() const = 0;
|
||||
virtual const View * subview(int index) const = 0;
|
||||
virtual void storeSubviewAtIndex(View * v, int index) = 0;
|
||||
virtual void layoutSubviews() = 0;
|
||||
private:
|
||||
void redraw(KDRect rect);
|
||||
KDRect absoluteDrawingArea();
|
||||
void redraw(KDRect rect) const;
|
||||
KDRect absoluteDrawingArea() const;
|
||||
|
||||
View * m_superview;
|
||||
KDRect m_frame;
|
||||
|
||||
@@ -7,9 +7,9 @@ class Window : public View {
|
||||
public:
|
||||
Window();
|
||||
protected:
|
||||
bool isOnScreen() override;
|
||||
int numberOfSubviews() override;
|
||||
View * subview(int index) override;
|
||||
bool isOnScreen() const override;
|
||||
int numberOfSubviews() const override;
|
||||
const View * subview(int index) const override;
|
||||
void layoutSubviews() override;
|
||||
void storeSubviewAtIndex(View * view, int index) override;
|
||||
private:
|
||||
|
||||
@@ -3,11 +3,11 @@ extern "C" {
|
||||
#include <assert.h>
|
||||
}
|
||||
|
||||
int ChildlessView::numberOfSubviews() {
|
||||
int ChildlessView::numberOfSubviews() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
View * ChildlessView::subview(int index) {
|
||||
const View * ChildlessView::subview(int index) const {
|
||||
assert(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,6 @@ SolidColorView::SolidColorView(KDColor color) :
|
||||
{
|
||||
}
|
||||
|
||||
void SolidColorView::drawRect(KDRect rect) {
|
||||
void SolidColorView::drawRect(KDRect rect) const {
|
||||
KDFillRect(rect, m_color);
|
||||
}
|
||||
|
||||
@@ -30,11 +30,11 @@ void TabView::setActiveIndex(int index) {
|
||||
m_cells[m_activeTabIndex].setActive(true);
|
||||
}
|
||||
|
||||
int TabView::numberOfSubviews() {
|
||||
int TabView::numberOfSubviews() const {
|
||||
return m_numberOfTabs;
|
||||
}
|
||||
|
||||
View * TabView::subview(int index) {
|
||||
const View * TabView::subview(int index) const {
|
||||
assert(index < m_numberOfTabs);
|
||||
return &m_cells[index];
|
||||
}
|
||||
|
||||
@@ -20,6 +20,6 @@ void TabViewCell::setActive(bool active) {
|
||||
redraw();
|
||||
}
|
||||
|
||||
void TabViewCell::drawRect(KDRect rect) {
|
||||
void TabViewCell::drawRect(KDRect rect) const {
|
||||
KDDrawString(m_name, {0,0}, m_active);
|
||||
}
|
||||
|
||||
@@ -33,11 +33,11 @@ void TabViewController::ContentView::layoutSubviews() {
|
||||
}
|
||||
}
|
||||
|
||||
int TabViewController::ContentView::numberOfSubviews() {
|
||||
int TabViewController::ContentView::numberOfSubviews() const {
|
||||
return 2;
|
||||
}
|
||||
|
||||
View * TabViewController::ContentView::subview(int index) {
|
||||
const View * TabViewController::ContentView::subview(int index) const {
|
||||
if (index == 0) {
|
||||
return &m_tabView;
|
||||
} else {
|
||||
|
||||
@@ -16,7 +16,7 @@ void TextView::setText(const char * text) {
|
||||
m_text = text;
|
||||
}
|
||||
|
||||
void TextView::drawRect(KDRect rect) {
|
||||
void TextView::drawRect(KDRect rect) const {
|
||||
KDSize textSize = KDStringSize(m_text);
|
||||
KDPoint origin = {
|
||||
(KDCoordinate)(m_horizontalAlignment*(bounds().width - textSize.width)),
|
||||
|
||||
@@ -14,12 +14,12 @@ View::View() :
|
||||
*/
|
||||
}
|
||||
|
||||
void View::drawRect(KDRect rect) {
|
||||
void View::drawRect(KDRect rect) const {
|
||||
// By default, a view doesn't do anything
|
||||
// It's transparent!
|
||||
}
|
||||
|
||||
bool View::isOnScreen() {
|
||||
bool View::isOnScreen() const {
|
||||
if (m_superview == nullptr) {
|
||||
return false;
|
||||
} else {
|
||||
@@ -27,11 +27,11 @@ bool View::isOnScreen() {
|
||||
}
|
||||
}
|
||||
|
||||
void View::redraw() {
|
||||
void View::redraw() const {
|
||||
redraw(bounds());
|
||||
}
|
||||
|
||||
void View::redraw(KDRect rect) {
|
||||
void View::redraw(KDRect rect) const {
|
||||
if (!isOnScreen()) {
|
||||
return;
|
||||
}
|
||||
@@ -41,7 +41,7 @@ void View::redraw(KDRect rect) {
|
||||
this->drawRect(rect);
|
||||
// Then, let's recursively draw our children over ourself
|
||||
for (uint8_t i=0; i<numberOfSubviews(); i++) {
|
||||
View * subview = this->subview(i);
|
||||
const View * subview = this->subview(i);
|
||||
if (subview == nullptr) {
|
||||
continue;
|
||||
}
|
||||
@@ -110,14 +110,14 @@ void View::setFrame(KDRect frame) {
|
||||
redraw();
|
||||
}
|
||||
|
||||
KDRect View::bounds() {
|
||||
KDRect View::bounds() const {
|
||||
KDRect bounds = m_frame;
|
||||
bounds.x = 0;
|
||||
bounds.y = 0;
|
||||
return bounds;
|
||||
}
|
||||
|
||||
KDRect View::absoluteDrawingArea() {
|
||||
KDRect View::absoluteDrawingArea() const {
|
||||
if (m_superview == nullptr) {
|
||||
return m_frame;
|
||||
} else {
|
||||
|
||||
@@ -8,15 +8,15 @@ Window::Window() :
|
||||
{
|
||||
}
|
||||
|
||||
bool Window::isOnScreen() {
|
||||
bool Window::isOnScreen() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
int Window::numberOfSubviews() {
|
||||
int Window::numberOfSubviews() const {
|
||||
return (m_contentView == nullptr ? 0 : 1);
|
||||
}
|
||||
|
||||
View * Window::subview(int index) {
|
||||
const View * Window::subview(int index) const {
|
||||
assert(m_contentView != nullptr && index == 0);
|
||||
return m_contentView;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user