View

The base view class for building UI layouts in Ceramic.

View extends Layer and adds sophisticated layout capabilities:

  • Flexible sizing with fixed, percentage, fill, and auto modes
  • Padding and offset support
  • Border rendering with customizable colors and sizes
  • Automatic layout computation and propagation
  • Integration with the view layout system

Views can be composed hierarchically to create complex UI layouts. The layout system automatically computes sizes based on constraints and propagates changes through the view tree.

Key concepts:

  • viewWidth/viewHeight: Define how the view should be sized
  • computedSize: The actual size after layout computation
  • padding: Inner spacing that affects content placement
  • offset: Position adjustment relative to default layout position
  • flex: Relative sizing weight for flexible layouts
var container = new View();
container.viewSize(ViewSize.fill(), 200); // Full width, 200px height
container.padding(10); // 10px padding on all sides
container.borderSize = 2;
container.borderColor = Color.WHITE;
See: LinearLayout For arranging views in rows/columns, LayersLayout For stacking views, ViewSize For sizing options

Static Members

ui
requestLayout(): Void

Request a layout update for all views in the next frame. This is called automatically when view properties change. Multiple calls are batched into a single layout pass.

view.width = 200; // Automatically calls requestLayout()
View.requestLayout(); // Manual call if needed

Instance Members

ui
subviews: ReadOnlyArray<View>

Same as children but typed as a list of View instances instead of Visual. Only contains children that are of View type, making it convenient for layout operations that only affect View children.


ui
computedSize: ComputedViewSize

ComputedSize after being computed by View layout engine from constraints and viewWidth/viewHeight. This represents the actual dimensions the view will have after layout computation, which may differ from explicitly set dimensions due to constraints.


ui
viewWidth: ViewSize

Width that will be processed by View layout engine. Options:

  • Numeric value: Fixed width in pixels
  • ViewSize.percent(n): Percentage of parent width
  • ViewSize.fill(): Fill available parent width
  • ViewSize.auto(): Size based on content Default: ViewSize.auto()

ui
viewHeight: ViewSize

Height that will be processed by View layout engine. Options:

  • Numeric value: Fixed height in pixels
  • ViewSize.percent(n): Percentage of parent height
  • ViewSize.fill(): Fill available parent height
  • ViewSize.auto(): Size based on content Default: ViewSize.auto()

ui
paddingLeft: Float

Left padding in pixels. Space between the left edge and content. Default: 0


ui
paddingRight: Float

Right padding in pixels. Space between the right edge and content. Default: 0


ui
paddingTop: Float

Top padding in pixels. Space between the top edge and content. Default: 0


ui
paddingBottom: Float

Bottom padding in pixels. Space between the bottom edge and content. Default: 0


ui
offsetX: Float

Horizontal offset in pixels. This offset is added to the view's X position after layout computation. Only affects views in layouts that support offsets (LinearLayout, LayersLayout). Default: 0


ui
offsetY: Float

Vertical offset in pixels. This offset is added to the view's Y position after layout computation. Only affects views in layouts that support offsets (LinearLayout, LayersLayout). Default: 0


ui
flex: Int

Flex weight for flexible layouts. Determines how much space this view should take relative to siblings. Only used in layouts that support flex distribution (e.g., LinearLayout).

// Three views in a horizontal layout:
view1.flex = 1; // Takes 1/6 of space
view2.flex = 2; // Takes 2/6 of space
view3.flex = 3; // Takes 3/6 of space

Default: 1


ui
canLayout: Bool

Controls whether this view participates in layout updates. Set to false to temporarily prevent layout computation. Useful for optimization when making multiple changes. Default: true (after initialization)


ui
layoutDirty: Bool

Indicates whether this view needs layout recomputation. Automatically set to true when properties affecting layout change. The layout system will process dirty views in the next update cycle.


ui
borderDepth: Float

Z-depth of the border visual. Controls rendering order relative to view content. Default: 0


ui
borderAlpha: Float

Alpha transparency of the border (0.0 to 1.0). Default: 1 (fully opaque)


ui
borderPosition: Anonymous

Position of the border relative to view bounds.

  • INSIDE: Border is drawn inside the view bounds
  • OUTSIDE: Border is drawn outside the view bounds
  • CENTER: Border is centered on the view edge Default: INSIDE

ui
borderSize: Float

Border thickness in pixels for all sides. Set to 0 to hide the border. Individual side sizes can override this value. Default: 0


ui
borderTopSize: Float

Top border thickness in pixels. Set to -1 to use borderSize value. Default: -1


ui
borderBottomSize: Float

