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:
Michael Davidson 2023-12-29 18:35:55 +11:00
parent 982942a512
commit f061ff4ee4
No known key found for this signature in database
GPG Key ID: B8D1A99712B8B0EB
4 changed files with 15 additions and 1 deletions

View File

@ -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_;
};

View File

@ -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; };

View File

@ -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");

View File

@ -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; };