Skip to main content

Code

Struct Code 

Source
pub struct Code { /* private fields */ }
Expand description

Read-only code block widget

For editable code, use code_editor() instead.

Implementations§

Source§

impl Code

Source

pub fn new(content: impl Into<String>) -> Code

Source

pub fn line_numbers(self, enabled: bool) -> Code

Source

pub fn syntax(self, config: SyntaxConfig) -> Code

Source

pub fn font_size(self, size: f32) -> Code

Source

pub fn line_height(self, multiplier: f32) -> Code

Source

pub fn padding(self, padding: f32) -> Code

Source

pub fn code_bg(self, color: Color) -> Code

Source

pub fn text_color(self, color: Color) -> Code

Source

pub fn w(self, px: f32) -> Code

Source

pub fn h(self, px: f32) -> Code

Source

pub fn w_full(self) -> Code

Source

pub fn rounded(self, radius: f32) -> Code

Source

pub fn border(self, width: f32, color: Color) -> Code

Source

pub fn m(self, value: f32) -> Code

Source

pub fn mt(self, value: f32) -> Code

Source

pub fn mb(self, value: f32) -> Code

Methods from Deref<Target = Div>§

Source

pub fn element_id(&self) -> Option<&str>

Get the element ID if set

Source

pub fn classes(&self) -> &[Arc<str>]

Get the element’s class list

Source

pub fn stateful_context_key(&self) -> Option<&str>

Get the stateful context key if set

Source

pub fn swap(&mut self) -> Div

Swap this Div with a default, returning the original

This is a convenience method for use in state callbacks where you need to consume self to chain builder methods, then assign back.

Note: This takes ownership of the current Div and leaves a default in its place. All properties are preserved in the returned Div. You must assign the result back to complete the update.

For updating specific properties without the swap pattern, consider using the setter methods directly (e.g., set_bg(), set_transform()).

§Example
ⓘ
.on_state(|state, div| match state {
    ButtonState::Idle => {
        *div = div.swap().bg(Color::BLUE).rounded(4.0);
    }
    ButtonState::Hovered => {
        *div = div.swap().bg(Color::CYAN).rounded(8.0);
    }
})
Source

pub fn set_bg(&mut self, color: impl Into<Brush>)

Set the background color/brush without consuming self

This is useful in state callbacks where you want to update properties without using the swap pattern.

Source

pub fn set_rounded(&mut self, radius: f32)

Set the corner radius without consuming self

Source

pub fn set_transform(&mut self, transform: Transform)

Set the transform without consuming self

Source

pub fn set_shadow(&mut self, shadow: Shadow)

Set the shadow without consuming self (replaces any existing stack).

Source

pub fn set_shadow_stack(&mut self, shadows: Vec<Shadow>)

Set a compound shadow stack without consuming self.

Source

pub fn set_opacity(&mut self, opacity: f32)

Set the opacity without consuming self

Source

pub fn set_border(&mut self, width: f32, color: Color)

Set border with width and color without consuming self

Source

pub fn set_overflow_clip(&mut self, clip: bool)

Set overflow clip without consuming self

Source

pub fn set_padding_x(&mut self, px: f32)

Set horizontal padding without consuming self

Source

pub fn set_padding_y(&mut self, px: f32)

Set vertical padding without consuming self

Source

