From 5a66c688616485a834925ec1f4289a75ca44d646 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Sun, 7 Feb 2016 11:24:25 -0800 Subject: [PATCH] Return Widget::children() by reference. --- firmware/common/ui_widget.cpp | 8 +++++--- firmware/common/ui_widget.hpp | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/firmware/common/ui_widget.cpp b/firmware/common/ui_widget.cpp index 8125c30e..788b7abf 100644 --- a/firmware/common/ui_widget.cpp +++ b/firmware/common/ui_widget.cpp @@ -46,6 +46,8 @@ bool is_dirty() { /* Widget ****************************************************************/ +const std::vector Widget::no_children { }; + Point Widget::screen_pos() { return screen_rect().pos; } @@ -153,8 +155,8 @@ bool Widget::on_touch(const TouchEvent event) { return false; } -const std::vector Widget::children() const { - return { }; +const std::vector& Widget::children() const { + return no_children; } Context& Widget::context() const { @@ -244,7 +246,7 @@ void View::remove_child(Widget* const widget) { } } -const std::vector View::children() const { +const std::vector& View::children() const { return children_; } diff --git a/firmware/common/ui_widget.hpp b/firmware/common/ui_widget.hpp index bf53ffd5..4a3e080c 100644 --- a/firmware/common/ui_widget.hpp +++ b/firmware/common/ui_widget.hpp @@ -94,7 +94,7 @@ public: virtual bool on_key(const KeyEvent event); virtual bool on_encoder(const EncoderEvent event); virtual bool on_touch(const TouchEvent event); - virtual const std::vector children() const; + virtual const std::vector& children() const; virtual Context& context() const; @@ -136,6 +136,8 @@ private: .highlighted = false, .visible = false, }; + + static const std::vector no_children; }; class View : public Widget { @@ -154,7 +156,7 @@ public: void add_child(Widget* const widget); void add_children(const std::vector& children); void remove_child(Widget* const widget); - const std::vector children() const override; + const std::vector& children() const override; virtual std::string title() const;