mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 06:10:06 -04:00
Draw separator between window title and its contents
This commit is contained in:
@@ -433,24 +433,39 @@ impl<'a> Widget for Slider<'a> {
|
||||
|
||||
pub struct Separator {
|
||||
line_width: f32,
|
||||
width: f32,
|
||||
min_length: f32,
|
||||
extra: f32,
|
||||
color: Color,
|
||||
}
|
||||
|
||||
impl Separator {
|
||||
pub fn new() -> Separator {
|
||||
Separator {
|
||||
line_width: 2.0,
|
||||
width: 6.0,
|
||||
min_length: 6.0,
|
||||
extra: 0.0,
|
||||
color: color::WHITE,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn line_width(&mut self, line_width: f32) -> &mut Self {
|
||||
pub fn line_width(mut self, line_width: f32) -> Self {
|
||||
self.line_width = line_width;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn width(&mut self, width: f32) -> &mut Self {
|
||||
self.width = width;
|
||||
pub fn min_length(mut self, min_length: f32) -> Self {
|
||||
self.min_length = min_length;
|
||||
self
|
||||
}
|
||||
|
||||
/// Draw this much longer on each side
|
||||
pub fn extra(mut self, extra: f32) -> Self {
|
||||
self.extra = extra;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn color(mut self, color: Color) -> Self {
|
||||
self.color = color;
|
||||
self
|
||||
}
|
||||
}
|
||||
@@ -460,21 +475,21 @@ impl Widget for Separator {
|
||||
let available_space = region.available_space;
|
||||
let (points, interact) = match region.direction() {
|
||||
Direction::Horizontal => {
|
||||
let interact = region.reserve_space(vec2(self.width, available_space.y), None);
|
||||
let interact = region.reserve_space(vec2(self.min_length, available_space.y), None);
|
||||
(
|
||||
vec![
|
||||
pos2(interact.rect.center().x, interact.rect.min().y),
|
||||
pos2(interact.rect.center().x, interact.rect.max().y),
|
||||
pos2(interact.rect.center().x, interact.rect.min().y - self.extra),
|
||||
pos2(interact.rect.center().x, interact.rect.max().y + self.extra),
|
||||
],
|
||||
interact,
|
||||
)
|
||||
}
|
||||
Direction::Vertical => {
|
||||
let interact = region.reserve_space(vec2(available_space.x, self.width), None);
|
||||
let interact = region.reserve_space(vec2(available_space.x, self.min_length), None);
|
||||
(
|
||||
vec![
|
||||
pos2(interact.rect.min().x, interact.rect.center().y),
|
||||
pos2(interact.rect.max().x, interact.rect.center().y),
|
||||
pos2(interact.rect.min().x - self.extra, interact.rect.center().y),
|
||||
pos2(interact.rect.max().x + self.extra, interact.rect.center().y),
|
||||
],
|
||||
interact,
|
||||
)
|
||||
@@ -482,7 +497,7 @@ impl Widget for Separator {
|
||||
};
|
||||
region.add_paint_cmd(PaintCmd::Line {
|
||||
points,
|
||||
color: color::WHITE,
|
||||
color: self.color,
|
||||
width: self.line_width,
|
||||
});
|
||||
region.response(interact)
|
||||
|
||||
Reference in New Issue
Block a user