Bottom border thickness in pixels. Set to -1 to use borderSize value. Default: -1


ui
borderLeftSize: Float

Left border thickness in pixels. Set to -1 to use borderSize value. Default: -1


ui
borderRightSize: Float

Right border thickness in pixels. Set to -1 to use borderSize value. Default: -1


ui
borderColor: Color

Border color for all sides. Individual side colors can override this value. Default: Color.GRAY


ui
borderTopColor: Color

Top border color. Set to Color.NONE to use borderColor value. Default: Color.NONE


ui
borderBottomColor: Color

Bottom border color. Set to Color.NONE to use borderColor value. Default: Color.NONE


ui
borderLeftColor: Color

Left border color. Set to Color.NONE to use borderColor value. Default: Color.NONE


ui
borderRightColor: Color

Right border color. Set to Color.NONE to use borderColor value. Default: Color.NONE


ui
parentView: Null<View>

The parent View of this view. Returns customParentView if set, otherwise checks if the visual parent is a View. This property is crucial for layout propagation.


ui
viewSize(width: ViewSize, height: ViewSize): Void

Set viewWidth and viewHeight in a single call.

Name Type Description
width ViewSize The width sizing mode
height ViewSize The height sizing mode

ui
padding(top: Float, ?right: Float, ?bottom: Float, ?left: Float): Void

Set padding using CSS-style shorthand. Padding creates space inside the view between its edges and content.

Name Type Default Description
top Float Top padding (or all sides if only parameter)
right Float (optional) Right padding (or horizontal if 2 params)
bottom Float (optional) Bottom padding (or bottom if 3+ params)
left Float (optional) Left padding * haxe padding(10); // All sides: 10px padding(10, 20); // Vertical: 10px, Horizontal: 20px padding(10, 20, 30); // Top: 10px, Horizontal: 20px, Bottom: 30px padding(10, 20, 30, 40); // Top: 10px, Right: 20px, Bottom: 30px, Left: 40px

ui
offset(x: Float, y: Float): Void

Offset this view position by x and y. This offset is added to the view's resulting position from its default layout. This has only effect when the view is layouted by a layout class that handle offsets: LinearLayout, LayersLayout. Useful for fine-tuning positions without breaking the layout flow.

Name Type Description
x Float Horizontal offset in pixels
y Float Vertical offset in pixels

ui
persistComputedSize(parentWidth: Float, parentHeight: Float, parentLayoutMask: ViewLayoutMask, computedWidth: Float, computedHeight: Float): ComputedViewSize
Name Type
parentWidth Float
parentHeight Float
parentLayoutMask ViewLayoutMask
computedWidth Float
computedHeight Float
Returns
ComputedViewSize

ui
assignComputedSize(computedWidth: Float, computedHeight: Float): ComputedViewSize
Name Type
computedWidth Float
computedHeight Float
Returns
ComputedViewSize

ui
hasPersistentComputedSizeWithContext(parentWidth: Float, parentHeight: Float, parentLayoutMask: ViewLayoutMask): Bool
Name Type
parentWidth Float
parentHeight Float
parentLayoutMask ViewLayoutMask
Returns
Bool

ui
resetComputedSize(?recursive: Bool = false): Void
Name Type Default
recursive Bool false

ui
shouldResetComputedSize(): Bool
Returns
Bool

ui
layoutDependsOnParent(): Bool
Returns
Bool

ui
add(visual: Visual): Void
Name Type
visual Visual

ui
remove(visual: Visual): Void
Name Type
visual Visual

ui
autorun(run: Function, ?afterRun: Function): tracker.Autorun

Creates a new Autorun instance with the given callback associated with the current entity.

Name Type Default Description
run Function The run callback
afterRun Function (optional)
Returns Description
tracker.Autorun The autorun instance

ui
destroy(): Void

ui
removeAllViews(): Void

Remove all child views from this view. This is more efficient than removing views one by one. Only affects View children, not other Visual types.


ui
autoComputeSize(?applyComputedSize: Bool = false): Void

Compute the view's size based on its sizing modes and constraints. This forces a size computation even if the view is not dirty.

Name Type Default Description
applyComputedSize Bool false if true, immediately apply the computed size using size() * haxe view.viewSize(ViewSize.auto(), ViewSize.fill()); view.autoComputeSize(true); // Computes and applies size

ui
autoComputeSizeIfNeeded(?applyComputedSize: Bool = false): Void

Compute the view's size only if it hasn't been computed for the current context. More efficient than autoComputeSize() as it avoids redundant calculations.

