1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 14:20:04 -04:00

MAIN -> ROOT

This commit is contained in:
Emil Ernerfeldt
2023-11-06 19:19:37 +01:00
parent 6a371e59cb
commit a52d38312c
10 changed files with 89 additions and 85 deletions

View File

@@ -349,16 +349,16 @@ impl ContextImpl {
}
impl ContextImpl {
/// Return the `ViewportId` of the current viewport
/// Return the `ViewportId` of the current viewport.
///
/// In the case of this viewport is the main viewport will be `ViewportId::MAIN`
/// For the root viewport this will return [`ViewportId::ROOT`].
pub(crate) fn viewport_id(&self) -> ViewportId {
self.viewport_stack.last().copied().unwrap_or_default().this
}
/// Return the `ViewportId` of his parent
/// Return the `ViewportId` of his parent.
///
/// In the case of this viewport is the main viewport will be `ViewportId::MAIN`
/// For the root viewport this will return [`ViewportId::ROOT`].
pub(crate) fn parent_viewport_id(&self) -> ViewportId {
self.viewport_stack
.last()
@@ -407,7 +407,7 @@ impl ContextImpl {
/// // Game loop:
/// loop {
/// let raw_input = egui::RawInput::default();
/// let full_output = ctx.run(raw_input, egui::ViewportIdPair::MAIN, |ctx| {
/// let full_output = ctx.run(raw_input, egui::ViewportIdPair::ROOT, |ctx| {
/// egui::CentralPanel::default().show(&ctx, |ui| {
/// ui.label("Hello world!");
/// if ui.button("Click me").clicked() {
@@ -416,7 +416,7 @@ impl ContextImpl {
/// });
/// });
/// handle_platform_output(full_output.platform_output);
/// let clipped_primitives = ctx.tessellate(full_output.shapes, egui::ViewportId::MAIN); // create triangles to paint
/// let clipped_primitives = ctx.tessellate(full_output.shapes, egui::ViewportId::ROOT); // create triangles to paint
/// paint(full_output.textures_delta, clipped_primitives);
/// }
/// ```
@@ -473,7 +473,7 @@ impl Context {
///
/// // Each frame:
/// let input = egui::RawInput::default();
/// let full_output = ctx.run(input, egui::ViewportIdPair::MAIN, |ctx| {
/// let full_output = ctx.run(input, egui::ViewportIdPair::ROOT, |ctx| {
/// egui::CentralPanel::default().show(&ctx, |ui| {
/// ui.label("Hello egui!");
/// });
@@ -502,7 +502,7 @@ impl Context {
///
/// // Each frame:
/// let input = egui::RawInput::default();
/// ctx.begin_frame(input, egui::ViewportIdPair::MAIN);
/// ctx.begin_frame(input, egui::ViewportIdPair::ROOT);
///
/// egui::CentralPanel::default().show(&ctx, |ui| {
/// ui.label("Hello egui!");
@@ -1341,7 +1341,7 @@ impl Context {
for viewport in ctx.viewports.values() {
ctx.repaint.request_repaint_settle(viewport.id_pair.this);
}
ctx.repaint.request_repaint_settle(ViewportId::MAIN);
ctx.repaint.request_repaint_settle(ViewportId::ROOT);
ctx.memory.override_pixels_per_point = Some(pixels_per_point);
});
}
@@ -1492,7 +1492,7 @@ impl Context {
);
ctx.viewports.values().map(|vp| vp.id_pair.this).collect()
});
viewports.push(ViewportId::MAIN);
viewports.push(ViewportId::ROOT);
if self.input(|i| i.wants_repaint()) {
self.request_repaint();
@@ -1556,7 +1556,7 @@ impl Context {
// If there are no viewport that contains the current viewport that viewport needs to be destroyed!
let available_viewports = self.read(|ctx| {
let mut available_viewports = vec![ViewportId::MAIN];
let mut available_viewports = vec![ViewportId::ROOT];
for vp in ctx.viewports.values() {
available_viewports.push(vp.id_pair.this);
}
@@ -2500,16 +2500,20 @@ impl Context {
/// ## Viewports
impl Context {
/// Return the `ViewportId` of the current viewport
/// In the case of this viewport is the main viewport will be `ViewportId::MAIN`
/// Don't use this outside of `Self::run`, or after `Self::end_frame`
/// Return the `ViewportId` of the current viewport.
///
/// If this is the root viewport, this will return [`ViewportId::ROOT`].
///
/// Don't use this outside of `Self::run`, or after `Self::end_frame`.
pub fn viewport_id(&self) -> ViewportId {
self.read(|ctx| ctx.viewport_id())
}
/// Return the `ViewportId` of his parent
/// In the case of this viewport is the main viewport will be `ViewportId::MAIN`
/// Don't use this outside of `Self::run`, or after `Self::end_frame`
/// Return the `ViewportId` of his parent.
///
/// If this is the root viewport, this will return [`ViewportId::ROOT`].
///
/// Don't use this outside of `Self::run`, or after `Self::end_frame`.
pub fn parent_viewport_id(&self) -> ViewportId {
self.read(|ctx| ctx.parent_viewport_id())
}

View File

@@ -125,7 +125,7 @@
//! loop {
//! let raw_input: egui::RawInput = gather_input();
//!
//! let full_output = ctx.run(raw_input, egui::ViewportIdPair::MAIN, |ctx| {
//! let full_output = ctx.run(raw_input, egui::ViewportIdPair::ROOT, |ctx| {
//! egui::CentralPanel::default().show(&ctx, |ui| {
//! ui.label("Hello world!");
//! if ui.button("Click me").clicked() {
@@ -134,7 +134,7 @@
//! });
//! });
//! handle_platform_output(full_output.platform_output);
//! let clipped_primitives = ctx.tessellate(full_output.shapes, egui::ViewportId::MAIN); // create triangles to paint
//! let clipped_primitives = ctx.tessellate(full_output.shapes, egui::ViewportId::ROOT); // create triangles to paint
//! paint(full_output.textures_delta, clipped_primitives);
//! }
//! ```
@@ -606,7 +606,7 @@ pub enum WidgetType {
pub fn __run_test_ctx(mut run_ui: impl FnMut(&Context)) {
let ctx = Context::default();
ctx.set_fonts(FontDefinitions::empty()); // prevent fonts from being loaded (save CPU time)
let _ = ctx.run(Default::default(), ViewportIdPair::MAIN, |ctx| {
let _ = ctx.run(Default::default(), ViewportIdPair::ROOT, |ctx| {
run_ui(ctx);
});
}
@@ -615,7 +615,7 @@ pub fn __run_test_ctx(mut run_ui: impl FnMut(&Context)) {
pub fn __run_test_ui(mut add_contents: impl FnMut(&mut Ui)) {
let ctx = Context::default();
ctx.set_fonts(FontDefinitions::empty()); // prevent fonts from being loaded (save CPU time)
let _ = ctx.run(Default::default(), ViewportIdPair::MAIN, |ctx| {
let _ = ctx.run(Default::default(), ViewportIdPair::ROOT, |ctx| {
crate::CentralPanel::default().show(ctx, |ui| {
add_contents(ui);
});

View File

@@ -23,7 +23,7 @@ pub struct ViewportId(pub Id);
impl Default for ViewportId {
fn default() -> Self {
Self::MAIN
Self::ROOT
}
}
@@ -34,8 +34,8 @@ impl std::fmt::Debug for ViewportId {
}
impl ViewportId {
/// This will return the `ViewportId` of the main viewport
pub const MAIN: Self = Self(Id::null());
/// The `ViewportId` of the root viewport.
pub const ROOT: Self = Self(Id::null());
pub fn from_hash_of(source: impl std::hash::Hash) -> Self {
Self(Id::new(source))
@@ -66,17 +66,17 @@ pub struct ViewportIdPair {
impl Default for ViewportIdPair {
fn default() -> Self {
Self {
this: ViewportId::MAIN,
parent: ViewportId::MAIN,
this: ViewportId::ROOT,
parent: ViewportId::ROOT,
}
}
}
impl ViewportIdPair {
/// This will return the `ViewportIdPair` of the main viewport
pub const MAIN: Self = Self {
this: ViewportId::MAIN,
parent: ViewportId::MAIN,
/// The `ViewportIdPair` of the root viewport, which is its own parent.
pub const ROOT: Self = Self {
this: ViewportId::ROOT,
parent: ViewportId::ROOT,
};
}