pub fn set_child(&mut self, child: impl ElementBuilder + 'static)

Clear all children and add a single child

Source

pub fn clear_children(&mut self)

Clear all children

Source

pub fn set_w(&mut self, px: f32)

Set width in pixels without consuming self

This is useful in state callbacks where you want to update layout properties without using the swap pattern.

Source

pub fn set_h(&mut self, px: f32)

Set height in pixels without consuming self

Source

pub fn set_h_auto(&mut self)

Set height to auto without consuming self

Source

pub fn set_style(&mut self, style: &ElementStyle)

Apply an ElementStyle without consuming self

This is useful in state callbacks where you want to update styling without using the swap pattern.

§Example
ⓘ
.on_state(|state, div| {
    div.set_style(&hover_style);
})
Source

pub fn merge(&mut self, other: Div)

Merge properties from another Div into this one

This applies the other Div’s non-default properties on top of this one. Useful in on_state callbacks to apply changes without reassignment:

ⓘ
.on_state(|state, div| {
    div.merge(div().bg(color).child(label));
})
Source

pub fn style_mut(&mut self) -> &mut Style

Get direct access to the taffy style for advanced configuration

Source

pub fn event_handlers(&self) -> &EventHandlers

Get a reference to the event handlers

Source

pub fn event_handlers_mut(&mut self) -> &mut EventHandlers

Get a mutable reference to the event handlers

Trait Implementations§

Source§

impl Deref for Code

Source§

type Target = Div

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<Code as Deref>::Target

Dereferences the value.
Source§

impl DerefMut for Code

Source§

fn deref_mut(&mut self) -> &mut <Code as Deref>::Target

Mutably dereferences the value.
Source§

impl ElementBuilder for Code

Source§

fn build(&self, tree: &mut LayoutTree) -> LayoutNodeId

Build this element into a layout tree, returning the node ID
Source§

fn render_props(&self) -> RenderProps

Get the render properties for this element
Source§

fn children_builders(&self) -> &[Box<dyn ElementBuilder>]

Get children builders (for recursive traversal)
Source§

fn element_type_id(&self) -> ElementTypeId

Get the element type identifier
Source§

fn semantic_type_name(&self) -> Option<&'static str>

Semantic HTML-like tag name for CSS type selectors (e.g., “button”, “a”, “ul”) Read more
Source§

fn event_handlers(&self) -> Option<&EventHandlers>

Get event handlers for this element Read more
Source§

fn layout_style(&self) -> Option<&Style>

Get the layout style for this element Read more
Source§

fn element_classes(&self) -> &[Arc<str>]

Get the element’s CSS class list for selector matching. Read more
Source§

fn element_id(&self) -> Option<&str>

Get the element ID for selector API queries Read more
Source§

fn as_any(&self) -> Option<&(dyn Any + 'static)>

Downcast handle, for a container that must read typed structure from its own children rather than just render them. Read more
Source§

fn text_render_info(&self) -> Option<TextRenderInfo>

Get text render info if this is a text element
Source§

fn styled_text_render_info(&self) -> Option<StyledTextRenderInfo>

Get styled text render info if this is a styled text element (rich_text)
Source§

fn svg_render_info(&self) -> Option<SvgRenderInfo>

Get SVG render info if this is an SVG element
Source§

fn image_render_info(&self) -> Option<ImageRenderInfo>

Get image render info if this is an image element
Source§

fn canvas_render_info( &self, ) -> Option<Rc<dyn Fn(&mut dyn DrawContext, CanvasBounds)>>

Get canvas render info if this is a canvas element
Source§

fn is_static_canvas(&self) -> bool

Whether this canvas’s render_fn produces deterministic output for a given bounds + closure captures, with no per-frame state (animations, timers, live signal reads). Static canvases get emitted to the bg batch normally but skip the per-frame overlay re-paint that would otherwise overdraw any children the walker layered on top of them in the static cache. They also don’t flip the had_canvas_painted gate, so the compositor fast path can still engage on frames where the only canvases are static. Read more
Source§

fn canvas_redraw_while(&self) -> Option<Rc<dyn Fn() -> bool>>

See crate::canvas::Canvas::redraw_while. Applies only when element_type_id is ElementTypeId::Canvas.
Source§

fn effective_layout_style(&self) -> Option<Style>

The taffy Style that this element actually installs on its layout node — i.e. the style after any widget-internal adjustments build() would apply. The default delegates to layout_style().cloned(), which is correct for elements whose build() just forwards self.style verbatim. Override when build() mutates the style before handing it to taffy (e.g. Notch::build adds scoop.depth to padding so children don’t render over the carved-out region). Read more
Source§

fn scroll_info(&self) -> Option<ScrollRenderInfo>

Get scroll render info if this is a scroll element
Source§

fn scroll_physics(&self) -> Option<Arc<Mutex<ScrollPhysics>>>

Get scroll physics handle if this is a scroll element
Source§

fn viewport_cull(&self) -> bool

Whether this element opts in to viewport culling for its descendants. The renderer skips painting any descendant whose post-scroll bounds don’t intersect the visible viewport (plus a small overscan buffer). Only meaningful on scroll containers.
Source§

fn motion_animation_for_child( &self, _child_index: usize, ) -> Option<MotionAnimation>

Get motion animation config for a child at given index Read more
Source§

fn motion_bindings(&self) -> Option<MotionBindings>

Get motion bindings for continuous animation Read more
Source§

fn motion_stable_id(&self) -> Option<&str>

Get stable ID for motion animation tracking Read more
Source§

fn motion_should_replay(&self) -> bool

Check if this motion should replay its animation Read more
Source§

fn motion_is_suspended(&self) -> bool

Check if this motion should start in suspended state Read more
Source§

fn motion_is_exiting(&self) -> bool

👎Deprecated since 0.1.0:

Use query_motion(key).exit() to explicitly trigger motion exit

DEPRECATED: Check if this motion should start its exit animation Read more
Source§

fn layout_bounds_storage(&self) -> Option<Arc<Mutex<Option<ElementBounds>>>>

Get layout bounds storage for this element Read more
Source§

fn layout_bounds_callback( &self, ) -> Option<Arc<dyn Fn(ElementBounds) + Send + Sync>>

Get layout bounds change callback for this element Read more
Source§

fn set_auto_id(&mut self, _id: String) -> bool

Set an auto-generated element ID (used by stateful containers for stable child IDs). Read more
Source§

fn children_builders_mut(&mut self) -> &mut [Box<dyn ElementBuilder>]

Get mutable access to children for auto-ID assignment
Source§

fn bound_scroll_ref(&self) -> Option<&ScrollRef>

Get the bound ScrollRef for programmatic scroll control Read more
Source§

fn bound_element_ref(&self) -> Option<&DivRef>

Get the bound crate::selector::DivRef, if the builder was given one. The renderer resolves it to this element’s node.
Source§

fn motion_on_ready_callback( &self, ) -> Option<Arc<dyn Fn(ElementBounds) + Send + Sync>>

Get the on_ready callback for this motion container Read more
Source§

fn layout_animation_config(&self) -> Option<LayoutAnimationConfig>

Get layout animation configuration for this element Read more
Source§

fn visual_animation_config(&self) -> Option<VisualAnimationConfig>

Get visual animation config for new FLIP-style animations (read-only layout) Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Code

§

impl !Send for Code

§

impl !Sync for Code

§

impl !UnwindSafe for Code

§

impl Freeze for Code

§

impl Unpin for Code

§

impl UnsafeUnpin for Code

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoReactive<T> for T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more