Class MarbleDensity
Density in Marble is a declarative knob: a data-density attribute
that overrides the semantic-layer size tokens (input height, row height, cell
padding, button/toolbar/tab heights, …). Because those are the tokens the
components actually read, the attribute takes effect at any scope —
the document root for the whole app, or a single component subtree for one
region. See doc/spec/data-dense-mode.md.
This helper exposes that knob from Java:
apply(Density)— whole app. The attribute is set on the document root (<html>), which is not a ZK component, so this goes throughClients.evalJavaScript(String).apply(Component, Density)— one region. Uses ZK's nativeComponent.setClientDataAttribute(String, String)(no JavaScript string), which re-renders that subtree when the value changes.
When to use this vs. the library property. This API is for runtime
switching (a user flipping a density preference). For a fixed whole-app
default, prefer the org.zkoss.theme.marble.density library property
in zk.xml, which renders data-density on <html> with the page.
The property applies only when ZK renders the whole HTML document (a top-level ZUL
page); a .zhtml page, a <?page complete="true"?> page or an included
page owns its <html> tag, so put data-density there instead. Calling
apply(Density) on page load runs after the first paint and can cause
a brief comfortable→compact flash (FOUC).
- Since:
- 11.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe density a scope is rendered at. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidapply(org.zkoss.zk.ui.Component scope, MarbleDensity.Density density) Applies the density to a single component subtree by settingdata-densityon that component's DOM element.static voidapply(MarbleDensity.Density density) Applies the density to the whole application by settingdata-densityon the document root (<html>).
-
Method Details
-
apply
Applies the density to the whole application by settingdata-densityon the document root (<html>). Covers body-appended popups (menus, modal windows, notifications) too, since they inherit from the root.Must run within an active ZK execution (e.g. inside an event listener or MVVM command) so the client update can be sent.
- Parameters:
density- the density to apply; nevernull.
-
apply
Applies the density to a single component subtree by settingdata-densityon that component's DOM element. Use this to make one region (e.g. a data-dense grid panel) compact while the rest of the app stays comfortable; it nests and can be overridden by a closer descendant.- Parameters:
scope- the component whose subtree should adopt the density.density- the density to apply; nevernull.
-