Skip to main content

StyledButton

Struct StyledButton 

Source
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

Source

pub fn new(text: impl Into<WidgetText>) -> Self

Source

pub fn image(self, img: Image<'static>) -> Self

Source

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.

Source

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.

Source

pub fn show(self, ui: &mut Ui) -> Response

Source§

impl StyledButton

Source

pub fn bg(self, color: Color32) -> Self

Set the base background fill colour.

Source

pub fn hover_bg(self, color: Color32) -> Self

Background fill while the pointer is hovering. Falls back to bg when unset.

Source

pub fn active_bg(self, color: Color32) -> Self

Background fill while the widget is pressed/active. Falls back to hover_bg / bg when unset.

Source

pub fn focus_bg(self, color: Color32) -> Self

Background fill while the widget has keyboard focus. Falls back to bg when unset.

Source

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).

Source

pub fn hover_accent(self, color: Color32) -> Self

Accent colour while hovering. Falls back to accent when unset.

Source

pub fn text_color(self, color: Color32) -> Self

Set the text/foreground colour for the widget’s label.

Source

pub fn hover_text_color(self, color: Color32) -> Self

Text/foreground colour while the pointer is hovering. Falls back to text_color when unset.

Source

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.

Source

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.

Source

pub fn border(self, width: f32, color: Color32) -> Self

Set the base border stroke (width in points, color).

Source

pub fn hover_border(self, width: f32, color: Color32) -> Self

Border stroke while hovering. Falls back to border when unset.

Source

pub fn focus_border(self, width: f32, color: Color32) -> Self

Border stroke while focused. Falls back to border when unset.

Source

pub fn border_top(self, width: f32, color: Color32) -> Self

Set the base top border (width in points, color).

Source

pub fn border_right(self, width: f32, color: Color32) -> Self

Set the base right border (width in points, color).

Source

pub fn border_bottom(self, width: f32, color: Color32) -> Self

Set the base bottom border (width in points, color).

Source

pub fn border_left(self, width: f32, color: Color32) -> Self

Set the base left border (width in points, color).

Source

pub fn border_x(self, width: f32, color: Color32) -> Self

Set the base left and right borders in one call.

Source

pub fn border_y(self, width: f32, color: Color32) -> Self

Set the base top and bottom borders in one call.

Source

pub fn hover_border_top(self, width: f32, color: Color32) -> Self

Top border while hovering. Falls back to border_top.

Source

pub fn hover_border_right(self, width: f32, color: Color32) -> Self

Right border while hovering. Falls back to border_right.

Source

pub fn hover_border_bottom(self, width: f32, color: Color32) -> Self

Bottom border while hovering. Falls back to border_bottom.

Source

pub fn hover_border_left(self, width: f32, color: Color32) -> Self

Left border while hovering. Falls back to border_left.

Source

pub fn hover_border_x(self, width: f32, color: Color32) -> Self

Left and right borders while hovering.

Source

pub fn hover_border_y(self, width: f32, color: Color32) -> Self

Top and bottom borders while hovering.

Source

pub fn focus_border_top(self, width: f32, color: Color32) -> Self

Top border while focused. Falls back to border_top.

Source

pub fn focus_border_right(self, width: f32, color: Color32) -> Self

Right border while focused. Falls back to border_right.

Source

pub fn focus_border_bottom(self, width: f32, color: Color32) -> Self

Bottom border while focused. Falls back to border_bottom.

Source

pub fn focus_border_left(self, width: f32, color: Color32) -> Self

Left border while focused. Falls back to border_left.

Source

pub fn focus_border_x(self, width: f32, color: Color32) -> Self

Left and right borders while focused.

Source

pub fn focus_border_y(self, width: f32, color: Color32) -> Self

Top and bottom borders while focused.

Source

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.

Source

pub fn padding(self, padding: impl Into<Margin>) -> Self

Set inner padding (space between the border and the content). Accepts any Into<egui::Margin>.

Source

pub fn margin_top(self, val: f32) -> Self

Set the top outer margin in points (space outside the border).

Source

pub fn margin_bottom(self, val: f32) -> Self

Set the bottom outer margin in points (space outside the border).

Source

pub fn margin_left(self, val: f32) -> Self

Set the left outer margin in points (space outside the border).

Source

pub fn margin_right(self, val: f32) -> Self

Set the right outer margin in points (space outside the border).

Source

pub fn full_width(self) -> Self

Stretch the widget to fill the available width of its parent.

Source

pub fn full_height(self) -> Self

Stretch the widget to fill the available height of its parent.

Source

pub fn min_width(self, width: f32) -> Self

Set a minimum width in points.

Source

