mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 06:10:06 -04:00
Make Memory::areas private
This commit is contained in:
@@ -259,7 +259,7 @@ impl Area {
|
|||||||
|
|
||||||
let layer_id = LayerId::new(order, id);
|
let layer_id = LayerId::new(order, id);
|
||||||
|
|
||||||
let state = ctx.memory(|mem| mem.areas.get(id).copied());
|
let state = ctx.memory(|mem| mem.areas().get(id).copied());
|
||||||
let is_new = state.is_none();
|
let is_new = state.is_none();
|
||||||
if is_new {
|
if is_new {
|
||||||
ctx.request_repaint(); // if we don't know the previous size we are likely drawing the area in the wrong place
|
ctx.request_repaint(); // if we don't know the previous size we are likely drawing the area in the wrong place
|
||||||
@@ -307,9 +307,9 @@ impl Area {
|
|||||||
|
|
||||||
if (move_response.dragged() || move_response.clicked())
|
if (move_response.dragged() || move_response.clicked())
|
||||||
|| pointer_pressed_on_area(ctx, layer_id)
|
|| pointer_pressed_on_area(ctx, layer_id)
|
||||||
|| !ctx.memory(|m| m.areas.visible_last_frame(&layer_id))
|
|| !ctx.memory(|m| m.areas().visible_last_frame(&layer_id))
|
||||||
{
|
{
|
||||||
ctx.memory_mut(|m| m.areas.move_to_top(layer_id));
|
ctx.memory_mut(|m| m.areas_mut().move_to_top(layer_id));
|
||||||
ctx.request_repaint();
|
ctx.request_repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,7 +353,7 @@ impl Area {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let layer_id = LayerId::new(self.order, self.id);
|
let layer_id = LayerId::new(self.order, self.id);
|
||||||
let area_rect = ctx.memory(|mem| mem.areas.get(self.id).map(|area| area.rect()));
|
let area_rect = ctx.memory(|mem| mem.areas().get(self.id).map(|area| area.rect()));
|
||||||
if let Some(area_rect) = area_rect {
|
if let Some(area_rect) = area_rect {
|
||||||
let clip_rect = ctx.available_rect();
|
let clip_rect = ctx.available_rect();
|
||||||
let painter = Painter::new(ctx.clone(), layer_id, clip_rect);
|
let painter = Painter::new(ctx.clone(), layer_id, clip_rect);
|
||||||
@@ -441,7 +441,7 @@ impl Prepared {
|
|||||||
|
|
||||||
state.size = content_ui.min_size();
|
state.size = content_ui.min_size();
|
||||||
|
|
||||||
ctx.memory_mut(|m| m.areas.set_state(layer_id, state));
|
ctx.memory_mut(|m| m.areas_mut().set_state(layer_id, state));
|
||||||
|
|
||||||
move_response
|
move_response
|
||||||
}
|
}
|
||||||
@@ -458,7 +458,7 @@ fn pointer_pressed_on_area(ctx: &Context, layer_id: LayerId) -> bool {
|
|||||||
|
|
||||||
fn automatic_area_position(ctx: &Context) -> Pos2 {
|
fn automatic_area_position(ctx: &Context) -> Pos2 {
|
||||||
let mut existing: Vec<Rect> = ctx.memory(|mem| {
|
let mut existing: Vec<Rect> = ctx.memory(|mem| {
|
||||||
mem.areas
|
mem.areas()
|
||||||
.visible_windows()
|
.visible_windows()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(State::rect)
|
.map(State::rect)
|
||||||
|
|||||||
@@ -244,7 +244,7 @@ fn combo_box_dyn<'c, R>(
|
|||||||
|
|
||||||
let is_popup_open = ui.memory(|m| m.is_popup_open(popup_id));
|
let is_popup_open = ui.memory(|m| m.is_popup_open(popup_id));
|
||||||
|
|
||||||
let popup_height = ui.memory(|m| m.areas.get(popup_id).map_or(100.0, |state| state.size.y));
|
let popup_height = ui.memory(|m| m.areas().get(popup_id).map_or(100.0, |state| state.size.y));
|
||||||
|
|
||||||
let above_or_below =
|
let above_or_below =
|
||||||
if ui.next_widget_position().y + ui.spacing().interact_size.y + popup_height
|
if ui.next_widget_position().y + ui.spacing().interact_size.y + popup_height
|
||||||
|
|||||||
@@ -280,7 +280,7 @@ pub fn was_tooltip_open_last_frame(ctx: &Context, tooltip_id: Id) -> bool {
|
|||||||
if *individual_id == tooltip_id {
|
if *individual_id == tooltip_id {
|
||||||
let area_id = common_id.with(count);
|
let area_id = common_id.with(count);
|
||||||
let layer_id = LayerId::new(Order::Tooltip, area_id);
|
let layer_id = LayerId::new(Order::Tooltip, area_id);
|
||||||
if ctx.memory(|mem| mem.areas.visible_last_frame(&layer_id)) {
|
if ctx.memory(|mem| mem.areas().visible_last_frame(&layer_id)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -580,7 +580,7 @@ fn interact(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.memory_mut(|mem| mem.areas.move_to_top(area_layer_id));
|
ctx.memory_mut(|mem| mem.areas_mut().move_to_top(area_layer_id));
|
||||||
Some(window_interaction)
|
Some(window_interaction)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ impl ContextImpl {
|
|||||||
// Ensure we register the background area so panels and background ui can catch clicks:
|
// Ensure we register the background area so panels and background ui can catch clicks:
|
||||||
let input = &self.input[&viewport_id];
|
let input = &self.input[&viewport_id];
|
||||||
let screen_rect = input.screen_rect();
|
let screen_rect = input.screen_rect();
|
||||||
self.memory.areas.set_state(
|
self.memory.areas_mut().set_state(
|
||||||
LayerId::background(),
|
LayerId::background(),
|
||||||
containers::area::State {
|
containers::area::State {
|
||||||
pivot_pos: screen_rect.left_top(),
|
pivot_pos: screen_rect.left_top(),
|
||||||
@@ -1624,7 +1624,7 @@ impl Context {
|
|||||||
ctx.graphics
|
ctx.graphics
|
||||||
.entry(ctx.viewport_id())
|
.entry(ctx.viewport_id())
|
||||||
.or_default()
|
.or_default()
|
||||||
.drain(ctx.memory.areas.order())
|
.drain(ctx.memory.areas().order())
|
||||||
.collect()
|
.collect()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -1702,7 +1702,7 @@ impl Context {
|
|||||||
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.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());
|
||||||
}
|
}
|
||||||
used
|
used
|
||||||
@@ -1830,7 +1830,7 @@ impl Context {
|
|||||||
///
|
///
|
||||||
/// [`Area`]:s and [`Window`]:s also do this automatically when being clicked on or interacted with.
|
/// [`Area`]:s and [`Window`]:s also do this automatically when being clicked on or interacted with.
|
||||||
pub fn move_to_top(&self, layer_id: LayerId) {
|
pub fn move_to_top(&self, layer_id: LayerId) {
|
||||||
self.memory_mut(|mem| mem.areas.move_to_top(layer_id));
|
self.memory_mut(|mem| mem.areas_mut().move_to_top(layer_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn rect_contains_pointer(&self, layer_id: LayerId, rect: Rect) -> bool {
|
pub(crate) fn rect_contains_pointer(&self, layer_id: LayerId, rect: Rect) -> bool {
|
||||||
@@ -2091,20 +2091,20 @@ impl Context {
|
|||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.label(format!(
|
ui.label(format!(
|
||||||
"{} areas (panels, windows, popups, …)",
|
"{} areas (panels, windows, popups, …)",
|
||||||
self.memory(|mem| mem.areas.count())
|
self.memory(|mem| mem.areas().count())
|
||||||
));
|
));
|
||||||
if ui.button("Reset").clicked() {
|
if ui.button("Reset").clicked() {
|
||||||
self.memory_mut(|mem| mem.areas = Default::default());
|
self.memory_mut(|mem| *mem.areas_mut() = Default::default());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ui.indent("areas", |ui| {
|
ui.indent("areas", |ui| {
|
||||||
ui.label("Visible areas, ordered back to front.");
|
ui.label("Visible areas, ordered back to front.");
|
||||||
ui.label("Hover to highlight");
|
ui.label("Hover to highlight");
|
||||||
let layers_ids: Vec<LayerId> = self.memory(|mem| mem.areas.order().to_vec());
|
let layers_ids: Vec<LayerId> = self.memory(|mem| mem.areas().order().to_vec());
|
||||||
for layer_id in layers_ids {
|
for layer_id in layers_ids {
|
||||||
let area = self.memory(|mem| mem.areas.get(layer_id.id).copied());
|
let area = self.memory(|mem| mem.areas().get(layer_id.id).copied());
|
||||||
if let Some(area) = area {
|
if let Some(area) = area {
|
||||||
let is_visible = self.memory(|mem| mem.areas.is_visible(&layer_id));
|
let is_visible = self.memory(|mem| mem.areas().is_visible(&layer_id));
|
||||||
if !is_visible {
|
if !is_visible {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ pub struct Memory {
|
|||||||
pub(crate) drag_value: crate::widgets::drag_value::MonoState,
|
pub(crate) drag_value: crate::widgets::drag_value::MonoState,
|
||||||
|
|
||||||
#[cfg_attr(feature = "persistence", serde(skip))]
|
#[cfg_attr(feature = "persistence", serde(skip))]
|
||||||
pub(crate) areas: Areas,
|
areas: Areas,
|
||||||
|
|
||||||
#[cfg_attr(feature = "persistence", serde(skip))]
|
#[cfg_attr(feature = "persistence", serde(skip))]
|
||||||
pub(crate) viewports_areas: ViewportIdMap<Areas>,
|
pub(crate) viewports_areas: ViewportIdMap<Areas>,
|
||||||
@@ -565,7 +565,7 @@ impl Memory {
|
|||||||
used_ids: &IdMap<Rect>,
|
used_ids: &IdMap<Rect>,
|
||||||
) {
|
) {
|
||||||
self.caches.update();
|
self.caches.update();
|
||||||
self.areas.end_frame();
|
self.areas_mut().end_frame();
|
||||||
self.interaction.focus.end_frame(used_ids);
|
self.interaction.focus.end_frame(used_ids);
|
||||||
self.interactions
|
self.interactions
|
||||||
.insert(self.viewport_id, std::mem::take(&mut self.interaction));
|
.insert(self.viewport_id, std::mem::take(&mut self.interaction));
|
||||||
@@ -588,14 +588,24 @@ impl Memory {
|
|||||||
self.window_interaction = self.window_interactions.remove(&viewport_id);
|
self.window_interaction = self.window_interactions.remove(&viewport_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Access memory of the [`Area`](crate::containers::area::Area)s, such as `Window`s.
|
||||||
|
pub fn areas(&self) -> &Areas {
|
||||||
|
&self.areas
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Access memory of the [`Area`](crate::containers::area::Area)s, such as `Window`s.
|
||||||
|
pub fn areas_mut(&mut self) -> &mut Areas {
|
||||||
|
&mut self.areas
|
||||||
|
}
|
||||||
|
|
||||||
/// Top-most layer at the given position.
|
/// Top-most layer at the given position.
|
||||||
pub fn layer_id_at(&self, pos: Pos2, resize_interact_radius_side: f32) -> Option<LayerId> {
|
pub fn layer_id_at(&self, pos: Pos2, resize_interact_radius_side: f32) -> Option<LayerId> {
|
||||||
self.areas.layer_id_at(pos, resize_interact_radius_side)
|
self.areas().layer_id_at(pos, resize_interact_radius_side)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An iterator over all layers. Back-to-front. Top is last.
|
/// An iterator over all layers. Back-to-front. Top is last.
|
||||||
pub fn layer_ids(&self) -> impl ExactSizeIterator<Item = LayerId> + '_ {
|
pub fn layer_ids(&self) -> impl ExactSizeIterator<Item = LayerId> + '_ {
|
||||||
self.areas.order().iter().copied()
|
self.areas().order().iter().copied()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn had_focus_last_frame(&self, id: Id) -> bool {
|
pub(crate) fn had_focus_last_frame(&self, id: Id) -> bool {
|
||||||
@@ -725,7 +735,7 @@ impl Memory {
|
|||||||
|
|
||||||
/// Obtain the previous rectangle of an area.
|
/// Obtain the previous rectangle of an area.
|
||||||
pub fn area_rect(&self, id: impl Into<Id>) -> Option<Rect> {
|
pub fn area_rect(&self, id: impl Into<Id>) -> Option<Rect> {
|
||||||
self.areas.get(id.into()).map(|state| state.rect())
|
self.areas().get(id.into()).map(|state| state.rect())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user