diff --git a/CHANGELOG.md b/CHANGELOG.md
index 05982d20..cbd48cc9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@ NOTE: [`eframe`](eframe/CHANGELOG.md), [`egui_web`](egui_web/CHANGELOG.md) and [
### Added ⭐
* Add support for [cint](https://crates.io/crates/cint) under `cint` feature.
* Add features `extra_asserts` and `extra_debug_asserts` to enable additional checks.
+* Add an option to overwrite frame of SidePanel and TopPanel
## 0.12.0 - 2021-05-10 - Multitouch, user memory, window pivots, and improved plots
diff --git a/egui/src/containers/panel.rs b/egui/src/containers/panel.rs
index 8eb0a674..e6cba26a 100644
--- a/egui/src/containers/panel.rs
+++ b/egui/src/containers/panel.rs
@@ -26,6 +26,7 @@ use crate::*;
pub struct SidePanel {
id: Id,
max_width: f32,
+ frame: Option,
}
impl SidePanel {
@@ -35,8 +36,15 @@ impl SidePanel {
Self {
id: Id::new(id_source),
max_width,
+ frame: None,
}
}
+
+ /// Change the background color, margins, etc.
+ pub fn frame(mut self, frame: Frame) -> Self {
+ self.frame = Some(frame);
+ self
+ }
}
impl SidePanel {
@@ -45,7 +53,11 @@ impl SidePanel {
ctx: &CtxRef,
add_contents: impl FnOnce(&mut Ui) -> R,
) -> InnerResponse {
- let Self { id, max_width } = self;
+ let Self {
+ id,
+ max_width,
+ frame,
+ } = self;
let mut panel_rect = ctx.available_rect();
panel_rect.max.x = panel_rect.max.x.at_most(panel_rect.min.x + max_width);
@@ -55,7 +67,7 @@ impl SidePanel {
let clip_rect = ctx.input().screen_rect();
let mut panel_ui = Ui::new(ctx.clone(), layer_id, id, panel_rect, clip_rect);
- let frame = Frame::side_top_panel(&ctx.style());
+ let frame = frame.unwrap_or_else(|| Frame::side_top_panel(&ctx.style()));
let inner_response = frame.show(&mut panel_ui, |ui| {
ui.set_min_height(ui.max_rect_finite().height()); // Make sure the frame fills the full height
add_contents(ui)
@@ -86,6 +98,7 @@ impl SidePanel {
pub struct TopPanel {
id: Id,
max_height: Option,
+ frame: Option,
}
impl TopPanel {
@@ -96,8 +109,15 @@ impl TopPanel {
Self {
id: Id::new(id_source),
max_height: None,
+ frame: None,
}
}
+
+ /// Change the background color, margins, etc.
+ pub fn frame(mut self, frame: Frame) -> Self {
+ self.frame = Some(frame);
+ self
+ }
}
impl TopPanel {
@@ -106,7 +126,11 @@ impl TopPanel {
ctx: &CtxRef,
add_contents: impl FnOnce(&mut Ui) -> R,
) -> InnerResponse {
- let Self { id, max_height } = self;
+ let Self {
+ id,
+ max_height,
+ frame,
+ } = self;
let max_height = max_height.unwrap_or_else(|| ctx.style().spacing.interact_size.y);
let mut panel_rect = ctx.available_rect();
@@ -117,7 +141,7 @@ impl TopPanel {
let clip_rect = ctx.input().screen_rect();
let mut panel_ui = Ui::new(ctx.clone(), layer_id, id, panel_rect, clip_rect);
- let frame = Frame::side_top_panel(&ctx.style());
+ let frame = frame.unwrap_or_else(|| Frame::side_top_panel(&ctx.style()));
let inner_response = frame.show(&mut panel_ui, |ui| {
ui.set_min_width(ui.max_rect_finite().width()); // Make the frame fill full width
add_contents(ui)