Add an option to overwrite frame of SidePanel
and TopPanel
(#418)
* Add an option to overwrite frame of SidePanel and TopPanel * Update CHANGELOG
This commit is contained in:
parent
c0929014bf
commit
d292b831a1
2 changed files with 29 additions and 4 deletions
|
@ -10,6 +10,7 @@ NOTE: [`eframe`](eframe/CHANGELOG.md), [`egui_web`](egui_web/CHANGELOG.md) and [
|
||||||
### Added ⭐
|
### Added ⭐
|
||||||
* Add support for [cint](https://crates.io/crates/cint) under `cint` feature.
|
* 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 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
|
## 0.12.0 - 2021-05-10 - Multitouch, user memory, window pivots, and improved plots
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ use crate::*;
|
||||||
pub struct SidePanel {
|
pub struct SidePanel {
|
||||||
id: Id,
|
id: Id,
|
||||||
max_width: f32,
|
max_width: f32,
|
||||||
|
frame: Option<Frame>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SidePanel {
|
impl SidePanel {
|
||||||
|
@ -35,8 +36,15 @@ impl SidePanel {
|
||||||
Self {
|
Self {
|
||||||
id: Id::new(id_source),
|
id: Id::new(id_source),
|
||||||
max_width,
|
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 {
|
impl SidePanel {
|
||||||
|
@ -45,7 +53,11 @@ impl SidePanel {
|
||||||
ctx: &CtxRef,
|
ctx: &CtxRef,
|
||||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||||
) -> InnerResponse<R> {
|
) -> InnerResponse<R> {
|
||||||
let Self { id, max_width } = self;
|
let Self {
|
||||||
|
id,
|
||||||
|
max_width,
|
||||||
|
frame,
|
||||||
|
} = self;
|
||||||
|
|
||||||
let mut panel_rect = ctx.available_rect();
|
let mut panel_rect = ctx.available_rect();
|
||||||
panel_rect.max.x = panel_rect.max.x.at_most(panel_rect.min.x + max_width);
|
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 clip_rect = ctx.input().screen_rect();
|
||||||
let mut panel_ui = Ui::new(ctx.clone(), layer_id, id, panel_rect, clip_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| {
|
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
|
ui.set_min_height(ui.max_rect_finite().height()); // Make sure the frame fills the full height
|
||||||
add_contents(ui)
|
add_contents(ui)
|
||||||
|
@ -86,6 +98,7 @@ impl SidePanel {
|
||||||
pub struct TopPanel {
|
pub struct TopPanel {
|
||||||
id: Id,
|
id: Id,
|
||||||
max_height: Option<f32>,
|
max_height: Option<f32>,
|
||||||
|
frame: Option<Frame>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TopPanel {
|
impl TopPanel {
|
||||||
|
@ -96,8 +109,15 @@ impl TopPanel {
|
||||||
Self {
|
Self {
|
||||||
id: Id::new(id_source),
|
id: Id::new(id_source),
|
||||||
max_height: None,
|
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 {
|
impl TopPanel {
|
||||||
|
@ -106,7 +126,11 @@ impl TopPanel {
|
||||||
ctx: &CtxRef,
|
ctx: &CtxRef,
|
||||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||||
) -> InnerResponse<R> {
|
) -> InnerResponse<R> {
|
||||||
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 max_height = max_height.unwrap_or_else(|| ctx.style().spacing.interact_size.y);
|
||||||
|
|
||||||
let mut panel_rect = ctx.available_rect();
|
let mut panel_rect = ctx.available_rect();
|
||||||
|
@ -117,7 +141,7 @@ impl TopPanel {
|
||||||
let clip_rect = ctx.input().screen_rect();
|
let clip_rect = ctx.input().screen_rect();
|
||||||
let mut panel_ui = Ui::new(ctx.clone(), layer_id, id, panel_rect, clip_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| {
|
let inner_response = frame.show(&mut panel_ui, |ui| {
|
||||||
ui.set_min_width(ui.max_rect_finite().width()); // Make the frame fill full width
|
ui.set_min_width(ui.max_rect_finite().width()); // Make the frame fill full width
|
||||||
add_contents(ui)
|
add_contents(ui)
|
||||||
|
|
Loading…
Reference in a new issue