pub struct Link { /* private fields */ }Expand description
A hyperlink widget
Implementations§
Source§impl Link
impl Link
Sourcepub fn new(label: impl Into<String>, url: impl Into<String>) -> Link
pub fn new(label: impl Into<String>, url: impl Into<String>) -> Link
Create a new link with text and URL
By default, clicking the link opens the URL in the system browser.
Use .on_click() to override this behavior.
Sourcepub fn on_click<F>(self, handler: F) -> Link
pub fn on_click<F>(self, handler: F) -> Link
Set a custom click handler (receives URL and event context)
This replaces the default behavior of opening the URL in the browser.
Sourcepub fn text_color(self, color: Color) -> Link
pub fn text_color(self, color: Color) -> Link
Set the text color
Note: This rebuilds the inner structure.
Sourcepub fn no_underline(self) -> Link
pub fn no_underline(self) -> Link
Remove underline decoration (convenience for .underline(false))
Sourcepub fn underline_on_hover(self) -> Link
pub fn underline_on_hover(self) -> Link
Show underline only on hover
Methods from Deref<Target = Div>§
Sourcepub fn element_id(&self) -> Option<&str>
pub fn element_id(&self) -> Option<&str>
Get the element ID if set
Sourcepub fn stateful_context_key(&self) -> Option<&str>
pub fn stateful_context_key(&self) -> Option<&str>
Get the stateful context key if set
Sourcepub fn swap(&mut self) -> Div
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);
}
})Sourcepub fn set_bg(&mut self, color: impl Into<Brush>)
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.
Sourcepub fn set_rounded(&mut self, radius: f32)
pub fn set_rounded(&mut self, radius: f32)
Set the corner radius without consuming self
Sourcepub fn set_transform(&mut self, transform: Transform)
pub fn set_transform(&mut self, transform: Transform)
Set the transform without consuming self
Sourcepub fn set_shadow(&mut self, shadow: Shadow)
pub fn set_shadow(&mut self, shadow: Shadow)
Set the shadow without consuming self (replaces any existing stack).
Sourcepub fn set_shadow_stack(&mut self, shadows: Vec<Shadow>)
pub fn set_shadow_stack(&mut self, shadows: Vec<Shadow>)
Set a compound shadow stack without consuming self.
Sourcepub fn set_opacity(&mut self, opacity: f32)
pub fn set_opacity(&mut self, opacity: f32)
Set the opacity without consuming self
Sourcepub fn set_border(&mut self, width: f32, color: Color)
pub fn set_border(&mut self, width: f32, color: Color)
Set border with width and color without consuming self
Sourcepub fn set_overflow_clip(&mut self, clip: bool)
pub fn set_overflow_clip(&mut self, clip: bool)
Set overflow clip without consuming self
Sourcepub fn set_padding_x(&mut self, px: f32)
pub fn set_padding_x(&mut self, px: f32)
Set horizontal padding without consuming self
Sourcepub fn set_padding_y(&mut self, px: f32)
pub fn set_padding_y(&mut self, px: f32)
Set vertical padding without consuming self
Sourcepub fn set_child(&mut self, child: impl ElementBuilder + 'static)
pub fn set_child(&mut self, child: impl ElementBuilder + 'static)
Clear all children and add a single child
Sourcepub fn clear_children(&mut self)
pub fn clear_children(&mut self)
Clear all children
Sourcepub fn set_w(&mut self, px: f32)
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.
Sourcepub fn set_h_auto(&mut self)
pub fn set_h_auto(&mut self)
Set height to auto without consuming self
Sourcepub fn set_style(&mut self, style: &ElementStyle)
pub fn set_style(&mut self, style: &ElementStyle)
Sourcepub fn merge(&mut self, other: Div)
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));
})Sourcepub fn style_mut(&mut self) -> &mut Style
pub fn style_mut(&mut self) -> &mut Style
Get direct access to the taffy style for advanced configuration
Sourcepub fn event_handlers(&self) -> &EventHandlers
pub fn event_handlers(&self) -> &EventHandlers
Get a reference to the event handlers
Sourcepub fn event_handlers_mut(&mut self) -> &mut EventHandlers
pub fn event_handlers_mut(&mut self) -> &mut EventHandlers
Get a mutable reference to the event handlers
Trait Implementations§
Source§impl ElementBuilder for Link
impl ElementBuilder for Link
Source§fn build(&self, tree: &mut LayoutTree) -> LayoutNodeId
fn build(&self, tree: &mut LayoutTree) -> LayoutNodeId
Source§fn render_props(&self) -> RenderProps
fn render_props(&self) -> RenderProps
Source§fn children_builders(&self) -> &[Box<dyn ElementBuilder>]
fn children_builders(&self) -> &[Box<dyn ElementBuilder>]
Source§fn element_type_id(&self) -> ElementTypeId
fn element_type_id(&self) -> ElementTypeId
Source§fn semantic_type_name(&self) -> Option<&'static str>
fn semantic_type_name(&self) -> Option<&'static str>
Source§fn element_classes(&self) -> &[Arc<str>]
fn element_classes(&self) -> &[Arc<str>]
Source§fn event_handlers(&self) -> Option<&EventHandlers>
fn event_handlers(&self) -> Option<&EventHandlers>
Source§fn as_any(&self) -> Option<&(dyn Any + 'static)>
fn as_any(&self) -> Option<&(dyn Any + 'static)>
Source§fn text_render_info(&self) -> Option<TextRenderInfo>
fn text_render_info(&self) -> Option<TextRenderInfo>
Source§fn styled_text_render_info(&self) -> Option<StyledTextRenderInfo>
fn styled_text_render_info(&self) -> Option<StyledTextRenderInfo>
Source§fn svg_render_info(&self) -> Option<SvgRenderInfo>
fn svg_render_info(&self) -> Option<SvgRenderInfo>
Source§fn image_render_info(&self) -> Option<ImageRenderInfo>
fn image_render_info(&self) -> Option<ImageRenderInfo>
Source§fn canvas_render_info(
&self,
) -> Option<Rc<dyn Fn(&mut dyn DrawContext, CanvasBounds)>>
fn canvas_render_info( &self, ) -> Option<Rc<dyn Fn(&mut dyn DrawContext, CanvasBounds)>>
Source§fn is_static_canvas(&self) -> bool
fn is_static_canvas(&self) -> bool
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 moreSource§fn canvas_redraw_while(&self) -> Option<Rc<dyn Fn() -> bool>>
fn canvas_redraw_while(&self) -> Option<Rc<dyn Fn() -> bool>>
crate::canvas::Canvas::redraw_while. Applies only when
element_type_id is ElementTypeId::Canvas.Source§fn effective_layout_style(&self) -> Option<Style>
fn effective_layout_style(&self) -> Option<Style>
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 moreSource§fn scroll_info(&self) -> Option<ScrollRenderInfo>
fn scroll_info(&self) -> Option<ScrollRenderInfo>
Source§fn scroll_physics(&self) -> Option<Arc<Mutex<ScrollPhysics>>>
fn scroll_physics(&self) -> Option<Arc<Mutex<ScrollPhysics>>>
Source§fn viewport_cull(&self) -> bool
fn viewport_cull(&self) -> bool
Source§fn motion_animation_for_child(
&self,
_child_index: usize,
) -> Option<MotionAnimation>
fn motion_animation_for_child( &self, _child_index: usize, ) -> Option<MotionAnimation>
Source§fn motion_bindings(&self) -> Option<MotionBindings>
fn motion_bindings(&self) -> Option<MotionBindings>
Source§fn motion_stable_id(&self) -> Option<&str>
fn motion_stable_id(&self) -> Option<&str>
Source§fn motion_should_replay(&self) -> bool
fn motion_should_replay(&self) -> bool
Source§fn motion_is_suspended(&self) -> bool
fn motion_is_suspended(&self) -> bool
Source§fn motion_is_exiting(&self) -> bool
fn motion_is_exiting(&self) -> bool
Use query_motion(key).exit() to explicitly trigger motion exit
Source§fn layout_bounds_storage(&self) -> Option<Arc<Mutex<Option<ElementBounds>>>>
fn layout_bounds_storage(&self) -> Option<Arc<Mutex<Option<ElementBounds>>>>
Source§fn layout_bounds_callback(
&self,
) -> Option<Arc<dyn Fn(ElementBounds) + Send + Sync>>
fn layout_bounds_callback( &self, ) -> Option<Arc<dyn Fn(ElementBounds) + Send + Sync>>
Source§fn set_auto_id(&mut self, _id: String) -> bool
fn set_auto_id(&mut self, _id: String) -> bool
Source§fn children_builders_mut(&mut self) -> &mut [Box<dyn ElementBuilder>]
fn children_builders_mut(&mut self) -> &mut [Box<dyn ElementBuilder>]
Source§fn bound_scroll_ref(&self) -> Option<&ScrollRef>
fn bound_scroll_ref(&self) -> Option<&ScrollRef>
Source§fn bound_element_ref(&self) -> Option<&DivRef>
fn bound_element_ref(&self) -> Option<&DivRef>
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>>
fn motion_on_ready_callback( &self, ) -> Option<Arc<dyn Fn(ElementBounds) + Send + Sync>>
Source§fn layout_animation_config(&self) -> Option<LayoutAnimationConfig>
fn layout_animation_config(&self) -> Option<LayoutAnimationConfig>
Source§fn visual_animation_config(&self) -> Option<VisualAnimationConfig>
fn visual_animation_config(&self) -> Option<VisualAnimationConfig>
Auto Trait Implementations§
impl !RefUnwindSafe for Link
impl !Send for Link
impl !Sync for Link
impl !UnwindSafe for Link
impl Freeze for Link
impl Unpin for Link
impl UnsafeUnpin for Link
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.