mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 22:00:03 -04:00
Remove get_*
This commit is contained in:
@@ -190,7 +190,7 @@ struct ContextImpl {
|
|||||||
frame_state: HashMap<ViewportId, FrameState>,
|
frame_state: HashMap<ViewportId, FrameState>,
|
||||||
|
|
||||||
/// Viewport Id, Parent Viewport Id
|
/// Viewport Id, Parent Viewport Id
|
||||||
frame_stack: Vec<(ViewportId, ViewportId)>,
|
frame_stack: Vec<ViewportIdPair>,
|
||||||
|
|
||||||
// The output of a frame:
|
// The output of a frame:
|
||||||
graphics: HashMap<ViewportId, GraphicLayers>,
|
graphics: HashMap<ViewportId, GraphicLayers>,
|
||||||
@@ -234,7 +234,7 @@ impl ContextImpl {
|
|||||||
) {
|
) {
|
||||||
// This is used to pause the last frame
|
// This is used to pause the last frame
|
||||||
if !self.frame_stack.is_empty() {
|
if !self.frame_stack.is_empty() {
|
||||||
let viewport_id = self.get_viewport_id();
|
let viewport_id = self.viewport_id();
|
||||||
|
|
||||||
self.memory.pause_frame(viewport_id);
|
self.memory.pause_frame(viewport_id);
|
||||||
self.layer_rects_this_viewports.insert(
|
self.layer_rects_this_viewports.insert(
|
||||||
@@ -247,9 +247,12 @@ impl ContextImpl {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.frame_stack.push((viewport_id, parent_viewport_id));
|
self.frame_stack.push(ViewportIdPair {
|
||||||
self.output.entry(self.get_viewport_id()).or_default();
|
this: viewport_id,
|
||||||
self.repaint.start_frame(self.get_viewport_id());
|
parent: parent_viewport_id,
|
||||||
|
});
|
||||||
|
self.output.entry(self.viewport_id()).or_default();
|
||||||
|
self.repaint.start_frame(self.viewport_id());
|
||||||
|
|
||||||
if let Some(new_pixels_per_point) = self.memory.new_pixels_per_point {
|
if let Some(new_pixels_per_point) = self.memory.new_pixels_per_point {
|
||||||
if self
|
if self
|
||||||
@@ -321,7 +324,7 @@ impl ContextImpl {
|
|||||||
let mut node_builders = IdMap::default();
|
let mut node_builders = IdMap::default();
|
||||||
node_builders.insert(id, builder);
|
node_builders.insert(id, builder);
|
||||||
self.frame_state
|
self.frame_state
|
||||||
.entry(self.get_viewport_id())
|
.entry(self.viewport_id())
|
||||||
.or_default()
|
.or_default()
|
||||||
.accesskit_state = Some(AccessKitFrameState {
|
.accesskit_state = Some(AccessKitFrameState {
|
||||||
node_builders,
|
node_builders,
|
||||||
@@ -334,7 +337,7 @@ impl ContextImpl {
|
|||||||
fn update_fonts_mut(&mut self) {
|
fn update_fonts_mut(&mut self) {
|
||||||
crate::profile_function!();
|
crate::profile_function!();
|
||||||
|
|
||||||
let input = self.input.entry(self.get_viewport_id()).or_default();
|
let input = self.input.entry(self.viewport_id()).or_default();
|
||||||
let pixels_per_point = input.pixels_per_point();
|
let pixels_per_point = input.pixels_per_point();
|
||||||
let max_texture_side = input.max_texture_side;
|
let max_texture_side = input.max_texture_side;
|
||||||
|
|
||||||
@@ -369,7 +372,7 @@ impl ContextImpl {
|
|||||||
fn accesskit_node_builder(&mut self, id: Id) -> &mut accesskit::NodeBuilder {
|
fn accesskit_node_builder(&mut self, id: Id) -> &mut accesskit::NodeBuilder {
|
||||||
let state = self
|
let state = self
|
||||||
.frame_state
|
.frame_state
|
||||||
.entry(self.get_viewport_id())
|
.entry(self.viewport_id())
|
||||||
.or_default()
|
.or_default()
|
||||||
.accesskit_state
|
.accesskit_state
|
||||||
.as_mut()
|
.as_mut()
|
||||||
@@ -389,15 +392,15 @@ 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`
|
/// In the case of this viewport is the main viewport will be `ViewportId::MAIN`
|
||||||
pub(crate) fn get_viewport_id(&self) -> ViewportId {
|
pub(crate) fn viewport_id(&self) -> ViewportId {
|
||||||
self.frame_stack.last().copied().unwrap_or_default().0
|
self.frame_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`
|
/// In the case of this viewport is the main viewport will be `ViewportId::MAIN`
|
||||||
pub(crate) fn get_parent_viewport_id(&self) -> ViewportId {
|
pub(crate) fn parent_viewport_id(&self) -> ViewportId {
|
||||||
self.frame_stack.last().copied().unwrap_or_default().1
|
self.frame_stack.last().copied().unwrap_or_default().parent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -593,7 +596,7 @@ impl Context {
|
|||||||
self.read(move |ctx| {
|
self.read(move |ctx| {
|
||||||
reader(
|
reader(
|
||||||
ctx.input
|
ctx.input
|
||||||
.get(&ctx.get_viewport_id())
|
.get(&ctx.viewport_id())
|
||||||
.unwrap_or(&Default::default()),
|
.unwrap_or(&Default::default()),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -608,7 +611,7 @@ impl Context {
|
|||||||
/// Read-write access to [`InputState`].
|
/// Read-write access to [`InputState`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn input_mut<R>(&self, writer: impl FnOnce(&mut InputState) -> R) -> R {
|
pub fn input_mut<R>(&self, writer: impl FnOnce(&mut InputState) -> R) -> R {
|
||||||
self.write(move |ctx| writer(ctx.input.entry(ctx.get_viewport_id()).or_default()))
|
self.write(move |ctx| writer(ctx.input.entry(ctx.viewport_id()).or_default()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This will create a `InputState::default()` if there is no input state for that viewport
|
/// This will create a `InputState::default()` if there is no input state for that viewport
|
||||||
@@ -644,7 +647,7 @@ impl Context {
|
|||||||
/// Read-write access to [`GraphicLayers`], where painted [`crate::Shape`]s are written to.
|
/// Read-write access to [`GraphicLayers`], where painted [`crate::Shape`]s are written to.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn graphics_mut<R>(&self, writer: impl FnOnce(&mut GraphicLayers) -> R) -> R {
|
pub(crate) fn graphics_mut<R>(&self, writer: impl FnOnce(&mut GraphicLayers) -> R) -> R {
|
||||||
self.write(move |ctx| writer(ctx.graphics.entry(ctx.get_viewport_id()).or_default()))
|
self.write(move |ctx| writer(ctx.graphics.entry(ctx.viewport_id()).or_default()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read-only access to [`PlatformOutput`].
|
/// Read-only access to [`PlatformOutput`].
|
||||||
@@ -660,7 +663,7 @@ impl Context {
|
|||||||
self.read(move |ctx| {
|
self.read(move |ctx| {
|
||||||
reader(
|
reader(
|
||||||
ctx.output
|
ctx.output
|
||||||
.get(&ctx.get_viewport_id())
|
.get(&ctx.viewport_id())
|
||||||
.unwrap_or(&Default::default()),
|
.unwrap_or(&Default::default()),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -669,19 +672,19 @@ impl Context {
|
|||||||
/// Read-write access to [`PlatformOutput`].
|
/// Read-write access to [`PlatformOutput`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn output_mut<R>(&self, writer: impl FnOnce(&mut PlatformOutput) -> R) -> R {
|
pub fn output_mut<R>(&self, writer: impl FnOnce(&mut PlatformOutput) -> R) -> R {
|
||||||
self.write(move |ctx| writer(ctx.output.entry(ctx.get_viewport_id()).or_default()))
|
self.write(move |ctx| writer(ctx.output.entry(ctx.viewport_id()).or_default()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read-only access to [`FrameState`].
|
/// Read-only access to [`FrameState`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn frame_state<R>(&self, reader: impl FnOnce(&FrameState) -> R) -> R {
|
pub(crate) fn frame_state<R>(&self, reader: impl FnOnce(&FrameState) -> R) -> R {
|
||||||
self.read(move |ctx| reader(&ctx.frame_state[&ctx.get_viewport_id()]))
|
self.read(move |ctx| reader(&ctx.frame_state[&ctx.viewport_id()]))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read-write access to [`FrameState`].
|
/// Read-write access to [`FrameState`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn frame_state_mut<R>(&self, writer: impl FnOnce(&mut FrameState) -> R) -> R {
|
pub(crate) fn frame_state_mut<R>(&self, writer: impl FnOnce(&mut FrameState) -> R) -> R {
|
||||||
self.write(move |ctx| writer(ctx.frame_state.entry(ctx.get_viewport_id()).or_default()))
|
self.write(move |ctx| writer(ctx.frame_state.entry(ctx.viewport_id()).or_default()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read-only access to [`Fonts`].
|
/// Read-only access to [`Fonts`].
|
||||||
@@ -863,7 +866,7 @@ impl Context {
|
|||||||
.push((id, interact_rect));
|
.push((id, interact_rect));
|
||||||
|
|
||||||
if hovered {
|
if hovered {
|
||||||
let pointer_pos = &ctx.input[&ctx.get_viewport_id()].pointer.interact_pos();
|
let pointer_pos = &ctx.input[&ctx.viewport_id()].pointer.interact_pos();
|
||||||
if let Some(pointer_pos) = pointer_pos {
|
if let Some(pointer_pos) = pointer_pos {
|
||||||
if let Some(rects) = ctx.layer_rects_prev_frame.get(&layer_id) {
|
if let Some(rects) = ctx.layer_rects_prev_frame.get(&layer_id) {
|
||||||
for &(prev_id, prev_rect) in rects.iter().rev() {
|
for &(prev_id, prev_rect) in rects.iter().rev() {
|
||||||
@@ -957,7 +960,7 @@ impl Context {
|
|||||||
|
|
||||||
let clicked_elsewhere = response.clicked_elsewhere();
|
let clicked_elsewhere = response.clicked_elsewhere();
|
||||||
self.write(|ctx| {
|
self.write(|ctx| {
|
||||||
let viewport_id = ctx.get_viewport_id();
|
let viewport_id = ctx.viewport_id();
|
||||||
let memory = &mut ctx.memory;
|
let memory = &mut ctx.memory;
|
||||||
|
|
||||||
if sense.focusable {
|
if sense.focusable {
|
||||||
@@ -1157,7 +1160,7 @@ impl Context {
|
|||||||
/// This will repaint the current viewport
|
/// This will repaint the current viewport
|
||||||
pub fn request_repaint(&self) {
|
pub fn request_repaint(&self) {
|
||||||
// request two frames of repaint, just to cover some corner cases (frame delays):
|
// request two frames of repaint, just to cover some corner cases (frame delays):
|
||||||
self.write(|ctx| ctx.repaint.request_repaint(ctx.get_viewport_id()));
|
self.write(|ctx| ctx.repaint.request_repaint(ctx.viewport_id()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Call this if there is need to repaint the UI, i.e. if you are showing an animation.
|
/// Call this if there is need to repaint the UI, i.e. if you are showing an animation.
|
||||||
@@ -1209,7 +1212,7 @@ impl Context {
|
|||||||
// Maybe we can check if duration is ZERO, and call self.request_repaint()?
|
// Maybe we can check if duration is ZERO, and call self.request_repaint()?
|
||||||
self.write(|ctx| {
|
self.write(|ctx| {
|
||||||
ctx.repaint
|
ctx.repaint
|
||||||
.request_repaint_after(duration, ctx.get_viewport_id());
|
.request_repaint_after(duration, ctx.viewport_id());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1480,7 +1483,7 @@ impl Context {
|
|||||||
|
|
||||||
let mut viewports: Vec<ViewportId> = self.write(|ctx| {
|
let mut viewports: Vec<ViewportId> = self.write(|ctx| {
|
||||||
ctx.layer_rects_prev_viewports.insert(
|
ctx.layer_rects_prev_viewports.insert(
|
||||||
ctx.get_viewport_id(),
|
ctx.viewport_id(),
|
||||||
std::mem::take(&mut ctx.layer_rects_this_frame),
|
std::mem::take(&mut ctx.layer_rects_this_frame),
|
||||||
);
|
);
|
||||||
ctx.viewports
|
ctx.viewports
|
||||||
@@ -1504,10 +1507,10 @@ impl Context {
|
|||||||
|
|
||||||
let textures_delta = self.write(|ctx| {
|
let textures_delta = self.write(|ctx| {
|
||||||
ctx.memory.end_frame(
|
ctx.memory.end_frame(
|
||||||
&ctx.input[&ctx.get_viewport_id()],
|
&ctx.input[&ctx.viewport_id()],
|
||||||
&viewports,
|
&viewports,
|
||||||
&ctx.frame_state
|
&ctx.frame_state
|
||||||
.entry(ctx.get_viewport_id())
|
.entry(ctx.viewport_id())
|
||||||
.or_default()
|
.or_default()
|
||||||
.used_ids,
|
.used_ids,
|
||||||
);
|
);
|
||||||
@@ -1571,7 +1574,7 @@ impl Context {
|
|||||||
avalibile_viewports
|
avalibile_viewports
|
||||||
});
|
});
|
||||||
|
|
||||||
let viewport_id = self.get_viewport_id();
|
let viewport_id = self.viewport_id();
|
||||||
|
|
||||||
let mut viewports = Vec::new();
|
let mut viewports = Vec::new();
|
||||||
self.write(|ctx| {
|
self.write(|ctx| {
|
||||||
@@ -1607,7 +1610,7 @@ impl Context {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if !is_last {
|
if !is_last {
|
||||||
let viewport_id = self.get_viewport_id();
|
let viewport_id = self.viewport_id();
|
||||||
self.write(|ctx| {
|
self.write(|ctx| {
|
||||||
ctx.layer_rects_prev_frame =
|
ctx.layer_rects_prev_frame =
|
||||||
ctx.layer_rects_prev_viewports.remove(&viewport_id).unwrap();
|
ctx.layer_rects_prev_viewports.remove(&viewport_id).unwrap();
|
||||||
@@ -1636,7 +1639,7 @@ impl Context {
|
|||||||
|
|
||||||
let repaint_after = self.write(|ctx| {
|
let repaint_after = self.write(|ctx| {
|
||||||
ctx.repaint
|
ctx.repaint
|
||||||
.end_frame(ctx.get_viewport_id(), &avalibile_viewports)
|
.end_frame(ctx.viewport_id(), &avalibile_viewports)
|
||||||
});
|
});
|
||||||
|
|
||||||
FullOutput {
|
FullOutput {
|
||||||
@@ -1658,7 +1661,7 @@ impl Context {
|
|||||||
crate::profile_function!();
|
crate::profile_function!();
|
||||||
self.write(|ctx| {
|
self.write(|ctx| {
|
||||||
ctx.graphics
|
ctx.graphics
|
||||||
.entry(ctx.get_viewport_id())
|
.entry(ctx.viewport_id())
|
||||||
.or_default()
|
.or_default()
|
||||||
.drain(ctx.memory.areas.order())
|
.drain(ctx.memory.areas.order())
|
||||||
.collect()
|
.collect()
|
||||||
@@ -1677,7 +1680,7 @@ impl Context {
|
|||||||
self.write(|ctx| {
|
self.write(|ctx| {
|
||||||
let pixels_per_point = ctx
|
let pixels_per_point = ctx
|
||||||
.input
|
.input
|
||||||
.entry(ctx.get_viewport_id())
|
.entry(ctx.viewport_id())
|
||||||
.or_default()
|
.or_default()
|
||||||
.pixels_per_point();
|
.pixels_per_point();
|
||||||
let tessellation_options = ctx.memory.options.tessellation_options;
|
let tessellation_options = ctx.memory.options.tessellation_options;
|
||||||
@@ -1749,7 +1752,7 @@ impl Context {
|
|||||||
/// How much space is used by panels and windows.
|
/// How much space is used by panels and windows.
|
||||||
pub fn used_rect(&self) -> Rect {
|
pub fn used_rect(&self) -> Rect {
|
||||||
self.read(|ctx| {
|
self.read(|ctx| {
|
||||||
let mut used = ctx.frame_state[&ctx.get_viewport_id()].used_by_panels;
|
let mut used = ctx.frame_state[&ctx.viewport_id()].used_by_panels;
|
||||||
for window in ctx.memory.areas.visible_windows() {
|
for window in ctx.memory.areas.visible_windows() {
|
||||||
used = used.union(window.rect());
|
used = used.union(window.rect());
|
||||||
}
|
}
|
||||||
@@ -1927,7 +1930,7 @@ impl Context {
|
|||||||
pub fn animate_bool_with_time(&self, id: Id, target_value: bool, animation_time: f32) -> f32 {
|
pub fn animate_bool_with_time(&self, id: Id, target_value: bool, animation_time: f32) -> f32 {
|
||||||
let animated_value = self.write(|ctx| {
|
let animated_value = self.write(|ctx| {
|
||||||
ctx.animation_manager.animate_bool(
|
ctx.animation_manager.animate_bool(
|
||||||
&ctx.input[&ctx.get_viewport_id()],
|
&ctx.input[&ctx.viewport_id()],
|
||||||
animation_time,
|
animation_time,
|
||||||
id,
|
id,
|
||||||
target_value,
|
target_value,
|
||||||
@@ -1947,7 +1950,7 @@ impl Context {
|
|||||||
pub fn animate_value_with_time(&self, id: Id, target_value: f32, animation_time: f32) -> f32 {
|
pub fn animate_value_with_time(&self, id: Id, target_value: f32, animation_time: f32) -> f32 {
|
||||||
let animated_value = self.write(|ctx| {
|
let animated_value = self.write(|ctx| {
|
||||||
ctx.animation_manager.animate_value(
|
ctx.animation_manager.animate_value(
|
||||||
&ctx.input[&ctx.get_viewport_id()],
|
&ctx.input[&ctx.viewport_id()],
|
||||||
animation_time,
|
animation_time,
|
||||||
id,
|
id,
|
||||||
target_value,
|
target_value,
|
||||||
@@ -2277,7 +2280,7 @@ impl Context {
|
|||||||
) -> Option<R> {
|
) -> Option<R> {
|
||||||
self.write(|ctx| {
|
self.write(|ctx| {
|
||||||
ctx.frame_state
|
ctx.frame_state
|
||||||
.entry(ctx.get_viewport_id())
|
.entry(ctx.viewport_id())
|
||||||
.or_default()
|
.or_default()
|
||||||
.accesskit_state
|
.accesskit_state
|
||||||
.is_some()
|
.is_some()
|
||||||
@@ -2538,18 +2541,18 @@ impl Context {
|
|||||||
impl Context {
|
impl Context {
|
||||||
/// 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`
|
/// In the case of this viewport is the main viewport will be `ViewportId::MAIN`
|
||||||
pub fn get_viewport_id(&self) -> ViewportId {
|
pub fn viewport_id(&self) -> ViewportId {
|
||||||
self.read(|ctx| ctx.get_viewport_id())
|
self.read(|ctx| ctx.viewport_id())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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`
|
/// In the case of this viewport is the main viewport will be `ViewportId::MAIN`
|
||||||
pub fn get_parent_viewport_id(&self) -> ViewportId {
|
pub fn parent_viewport_id(&self) -> ViewportId {
|
||||||
self.read(|ctx| ctx.get_parent_viewport_id())
|
self.read(|ctx| ctx.parent_viewport_id())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This will return the `ViewportIdPair` of the specified id
|
/// This will return the `ViewportIdPair` of the specified id
|
||||||
pub fn get_viewport_id_pair(&self, id: impl Into<Id>) -> Option<ViewportIdPair> {
|
pub fn viewport_id_pair(&self, id: impl Into<Id>) -> Option<ViewportIdPair> {
|
||||||
self.read(|ctx| ctx.viewports.get(&id.into()).map(|v| v.pair))
|
self.read(|ctx| ctx.viewports.get(&id.into()).map(|v| v.pair))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2582,7 +2585,7 @@ impl Context {
|
|||||||
|
|
||||||
/// This will send the `ViewportCommand` to the current viewport
|
/// This will send the `ViewportCommand` to the current viewport
|
||||||
pub fn viewport_command(&self, command: ViewportCommand) {
|
pub fn viewport_command(&self, command: ViewportCommand) {
|
||||||
self.viewport_command_for(self.get_viewport_id(), command);
|
self.viewport_command_for(self.viewport_id(), command);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// With this you can send a command to a viewport
|
/// With this you can send a command to a viewport
|
||||||
@@ -2606,7 +2609,7 @@ impl Context {
|
|||||||
) {
|
) {
|
||||||
if !self.force_embedding() {
|
if !self.force_embedding() {
|
||||||
self.write(|ctx| {
|
self.write(|ctx| {
|
||||||
let viewport_id = ctx.get_viewport_id();
|
let viewport_id = ctx.viewport_id();
|
||||||
if let Some(window) = ctx.viewports.get_mut(&viewport_builder.id) {
|
if let Some(window) = ctx.viewports.get_mut(&viewport_builder.id) {
|
||||||
window.builder = viewport_builder;
|
window.builder = viewport_builder;
|
||||||
window.pair.parent = viewport_id;
|
window.pair.parent = viewport_id;
|
||||||
@@ -2649,7 +2652,7 @@ impl Context {
|
|||||||
if !self.force_embedding() {
|
if !self.force_embedding() {
|
||||||
let mut id_pair = ViewportIdPair::MAIN;
|
let mut id_pair = ViewportIdPair::MAIN;
|
||||||
let render_sync = self.write(|ctx| {
|
let render_sync = self.write(|ctx| {
|
||||||
id_pair.parent = ctx.get_viewport_id();
|
id_pair.parent = ctx.viewport_id();
|
||||||
if let Some(window) = ctx.viewports.get_mut(&viewport_builder.id) {
|
if let Some(window) = ctx.viewports.get_mut(&viewport_builder.id) {
|
||||||
window.builder = viewport_builder.clone();
|
window.builder = viewport_builder.clone();
|
||||||
window.pair.parent = id_pair.parent;
|
window.pair.parent = id_pair.parent;
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ impl eframe::App for App {
|
|||||||
|
|
||||||
if ui.button("Set parent pos {0, 0}").clicked() {
|
if ui.button("Set parent pos {0, 0}").clicked() {
|
||||||
let ctx = ui.ctx().clone();
|
let ctx = ui.ctx().clone();
|
||||||
let parent_id = ctx.get_parent_viewport_id();
|
let parent_id = ctx.parent_viewport_id();
|
||||||
ctx.viewport_command_for(
|
ctx.viewport_command_for(
|
||||||
parent_id,
|
parent_id,
|
||||||
egui::ViewportCommand::OuterPosition(
|
egui::ViewportCommand::OuterPosition(
|
||||||
@@ -125,7 +125,7 @@ impl eframe::App for App {
|
|||||||
|
|
||||||
if ui.button("Set parent pos {0, 0}").clicked() {
|
if ui.button("Set parent pos {0, 0}").clicked() {
|
||||||
let ctx = ui.ctx().clone();
|
let ctx = ui.ctx().clone();
|
||||||
let parent_id = ctx.get_parent_viewport_id();
|
let parent_id = ctx.parent_viewport_id();
|
||||||
ctx.viewport_command_for(
|
ctx.viewport_command_for(
|
||||||
parent_id,
|
parent_id,
|
||||||
egui::ViewportCommand::OuterPosition(
|
egui::ViewportCommand::OuterPosition(
|
||||||
@@ -185,7 +185,7 @@ impl eframe::App for App {
|
|||||||
|
|
||||||
if ui.button("Set parent pos {0, 0}").clicked() {
|
if ui.button("Set parent pos {0, 0}").clicked() {
|
||||||
let ctx = ui.ctx().clone();
|
let ctx = ui.ctx().clone();
|
||||||
let parent_id = ctx.get_parent_viewport_id();
|
let parent_id = ctx.parent_viewport_id();
|
||||||
ctx.viewport_command_for(
|
ctx.viewport_command_for(
|
||||||
parent_id,
|
parent_id,
|
||||||
egui::ViewportCommand::OuterPosition(
|
egui::ViewportCommand::OuterPosition(
|
||||||
@@ -221,7 +221,7 @@ impl eframe::App for App {
|
|||||||
|
|
||||||
if ui.button("Set parent pos {0, 0}").clicked() {
|
if ui.button("Set parent pos {0, 0}").clicked() {
|
||||||
let ctx = ui.ctx().clone();
|
let ctx = ui.ctx().clone();
|
||||||
let parent_id = ctx.get_parent_viewport_id();
|
let parent_id = ctx.parent_viewport_id();
|
||||||
ctx.viewport_command_for(
|
ctx.viewport_command_for(
|
||||||
parent_id,
|
parent_id,
|
||||||
egui::ViewportCommand::OuterPosition(
|
egui::ViewportCommand::OuterPosition(
|
||||||
@@ -251,7 +251,7 @@ impl eframe::App for App {
|
|||||||
|
|
||||||
/// This will make the content as a popup if cannot has his own native window
|
/// This will make the content as a popup if cannot has his own native window
|
||||||
fn show_as_popup(ctx: &egui::Context, name: &str, content: impl FnOnce(&mut egui::Ui)) {
|
fn show_as_popup(ctx: &egui::Context, name: &str, content: impl FnOnce(&mut egui::Ui)) {
|
||||||
if ctx.get_viewport_id() == ctx.get_parent_viewport_id() {
|
if ctx.viewport_id() == ctx.parent_viewport_id() {
|
||||||
egui::Window::new(name).show(ctx, content);
|
egui::Window::new(name).show(ctx, content);
|
||||||
} else {
|
} else {
|
||||||
egui::CentralPanel::default().show(ctx, content);
|
egui::CentralPanel::default().show(ctx, content);
|
||||||
@@ -261,11 +261,8 @@ fn show_as_popup(ctx: &egui::Context, name: &str, content: impl FnOnce(&mut egui
|
|||||||
fn ui_info(ui: &mut egui::Ui) {
|
fn ui_info(ui: &mut egui::Ui) {
|
||||||
let ctx = ui.ctx().clone();
|
let ctx = ui.ctx().clone();
|
||||||
ui.label(format!("Frame: {}", ctx.frame_nr()));
|
ui.label(format!("Frame: {}", ctx.frame_nr()));
|
||||||
ui.label(format!("Current Viewport Id: {}", ctx.get_viewport_id()));
|
ui.label(format!("Current Viewport Id: {}", ctx.viewport_id()));
|
||||||
ui.label(format!(
|
ui.label(format!("Current Parent Viewport Id: {}", ctx.viewport_id()));
|
||||||
"Current Parent Viewport Id: {}",
|
|
||||||
ctx.get_viewport_id()
|
|
||||||
));
|
|
||||||
ui.label(format!("Pos: {:?}", ctx.viewport_outer_pos()));
|
ui.label(format!("Pos: {:?}", ctx.viewport_outer_pos()));
|
||||||
ui.label(format!("Size: {:?}", ctx.viewport_inner_size()));
|
ui.label(format!("Size: {:?}", ctx.viewport_inner_size()));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user