Add Widget::parent_rect() accessor, rename member variable.

Some day I will settle on a convention for naming members... I think that day is near.
This commit is contained in:
Jared Boone 2016-12-06 09:28:48 -08:00
parent 3f94591083
commit f2dd6827ea
2 changed files with 13 additions and 8 deletions

View File

@ -53,15 +53,19 @@ Point Widget::screen_pos() {
}
Size Widget::size() const {
return parent_rect.size();
return _parent_rect.size();
}
Rect Widget::screen_rect() const {
return parent() ? (parent_rect + parent()->screen_pos()) : parent_rect;
return parent() ? (parent_rect() + parent()->screen_pos()) : parent_rect();
}
Rect Widget::parent_rect() const {
return _parent_rect;
}
void Widget::set_parent_rect(const Rect new_parent_rect) {
parent_rect = new_parent_rect;
_parent_rect = new_parent_rect;
set_dirty();
}
@ -106,7 +110,7 @@ void Widget::hidden(bool hide) {
if( hide ) {
// TODO: Instead of dirtying parent entirely, dirty only children
// that overlap with this widget.
parent()->dirty_overlapping_children_in_rect(parent_rect);
parent()->dirty_overlapping_children_in_rect(parent_rect());
/* TODO: Notify self and all non-hidden children that they're
* now effectively hidden?
*/
@ -214,7 +218,7 @@ void Widget::set_highlighted(const bool value) {
void Widget::dirty_overlapping_children_in_rect(const Rect& child_rect) {
for(auto child : children()) {
if( !child_rect.intersect(child->parent_rect).is_empty() ) {
if( !child_rect.intersect(child->parent_rect()).is_empty() ) {
child->set_dirty();
}
}

View File

@ -52,13 +52,13 @@ private:
class Widget {
public:
Widget(
) : parent_rect { }
) : _parent_rect { }
{
}
Widget(
Rect parent_rect
) : parent_rect { parent_rect }
) : _parent_rect { parent_rect }
{
}
@ -72,6 +72,7 @@ public:
Point screen_pos();
Size size() const;
Rect screen_rect() const;
Rect parent_rect() const;
virtual void set_parent_rect(const Rect new_parent_rect);
Widget* parent() const;
@ -119,7 +120,7 @@ protected:
private:
/* Widget rectangle relative to parent pos(). */
Rect parent_rect;
Rect _parent_rect;
const Style* style_ { nullptr };
Widget* parent_ { nullptr };