Dimensions, padding, gaps, and growth factors must be finite and nonnegative. Minimum dimensions cannot exceed their maximum. Refract uses logical pixels and has no margin modifier.
Method
Behavior
padding(impl Into<Insets>)
Adds a wrapper with uniform f32 padding or explicit Insets. Insets::symmetric(horizontal, vertical) configures pairs of edges.
frame(width: f32, height: f32)
Adds a wrapper with fixed dimensions.
width(f32), height(f32)
Sets a dimension on the current outer element.
min_width(f32), max_width(f32)
Constrains width.
min_height(f32), max_height(f32)
Constrains height.
fill_width(), fill_height()
Requests available space from the parent.
grow(f32)
Sets the relative growth factor within the parent layout.
Adds an indicator while this element or a descendant is focused. Ancestor clips still apply.
shadow(BoxShadow)
Adds a single outer rounded-box shadow.
opacity(f32)
Sets opacity in the inclusive range 0–1.
clipped()
Clips content to the element's bounds.
z_index(i32)
Sets sibling stacking order on web and native. Higher values paint in front and receive pointer input first; equal values retain declaration order. Defaults to zero; negative values are supported. Apply after structural wrappers to order the whole view.
Typography belongs to Text and Field, truncation to Text, and image fitting to Image. These are concrete builder methods, not blanket ViewExt methods. Configure them before structural wrappers or type erasure.
These modifiers describe mounted identity, shared values, or semantic information. They are available to composed views as well as primitives.
Method
Behavior
key(impl ToString)
Returns KeyView with a sibling-local identity. Use stable keys when children reorder.
memo<T: PartialEq + 'static>(props: T)
Returns MemoView. Reuses the subtree when explicit props and provider scope match; reactive dependencies can still invalidate it.
environment<K: EnvironmentKey>(K::Value)
Returns Provided with a typed value for the subtree.
environment_object<T: 'static>(Rc<T>)
Provides a shared model by identity for cx.object() reads.
label(impl Into<String>)
Sets a semantic label on the current outer element (aria-label on web), and also sets alternative text on images. For Field, use its label builder to label the editable control directly.
geometry_tag(impl Into<String>)
Includes the element in tagged geometry snapshots for spatial interactions. Read them through ActionContext::tagged_geometry() during pointer and scroll dispatch; see element geometry. Preserves concrete builders and targets the current outer element after wrappers.
Shared event methods preserve concrete builder types. Callbacks receive &mut ActionContext first; use cx.runtime() to update bindings. Multiple callbacks of the same family run in registration order. See Input & Focus for payloads, propagation, default prevention, and pointer capture.
Canvas pointer callbacks can use cx.local_position(event.position) and cx.local_bounds() to observe the current handler's border-box geometry. These are context methods, not view modifiers; see local coordinates.
Field also provides on_input and on_submit; ScrollView provides on_scroll. Configure those on their concrete builders before adding structural wrappers.
Method
Behavior
on_key(action)
Receives &KeyEvent for key down and up before native defaults. Bubbles through mounted ancestors.
on_pointer(action)
Receives &PointerEvent for down, move, up, cancel, enter, and leave. Down, move, up, and cancel bubble; enter and leave are targeted.
on_hover(action)
Receives bool when the mouse or pen enters or leaves the element and its descendants. Touch does not produce hover callbacks.
on_focus_change(action)
Receives bool for confirmed direct focus changes. Focus on a descendant does not focus its ancestor.
on_focus_within_change(action)
Receives bool when confirmed focus enters or leaves this element or its subtree. Moving between children does not blur their common ancestors.
on_wheel(action)
Receives &WheelEvent before host scrolling. Bubbles; prevent the default to suppress scrolling. See wheel input.
on_clipboard(action)
Receives &ClipboardEvent for copy, cut, and paste, including host edit-menu commands. Bubbles; see clipboard commands for synchronous content and default handling.
Focus uses ordinary graph bindings. These methods preserve concrete primitives, fields, and scroll views; the ViewExt fallback returns Modified and targets the current outer element. Attach a field's binding before padding or framing it. See Input & Focus for examples and host behavior.
A binding requests focus after commit and receives the actual host selection. Bindings do not add tab stops. Each binding/value must identify one mounted target; invalid requests reconcile to actual focus, while duplicate attachments and conflicting requests report errors.
Method
Behavior
focused(Binding<bool>)
Binds direct focus on one element. true requests focus; false only blurs the target when this binding owns focus.
focused_value<T>(Binding<Option<T>>, T)
Associates an element with a shared selection value. T: Clone + PartialEq + 'static. Some(value) requests that element; None clears focus owned by the selection.
focusable(bool)
Controls Tab participation without adding button semantics. Fields and activation targets default to included. false retains pointer and programmatic focus.
i
Use on_focus_change for direct observation and on_focus_within_change for subtree observation. Use focus_ring or focus_within for built-in paint, or update ordinary state in callbacks to change other properties.
on_press and disabled are shared ViewExt methods. They work before or after styling on view, text, and images. Equivalent builders preserve the concrete primitive or scroll type so child, semantic, and scroll configuration can continue.
Text and images retain their host element. Opaque views receive an outer activation box; their content must not contain another interactive control. Existing roles are preserved; otherwise the target receives button semantics. Activation is targeted and is not an editable-control event hook.
On the web, activation targets and their labels suppress user text selection, including when disabled. This prevents repeated clicks from selecting button text. Ordinary text outside an activation target remains selectable in the browser; editable fields retain their selection behavior.
Method
Behavior
on_press(action)
Adds pointer-click and Enter/Space keyboard activation. The callback receives &mut ActionContext. Multiple callbacks run in registration order in one mutation batch, preserving other handlers such as scroll observers.
disabled(bool)
Suppresses user input and keyboard focus traversal on the current element, not its descendants. Focus-loss notifications still run. The element remains in layout.
i
Apply on_press after padding to include the padded area, or before it to target only the content. Apply disabled to the same target. For typed keyboard and pointer events, hover, focus, and bubbling, see Input & Focus.
Shared modifiers act on the current outer element. See Layout & Style for composition examples and paint effects for gradients, blur, and borders.
Modifier group
Target and return type
Dimensions, paint, labels, and disabled state
Preserve element builders, including Canvas<I>. ShapeView<S> uses ViewExt wrappers; configure its fill and stroke first.
Canvas, shader, and shape configuration
view_box, schedule, and animatable_inputs preserve Canvas<I>. schedule and animatable_inputs preserve ShaderView. fill, no_fill, and stroke preserve ShapeView<S>. Configure these before wrappers.
padding, frame
Always add a box wrapper and return Modified. Later paint modifiers target that wrapper.
Typography and image fitting
Configure Text / Field typography or Image fitting before introducing a wrapper.
ViewExt on composed views
Modifies a direct element description when available; otherwise adds a box. Shared style methods return Modified.
Transforms change presentation without changing layout allocation. They compose around the configured anchor; displayed drawing, clipping, and hit testing follow the result. See Animation.
Method
Behavior
offset(x: f32, y: f32)
Translates by logical pixels.
scale_effect(scale: f32)
Scales both axes uniformly.
rotation_effect(degrees: f32)
Rotates around the anchor, in degrees.
transform_anchor(UnitPoint)
Sets the normalized anchor; the default is UnitPoint::CENTER.
Apply canvas-, shader-, and shape-specific methods before these wrappers. Animation intent controls presentation updates, including opted-in canvas inputs and shader uniforms; it does not turn on a continuous drawing clock. See Animation for transactions, interruptions, and supported properties.
These methods belong to concrete drawing builders, not blanket ViewExt. Configure them before wrapper modifiers. Canvas dimensions, paint, and typed event callbacks preserve Canvas<I>; shared style modifiers on ShapeView<S> wrap it, so set fill and stroke before width or height.
GraphicsContext operations such as clipped, transformed, and layer act inside a drawing callback. Layer::blur and Layer::opacity affect that drawing group; the shared view blur and opacity modifiers affect the outer view and its descendants.
Fits logical drawing bounds into the allocated content box, centered and preserving aspect ratio. Width and height must be positive and all values finite. This changes drawing coordinates, not layout size; use width and height to allocate space.
Chooses OnChange (the default), Animation, or Paused. OnChange draws at time zero when inputs or size change. Animation advances visible elapsed time and requests frames. Paused freezes elapsed time while still allowing input and size updates. CanvasSchedule::animation() constructs Animation.
Opts prepared inputs into existing animation transactions. A subsequent update needs animation intent, such as with_animation; this method alone starts no motion. Built-in inputs include f32, f64, Point, Size, Color, and pairs of Animatable values. Without this modifier, prepared inputs update immediately.
Sets the shape's fill to a solid Color or a Paint gradient. Shapes start with a black fill. Filling does not remove an existing stroke; the fill is drawn first.
Sets the outline paint and stroke style. Width uses logical pixels; caps, joins, dashes, and dash offset come from StrokeStyle. Strokes are centered on the path, and ink outside the canvas content box is clipped. This does not remove the fill or inset the geometry.
These methods belong to ShaderView, returned by shader and shader_with. Configure them before wrapper modifiers. Shared dimensions, paint, labels, and typed events preserve the concrete shader builder.
Shader::uniform, image, and fallback configure the program and its inputs before it becomes a view. They are not view modifiers. Shader views have no view_box; use ShaderFrame.position, size, and uv in WGSL. See Shaders for source, image, and fallback usage.
Chooses OnChange (the default), Animation, or Paused. OnChange renders at time zero when inputs or dimensions change. Animation advances visible time and requests frames; Paused retains the clock phase while still accepting input and size updates. ShaderSchedule aliases CanvasSchedule and follows its visibility and reduced-motion policy.
Opts bound scalar and vector uniforms into animation transactions. Use with_animation or a value-scoped animation wrapper to supply animation intent. Keep bound names and vector dimensions stable. Images and fallback colors switch immediately. Uniform transitions can continue while the shader clock is paused.