egui::containers::frame

Struct 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<'de> Deserialize<'de> for Frame

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. 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 Serialize for Frame

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
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 u8)

🔬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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

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