mirror of
https://github.com/esphome/esphome.git
synced 2024-12-12 08:24:55 +01:00
Add setup_complete hook
Called at the end of setup() of the underlying Component. Last chance to do pre-run-time initialisation in LayoutItems
This commit is contained in:
parent
982942a512
commit
f061ff4ee4
4 changed files with 15 additions and 1 deletions
|
@ -18,6 +18,12 @@ class ContainerLayoutItem : public LayoutItem {
|
|||
/** Adds an item to this container */
|
||||
void add_item(LayoutItem *child) { this->children_.push_back(child); }
|
||||
|
||||
void setup_complete() override {
|
||||
for (LayoutItem *child : this->children_) {
|
||||
child->setup_complete();
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
std::vector<LayoutItem *> children_;
|
||||
};
|
||||
|
|
|
@ -13,6 +13,7 @@ class FixedDimensionPanel : public LayoutItem {
|
|||
display::Rect measure_item_internal(display::Display *display) override;
|
||||
void render_internal(display::Display *display, display::Rect bounds) override;
|
||||
void dump_config(int indent_depth, int additional_level_depth) override;
|
||||
void setup_complete() override { this->child_->setup_complete(); }
|
||||
|
||||
void set_child(LayoutItem *child) { this->child_ = child; };
|
||||
template<typename V> void set_width(V width) { this->width_ = width; };
|
||||
|
|
|
@ -8,7 +8,9 @@ namespace graphical_layout {
|
|||
|
||||
static const char *const TAG = "rootlayoutcomponent";
|
||||
|
||||
void RootLayoutComponent::setup() {}
|
||||
void RootLayoutComponent::setup() {
|
||||
this->layout_root_->setup_complete();
|
||||
}
|
||||
|
||||
void RootLayoutComponent::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "Graphical Layout");
|
||||
|
|
|
@ -83,6 +83,11 @@ class LayoutItem {
|
|||
*/
|
||||
virtual void dump_config(int indent_depth, int additional_level_depth) = 0;
|
||||
|
||||
/** Called once all setup has been completed (i.e. after code generation and all your set_ methods
|
||||
* have been called). Can be used to finalise any configuration
|
||||
*/
|
||||
virtual void setup_complete() {};
|
||||
|
||||
void set_margin(int margin) { this->margin_ = margin; };
|
||||
void set_padding(int padding) { this->padding_ = padding; };
|
||||
void set_border(int border) { this->border_ = border; };
|
||||
|
|
Loading…
Reference in a new issue