Skip to content

Commit

Permalink
fix uninitialised inherited background color
Browse files Browse the repository at this point in the history
  • Loading branch information
Skyler84 committed Sep 15, 2023
1 parent 3cc4855 commit 70bab81
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 14 additions & 2 deletions include/gui/view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -62,6 +73,7 @@ namespace gui

View *childView;
Widget *childWidgets = nullptr;
bool m_backgroundInherited;
Color m_backgroundColor;

enum TimerEventType{
Expand Down
4 changes: 3 additions & 1 deletion src/view_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 70bab81

Please sign in to comment.