Rename Floating to Area
This commit is contained in:
parent
90020b41a8
commit
fd99213222
6 changed files with 54 additions and 58 deletions
|
@ -1,12 +1,12 @@
|
||||||
|
pub mod area;
|
||||||
pub mod collapsing_header;
|
pub mod collapsing_header;
|
||||||
pub mod floating;
|
|
||||||
pub mod frame;
|
pub mod frame;
|
||||||
pub mod resize;
|
pub mod resize;
|
||||||
pub mod scroll_area;
|
pub mod scroll_area;
|
||||||
pub mod window;
|
pub mod window;
|
||||||
|
|
||||||
pub use {
|
pub use {
|
||||||
collapsing_header::CollapsingHeader, floating::Floating, frame::Frame, resize::Resize,
|
area::Area, collapsing_header::CollapsingHeader, frame::Frame, resize::Resize,
|
||||||
scroll_area::ScrollArea, window::Window,
|
scroll_area::ScrollArea, window::Window,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
//! A Floating is an Ui that has no parent, it floats on the background.
|
//! Area is a `Ui` that has no parent, it floats on the background.
|
||||||
//! It is potentioally movable.
|
//! It has no frame or own size. It is potentioally movable.
|
||||||
//! It has no frame or own size.
|
//! It is the foundation for windows and popups.
|
||||||
//! It is the foundation for a window
|
|
||||||
|
|
||||||
use std::{fmt::Debug, hash::Hash, sync::Arc};
|
use std::{fmt::Debug, hash::Hash, sync::Arc};
|
||||||
|
|
||||||
|
@ -15,14 +14,14 @@ pub(crate) struct State {
|
||||||
/// Last know size. Used for catching clicks.
|
/// Last know size. Used for catching clicks.
|
||||||
pub size: Vec2,
|
pub size: Vec2,
|
||||||
|
|
||||||
/// You can throw a Floating thing. It's fun.
|
/// You can throw a moveable Area. It's fun.
|
||||||
|
/// TODO: separate out moveable to container?
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub vel: Vec2,
|
pub vel: Vec2,
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: rename Floating to something else. Area?
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub struct Floating {
|
pub struct Area {
|
||||||
id: Id,
|
id: Id,
|
||||||
movable: bool,
|
movable: bool,
|
||||||
always_on_top: bool,
|
always_on_top: bool,
|
||||||
|
@ -30,7 +29,7 @@ pub struct Floating {
|
||||||
fixed_pos: Option<Pos2>,
|
fixed_pos: Option<Pos2>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Floating {
|
impl Area {
|
||||||
pub fn new(id_source: impl Hash) -> Self {
|
pub fn new(id_source: impl Hash) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id: Id::new(id_source),
|
id: Id::new(id_source),
|
||||||
|
@ -46,7 +45,7 @@ impl Floating {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Always show as top Floating
|
/// Always show as top Area
|
||||||
pub fn always_on_top(mut self) -> Self {
|
pub fn always_on_top(mut self) -> Self {
|
||||||
self.always_on_top = true;
|
self.always_on_top = true;
|
||||||
self
|
self
|
||||||
|
@ -65,14 +64,14 @@ impl Floating {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Floating {
|
impl Area {
|
||||||
// TODO
|
// TODO
|
||||||
// pub fn show(self, ui: &Ui, add_contents: impl FnOnce(&mut Ui)) {
|
// pub fn show(self, ui: &Ui, add_contents: impl FnOnce(&mut Ui)) {
|
||||||
// let default_pos = self.default_pos.unwrap_or_else(|| ui.top_left() + pos2(100.0, 100.0)); // TODO
|
// let default_pos = self.default_pos.unwrap_or_else(|| ui.top_left() + pos2(100.0, 100.0)); // TODO
|
||||||
// }
|
// }
|
||||||
|
|
||||||
pub fn show(self, ctx: &Arc<Context>, add_contents: impl FnOnce(&mut Ui)) -> InteractInfo {
|
pub fn show(self, ctx: &Arc<Context>, add_contents: impl FnOnce(&mut Ui)) -> InteractInfo {
|
||||||
let Floating {
|
let Area {
|
||||||
id,
|
id,
|
||||||
movable,
|
movable,
|
||||||
always_on_top,
|
always_on_top,
|
||||||
|
@ -81,10 +80,10 @@ impl Floating {
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
let default_pos = default_pos.unwrap_or_else(|| pos2(100.0, 100.0)); // TODO
|
let default_pos = default_pos.unwrap_or_else(|| pos2(100.0, 100.0)); // TODO
|
||||||
let id = ctx.register_unique_id(id, "Floating", default_pos);
|
let id = ctx.register_unique_id(id, "Area", default_pos);
|
||||||
let layer = Layer::Window(id);
|
let layer = Layer::Window(id);
|
||||||
|
|
||||||
let (mut state, _is_new) = match ctx.memory().get_floating(id) {
|
let (mut state, _is_new) = match ctx.memory().get_area(id) {
|
||||||
Some(state) => (state, false),
|
Some(state) => (state, false),
|
||||||
None => {
|
None => {
|
||||||
let state = State {
|
let state = State {
|
||||||
|
@ -142,19 +141,19 @@ impl Floating {
|
||||||
|
|
||||||
// ctx.debug_rect(
|
// ctx.debug_rect(
|
||||||
// Rect::from_min_size(state.pos, state.size),
|
// Rect::from_min_size(state.pos, state.size),
|
||||||
// &format!("Floating size: {:?}", state.size),
|
// &format!("Area size: {:?}", state.size),
|
||||||
// );
|
// );
|
||||||
|
|
||||||
if move_interact.active || mouse_pressed_on_floating(ctx, id) || always_on_top {
|
if move_interact.active || mouse_pressed_on_area(ctx, id) || always_on_top {
|
||||||
ctx.memory().move_floating_to_top(id);
|
ctx.memory().move_area_to_top(id);
|
||||||
}
|
}
|
||||||
ctx.memory().set_floating_state(id, state);
|
ctx.memory().set_area_state(id, state);
|
||||||
|
|
||||||
move_interact
|
move_interact
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mouse_pressed_on_floating(ctx: &Context, id: Id) -> bool {
|
fn mouse_pressed_on_area(ctx: &Context, id: Id) -> bool {
|
||||||
if let Some(mouse_pos) = ctx.input().mouse_pos {
|
if let Some(mouse_pos) = ctx.input().mouse_pos {
|
||||||
ctx.input().mouse_pressed && ctx.memory().layer_at(mouse_pos) == Layer::Window(id)
|
ctx.input().mouse_pressed && ctx.memory().layer_at(mouse_pos) == Layer::Window(id)
|
||||||
} else {
|
} else {
|
|
@ -7,7 +7,7 @@ use super::*;
|
||||||
/// A wrapper around other containers for things you often want in a window
|
/// A wrapper around other containers for things you often want in a window
|
||||||
pub struct Window {
|
pub struct Window {
|
||||||
pub title_label: Label,
|
pub title_label: Label,
|
||||||
pub floating: Floating,
|
pub area: Area,
|
||||||
pub frame: Option<Frame>,
|
pub frame: Option<Frame>,
|
||||||
pub resize: Resize,
|
pub resize: Resize,
|
||||||
pub scroll: ScrollArea,
|
pub scroll: ScrollArea,
|
||||||
|
@ -17,13 +17,13 @@ impl Window {
|
||||||
// TODO: Into<Label>
|
// TODO: Into<Label>
|
||||||
pub fn new(title: impl Into<String>) -> Self {
|
pub fn new(title: impl Into<String>) -> Self {
|
||||||
let title = title.into();
|
let title = title.into();
|
||||||
let floating = Floating::new(&title);
|
let area = Area::new(&title);
|
||||||
let title_label = Label::new(title)
|
let title_label = Label::new(title)
|
||||||
.text_style(TextStyle::Heading)
|
.text_style(TextStyle::Heading)
|
||||||
.multiline(false);
|
.multiline(false);
|
||||||
Self {
|
Self {
|
||||||
title_label,
|
title_label,
|
||||||
floating,
|
area,
|
||||||
frame: None,
|
frame: None,
|
||||||
resize: Resize::default()
|
resize: Resize::default()
|
||||||
.handle_offset(Vec2::splat(4.0))
|
.handle_offset(Vec2::splat(4.0))
|
||||||
|
@ -52,7 +52,7 @@ impl Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn default_pos(mut self, default_pos: Pos2) -> Self {
|
pub fn default_pos(mut self, default_pos: Pos2) -> Self {
|
||||||
self.floating = self.floating.default_pos(default_pos);
|
self.area = self.area.default_pos(default_pos);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ impl Window {
|
||||||
pub fn show(self, ctx: &Arc<Context>, add_contents: impl FnOnce(&mut Ui)) -> InteractInfo {
|
pub fn show(self, ctx: &Arc<Context>, add_contents: impl FnOnce(&mut Ui)) -> InteractInfo {
|
||||||
let Window {
|
let Window {
|
||||||
title_label,
|
title_label,
|
||||||
floating,
|
area,
|
||||||
frame,
|
frame,
|
||||||
resize,
|
resize,
|
||||||
scroll,
|
scroll,
|
||||||
|
@ -96,7 +96,7 @@ impl Window {
|
||||||
let frame = frame.unwrap_or_else(|| Frame::window(&ctx.style()));
|
let frame = frame.unwrap_or_else(|| Frame::window(&ctx.style()));
|
||||||
|
|
||||||
// TODO: easier way to compose these
|
// TODO: easier way to compose these
|
||||||
floating.show(ctx, |ui| {
|
area.show(ctx, |ui| {
|
||||||
frame.show(ui, |ui| {
|
frame.show(ui, |ui| {
|
||||||
resize.show(ui, |ui| {
|
resize.show(ui, |ui| {
|
||||||
ui.add(title_label);
|
ui.add(title_label);
|
||||||
|
|
|
@ -182,7 +182,7 @@ impl Context {
|
||||||
|
|
||||||
fn drain_paint_lists(&self) -> Vec<(Rect, PaintCmd)> {
|
fn drain_paint_lists(&self) -> Vec<(Rect, PaintCmd)> {
|
||||||
let memory = self.memory();
|
let memory = self.memory();
|
||||||
self.graphics().drain(memory.floating_order()).collect()
|
self.graphics().drain(memory.area_order()).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn paint(&self) -> PaintBatches {
|
fn paint(&self) -> PaintBatches {
|
||||||
|
@ -208,7 +208,7 @@ impl Context {
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
/// An ui for the entire screen, behind any windows.
|
/// A `Ui` for the entire screen, behind any windows.
|
||||||
pub fn fullscreen_ui(self: &Arc<Self>) -> Ui {
|
pub fn fullscreen_ui(self: &Arc<Self>) -> Ui {
|
||||||
let rect = Rect::from_min_size(Default::default(), self.input().screen_size);
|
let rect = Rect::from_min_size(Default::default(), self.input().screen_size);
|
||||||
Ui::new(self.clone(), Layer::Background, Id::background(), rect)
|
Ui::new(self.clone(), Layer::Background, Id::background(), rect)
|
||||||
|
|
|
@ -35,13 +35,10 @@ impl GraphicLayers {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn drain(
|
pub fn drain(&mut self, area_order: &[Id]) -> impl ExactSizeIterator<Item = (Rect, PaintCmd)> {
|
||||||
&mut self,
|
|
||||||
window_order: &[Id],
|
|
||||||
) -> impl ExactSizeIterator<Item = (Rect, PaintCmd)> {
|
|
||||||
let mut all_commands: Vec<_> = self.bg.drain(..).collect();
|
let mut all_commands: Vec<_> = self.bg.drain(..).collect();
|
||||||
|
|
||||||
for id in window_order {
|
for id in area_order {
|
||||||
if let Some(window) = self.windows.get_mut(id) {
|
if let Some(window) = self.windows.get_mut(id) {
|
||||||
all_commands.extend(window.drain(..));
|
all_commands.extend(window.drain(..));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
containers::{collapsing_header, floating, resize, scroll_area},
|
containers::{area, collapsing_header, resize, scroll_area},
|
||||||
Id, Layer, Pos2, Rect,
|
Id, Layer, Pos2, Rect,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -21,40 +21,40 @@ pub struct Memory {
|
||||||
pub(crate) scroll_areas: HashMap<Id, scroll_area::State>,
|
pub(crate) scroll_areas: HashMap<Id, scroll_area::State>,
|
||||||
pub(crate) resize: HashMap<Id, resize::State>,
|
pub(crate) resize: HashMap<Id, resize::State>,
|
||||||
|
|
||||||
floating: HashMap<Id, floating::State>,
|
area: HashMap<Id, area::State>,
|
||||||
/// Top is last
|
/// Top is last
|
||||||
floating_order: Vec<Id>,
|
area_order: Vec<Id>,
|
||||||
floating_visible_last_frame: HashSet<Id>,
|
area_visible_last_frame: HashSet<Id>,
|
||||||
floating_visible_current_frame: HashSet<Id>,
|
area_visible_current_frame: HashSet<Id>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Memory {
|
impl Memory {
|
||||||
pub(crate) fn get_floating(&mut self, id: Id) -> Option<floating::State> {
|
pub(crate) fn get_area(&mut self, id: Id) -> Option<area::State> {
|
||||||
self.floating.get(&id).cloned()
|
self.area.get(&id).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn floating_order(&self) -> &[Id] {
|
pub(crate) fn area_order(&self) -> &[Id] {
|
||||||
&self.floating_order
|
&self.area_order
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn set_floating_state(&mut self, id: Id, state: floating::State) {
|
pub(crate) fn set_area_state(&mut self, id: Id, state: area::State) {
|
||||||
self.floating_visible_current_frame.insert(id);
|
self.area_visible_current_frame.insert(id);
|
||||||
let did_insert = self.floating.insert(id, state).is_none();
|
let did_insert = self.area.insert(id, state).is_none();
|
||||||
if did_insert {
|
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
|
/// TODO: call once at the start of the frame for the current mouse pos
|
||||||
pub fn layer_at(&self, pos: Pos2) -> Layer {
|
pub fn layer_at(&self, pos: Pos2) -> Layer {
|
||||||
for floating_id in self.floating_order.iter().rev() {
|
for area_id in self.area_order.iter().rev() {
|
||||||
if self.floating_visible_last_frame.contains(floating_id)
|
if self.area_visible_last_frame.contains(area_id)
|
||||||
|| self.floating_visible_current_frame.contains(floating_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);
|
let rect = Rect::from_min_size(state.pos, state.size);
|
||||||
if rect.contains(pos) {
|
if rect.contains(pos) {
|
||||||
return Layer::Window(*floating_id);
|
return Layer::Window(*area_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,18 +62,18 @@ impl Memory {
|
||||||
Layer::Background
|
Layer::Background
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn move_floating_to_top(&mut self, id: Id) {
|
pub fn move_area_to_top(&mut self, id: Id) {
|
||||||
if self.floating_order.last() == Some(&id) {
|
if self.area_order.last() == Some(&id) {
|
||||||
return; // common case early-out
|
return; // common case early-out
|
||||||
}
|
}
|
||||||
if let Some(index) = self.floating_order.iter().position(|x| *x == id) {
|
if let Some(index) = self.area_order.iter().position(|x| *x == id) {
|
||||||
self.floating_order.remove(index);
|
self.area_order.remove(index);
|
||||||
}
|
}
|
||||||
self.floating_order.push(id);
|
self.area_order.push(id);
|
||||||
self.floating_visible_current_frame.insert(id);
|
self.area_visible_current_frame.insert(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn begin_frame(&mut self) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue