Frame: more customizeable
This commit is contained in:
parent
2dd1c5ba78
commit
f7291e4a0d
2 changed files with 34 additions and 16 deletions
|
@ -4,20 +4,40 @@ use crate::*;
|
|||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct Frame {
|
||||
pub margin: Option<Vec2>,
|
||||
pub margin: Vec2,
|
||||
pub corner_radius: f32,
|
||||
pub fill_color: Option<Color>,
|
||||
pub outline: Option<Outline>,
|
||||
}
|
||||
|
||||
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,
|
||||
},
|
||||
);
|
||||
|
|
|
@ -8,7 +8,7 @@ use super::*;
|
|||
pub struct Window {
|
||||
pub title_label: Label,
|
||||
pub floating: Floating,
|
||||
pub frame: Frame,
|
||||
pub frame: Option<Frame>,
|
||||
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<Context>, add_contents: impl FnOnce(&mut Ui)) {
|
||||
pub fn show(self, ctx: &Arc<Context>, 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)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue