mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 06:40:06 -04:00
Added now window can be toggled embeded or not
This commit is contained in:
@@ -166,6 +166,8 @@ pub struct Window<'open> {
|
|||||||
collapsible: bool,
|
collapsible: bool,
|
||||||
default_open: bool,
|
default_open: bool,
|
||||||
with_title_bar: bool,
|
with_title_bar: bool,
|
||||||
|
embedded: bool,
|
||||||
|
window_builder: WindowBuilder,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'open> Window<'open> {
|
impl<'open> Window<'open> {
|
||||||
@@ -176,6 +178,7 @@ impl<'open> Window<'open> {
|
|||||||
let title = title.into().fallback_text_style(TextStyle::Heading);
|
let title = title.into().fallback_text_style(TextStyle::Heading);
|
||||||
let area = Area::new(Id::new(title.text()));
|
let area = Area::new(Id::new(title.text()));
|
||||||
Self {
|
Self {
|
||||||
|
window_builder: WindowBuilder::default().with_title(title.text()),
|
||||||
title,
|
title,
|
||||||
open: None,
|
open: None,
|
||||||
area,
|
area,
|
||||||
@@ -188,6 +191,7 @@ impl<'open> Window<'open> {
|
|||||||
collapsible: true,
|
collapsible: true,
|
||||||
default_open: true,
|
default_open: true,
|
||||||
with_title_bar: true,
|
with_title_bar: true,
|
||||||
|
embedded: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,6 +406,11 @@ impl<'open> Window<'open> {
|
|||||||
self.area = self.area.drag_bounds(bounds);
|
self.area = self.area.drag_bounds(bounds);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn embedded(mut self, value: bool) -> Self {
|
||||||
|
self.embedded = value;
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'open> Window<'open> {
|
impl<'open> Window<'open> {
|
||||||
@@ -421,8 +430,6 @@ impl<'open> Window<'open> {
|
|||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
add_contents: Box<dyn FnOnce(&mut Ui) -> R + 'c>,
|
add_contents: Box<dyn FnOnce(&mut Ui) -> R + 'c>,
|
||||||
) -> Option<InnerResponse<Option<R>>> {
|
) -> Option<InnerResponse<Option<R>>> {
|
||||||
let window_id = ctx.create_window(WindowBuilder::default().with_title(self.title.text()));
|
|
||||||
println!("Window id: {}", window_id);
|
|
||||||
let Window {
|
let Window {
|
||||||
title,
|
title,
|
||||||
open,
|
open,
|
||||||
@@ -433,8 +440,17 @@ impl<'open> Window<'open> {
|
|||||||
collapsible,
|
collapsible,
|
||||||
default_open,
|
default_open,
|
||||||
with_title_bar,
|
with_title_bar,
|
||||||
|
embedded,
|
||||||
|
window_builder,
|
||||||
} = self;
|
} = 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 frame = frame.unwrap_or_else(|| Frame::window(&ctx.style()));
|
||||||
|
|
||||||
let is_explicitly_closed = matches!(open, Some(false));
|
let is_explicitly_closed = matches!(open, Some(false));
|
||||||
@@ -448,8 +464,11 @@ impl<'open> Window<'open> {
|
|||||||
let area_id = area.id;
|
let area_id = area.id;
|
||||||
let area_layer_id = area.layer();
|
let area_layer_id = area.layer();
|
||||||
let resize_id = area_id.with("resize");
|
let resize_id = area_id.with("resize");
|
||||||
let mut collapsing =
|
let mut collapsing = CollapsingState::load_with_default_open(
|
||||||
CollapsingState::load_with_default_open(ctx, area_id.with("collapsing"), default_open);
|
ctx,
|
||||||
|
area_id.with("collapsing"),
|
||||||
|
default_open,
|
||||||
|
);
|
||||||
|
|
||||||
let is_collapsed = with_title_bar && !collapsing.is_open();
|
let is_collapsed = with_title_bar && !collapsing.is_open();
|
||||||
let possible = PossibleInteractions::new(&area, &resize, is_collapsed);
|
let possible = PossibleInteractions::new(&area, &resize, is_collapsed);
|
||||||
@@ -496,7 +515,8 @@ impl<'open> Window<'open> {
|
|||||||
} else {
|
} else {
|
||||||
None
|
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);
|
let mut area_content_ui = area.content_ui(ctx);
|
||||||
|
|
||||||
@@ -588,6 +608,9 @@ impl<'open> Window<'open> {
|
|||||||
response: full_response,
|
response: full_response,
|
||||||
};
|
};
|
||||||
Some(inner_response)
|
Some(inner_response)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,9 @@ fn main() -> Result<(), eframe::Error> {
|
|||||||
}
|
}
|
||||||
ui.label(format!("Hello '{name}', age {age}"));
|
ui.label(format!("Hello '{name}', age {age}"));
|
||||||
egui::CollapsingHeader::new("Show Test1").show(ui, |ui| {
|
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::CollapsingHeader::new("Shout Test2").show(ui, |ui| {
|
||||||
egui::Window::new("Test2").show(ctx, |ui| ui.label("Inside a window! 222"));
|
egui::Window::new("Test2").show(ctx, |ui| ui.label("Inside a window! 222"));
|
||||||
|
|||||||
Reference in New Issue
Block a user