Class LayoutCss
LayoutManager parameters into the
container-wide CSS a Vaadin host element needs, plus applyContainerCss(Element, String, Map)
which writes a built block onto that element. One-way build + apply — there is
no round-trip back to a LayoutManager (layout is best-effort per R_best_effort_behaviour/R_layouts_close_enough),
so this is deliberately not an S*Convert-shaped pair.
Shared by both modules in the SD_shelper_statics-allowed direction (:emulators →
:surrogates): emulator LayoutManagers route their output through
vaadinx.EHelper.applyContainerCss (a thin forwarder to
applyContainerCss(Element, String, Map)); the surrogate ContainerMixin calls the
builders directly. BoxLayout axis constants are referenced by literal
int (that layout lives in :emulators, which :surrogates
can't depend on); FlowLayout's constants are JDK-side and
referenced by symbol.
Implementation details
Each grid/flex builder writes an explicit value for every key any
sibling builder might have written, not just its own — a JPanel's default ctor
installs FlowLayout (writing flex-wrap / align-items /
justify-content / gap) and other layouts write
grid-template-areas, so a later setLayout(...) that set only its
own keys would inherit stale ones (a leftover flex-wrap: wrap wraps a
BoxLayout column into several visual columns, a leftover named-areas template
pins children into the wrong grid cells). The per-builder reset comments note
only the layout-specific consequence.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe value a layout writes intoPREF_W_VAR/PREF_H_VARto take an axis over:autorestores the container's ownstretch, which sizes the border box (wherewidth: 100%overflows a content-box element by its border).static final StringThe value a layout writes to leave an axis to the child's preferred size.static final StringVertical counterpart ofPREF_W_VAR.static final StringThe custom property through which a child's preferred width reaches CSS, and through which its parent layout overrides it. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidapplyChildCss(com.vaadin.flow.dom.Element target, Map<String, String> css) Apply per-child layout CSS to one child's element — the per-child leg of aCssEmittingLayoutManagerpass.static voidapplyContainerCss(com.vaadin.flow.dom.Element target, String layoutManagerName, Map<String, String> css) Apply a block of layout CSS to a container's host element.borderLayoutCss(int hgap, int vgap) Build the container-wide CSS forBorderLayout.boxLayoutCss(int axis) Build the container-wide CSS forvaadinx.swing.BoxLayout.TheCONTAINER_KEYSunion, for the drift guard inLayoutCssTest.flowLayoutCss(int align, int hgap, int vgap) Build the container-wide CSS forFlowLayout.gridBagLayoutCss(double[] columnWeights, double[] rowWeights) Build the container-wide CSS forvaadinx.awt.GridBagLayout.gridLayoutCss(int nrows, int ncols, int hgap, int vgap) Build the container-wide CSS forvaadinx.awt.GridLayout.groupLayoutCss(String colTemplate, String rowTemplate, int gapPx) Build the container-wide CSS forvaadinx.swing.GroupLayout(D_grouplayout).static StringprefHeight(String fallback) Vertical counterpart ofprefWidth(String).static StringWrap a preferred width in thePREF_W_VARindirection: the value a child writes to its ownwidth, letting its parent layout override the axis without a write ordering between the two.static voidresetContainerCss(com.vaadin.flow.dom.Element target) Drop every container-side layout property fromtarget— the undo forapplyContainerCss(Element, String, Map), called when a container'sLayoutManageris replaced or cleared.sizingCss(boolean layoutSizesWidth, boolean layoutSizesHeight) The per-child half ofD_layout_owns_child_sizing: which axes of one child the parent layout sizes itself, and which it leaves to the child's preferred size.Container CSS for the custom-LayoutManagerfallback: a readable vertical stack.
-
Field Details
-
PREF_W_VAR
The custom property through which a child's preferred width reaches CSS, and through which its parent layout overrides it. SeesizingCss(boolean, boolean)for the two-owner contract;D_layout_owns_child_sizingfor why it exists.- See Also:
-
PREF_H_VAR
-
AXIS_LAYOUT
The value a layout writes intoPREF_W_VAR/PREF_H_VARto take an axis over:autorestores the container's ownstretch, which sizes the border box (wherewidth: 100%overflows a content-box element by its border).- See Also:
-
AXIS_PREF
The value a layout writes to leave an axis to the child's preferred size.initialon a custom property is the guaranteed-invalid value, so the child'svar(--emul-layout-w, <pref>px)falls back to the pref — which is what lets a layout express its whole policy in the variable and never touchwidth.- See Also:
-
-
Method Details
-
applyContainerCss
public static void applyContainerCss(com.vaadin.flow.dom.Element target, String layoutManagerName, Map<String, String> css) Apply a block of layout CSS to a container's host element. Gates on the element being a plain<div>: non-Div hosts get aSHelper.onUnsupportedPeerShape(String, String)ERROR log and no CSS is written — setting aLayoutManageron a surrogate whose element is, say, a<vaadin-button>would corrupt its rendering.nullvalues remove the corresponding style property, mirroring thenull → inherit from parentcontract used elsewhere in the Vaadin-first style layer (seeComponentMixin.setBackground(Color)convention). -
applyChildCss
Apply per-child layout CSS to one child's element — the per-child leg of aCssEmittingLayoutManagerpass. UnlikeapplyContainerCss(Element, String, Map)there is no<div>gate: a child is any element.nullremoves, absent key untouched (same key-by-key contract). -
prefWidth
Wrap a preferred width in thePREF_W_VARindirection: the value a child writes to its ownwidth, letting its parent layout override the axis without a write ordering between the two.nullin,nullout — so a caller whose hint is "no preference" (CssConvert.columnsToCssWidth(int)on zero columns) can pass it straight through to asetWidththat clears the property.- Parameters:
fallback- the CSS length the child prefers, e.g."850px"or"calc(10ch + 2em)"
-
prefHeight
Vertical counterpart ofprefWidth(String). -
sizingCss
The per-child half ofD_layout_owns_child_sizing: which axes of one child the parent layout sizes itself, and which it leaves to the child's preferred size.A preferred size means nothing on its own — AWT's child never sizes itself, and
layoutContainerdecides per axis whether to consult, clamp or ignore the pref (BorderLayoutNORTH takes the container's width and only the pref height;GridLayoutignores both). So the child writes the pref aswidth: var(--emul-layout-w, Npx)and each layout writes the two variables here, one per axis.Both variables are always written,
initialincluded: custom properties inherit, so a child that left one unset would read its ancestor's value — a BorderLayout CENTER panel'sautowould otherwise erase the pref widths of every descendant under an absolute-layout child. The@property … inherits: falseregistrations inemul/emulator-theme.cssare the other half of that defence; this one holds without the stylesheet.- Parameters:
layoutSizesWidth- the layout drives the horizontal axis (pref width ignored)layoutSizesHeight- the layout drives the vertical axis (pref height ignored)
-
containerKeys
-
resetContainerCss
public static void resetContainerCss(com.vaadin.flow.dom.Element target) Drop every container-side layout property fromtarget— the undo forapplyContainerCss(Element, String, Map), called when a container'sLayoutManageris replaced or cleared.Why an undo is needed at all: AWT's
setLayoutonly invalidates, so the new manager's container CSS does not land untilvalidate()/revalidate(). That quirk is faithful and deliberately kept (seevaadinx.awt.FlowLayout#setAlignment) — but a browser makes the un-revalidated interval visible in a way Swing never does: the host keeps the old manager'sdisplay:flexwhile children added under the new manager already carry itsgrid-area, so the container renders scrambled rather than merely un-laid-out. Clearing the container side turns that interval into plain block flow — still stale, like Swing's, but coherent.Per-child CSS is deliberately left alone:
grid-*properties are inert without a grid parent, and clearing them would fightGridBagLayout's deliberate retention of childwidth/height.Silent no-op on a non-
<div>host —applyContainerCss(Element, String, Map)never wrote layout CSS there, so there is nothing to undo and no unsupported shape to report to report. -
verticalFallbackCss
Container CSS for the custom-LayoutManagerfallback: a readable vertical stack. Installed byContainer.doLayoutwhen a container's layout is a hand-rolled pixelLayoutManagerthe emulator can't translate (M1D_custom_layoutmanager). Stretch-fills the cross axis so children stay full-width and nothing clips; resetsgrid-template-areasso a prior grid layout's named cells don't pin children (leftovergrid-template-columns/rowsare inert underdisplay:flex). -
flowLayoutCss
Build the container-wide CSS forFlowLayout.alignmatches FlowLayout's int constants (FlowLayout.LEFT/CENTER/RIGHT/LEADING/TRAILING).LEADING/TRAILINGmap toflex-start/flex-end— thedir="rtl"attribute on the host flips them automatically per Swing's leading/trailing-under-RTL contract. Ports the emulator's existingFlowLayout.layoutContainerbody factored by primitives so both layers (and JDK / emulator FlowLayout flavours) call the same builder. -
boxLayoutCss
Build the container-wide CSS forvaadinx.swing.BoxLayout.axismatches BoxLayout's int constants (X_AXIS=0/Y_AXIS=1/LINE_AXIS=2/PAGE_AXIS=3). LINE_AXIS pins torowand PAGE_AXIS tocolumn— full RTL flipping (row-reverseondir="rtl") would require tracking orientation at layoutContainer time; pinned LTR per R_layouts_close_enough same-shape as BorderLayout's LINE_START / LINE_END caveat. Nogapkey — JDK BoxLayout has no inherent inter-component spacing;Box.createVerticalStrut/createGluecomponents carry that responsibility via their own per-element CSS. Constants referenced by literal int rather than by symbol —vaadinx.swing.BoxLayoutsits in:emulatorsand:surrogatescan't depend on it. -
borderLayoutCss
Build the container-wide CSS forBorderLayout. Per- childgrid-areawrites happen separately in the layout'saddLayoutComponent(see:emulators.BorderLayout); this helper just handles the grid setup. -
gridBagLayoutCss
Build the container-wide CSS forvaadinx.awt.GridBagLayout.columnWeightsandrowWeightscarry the per-track weight, max-aggregated across each track's children — JDK GridBagLayout's "any non-zero weight in a column makes that column absorb extra space" rule. A non-zero weight maps toNfr(normalised so the sum of fr units across tracks reads naturally — we just use the raw weight as the fr count, which preserves the relative-ratio contract); a zero weight maps toautoso the track sizes to its content.minmax(0, …)on fr tracks lets them shrink below intrinsic size when the grid is height-bounded — BorderLayout CENTER precedent.hgap/vgapwrite throughgap(column-gap row-gap shorthand). JDK GridBagLayout has no hgap/vgap of its own — spacing comes from per-childInsets. We pin gap to0here; all spacing rides on per-child margin (insets) / padding (ipadx/ipady) writes fromGridBagLayout.layoutContainer.Per-child
grid-row/grid-column/justify-self/align-self/margin/padding/min-*writes happen separately in the layout'sapplyChildConstraintsCss; this helper just handles the grid setup. Resets flex-era keys for the same reason borderLayoutCss does — JPanel's default ctor installs FlowLayout and a setLayout(GridBagLayout) follow-up would otherwise leave them behind. -
gridLayoutCss
Build the container-wide CSS forvaadinx.awt.GridLayout.nrows/ncolsare the resolved grid dimensions — GridLayout fixes one dimension and derives the other from the live child count, so the emulator does that arithmetic and passes the final numbers here. All cells are equal:repeat(N, 1fr)on both axes, matching JDK GridLayout's "divide the container into equal-sized rectangles" contract. Children auto-place row-major (grid-auto-flow: row, the CSS default) which reproduces GridLayout's left-to-right, top-to-bottom fill without any per-child placement.align-items/justify-items: stretchmakes each child fill its cell — GridLayout resizes every component to the cell size (unlike FlowLayout, which uses preferred sizes).hgap/vgapwrite throughgap(row-gap column-gap shorthand:vgapis the space between rows,hgapbetween columns). Resets the flex-era keys andgrid-template-areasper the class-doc reset rule.nrows/ncolsare clamped to at least 1 by the caller sorepeat(0, 1fr)— invalid CSS — can never be emitted for an empty container. -
groupLayoutCss
Build the container-wide CSS forvaadinx.swing.GroupLayout(D_grouplayout). The emulator reconstructs a CSS grid from GroupLayout's two axis group-trees and passes the finishedrepeat/autotrack templates here (colTemplate/rowTemplate), each a space-separated track list where content-sized tracks areautoand resizable tracks areminmax(0, 1fr).align-items/justify-items: startis the default cell anchoring — GroupLayout'sLEADINGalignment — with per-childalign-self/justify-selfoverrides written by the emulator from each component's effective parallel-group alignment.align-content/justify-content: startkeeps the whole track group top-left anchored (resetting anyjustify-content: centerleft over from a JPanel's default FlowLayout, which on a grid would center the tracks).gapPxis a single uniform inter-track gap approximating GroupLayout's per-gap spacing — GroupLayout's gaps don't map to grid tracks in the reconstruction (R_layouts_close_enough; exact per-gap sizing is the deferred pixel-accurate layout is out of scope permanently, D_pixel_layout_not_planned).grid-template-areasis cleared per the class-doc reset rule.
-