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.