OpenTUI 0.6 removed Renderable.getLayoutNode(). Before 0.6, plugins used it to read the layout styles of host renderables that they did not create. Some plugins saved a container's getMaxWidth() and getAlignSelf() so they could restore the container after they restyled it. Others checked the host layout with getFlexDirection(), or sized a panel inside a padded sidebar with getPadding(). 0.6 kept only getWidth() and getMargin(edge), so this code had nothing to call.
In 0.6.5, renderables have the other style getters of a Yoga Node, with the same names and return types. To move, remove the getLayoutNode() call:
// Before 0.6
const saved = host.getLayoutNode().getMaxWidth()
// 0.6.5
const saved = host.getMaxWidth()These getters return the declared style, not the computed layout. A write shows up at once, before the next layout pass. After box.maxWidth = 40, box.getMaxWidth() returns { unit: Unit.Point, value: 40 }, but box.width still holds the computed width from the last pass. After destroy(), the getters do not throw. They return Yoga's unset values, as getWidth() does.
An edge getter reads only the value set for that exact edge, so this case needs care. The padding option sets Edge.All, paddingX sets Edge.Horizontal, and paddingLeft sets Edge.Left. After padding: 2, getPadding(Edge.Left) returns a Unit.Undefined value, but layout still pads the left side by 2. That is because Yoga falls back from Edge.Left to Edge.Horizontal and then to Edge.All. To get the declared left padding, check the edges in that same order:
import { Edge, Unit } from "@opentui/core/yoga"
const left = [Edge.Left, Edge.Horizontal, Edge.All]
.map((edge) => sidebar.getPadding(edge))
.find((value) => value.unit !== Unit.Undefined)Renderables still have no getter for computed padding, margin, or border. For padding declared in points, the declared value and the computed value are the same.
Added
- core: Renderables have the remaining Yoga
Nodestyle getters, such asgetHeight(),getMaxWidth(),getPadding(edge),getGap(gutter),getFlexDirection(), andgetAlignSelf(). Use them instead of style reads throughgetLayoutNode(). See Layout. (#1667)
API changes and documentation: https://opentui.com/docs/releases/0.6.5
What's Changed
- core: read declared layout styles on renderables by @simonklee in #1667
Full Changelog: v0.6.4...v0.6.5