mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 06:10:06 -04:00
add: Context::get_viewport_id_by_name, Context::get_viewport_parent_id_by_name, Context::input_for and Context::input_mut_for
This commit is contained in:
@@ -580,12 +580,24 @@ impl Context {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This will create a `InputState::default()` if there is no input state for that viewport
|
||||||
|
#[inline]
|
||||||
|
pub fn input_for<R>(&self, id: ViewportId, reader: impl FnOnce(&InputState) -> R) -> R {
|
||||||
|
self.read(move |ctx| reader(ctx.input.get(&id).unwrap_or(&Default::default())))
|
||||||
|
}
|
||||||
|
|
||||||
/// 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.get_viewport_id()).or_default()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This will create a `InputState::default()` if there is no input state for that viewport
|
||||||
|
#[inline]
|
||||||
|
pub fn input_mut_for<R>(&self, id: ViewportId, writer: impl FnOnce(&mut InputState) -> R) -> R {
|
||||||
|
self.write(move |ctx| writer(ctx.input.entry(id).or_default()))
|
||||||
|
}
|
||||||
|
|
||||||
/// Read-only access to [`Memory`].
|
/// Read-only access to [`Memory`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn memory<R>(&self, reader: impl FnOnce(&Memory) -> R) -> R {
|
pub fn memory<R>(&self, reader: impl FnOnce(&Memory) -> R) -> R {
|
||||||
@@ -1576,7 +1588,7 @@ impl Context {
|
|||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
/// Position and size of the egui area.
|
/// Position and size of the current viewport.
|
||||||
/// min is the position, max is the size
|
/// min is the position, max is the size
|
||||||
pub fn screen_rect(&self) -> Rect {
|
pub fn screen_rect(&self) -> Rect {
|
||||||
self.input(|i| i.screen_rect())
|
self.input(|i| i.screen_rect())
|
||||||
@@ -2167,6 +2179,14 @@ impl Context {
|
|||||||
self.read(|ctx| ctx.get_parent_viewport_id())
|
self.read(|ctx| ctx.get_parent_viewport_id())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_viewport_id_by_name(&self, name: &str) -> Option<ViewportId> {
|
||||||
|
self.read(|ctx| ctx.viewports.get(name).map(|v| v.1))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_viewport_parent_id_by_name(&self, name: &str) -> Option<ViewportId> {
|
||||||
|
self.read(|ctx| ctx.viewports.get(name).map(|v| v.1))
|
||||||
|
}
|
||||||
|
|
||||||
/// This should only be used by the backend!
|
/// This should only be used by the backend!
|
||||||
///
|
///
|
||||||
/// When a viewport sync is created will be rendered by this function
|
/// When a viewport sync is created will be rendered by this function
|
||||||
|
|||||||
Reference in New Issue
Block a user