pub struct StyledButton { /* private fields */ }Expand description
A clickable button with per-state (hover / focus / active) styling.
Wraps egui’s button with the SharedStyle box builders (bg, border,
corner_radius, padding, …) plus per-state color variants (hover_bg,
active_bg, focus_bg, …) that resolve through egui’s active Visuals
for anything left unset. An optional leading image and an
explicit font round out the label.
Construct via Styled::button and call
show to add it to a Ui. Set id when the
button is conditionally rendered so its pseudo-state stays stable.
Implementations§
Source§impl StyledButton
impl StyledButton
pub fn new(text: impl Into<WidgetText>) -> Self
pub fn image(self, img: Image<'static>) -> Self
Sourcepub fn font(self, font: FontId) -> Self
pub fn font(self, font: FontId) -> Self
Set the font (family + size) used to render the button label.
Overrides SharedStyle::font_size when both are set.
Sourcepub fn id(self, id: impl Hash + Debug) -> Self
pub fn id(self, id: impl Hash + Debug) -> Self
Override the auto-generated widget id. Use this to pin pseudo-state
(hover / active / focus) across conditional rendering - without an
explicit id, ui.next_auto_id() shifts when a sibling appears or
disappears, misattributing one frame of state.
pub fn show(self, ui: &mut Ui) -> Response
Source§impl StyledButton
impl StyledButton
Sourcepub fn hover_bg(self, color: Color32) -> Self
pub fn hover_bg(self, color: Color32) -> Self
Background fill while the pointer is hovering. Falls back to
bg when unset.
Sourcepub fn focus_bg(self, color: Color32) -> Self
pub fn focus_bg(self, color: Color32) -> Self
Background fill while the widget has keyboard focus. Falls back to
bg when unset.
Sourcepub fn accent(self, color: Color32) -> Self
pub fn accent(self, color: Color32) -> Self
Set the accent colour — maps to selection.bg_fill in egui
(slider trailing fill, text-selection highlight, focus ring).
Sourcepub fn hover_accent(self, color: Color32) -> Self
pub fn hover_accent(self, color: Color32) -> Self
Accent colour while hovering. Falls back to accent
when unset.
Sourcepub fn text_color(self, color: Color32) -> Self
pub fn text_color(self, color: Color32) -> Self
Set the text/foreground colour for the widget’s label.
Sourcepub fn hover_text_color(self, color: Color32) -> Self
pub fn hover_text_color(self, color: Color32) -> Self
Text/foreground colour while the pointer is hovering. Falls back
to text_color when unset.
Sourcepub fn focus_text_color(self, color: Color32) -> Self
pub fn focus_text_color(self, color: Color32) -> Self
Text/foreground colour while the widget has keyboard focus.
Falls back to hover_text_color /
text_color when unset.
Sourcepub fn font_size(self, size: f32) -> Self
pub fn font_size(self, size: f32) -> Self
Set the label font size in points. On widgets with a dedicated
font builder, an explicit font takes precedence.
Sourcepub fn border(self, width: f32, color: Color32) -> Self
pub fn border(self, width: f32, color: Color32) -> Self
Set the base border stroke (width in points, color).
Sourcepub fn hover_border(self, width: f32, color: Color32) -> Self
pub fn hover_border(self, width: f32, color: Color32) -> Self
Border stroke while hovering. Falls back to border
when unset.
Sourcepub fn focus_border(self, width: f32, color: Color32) -> Self
pub fn focus_border(self, width: f32, color: Color32) -> Self
Border stroke while focused. Falls back to border
when unset.
Sourcepub fn border_top(self, width: f32, color: Color32) -> Self
pub fn border_top(self, width: f32, color: Color32) -> Self
Set the base top border (width in points, color).
Sourcepub fn border_right(self, width: f32, color: Color32) -> Self
pub fn border_right(self, width: f32, color: Color32) -> Self
Set the base right border (width in points, color).
Sourcepub fn border_bottom(self, width: f32, color: Color32) -> Self
pub fn border_bottom(self, width: f32, color: Color32) -> Self
Set the base bottom border (width in points, color).
Sourcepub fn border_left(self, width: f32, color: Color32) -> Self
pub fn border_left(self, width: f32, color: Color32) -> Self
Set the base left border (width in points, color).
Sourcepub fn border_x(self, width: f32, color: Color32) -> Self
pub fn border_x(self, width: f32, color: Color32) -> Self
Set the base left and right borders in one call.
Sourcepub fn border_y(self, width: f32, color: Color32) -> Self
pub fn border_y(self, width: f32, color: Color32) -> Self
Set the base top and bottom borders in one call.
Sourcepub fn hover_border_top(self, width: f32, color: Color32) -> Self
pub fn hover_border_top(self, width: f32, color: Color32) -> Self
Top border while hovering. Falls back to border_top.
Sourcepub fn hover_border_right(self, width: f32, color: Color32) -> Self
pub fn hover_border_right(self, width: f32, color: Color32) -> Self
Right border while hovering. Falls back to border_right.
Sourcepub fn hover_border_bottom(self, width: f32, color: Color32) -> Self
pub fn hover_border_bottom(self, width: f32, color: Color32) -> Self
Bottom border while hovering. Falls back to border_bottom.
Sourcepub fn hover_border_left(self, width: f32, color: Color32) -> Self
pub fn hover_border_left(self, width: f32, color: Color32) -> Self
Left border while hovering. Falls back to border_left.
Sourcepub fn hover_border_x(self, width: f32, color: Color32) -> Self
pub fn hover_border_x(self, width: f32, color: Color32) -> Self
Left and right borders while hovering.
Sourcepub fn hover_border_y(self, width: f32, color: Color32) -> Self
pub fn hover_border_y(self, width: f32, color: Color32) -> Self
Top and bottom borders while hovering.
Sourcepub fn focus_border_top(self, width: f32, color: Color32) -> Self
pub fn focus_border_top(self, width: f32, color: Color32) -> Self
Top border while focused. Falls back to border_top.
Sourcepub fn focus_border_right(self, width: f32, color: Color32) -> Self
pub fn focus_border_right(self, width: f32, color: Color32) -> Self
Right border while focused. Falls back to border_right.
Sourcepub fn focus_border_bottom(self, width: f32, color: Color32) -> Self
pub fn focus_border_bottom(self, width: f32, color: Color32) -> Self
Bottom border while focused. Falls back to border_bottom.
Sourcepub fn focus_border_left(self, width: f32, color: Color32) -> Self
pub fn focus_border_left(self, width: f32, color: Color32) -> Self
Left border while focused. Falls back to border_left.
Sourcepub fn focus_border_x(self, width: f32, color: Color32) -> Self
pub fn focus_border_x(self, width: f32, color: Color32) -> Self
Left and right borders while focused.
Sourcepub fn focus_border_y(self, width: f32, color: Color32) -> Self
pub fn focus_border_y(self, width: f32, color: Color32) -> Self
Top and bottom borders while focused.
Sourcepub fn corner_radius(self, corner_radius: impl Into<CornerRadius>) -> Self
pub fn corner_radius(self, corner_radius: impl Into<CornerRadius>) -> Self
Set the corner radius. Accepts an f32 (uniform) or any
Into<egui::CornerRadius> for per-corner control.
Sourcepub fn padding(self, padding: impl Into<Margin>) -> Self
pub fn padding(self, padding: impl Into<Margin>) -> Self
Set inner padding (space between the border and the content).
Accepts any Into<egui::Margin>.
Sourcepub fn margin_top(self, val: f32) -> Self
pub fn margin_top(self, val: f32) -> Self
Set the top outer margin in points (space outside the border).
Sourcepub fn margin_bottom(self, val: f32) -> Self
pub fn margin_bottom(self, val: f32) -> Self
Set the bottom outer margin in points (space outside the border).
Sourcepub fn margin_left(self, val: f32) -> Self
pub fn margin_left(self, val: f32) -> Self
Set the left outer margin in points (space outside the border).
Sourcepub fn margin_right(self, val: f32) -> Self
pub fn margin_right(self, val: f32) -> Self
Set the right outer margin in points (space outside the border).
Sourcepub fn full_width(self) -> Self
pub fn full_width(self) -> Self
Stretch the widget to fill the available width of its parent.
Sourcepub fn full_height(self) -> Self
pub fn full_height(self) -> Self
Stretch the widget to fill the available height of its parent.
Sourcepub fn min_height(self, height: f32) -> Self
pub fn min_height(self, height: f32) -> Self
Set a minimum height in points.
Sourcepub fn max_height(self, height: f32) -> Self
pub fn max_height(self, height: f32) -> Self
Set a maximum height in points.
Sourcepub fn width_pct(self, pct: f32) -> Self
pub fn width_pct(self, pct: f32) -> Self
Set width as a percentage (0–100) of the parent’s available width.
Resolves to a definite size at render time, superseding full_width.
Composes with min_width/max_width as clamps after resolution.
Sourcepub fn height_pct(self, pct: f32) -> Self
pub fn height_pct(self, pct: f32) -> Self
Set height as a percentage (0–100) of the parent’s available height.
Resolves to a definite size at render time, superseding full_height.
Composes with min_height/max_height as clamps after resolution.
Sourcepub fn aspect_ratio(self, ratio: f32) -> Self
pub fn aspect_ratio(self, ratio: f32) -> Self
Derive height from width (width ÷ height, e.g. 16.0/9.0).
Requires a definite width (width_pct or full_width); no-op otherwise.
Overridden by an explicit height_pct or full_height.
Sourcepub fn cursor(self, icon: CursorIcon) -> Self
pub fn cursor(self, icon: CursorIcon) -> Self
Set the cursor icon shown while hovering the widget.
Sourcepub fn visible(self, visible: bool) -> Self
pub fn visible(self, visible: bool) -> Self
Show or hide the widget. When false the widget still occupies
its layout space but is not painted or interactive.
Sourcepub fn background_image(self, image: impl Into<Image<'static>>) -> Self
pub fn background_image(self, image: impl Into<Image<'static>>) -> Self
Set a background texture drawn on top of bg fill, clipped to the
same rounded rect. Accepts egui::Image, egui::ImageSource, or
an include_image!(...) macro result.
Texture loading is the app’s responsibility — install loaders via
egui_extras::install_image_loaders or register textures with
ctx.load_texture. egui_styled only paints, never loads.
Sourcepub fn background_image_fit(self, fit: BackgroundImageFit) -> Self
pub fn background_image_fit(self, fit: BackgroundImageFit) -> Self
Override the fill mode for background_image.
Default: BackgroundImageFit::Stretch (maps full texture over the rect).
Sourcepub fn background_image_tint(self, tint: Color32) -> Self
pub fn background_image_tint(self, tint: Color32) -> Self
Multiply the background image colour by tint (default: WHITE = no tint).
Sourcepub fn background_image_fade_in(self, seconds: f32) -> Self
pub fn background_image_fade_in(self, seconds: f32) -> Self
Fade the background image in over seconds the first time its
texture finishes loading, instead of snapping in. Default: no fade.
Sourcepub fn reveal_with_background_image(self, seconds: f32) -> Self
pub fn reveal_with_background_image(self, seconds: f32) -> Self
Reveal the whole area — background image and body content — in
together over seconds, the first time the image’s texture
finishes loading. The bg backdrop stays opaque, so the area
reveals as a unit instead of content showing over a bare backdrop
while the art is still decoding.
Sourcepub fn shadow(self, offset: Vec2, width: f32, color: Color32) -> Self
pub fn shadow(self, offset: Vec2, width: f32, color: Color32) -> Self
Paint an offset stroke rect behind the widget.
Multiple calls append; each shadow uses the widget’s corner_radius.
Sourcepub fn shadow_filled(self, offset: Vec2, color: Color32) -> Self
pub fn shadow_filled(self, offset: Vec2, color: Color32) -> Self
Paint a filled (+ optionally stroked) offset rect behind the widget. Use for conventional drop shadows.
Sourcepub fn bg_gradient(
self,
top_left: Color32,
top_right: Color32,
bottom_left: Color32,
bottom_right: Color32,
) -> Self
pub fn bg_gradient( self, top_left: Color32, top_right: Color32, bottom_left: Color32, bottom_right: Color32, ) -> Self
Four-corner bilinear gradient painted over the solid bg fill.
Colors are interpolated across the rect using a cached 2×2 GPU texture,
so corner_radius is respected. See also bg_gradient_v / bg_gradient_h
for two-stop shortcuts and bg_gradient_stops for N-stop ramps.
Sourcepub fn bg_gradient_v(self, top: Color32, bottom: Color32) -> Self
pub fn bg_gradient_v(self, top: Color32, bottom: Color32) -> Self
Vertical two-stop gradient (top → bottom). Shorthand for bg_gradient.
Sourcepub fn bg_gradient_h(self, left: Color32, right: Color32) -> Self
pub fn bg_gradient_h(self, left: Color32, right: Color32) -> Self
Horizontal two-stop gradient (left → right). Shorthand for bg_gradient.
Sourcepub fn hover_bg_gradient(
self,
top_left: Color32,
top_right: Color32,
bottom_left: Color32,
bottom_right: Color32,
) -> Self
pub fn hover_bg_gradient( self, top_left: Color32, top_right: Color32, bottom_left: Color32, bottom_right: Color32, ) -> Self
bg_gradient applied when hovered.
Sourcepub fn hover_bg_gradient_v(self, top: Color32, bottom: Color32) -> Self
pub fn hover_bg_gradient_v(self, top: Color32, bottom: Color32) -> Self
Vertical two-stop hover_bg_gradient.
Sourcepub fn hover_bg_gradient_h(self, left: Color32, right: Color32) -> Self
pub fn hover_bg_gradient_h(self, left: Color32, right: Color32) -> Self
Horizontal two-stop hover_bg_gradient.
Sourcepub fn active_bg_gradient(
self,
top_left: Color32,
top_right: Color32,
bottom_left: Color32,
bottom_right: Color32,
) -> Self
pub fn active_bg_gradient( self, top_left: Color32, top_right: Color32, bottom_left: Color32, bottom_right: Color32, ) -> Self
bg_gradient applied when active (pointer pressed).
Sourcepub fn active_bg_gradient_v(self, top: Color32, bottom: Color32) -> Self
pub fn active_bg_gradient_v(self, top: Color32, bottom: Color32) -> Self
Vertical two-stop active_bg_gradient.
Sourcepub fn active_bg_gradient_h(self, left: Color32, right: Color32) -> Self
pub fn active_bg_gradient_h(self, left: Color32, right: Color32) -> Self
Horizontal two-stop active_bg_gradient.
Sourcepub fn focus_bg_gradient(
self,
top_left: Color32,
top_right: Color32,
bottom_left: Color32,
bottom_right: Color32,
) -> Self
pub fn focus_bg_gradient( self, top_left: Color32, top_right: Color32, bottom_left: Color32, bottom_right: Color32, ) -> Self
bg_gradient applied when focused.
Sourcepub fn focus_bg_gradient_v(self, top: Color32, bottom: Color32) -> Self
pub fn focus_bg_gradient_v(self, top: Color32, bottom: Color32) -> Self
Vertical two-stop focus_bg_gradient.
Sourcepub fn focus_bg_gradient_h(self, left: Color32, right: Color32) -> Self
pub fn focus_bg_gradient_h(self, left: Color32, right: Color32) -> Self
Horizontal two-stop focus_bg_gradient.
Sourcepub fn bg_gradient_stops(
self,
stops: impl IntoIterator<Item = (f32, Color32)>,
) -> Self
pub fn bg_gradient_stops( self, stops: impl IntoIterator<Item = (f32, Color32)>, ) -> Self
Vertical N-stop linear gradient over the solid bg fill. stops are
(position, color) pairs with position in 0.0..=1.0 (sorted for you).
Respects corner_radius. Use bg_gradient_stops_h for horizontal.
Sourcepub fn bg_gradient_stops_h(
self,
stops: impl IntoIterator<Item = (f32, Color32)>,
) -> Self
pub fn bg_gradient_stops_h( self, stops: impl IntoIterator<Item = (f32, Color32)>, ) -> Self
Horizontal N-stop linear gradient. See bg_gradient_stops.
Sourcepub fn hover_bg_gradient_stops(
self,
stops: impl IntoIterator<Item = (f32, Color32)>,
) -> Self
pub fn hover_bg_gradient_stops( self, stops: impl IntoIterator<Item = (f32, Color32)>, ) -> Self
bg_gradient_stops applied when hovered.
Sourcepub fn active_bg_gradient_stops(
self,
stops: impl IntoIterator<Item = (f32, Color32)>,
) -> Self
pub fn active_bg_gradient_stops( self, stops: impl IntoIterator<Item = (f32, Color32)>, ) -> Self
bg_gradient_stops applied when active (pointer pressed).
Sourcepub fn focus_bg_gradient_stops(
self,
stops: impl IntoIterator<Item = (f32, Color32)>,
) -> Self
pub fn focus_bg_gradient_stops( self, stops: impl IntoIterator<Item = (f32, Color32)>, ) -> Self
bg_gradient_stops applied when focused.
Sourcepub fn inner_glow(self, width: f32, color: Color32) -> Self
pub fn inner_glow(self, width: f32, color: Color32) -> Self
Inward glow: width logical pixels deep, fading from color at the
edge to transparent toward the center. Drawn as a smooth vertex-colored
ring that follows corner_radius.
Sourcepub fn inner_glow_sides(self, sides: Sides, width: f32, color: Color32) -> Self
pub fn inner_glow_sides(self, sides: Sides, width: f32, color: Color32) -> Self
Inner glow drawn only from the given sides.
See inner_glow; partial selections draw straight
bands (corners are not rounded).
Sourcepub fn inner_glow_top(self, width: f32, color: Color32) -> Self
pub fn inner_glow_top(self, width: f32, color: Color32) -> Self
Inner glow from the top edge only.
Sourcepub fn inner_glow_bottom(self, width: f32, color: Color32) -> Self
pub fn inner_glow_bottom(self, width: f32, color: Color32) -> Self
Inner glow from the bottom edge only.
Sourcepub fn inner_glow_left(self, width: f32, color: Color32) -> Self
pub fn inner_glow_left(self, width: f32, color: Color32) -> Self
Inner glow from the left edge only.
Sourcepub fn inner_glow_right(self, width: f32, color: Color32) -> Self
pub fn inner_glow_right(self, width: f32, color: Color32) -> Self
Inner glow from the right edge only.
Sourcepub fn inner_glow_x(self, width: f32, color: Color32) -> Self
pub fn inner_glow_x(self, width: f32, color: Color32) -> Self
Inner glow from the left and right edges.
Sourcepub fn inner_glow_y(self, width: f32, color: Color32) -> Self
pub fn inner_glow_y(self, width: f32, color: Color32) -> Self
Inner glow from the top and bottom edges.
Sourcepub fn hover_inner_glow(self, width: f32, color: Color32) -> Self
pub fn hover_inner_glow(self, width: f32, color: Color32) -> Self
inner_glow applied when hovered.
Sourcepub fn active_inner_glow(self, width: f32, color: Color32) -> Self
pub fn active_inner_glow(self, width: f32, color: Color32) -> Self
inner_glow applied when active (pointer pressed).
Sourcepub fn focus_inner_glow(self, width: f32, color: Color32) -> Self
pub fn focus_inner_glow(self, width: f32, color: Color32) -> Self
inner_glow applied when focused.
Sourcepub fn border_gradient(self, width: f32, top: Color32, bottom: Color32) -> Self
pub fn border_gradient(self, width: f32, top: Color32, bottom: Color32) -> Self
Vertically-interpolated border: top color at the top edge, bottom
at the bottom, linearly interpolated down. Wins over uniform border and
per-side overrides. Corner radius is not rounded (straight mitered edges).
Sourcepub fn hover_border_gradient(
self,
width: f32,
top: Color32,
bottom: Color32,
) -> Self
pub fn hover_border_gradient( self, width: f32, top: Color32, bottom: Color32, ) -> Self
border_gradient applied when hovered.
Sourcepub fn active_border_gradient(
self,
width: f32,
top: Color32,
bottom: Color32,
) -> Self
pub fn active_border_gradient( self, width: f32, top: Color32, bottom: Color32, ) -> Self
border_gradient applied when active (pointer pressed).
Sourcepub fn focus_border_gradient(
self,
width: f32,
top: Color32,
bottom: Color32,
) -> Self
pub fn focus_border_gradient( self, width: f32, top: Color32, bottom: Color32, ) -> Self
border_gradient applied when focused.
Trait Implementations§
Source§impl Apply for StyledButton
impl Apply for StyledButton
Source§impl StyledWidget for StyledButton
impl StyledWidget for StyledButton
Auto Trait Implementations§
impl Freeze for StyledButton
impl RefUnwindSafe for StyledButton
impl Send for StyledButton
impl Sync for StyledButton
impl Unpin for StyledButton
impl UnsafeUnpin for StyledButton
impl UnwindSafe for StyledButton
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more