SquareBracketAssociates / BuildingApplicationWithSpec2

A book to build user interfaces using the Spec 2.0 framework.
21 stars 12 forks source link

Important point on Layout #103

Closed Ducasse closed 2 months ago

Ducasse commented 4 months ago

Hi koen

Guille told me the following and I try to understand it :) @guillep

To optimize the speed once the settings browser is open we should build the layout before setting it to avoid too many rebuild: This boils down to building the children and then adding them to your dynamic layout.

| layout |
layout := SpBoxLayout new.
"50 times"
layout add: [bla bla bla]
myPresenter (self) layout: layout

In the case you build a tree of presenters, build the tree bottoms-up, first the leaves, then bubbling up in the tree.

Ducasse commented 4 months ago

In fact, this is more general: when you update a layout that is already visible, it is preferable to do the update in one step. It will only recompute the layout one time. It is doable when you have nested layouts: you create layouts (not visible, e.g. SpBoxLayout newTopToBottom ad: …) starting from leafs, and then go up until all layouts are ready. Then you set the top layout to the currently visible layout, e.g. visiblePresenter layout: myNewlyCreatedLayout

koendehondt commented 4 months ago

It is something to mention in the book.

I never saw the problem, because I always build layouts bottom-up 😄.

Ducasse commented 3 months ago

TODO: add "Pay attention" to chapter on Dynamic Presenters.