1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 23:00:04 -04:00

Added now window can be toggled embeded or not

This commit is contained in:
Konkitoman
2023-07-19 10:57:13 +03:00
parent 680a547a68
commit cd48e2b1ad
2 changed files with 157 additions and 132 deletions

View File

@@ -166,6 +166,8 @@ pub struct Window<'open> {
collapsible: bool,
default_open: bool,
with_title_bar: bool,
embedded: bool,
window_builder: WindowBuilder,
}
impl<'open> Window<'open> {
@@ -176,6 +178,7 @@ impl<'open> Window<'open> {
let title = title.into().fallback_text_style(TextStyle::Heading);
let area = Area::new(Id::new(title.text()));
Self {
window_builder: WindowBuilder::default().with_title(title.text()),
title,
open: None,
area,
@@ -188,6 +191,7 @@ impl<'open> Window<'open> {
collapsible: true,
default_open: true,
with_title_bar: true,
embedded: true,
}
}
@@ -402,6 +406,11 @@ impl<'open> Window<'open> {
self.area = self.area.drag_bounds(bounds);
self
}
pub fn embedded(mut self, value: bool) -> Self {
self.embedded = value;
self
}
}
impl<'open> Window<'open> {
@@ -421,8 +430,6 @@ impl<'open> Window<'open> {
ctx: &Context,
add_contents: Box<dyn FnOnce(&mut Ui) -> R + 'c>,
) -> Option<InnerResponse<Option<R>>> {
let window_id = ctx.create_window(WindowBuilder::default().with_title(self.title.text()));
println!("Window id: {}", window_id);
let Window {
title,
open,
@@ -433,8 +440,17 @@ impl<'open> Window<'open> {
collapsible,
default_open,
with_title_bar,
embedded,
window_builder,
} = self;
let window_id = if !embedded {
ctx.create_window(window_builder)
} else {
0
};
if embedded || ctx.current_window_id() == window_id {
let frame = frame.unwrap_or_else(|| Frame::window(&ctx.style()));
let is_explicitly_closed = matches!(open, Some(false));
@@ -448,8 +464,11 @@ impl<'open> Window<'open> {
let area_id = area.id;
let area_layer_id = area.layer();
let resize_id = area_id.with("resize");
let mut collapsing =
CollapsingState::load_with_default_open(ctx, area_id.with("collapsing"), default_open);
let mut collapsing = CollapsingState::load_with_default_open(
ctx,
area_id.with("collapsing"),
default_open,
);
let is_collapsed = with_title_bar && !collapsing.is_open();
let possible = PossibleInteractions::new(&area, &resize, is_collapsed);
@@ -496,7 +515,8 @@ impl<'open> Window<'open> {
} else {
None
};
let hover_interaction = resize_hover(ctx, possible, area_layer_id, last_frame_outer_rect);
let hover_interaction =
resize_hover(ctx, possible, area_layer_id, last_frame_outer_rect);
let mut area_content_ui = area.content_ui(ctx);
@@ -588,6 +608,9 @@ impl<'open> Window<'open> {
response: full_response,
};
Some(inner_response)
} else {
None
}
}
}

View File

@@ -28,7 +28,9 @@ fn main() -> Result<(), eframe::Error> {
}
ui.label(format!("Hello '{name}', age {age}"));
egui::CollapsingHeader::new("Show Test1").show(ui, |ui| {
egui::Window::new("Test1").show(ctx, |ui| ui.label("Inside a window!"));
egui::Window::new("Test1")
.embedded(false)
.show(ctx, |ui| ui.label("Inside a window!"));
});
egui::CollapsingHeader::new("Shout Test2").show(ui, |ui| {
egui::Window::new("Test2").show(ctx, |ui| ui.label("Inside a window! 222"));