1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 21:30:03 -04:00

Rename Floating to Area

This commit is contained in:
Emil Ernerfeldt
2020-05-10 13:14:52 +02:00
parent 90020b41a8
commit fd99213222
6 changed files with 54 additions and 58 deletions

View File

@@ -1,7 +1,7 @@
use std::collections::{HashMap, HashSet};
use crate::{
containers::{collapsing_header, floating, resize, scroll_area},
containers::{area, collapsing_header, resize, scroll_area},
Id, Layer, Pos2, Rect,
};
@@ -21,40 +21,40 @@ pub struct Memory {
pub(crate) scroll_areas: HashMap<Id, scroll_area::State>,
pub(crate) resize: HashMap<Id, resize::State>,
floating: HashMap<Id, floating::State>,
area: HashMap<Id, area::State>,
/// Top is last
floating_order: Vec<Id>,
floating_visible_last_frame: HashSet<Id>,
floating_visible_current_frame: HashSet<Id>,
area_order: Vec<Id>,
area_visible_last_frame: HashSet<Id>,
area_visible_current_frame: HashSet<Id>,
}
impl Memory {
pub(crate) fn get_floating(&mut self, id: Id) -> Option<floating::State> {
self.floating.get(&id).cloned()
pub(crate) fn get_area(&mut self, id: Id) -> Option<area::State> {
self.area.get(&id).cloned()
}
pub(crate) fn floating_order(&self) -> &[Id] {
&self.floating_order
pub(crate) fn area_order(&self) -> &[Id] {
&self.area_order
}
pub(crate) fn set_floating_state(&mut self, id: Id, state: floating::State) {
self.floating_visible_current_frame.insert(id);
let did_insert = self.floating.insert(id, state).is_none();
pub(crate) fn set_area_state(&mut self, id: Id, state: area::State) {
self.area_visible_current_frame.insert(id);
let did_insert = self.area.insert(id, state).is_none();
if did_insert {
self.floating_order.push(id);
self.area_order.push(id);
}
}
/// TODO: call once at the start of the frame for the current mouse pos
pub fn layer_at(&self, pos: Pos2) -> Layer {
for floating_id in self.floating_order.iter().rev() {
if self.floating_visible_last_frame.contains(floating_id)
|| self.floating_visible_current_frame.contains(floating_id)
for area_id in self.area_order.iter().rev() {
if self.area_visible_last_frame.contains(area_id)
|| self.area_visible_current_frame.contains(area_id)
{
if let Some(state) = self.floating.get(floating_id) {
if let Some(state) = self.area.get(area_id) {
let rect = Rect::from_min_size(state.pos, state.size);
if rect.contains(pos) {
return Layer::Window(*floating_id);
return Layer::Window(*area_id);
}
}
}
@@ -62,18 +62,18 @@ impl Memory {
Layer::Background
}
pub fn move_floating_to_top(&mut self, id: Id) {
if self.floating_order.last() == Some(&id) {
pub fn move_area_to_top(&mut self, id: Id) {
if self.area_order.last() == Some(&id) {
return; // common case early-out
}
if let Some(index) = self.floating_order.iter().position(|x| *x == id) {
self.floating_order.remove(index);
if let Some(index) = self.area_order.iter().position(|x| *x == id) {
self.area_order.remove(index);
}
self.floating_order.push(id);
self.floating_visible_current_frame.insert(id);
self.area_order.push(id);
self.area_visible_current_frame.insert(id);
}
pub(crate) fn begin_frame(&mut self) {
self.floating_visible_last_frame = std::mem::take(&mut self.floating_visible_current_frame);
self.area_visible_last_frame = std::mem::take(&mut self.area_visible_current_frame);
}
}