Name Type Default Description
applyComputedSize Bool false if true, immediately apply the computed size using size()

ui
applyComputedSize(): Void

Apply the computed size to the view's actual width and height. This is equivalent to size(computedSize.computedWidth, computedSize.computedHeight). Does nothing if no computed size is available.


ui
computeSizeWithIntrinsicBounds(parentWidth: Float, parentHeight: Float, layoutMask: ViewLayoutMask, persist: Bool, intrinsicWidth: Float, intrinsicHeight: Float): Float

Compute size while maintaining aspect ratio of intrinsic bounds. Useful for images, videos, or any content with a natural aspect ratio.

Name Type Description
parentWidth Float Available width from parent
parentHeight Float Available height from parent
layoutMask ViewLayoutMask Constraints on how the view can be sized
persist Bool Whether to persist the computed size for reuse
intrinsicWidth Float Natural width of the content
intrinsicHeight Float Natural height of the content
Returns Description
Float Scale factor applied to fit the content

ui
computeSizeIfNeeded(parentWidth: Float, parentHeight: Float, layoutMask: ViewLayoutMask, persist: Bool): Void
Name Type
parentWidth Float
parentHeight Float
layoutMask ViewLayoutMask
persist Bool

ui
computeSize(parentWidth: Float, parentHeight: Float, layoutMask: ViewLayoutMask, persist: Bool): Void

Core size computation method. Calculates the view's dimensions based on its sizing mode and parent constraints.

Name Type Description
parentWidth Float Available width from parent container
parentHeight Float Available height from parent container
layoutMask ViewLayoutMask Constraints defining how the view can grow/shrink
persist Bool Whether to cache the result for the given context

ui
bindToScreenSize(?factor: Float = 1.0): Void

Bind this view's size to the screen dimensions. The view will automatically resize when the screen size changes.

Name Type Default Description
factor Float 1.0 Scale factor to apply to screen dimensions (default: 1.0) * haxe view.bindToScreenSize(); // Full screen size view.bindToScreenSize(0.5); // Half screen size

ui
bindToTargetSize(): Void

Bind this view's size to the target resolution defined in settings. Useful for maintaining consistent UI across different screen sizes. The view will automatically resize when target settings change.


ui
percent(value: Float): Float

Create a percentage-based ViewSize value.

Name Type Description
value Float Percentage (0-100)
Returns Description
Float Encoded percentage value for use with viewWidth/viewHeight

ui
percentToFloat(encoded: Float): Float
Name Type
encoded Float
Returns
Float

ui
fill(): Float

Create a fill ViewSize value. The view will fill all available space in its parent.

Returns Description
Float Fill size constant

ui
auto(): Float

Create an auto ViewSize value. The view will size itself based on its content.

Returns Description
Float Auto size constant

ui
new(): Void

Create a new View. Initializes the view with sensible defaults and registers it with the ViewSystem. Layout computation is deferred until after initialization to prevent premature calculations.

Private Members

ui
border: Border

Internal border visual component. Created on demand when border properties are set.


ui
persistedComputedSizes: Array<ComputedViewSize>

ui
customParentView: Null<View>

Custom parent view override. Used by containers like ScrollView to establish parent-child relationships without actual visual hierarchy changes.


ui
emitLayout(): Void

Emitted when the view's layout is computed. This happens after size computation and before visual positioning.


ui
shouldDisplayBorder(): Bool

Check if any border should be displayed based on size settings.

Returns Description
Bool true if any border side has a size > 0

ui
initBorder(): Void

Create and initialize the border visual component. Called automatically when border properties are set.


ui
updateBorder(): Void

Update or create the border visual based on current properties. Handles border creation, updates, and cleanup when no border is needed.


ui
persistedComputedSizeForContext(parentWidth: Float, parentHeight: Float, parentLayoutMask: ViewLayoutMask): Null<ComputedViewSize>
Name Type
parentWidth Float
parentHeight Float
parentLayoutMask ViewLayoutMask
Returns
Null<ComputedViewSize>

ui
willEmitLayout(): Void

Called just before emitting the layout event. Updates borders and calls the layout() method.


ui
layout(): Void

Perform layout operations for this view. Override this method in subclasses to implement custom layout logic. Called after size computation and before the layout event is emitted.

Common operations in layout():

  • Position child views
  • Update visual components
  • Apply computed dimensions

Metadata

Name Parameters
:build tracker.macros.EventsMacro.build()
:autoBuild tracker.macros.EventsMacro.build()
:build ceramic.macros.EntityMacro.buildForCompletion()
:autoBuild ceramic.macros.EntityMacro.buildForCompletion()