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
impl Frame
pub fn none() -> Self
sourcepub fn group(style: &Style) -> Self
pub fn group(style: &Style) -> Self
For when you want to group a few widgets together within a frame.
pub fn side_top_panel(style: &Style) -> Self
pub fn central_panel(style: &Style) -> Self
pub fn window(style: &Style) -> Self
pub fn popup(style: &Style) -> Self
sourcepub fn canvas(style: &Style) -> Self
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.
sourcepub fn dark_canvas(style: &Style) -> Self
pub fn dark_canvas(style: &Style) -> Self
A dark canvas to draw on.
source§impl Frame
impl Frame
pub fn fill(self, fill: Color32) -> Self
pub fn stroke(self, stroke: impl Into<Stroke>) -> Self
pub fn rounding(self, rounding: impl Into<Rounding>) -> Self
sourcepub fn inner_margin(self, inner_margin: impl Into<Margin>) -> Self
pub fn inner_margin(self, inner_margin: impl Into<Margin>) -> Self
Margin within the painted frame.
sourcepub fn outer_margin(self, outer_margin: impl Into<Margin>) -> Self
pub fn outer_margin(self, outer_margin: impl Into<Margin>) -> Self
Margin outside the painted frame.
pub fn shadow(self, shadow: Shadow) -> Self
sourcepub fn multiply_with_opacity(self, opacity: f32) -> Self
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
impl Frame
sourcepub fn begin(self, ui: &mut Ui) -> Prepared
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.
sourcepub fn show<R>(
self,
ui: &mut Ui,
add_contents: impl FnOnce(&mut Ui) -> R,
) -> InnerResponse<R>
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.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Frame
impl<'de> Deserialize<'de> for Frame
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Copy for Frame
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> 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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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