diff --git a/emigui/src/containers/frame.rs b/emigui/src/containers/frame.rs index 93ec5cc7..158e5289 100644 --- a/emigui/src/containers/frame.rs +++ b/emigui/src/containers/frame.rs @@ -4,20 +4,40 @@ use crate::*; #[derive(Clone, Debug, Default)] pub struct Frame { - pub margin: Option, + pub margin: Vec2, + pub corner_radius: f32, + pub fill_color: Option, + pub outline: Option, } impl Frame { - pub fn margin(mut self, margin: Vec2) -> Self { - self.margin = Some(margin); - self + pub fn window(style: &Style) -> Self { + Self { + margin: style.window_padding, + corner_radius: style.window.corner_radius, + fill_color: Some(style.background_fill_color()), + outline: Some(Outline::new(1.0, color::WHITE)), + } + } + + pub fn menu(style: &Style) -> Self { + Self { + margin: Vec2::splat(1.0), + corner_radius: 2.0, + fill_color: Some(style.background_fill_color()), + outline: Some(Outline::new(1.0, color::white(128))), + } } } impl Frame { pub fn show(self, ui: &mut Ui, add_contents: impl FnOnce(&mut Ui)) { - let style = ui.style(); - let margin = self.margin.unwrap_or_default(); + let Frame { + margin, + corner_radius, + fill_color, + outline, + } = self; let outer_pos = ui.cursor(); let inner_rect = @@ -32,14 +52,12 @@ impl Frame { let outer_rect = Rect::from_min_size(outer_pos, margin + inner_size + margin); - let corner_radius = style.window.corner_radius; - let fill_color = style.background_fill_color(); ui.insert_paint_cmd( where_to_put_background, PaintCmd::Rect { corner_radius, - fill_color: Some(fill_color), - outline: Some(Outline::new(1.0, color::WHITE)), + fill_color, + outline, rect: outer_rect, }, ); diff --git a/emigui/src/containers/window.rs b/emigui/src/containers/window.rs index 58d3f7e9..c3e5e86d 100644 --- a/emigui/src/containers/window.rs +++ b/emigui/src/containers/window.rs @@ -8,7 +8,7 @@ use super::*; pub struct Window { pub title_label: Label, pub floating: Floating, - pub frame: Frame, + pub frame: Option, pub resize: Resize, pub scroll: ScrollArea, } @@ -24,7 +24,7 @@ impl Window { Self { title_label, floating, - frame: Frame::default(), + frame: None, resize: Resize::default() .handle_offset(Vec2::splat(4.0)) .auto_shrink_width(true) @@ -85,15 +85,15 @@ impl Window { } impl Window { - pub fn show(self, ctx: &Arc, add_contents: impl FnOnce(&mut Ui)) { + pub fn show(self, ctx: &Arc, add_contents: impl FnOnce(&mut Ui)) -> InteractInfo { let Window { title_label, floating, - mut frame, + frame, resize, scroll, } = self; - frame.margin = Some(frame.margin.unwrap_or_else(|| ctx.style().window_padding)); + let frame = frame.unwrap_or_else(|| Frame::window(&ctx.style())); // TODO: easier way to compose these floating.show(ctx, |ui| { @@ -101,7 +101,7 @@ impl Window { resize.show(ui, |ui| { ui.add(title_label); ui.add(Separator::new().line_width(1.0)); // TODO: nicer way to split window title from contents - scroll.show(ui, |ui| add_contents(ui)) + scroll.show(ui, add_contents) }) }) })