|
|
@ -4,18 +4,6 @@ use parking_lot::Mutex; |
|
|
|
|
|
|
|
use crate::{layout::align_rect, *}; |
|
|
|
|
|
|
|
#[derive(Clone, Copy)] |
|
|
|
pub enum CursorIcon { |
|
|
|
Default, |
|
|
|
ResizeNorthWestSouthEast, |
|
|
|
} |
|
|
|
|
|
|
|
impl Default for CursorIcon { |
|
|
|
fn default() -> Self { |
|
|
|
CursorIcon::Default |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// Contains the input, style and output of all GUI commands.
|
|
|
|
pub struct Context { |
|
|
|
/// The default style for new regions
|
|
|
@ -25,8 +13,7 @@ pub struct Context { |
|
|
|
pub(crate) memory: Mutex<Memory>, |
|
|
|
pub(crate) graphics: Mutex<GraphicLayers>, |
|
|
|
|
|
|
|
/// Set each frame to what the mouse cursor should look like.
|
|
|
|
pub cursor_icon: Mutex<CursorIcon>, |
|
|
|
pub output: Mutex<Output>, |
|
|
|
|
|
|
|
/// Used to debug name clashes of e.g. windows
|
|
|
|
used_ids: Mutex<HashMap<Id, Pos2>>, |
|
|
@ -41,7 +28,7 @@ impl Clone for Context { |
|
|
|
input: self.input, |
|
|
|
memory: Mutex::new(self.memory.lock().clone()), |
|
|
|
graphics: Mutex::new(self.graphics.lock().clone()), |
|
|
|
cursor_icon: Mutex::new(self.cursor_icon.lock().clone()), |
|
|
|
output: Mutex::new(self.output.lock().clone()), |
|
|
|
used_ids: Mutex::new(self.used_ids.lock().clone()), |
|
|
|
} |
|
|
|
} |
|
|
@ -55,11 +42,16 @@ impl Context { |
|
|
|
input: Default::default(), |
|
|
|
memory: Default::default(), |
|
|
|
graphics: Default::default(), |
|
|
|
cursor_icon: Default::default(), |
|
|
|
output: Default::default(), |
|
|
|
used_ids: Default::default(), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// Useful for pixel-perfect rendering
|
|
|
|
pub fn round_to_pixel(&self, point: f32) -> f32 { |
|
|
|
(point * self.input.pixels_per_point).round() / self.input.pixels_per_point |
|
|
|
} |
|
|
|
|
|
|
|
pub fn input(&self) -> &GuiInput { |
|
|
|
&self.input |
|
|
|
} |
|
|
@ -73,10 +65,13 @@ impl Context { |
|
|
|
} |
|
|
|
|
|
|
|
// TODO: move
|
|
|
|
pub fn new_frame(&mut self, gui_input: GuiInput) { |
|
|
|
pub fn begin_frame(&mut self, gui_input: GuiInput) { |
|
|
|
self.used_ids.lock().clear(); |
|
|
|
self.input = gui_input; |
|
|
|
*self.cursor_icon.lock() = CursorIcon::Default; |
|
|
|
} |
|
|
|
|
|
|
|
pub fn end_frame(&self) -> Output { |
|
|
|
std::mem::take(&mut self.output.lock()) |
|
|
|
} |
|
|
|
|
|
|
|
pub fn drain_paint_lists(&self) -> Vec<(Rect, PaintCmd)> { |
|
|
|