Struct egui::containers::frame::Frame

source ·
pub struct Frame {
    pub inner_margin: Margin,
    pub outer_margin: Margin,
    pub rounding: Rounding,
    pub shadow: Shadow,
    pub fill: Color32,
    pub stroke: Stroke,
}
Expand description

Add a background, frame and/or margin to a rectangular background of a Ui.

egui::Frame::none()
    .fill(egui::Color32::RED)
    .show(ui, |ui| {
        ui.label("Label with red background");
    });

§Dynamic color

If you want to change the color of the frame based on the response of the widget, you needs to break it up into multiple steps:

let mut frame = egui::Frame::default().inner_margin(4.0).begin(ui);
{
    let response = frame.content_ui.label("Inside the frame");
    if response.hovered() {
        frame.frame.fill = egui::Color32::RED;
    }
}
frame.end(ui); // Will "close" the frame.

You can also respond to the hovering of the frame itself:

let mut frame = egui::Frame::default().inner_margin(4.0).begin(ui);
{
    frame.content_ui.label("Inside the frame");
    frame.content_ui.label("This too");
}
let response = frame.allocate_space(ui);
if response.hovered() {
    frame.frame.fill = egui::Color32::RED;
}
frame.paint(ui);

Note that you cannot change the margins after calling begin.

Fields§

§inner_margin: Margin

Margin within the painted frame.

§outer_margin: Margin

Margin outside the painted frame.

§rounding: Rounding§shadow: Shadow§fill: Color32§stroke: Stroke

Implementations§

source§

impl Frame

source

pub fn none() -> Self

source

pub fn group(style: &Style) -> Self

For when you want to group a few widgets together within a frame.

source

pub fn side_top_panel(style: &Style) -> Self

source

pub fn central_panel(style: &Style) -> Self

source

pub fn window(style: &Style) -> Self

source

pub fn menu(style: &Style) -> Self

source

pub fn popup(style: &Style) -> Self

source

pub fn canvas(style: &Style) -> Self

A canvas to draw on.

In bright mode this will be very bright, and in dark mode this will be very dark.

source

pub fn dark_canvas(style: &Style) -> Self

A dark canvas to draw on.

source§

impl Frame

source

pub fn fill(self, fill: Color32) -> Self

source

pub fn stroke(self, stroke: impl Into<Stroke>) -> Self

source

pub fn rounding(self, rounding: impl Into<Rounding>) -> Self

source

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

Margin within the painted frame.

source

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

Margin outside the painted frame.

source

pub fn shadow(self, shadow: Shadow) -> Self

source

pub fn multiply_with_opacity(self, opacity: f32) -> Self

Opacity multiplier in gamma space.

For instance, multiplying with 0.5 will make the frame half transparent.

source§

impl Frame

source

pub fn total_margin(&self) -> Margin

inner margin plus outer margin.

source§

impl Frame

source

pub fn begin(self, ui: &mut Ui) -> Prepared

Begin a dynamically colored frame.

This is a more advanced API. Usually you want to use Self::show instead.

See docs for Frame for an example.

source

pub fn show<R>( self, ui: &mut Ui, add_contents: impl FnOnce(&mut Ui) -> R, ) -> InnerResponse<R>

Show the given ui surrounded by this frame.

source

pub fn show_dyn<'c, R>( self, ui: &mut Ui, add_contents: Box<dyn FnOnce(&mut Ui) -> R + 'c>, ) -> InnerResponse<R>

Show using dynamic dispatch.

source

pub fn paint(&self, outer_rect: Rect) -> Shape

Paint this frame as a shape.

The margin is ignored.

Trait Implementations§

source§

impl Clone for Frame

source§

fn clone(&self) -> Frame

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Frame

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Frame

source§

fn default() -> Frame

Returns the “default value” for a type. Read more
source§

impl PartialEq for Frame

source§

fn eq(&self, other: &Frame) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Widget for &mut Frame

source§

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

Allocate space, interact, paint, and return a Response. Read more
source§

impl Copy for Frame

source§

impl StructuralPartialEq for Frame

Auto Trait Implementations§

§

impl Freeze for Frame

§

impl RefUnwindSafe for Frame

§

impl Send for Frame

§

impl Sync for Frame

§

impl Unpin for Frame

§

impl UnwindSafe for Frame

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
source§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,