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§
§impl Frame
impl Frame
pub fn none() -> Frame
pub fn group(style: &Style) -> Frame
pub fn group(style: &Style) -> Frame
For when you want to group a few widgets together within a frame.
pub fn side_top_panel(style: &Style) -> Frame
pub fn central_panel(style: &Style) -> Frame
pub fn window(style: &Style) -> Frame
pub fn popup(style: &Style) -> Frame
pub fn canvas(style: &Style) -> Frame
pub fn canvas(style: &Style) -> Frame
A canvas to draw on.
In bright mode this will be very bright, and in dark mode this will be very dark.
pub fn dark_canvas(style: &Style) -> Frame
pub fn dark_canvas(style: &Style) -> Frame
A dark canvas to draw on.
§impl Frame
impl Frame
pub fn fill(self, fill: Color32) -> Frame
pub fn stroke(self, stroke: impl Into<Stroke>) -> Frame
pub fn rounding(self, rounding: impl Into<Rounding>) -> Frame
pub fn inner_margin(self, inner_margin: impl Into<Margin>) -> Frame
pub fn inner_margin(self, inner_margin: impl Into<Margin>) -> Frame
Margin within the painted frame.
pub fn outer_margin(self, outer_margin: impl Into<Margin>) -> Frame
pub fn outer_margin(self, outer_margin: impl Into<Margin>) -> Frame
Margin outside the painted frame.
pub fn shadow(self, shadow: Shadow) -> Frame
pub fn multiply_with_opacity(self, opacity: f32) -> Frame
pub fn multiply_with_opacity(self, opacity: f32) -> Frame
Opacity multiplier in gamma space.
For instance, multiplying with 0.5
will make the frame half transparent.
§impl Frame
impl Frame
pub fn total_margin(&self) -> Margin
pub fn total_margin(&self) -> Margin
inner margin plus outer margin.
§impl Frame
impl Frame
pub 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.
pub 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§
§impl<'de> Deserialize<'de> for Frame
impl<'de> Deserialize<'de> for Frame
§fn deserialize<__D>(
__deserializer: __D
) -> Result<Frame, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<Frame, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl Serialize for Frame
impl Serialize for Frame
§fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
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> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moresource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request