pub fn max_width(self, width: f32) -> Self

Set a maximum width in points.

Source

pub fn min_height(self, height: f32) -> Self

Set a minimum height in points.

Source

pub fn max_height(self, height: f32) -> Self

Set a maximum height in points.

Source

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.

Source

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.

Source

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.

Source

pub fn cursor(self, icon: CursorIcon) -> Self

Set the cursor icon shown while hovering the widget.

Source

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.

Source

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.

Source

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).

Source

pub fn background_image_tint(self, tint: Color32) -> Self

Multiply the background image colour by tint (default: WHITE = no tint).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn bg_gradient_v(self, top: Color32, bottom: Color32) -> Self

Vertical two-stop gradient (top → bottom). Shorthand for bg_gradient.

Source

pub fn bg_gradient_h(self, left: Color32, right: Color32) -> Self

Horizontal two-stop gradient (left → right). Shorthand for bg_gradient.

Source

pub fn hover_bg_gradient( self, top_left: Color32, top_right: Color32, bottom_left: Color32, bottom_right: Color32, ) -> Self

bg_gradient applied when hovered.

Source

pub fn hover_bg_gradient_v(self, top: Color32, bottom: Color32) -> Self

Vertical two-stop hover_bg_gradient.

Source

pub fn hover_bg_gradient_h(self, left: Color32, right: Color32) -> Self

Horizontal two-stop hover_bg_gradient.

Source

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).

Source

pub fn active_bg_gradient_v(self, top: Color32, bottom: Color32) -> Self

Vertical two-stop active_bg_gradient.

Source

pub fn active_bg_gradient_h(self, left: Color32, right: Color32) -> Self

Horizontal two-stop active_bg_gradient.

Source

pub fn focus_bg_gradient( self, top_left: Color32, top_right: Color32, bottom_left: Color32, bottom_right: Color32, ) -> Self

bg_gradient applied when focused.

Source

pub fn focus_bg_gradient_v(self, top: Color32, bottom: Color32) -> Self

Vertical two-stop focus_bg_gradient.

Source

pub fn focus_bg_gradient_h(self, left: Color32, right: Color32) -> Self

Horizontal two-stop focus_bg_gradient.

Source

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.

Source

pub fn bg_gradient_stops_h( self, stops: impl IntoIterator<Item = (f32, Color32)>, ) -> Self

Horizontal N-stop linear gradient. See bg_gradient_stops.

Source

pub fn hover_bg_gradient_stops( self, stops: impl IntoIterator<Item = (f32, Color32)>, ) -> Self

bg_gradient_stops applied when hovered.

Source

pub fn active_bg_gradient_stops( self, stops: impl IntoIterator<Item = (f32, Color32)>, ) -> Self

bg_gradient_stops applied when active (pointer pressed).

Source

pub fn focus_bg_gradient_stops( self, stops: impl IntoIterator<Item = (f32, Color32)>, ) -> Self

bg_gradient_stops applied when focused.

Source

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.

Source

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).

Source

pub fn inner_glow_top(self, width: f32, color: Color32) -> Self

Inner glow from the top edge only.

Source

pub fn inner_glow_bottom(self, width: f32, color: Color32) -> Self

Inner glow from the bottom edge only.

Source

pub fn inner_glow_left(self, width: f32, color: Color32) -> Self

Inner glow from the left edge only.

Source

pub fn inner_glow_right(self, width: f32, color: Color32) -> Self

Inner glow from the right edge only.

Source

pub fn inner_glow_x(self, width: f32, color: Color32) -> Self

Inner glow from the left and right edges.

Source

pub fn inner_glow_y(self, width: f32, color: Color32) -> Self

Inner glow from the top and bottom edges.

Source

pub fn hover_inner_glow(self, width: f32, color: Color32) -> Self

inner_glow applied when hovered.

Source

pub fn active_inner_glow(self, width: f32, color: Color32) -> Self

inner_glow applied when active (pointer pressed).

Source

pub fn focus_inner_glow(self, width: f32, color: Color32) -> Self

inner_glow applied when focused.

Source

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).

Source

pub fn hover_border_gradient( self, width: f32, top: Color32, bottom: Color32, ) -> Self

border_gradient applied when hovered.

Source

pub fn active_border_gradient( self, width: f32, top: Color32, bottom: Color32, ) -> Self

border_gradient applied when active (pointer pressed).

Source

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

Source§

fn apply(self, f: impl FnOnce(Self) -> Self) -> Self

Apply a style function to this builder.
Source§

impl StyledWidget for StyledButton

Source§

fn show(self, ui: &mut Ui) -> Response

Auto Trait Implementations§

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.