diff --git a/include/gui/view.hpp b/include/gui/view.hpp index 72db87e..017c44f 100644 --- a/include/gui/view.hpp +++ b/include/gui/view.hpp @@ -19,8 +19,19 @@ namespace gui View(View* parent); ~View(); - void setBackgroundColor(gui::Color c) { m_backgroundColor = c; } - gui::Color getBackgroundColor() const { return m_backgroundColor; } + void setBackgroundColor(gui::Color c) { + m_backgroundColor = c; + m_backgroundInherited = false; + } + gui::Color getBackgroundColor() const { + if (!m_backgroundInherited) + return m_backgroundColor; + if (getParentView()) + return getParentView()->getBackgroundColor(); + return ViewController::get().getBackgroundColor(); + } + bool isBackgroundInherited() const { return m_backgroundInherited; } + void inheritBackgroundColor() { m_backgroundInherited = true; } protected: gui::Graphics &get_default_graphics(); gui::Display &get_default_display(); @@ -62,6 +73,7 @@ namespace gui View *childView; Widget *childWidgets = nullptr; + bool m_backgroundInherited; Color m_backgroundColor; enum TimerEventType{ diff --git a/src/view_controller.cpp b/src/view_controller.cpp index 6f343ac..8d0838a 100644 --- a/src/view_controller.cpp +++ b/src/view_controller.cpp @@ -88,7 +88,9 @@ void ViewController::poll_event_loop(){ } gui::Color ViewController::getBackgroundColor() const{ - return this->current_view? + gui::Color c; + c = this->current_view? this->current_view->m_backgroundColor: 0; + return c; } \ No newline at end of file