Cogent Core Docs

0%

Loading...

Static preview:

Cogent Core DocsBasics

Plans

The previous two pages cover how to update the properties of a widget, but what if you want to update the structure of a widget? To answer that question, Cogent Core provides tree.Plan, a mechanism for specifying what the children of a widget should be, which is then used to automatically update the actual children to reflect that.

For example, this code uses tree.Plan through core.WidgetBase.Maker to dynamically update the number of buttons in a frame:

Plans are a powerful tool that are critical for some widgets such as those that need to dynamically manage hundreds of children in a convenient and performant way. They aren’t always necessary, but you will find them being used a lot in complicated apps, and you will see more examples of them in the rest of this documentation.

In general, you can see that all of the major steps for configuring Widget elements in core are based on specifying closure functions that are run when needed to perform styling, updating, plan making, etc. Thus, it is important to remember that these functions are not run immediately where they are written, but will be run later in the proper sequence. See advanced updating for more details.