Add Frame::group for putting a frame around some widgets
Closes https://github.com/emilk/egui/issues/125
This commit is contained in:
parent
3bec7c4f68
commit
9f4c31c0e0
3 changed files with 16 additions and 7 deletions
|
@ -18,7 +18,17 @@ impl Frame {
|
||||||
Self::default()
|
Self::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn panel(style: &Style) -> Self {
|
/// For when you want to group a few widgets together within a frame.
|
||||||
|
pub fn group(style: &Style) -> Self {
|
||||||
|
Self {
|
||||||
|
margin: Vec2::new(8.0, 8.0),
|
||||||
|
corner_radius: 4.0,
|
||||||
|
stroke: style.visuals.widgets.noninteractive.bg_stroke,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn side_top_panel(style: &Style) -> Self {
|
||||||
Self {
|
Self {
|
||||||
margin: Vec2::new(8.0, 2.0),
|
margin: Vec2::new(8.0, 2.0),
|
||||||
corner_radius: 0.0,
|
corner_radius: 0.0,
|
||||||
|
@ -28,7 +38,7 @@ impl Frame {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn central_panel(style: &Style) -> Self {
|
pub(crate) fn central_panel(style: &Style) -> Self {
|
||||||
Self {
|
Self {
|
||||||
margin: Vec2::new(8.0, 8.0),
|
margin: Vec2::new(8.0, 8.0),
|
||||||
corner_radius: 0.0,
|
corner_radius: 0.0,
|
||||||
|
|
|
@ -46,7 +46,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::panel(&ctx.style());
|
let frame = Frame::side_top_panel(&ctx.style());
|
||||||
let (r, used_space) = frame.show(&mut panel_ui, |ui| {
|
let (r, used_space) = frame.show(&mut panel_ui, |ui| {
|
||||||
let r = add_contents(ui);
|
let r = add_contents(ui);
|
||||||
let used_space = ui.min_rect();
|
let used_space = ui.min_rect();
|
||||||
|
@ -109,7 +109,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::panel(&ctx.style());
|
let frame = Frame::side_top_panel(&ctx.style());
|
||||||
let (r, used_space) = frame.show(&mut panel_ui, |ui| {
|
let (r, used_space) = frame.show(&mut panel_ui, |ui| {
|
||||||
let r = add_contents(ui);
|
let r = add_contents(ui);
|
||||||
let used_space = ui.min_rect();
|
let used_space = ui.min_rect();
|
||||||
|
|
|
@ -104,8 +104,7 @@ impl Widgets {
|
||||||
ui.label(format!("The button has been clicked {} times.", self.count));
|
ui.label(format!("The button has been clicked {} times.", self.count));
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.separator();
|
egui::Frame::group(ui.style()).show(ui, |ui| {
|
||||||
{
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.label("Drag this value to change it:");
|
ui.label("Drag this value to change it:");
|
||||||
ui.add(DragValue::f64(&mut self.sliders.value).speed(0.01));
|
ui.add(DragValue::f64(&mut self.sliders.value).speed(0.01));
|
||||||
|
@ -122,7 +121,7 @@ impl Widgets {
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
self.sliders.ui(ui);
|
self.sliders.ui(ui);
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
ui.separator();
|
ui.separator();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue