spelling fixes
This commit is contained in:
parent
d41b7a6234
commit
98c9e9bb41
7 changed files with 25 additions and 155 deletions
|
@ -1,5 +1,5 @@
|
||||||
//! Area is a `Ui` that has no parent, it floats on the background.
|
//! Area is a `Ui` that has no parent, it floats on the background.
|
||||||
//! It has no frame or own size. It is potentioally movable.
|
//! It has no frame or own size. It is potentially movable.
|
||||||
//! It is the foundation for windows and popups.
|
//! It is the foundation for windows and popups.
|
||||||
|
|
||||||
use std::{fmt::Debug, hash::Hash, sync::Arc};
|
use std::{fmt::Debug, hash::Hash, sync::Arc};
|
||||||
|
@ -16,7 +16,7 @@ pub(crate) struct State {
|
||||||
/// Last know size. Used for catching clicks.
|
/// Last know size. Used for catching clicks.
|
||||||
pub size: Vec2,
|
pub size: Vec2,
|
||||||
|
|
||||||
/// If false, clicks goes stright throught to what is behind us.
|
/// If false, clicks goes straight through to what is behind us.
|
||||||
/// Good for tooltips etc.
|
/// Good for tooltips etc.
|
||||||
pub interactable: bool,
|
pub interactable: bool,
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ impl Frame {
|
||||||
margin: style.window_padding,
|
margin: style.window_padding,
|
||||||
corner_radius: style.window.corner_radius,
|
corner_radius: style.window.corner_radius,
|
||||||
fill: Some(style.background_fill),
|
fill: Some(style.background_fill),
|
||||||
outline: style.interact.inactive.rect_outline, // becauce we can resize windows
|
outline: style.interact.inactive.rect_outline, // because we can resize windows
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ impl Default for Resize {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Resize {
|
impl Resize {
|
||||||
/// Assign an explicit and globablly unique id.
|
/// Assign an explicit and globally unique id.
|
||||||
pub fn id(mut self, id: Id) -> Self {
|
pub fn id(mut self, id: Id) -> Self {
|
||||||
self.id = Some(id);
|
self.id = Some(id);
|
||||||
self
|
self
|
||||||
|
@ -169,7 +169,7 @@ impl Resize {
|
||||||
|
|
||||||
let mut content_clip_rect = inner_rect.expand(ui.style().clip_rect_margin);
|
let mut content_clip_rect = inner_rect.expand(ui.style().clip_rect_margin);
|
||||||
|
|
||||||
// If we pull the resize handle to shrink, we want to TRY to shink it.
|
// If we pull the resize handle to shrink, we want to TRY to shrink it.
|
||||||
// After laying out the contents, we might be much bigger.
|
// After laying out the contents, we might be much bigger.
|
||||||
// In those cases we don't want the clip_rect to be smaller, because
|
// In those cases we don't want the clip_rect to be smaller, because
|
||||||
// then we will clip the contents of the region even thought the result gets larger. This is simply ugly!
|
// then we will clip the contents of the region even thought the result gets larger. This is simply ugly!
|
||||||
|
|
|
@ -406,7 +406,7 @@ fn resize_window(ctx: &Context, window_interaction: &WindowInteraction) -> Optio
|
||||||
rect.max.y = ctx.round_to_pixel(mouse_pos.y);
|
rect.max.y = ctx.round_to_pixel(mouse_pos.y);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// movevement
|
// movement
|
||||||
rect = rect.translate(mouse_pos - ctx.input().mouse.press_origin?);
|
rect = rect.translate(mouse_pos - ctx.input().mouse.press_origin?);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,130 +0,0 @@
|
||||||
use std::collections::VecDeque;
|
|
||||||
|
|
||||||
/// This struct tracks recent values of some time series.
|
|
||||||
/// This can be used for things like smoothed averages (for e.g. FPS)
|
|
||||||
/// or for smoothed velocity (e.g. mouse pointer speed).
|
|
||||||
/// All times are in seconds.
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct MovementTracker<T> {
|
|
||||||
max_len: usize,
|
|
||||||
max_age: f64,
|
|
||||||
|
|
||||||
/// (time, value) pais
|
|
||||||
values: VecDeque<(f64, T)>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> MovementTracker<T>
|
|
||||||
where
|
|
||||||
T: Copy,
|
|
||||||
{
|
|
||||||
pub fn new(max_len: usize, max_age: f64) -> Self {
|
|
||||||
Self {
|
|
||||||
max_len,
|
|
||||||
max_age,
|
|
||||||
values: Default::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_empty(&self) -> bool {
|
|
||||||
self.values.is_empty()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn len(&self) -> usize {
|
|
||||||
self.values.len()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Amount of time contained from start to end in this `MovementTracker`
|
|
||||||
pub fn dt(&self) -> f32 {
|
|
||||||
if let (Some(front), Some(back)) = (self.values.front(), self.values.back()) {
|
|
||||||
(back.0 - front.0) as f32
|
|
||||||
} else {
|
|
||||||
0.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn values<'a>(&'a self) -> impl Iterator<Item = T> + 'a {
|
|
||||||
self.values.iter().map(|(_time, value)| *value)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn clear(&mut self) {
|
|
||||||
self.values.clear()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Values must be added with a monotonically increasing time, or at least not decreasing.
|
|
||||||
pub fn add(&mut self, now: f64, value: T) {
|
|
||||||
if let Some((last_time, _)) = self.values.back() {
|
|
||||||
debug_assert!(now >= *last_time, "Time shouldn't go backwards");
|
|
||||||
}
|
|
||||||
self.values.push_back((now, value));
|
|
||||||
self.flush(now);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Mean time difference between values in this `MovementTracker`.
|
|
||||||
pub fn mean_time_interval(&self) -> Option<f32> {
|
|
||||||
if let (Some(first), Some(last)) = (self.values.front(), self.values.back()) {
|
|
||||||
let n = self.len();
|
|
||||||
if n >= 2 {
|
|
||||||
Some((last.0 - first.0) as f32 / ((n - 1) as f32))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Remove samples that are too old
|
|
||||||
pub fn flush(&mut self, now: f64) {
|
|
||||||
while self.values.len() > self.max_len {
|
|
||||||
self.values.pop_front();
|
|
||||||
}
|
|
||||||
while let Some((front_time, _)) = self.values.front() {
|
|
||||||
if *front_time < now - self.max_age {
|
|
||||||
self.values.pop_front();
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> MovementTracker<T>
|
|
||||||
where
|
|
||||||
T: Copy,
|
|
||||||
T: std::iter::Sum,
|
|
||||||
T: std::ops::Div<f32, Output = T>,
|
|
||||||
{
|
|
||||||
pub fn sum(&self) -> T {
|
|
||||||
self.values().sum()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn average(&self) -> Option<T> {
|
|
||||||
let num = self.len();
|
|
||||||
if num > 0 {
|
|
||||||
Some(self.sum() / (num as f32))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, Vel> MovementTracker<T>
|
|
||||||
where
|
|
||||||
T: Copy,
|
|
||||||
T: std::ops::Sub<Output = Vel>,
|
|
||||||
Vel: std::ops::Div<f32, Output = Vel>,
|
|
||||||
{
|
|
||||||
/// Calculate a smooth velocity (per second) over the entire time span
|
|
||||||
pub fn velocity(&self) -> Option<Vel> {
|
|
||||||
if let (Some(first), Some(last)) = (self.values.front(), self.values.back()) {
|
|
||||||
let dt = (last.0 - first.0) as f32;
|
|
||||||
if dt > 0.0 {
|
|
||||||
Some((last.1 - first.1) / dt)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -185,7 +185,7 @@ pub struct WidgetStyle {
|
||||||
/// like buttons, the box of the checkbox, etc.
|
/// like buttons, the box of the checkbox, etc.
|
||||||
pub rect_outline: Option<LineStyle>,
|
pub rect_outline: Option<LineStyle>,
|
||||||
|
|
||||||
/// Button frames etdc
|
/// Button frames etc
|
||||||
pub corner_radius: f32,
|
pub corner_radius: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ pub struct Ui {
|
||||||
/// but may overflow (which you will see in child_bounds).
|
/// but may overflow (which you will see in child_bounds).
|
||||||
/// Some widgets (like separator lines) will try to fill the full desired width of the ui.
|
/// Some widgets (like separator lines) will try to fill the full desired width of the ui.
|
||||||
/// If the desired size is zero, it is a signal that child widgets should be as small as possible.
|
/// If the desired size is zero, it is a signal that child widgets should be as small as possible.
|
||||||
/// If the desired size is initie, it is a signal that child widgets should take up as much room as they want.
|
/// If the desired size is infinite, it is a signal that child widgets should take up as much room as they want.
|
||||||
desired_rect: Rect, // TODO: rename as max_rect ?
|
desired_rect: Rect, // TODO: rename as max_rect ?
|
||||||
|
|
||||||
/// Bounding box of all children.
|
/// Bounding box of all children.
|
||||||
|
@ -30,7 +30,7 @@ pub struct Ui {
|
||||||
/// You can think of this as the minimum size.
|
/// You can think of this as the minimum size.
|
||||||
child_bounds: Rect, // TODO: rename as min_rect ?
|
child_bounds: Rect, // TODO: rename as min_rect ?
|
||||||
|
|
||||||
/// Overide default style in this ui
|
/// Override default style in this ui
|
||||||
style: Style,
|
style: Style,
|
||||||
|
|
||||||
layout: Layout,
|
layout: Layout,
|
||||||
|
@ -164,16 +164,16 @@ impl Ui {
|
||||||
|
|
||||||
/// Screen-space position of the current bottom right corner of this Ui.
|
/// Screen-space position of the current bottom right corner of this Ui.
|
||||||
/// This may move when we add children that overflow our desired rectangle bounds.
|
/// This may move when we add children that overflow our desired rectangle bounds.
|
||||||
/// This position may be at inifnity if the desired rect is initinite,
|
/// This position may be at infinity if the desired rect is infinite,
|
||||||
/// which mappens when a parent widget says "be as big as you want to be".
|
/// which happens when a parent widget says "be as big as you want to be".
|
||||||
pub fn bottom_right(&self) -> Pos2 {
|
pub fn bottom_right(&self) -> Pos2 {
|
||||||
// If a child doesn't fit in desired_rect, we have effectively expanded:
|
// If a child doesn't fit in desired_rect, we have effectively expanded:
|
||||||
self.desired_rect.max.max(self.child_bounds.max)
|
self.desired_rect.max.max(self.child_bounds.max)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Position and current size of the ui.
|
/// Position and current size of the ui.
|
||||||
/// The size is the maximum of the origional (minimum/desired) size and
|
/// The size is the maximum of the original (minimum/desired) size and
|
||||||
/// the size of the containted children.
|
/// the size of the contained children.
|
||||||
pub fn rect(&self) -> Rect {
|
pub fn rect(&self) -> Rect {
|
||||||
Rect::from_min_max(self.top_left(), self.bottom_right())
|
Rect::from_min_max(self.top_left(), self.bottom_right())
|
||||||
}
|
}
|
||||||
|
@ -239,8 +239,8 @@ impl Ui {
|
||||||
/// The available space at the moment, given the current cursor.
|
/// The available space at the moment, given the current cursor.
|
||||||
/// This how much more space we can take up without overflowing our parent.
|
/// This how much more space we can take up without overflowing our parent.
|
||||||
/// Shrinks as widgets allocate space and the cursor moves.
|
/// Shrinks as widgets allocate space and the cursor moves.
|
||||||
/// A small rectangle should be intepreted as "as little as possible".
|
/// A small rectangle should be interpreted as "as little as possible".
|
||||||
/// An infinite rectangle should be interpred as "as much as you want".
|
/// An infinite rectangle should be interpreted as "as much as you want".
|
||||||
/// In most layouts the next widget will be put in the top left corner of this `Rect`.
|
/// In most layouts the next widget will be put in the top left corner of this `Rect`.
|
||||||
pub fn available(&self) -> Rect {
|
pub fn available(&self) -> Rect {
|
||||||
self.layout.available(self.cursor, self.rect())
|
self.layout.available(self.cursor, self.rect())
|
||||||
|
@ -292,7 +292,7 @@ impl Ui {
|
||||||
|
|
||||||
/// Ideally, all widgets should use this. TODO
|
/// Ideally, all widgets should use this. TODO
|
||||||
/// Widgets can set an explicit id source (user picked, e.g. some loop index),
|
/// Widgets can set an explicit id source (user picked, e.g. some loop index),
|
||||||
/// and a defualt id source (e.g. label).
|
/// and a default id source (e.g. label).
|
||||||
/// If they fail to be unique, a positional id will be used instead.
|
/// If they fail to be unique, a positional id will be used instead.
|
||||||
pub fn make_unique_child_id_full(
|
pub fn make_unique_child_id_full(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -313,7 +313,7 @@ impl Ui {
|
||||||
.register_unique_id(id, default_id_source.unwrap_or_default(), self.cursor)
|
.register_unique_id(id, default_id_source.unwrap_or_default(), self.cursor)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Make an Id that is unique to this positon.
|
/// Make an Id that is unique to this position.
|
||||||
/// Can be used for widgets that do NOT persist state in Memory
|
/// Can be used for widgets that do NOT persist state in Memory
|
||||||
/// but you still need to interact with (e.g. buttons, sliders).
|
/// but you still need to interact with (e.g. buttons, sliders).
|
||||||
pub fn make_position_id(&self) -> Id {
|
pub fn make_position_id(&self) -> Id {
|
||||||
|
@ -437,7 +437,7 @@ impl Ui {
|
||||||
/// Ask to allocate a certain amount of space and return a Painter for that region.
|
/// Ask to allocate a certain amount of space and return a Painter for that region.
|
||||||
///
|
///
|
||||||
/// You may get back a `Painter` with a smaller or larger size than what you desired,
|
/// You may get back a `Painter` with a smaller or larger size than what you desired,
|
||||||
/// depending on the avilable space and the current layout.
|
/// depending on the available space and the current layout.
|
||||||
pub fn allocate_canvas(&mut self, desired_size: Vec2) -> Painter {
|
pub fn allocate_canvas(&mut self, desired_size: Vec2) -> Painter {
|
||||||
let rect = self.allocate_space(desired_size);
|
let rect = self.allocate_space(desired_size);
|
||||||
self.painter_at(rect)
|
self.painter_at(rect)
|
||||||
|
@ -482,17 +482,17 @@ impl Ui {
|
||||||
self.add(TextEdit::new(text))
|
self.add(TextEdit::new(text))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Show a radio button. It is selected if `*curr_value == radio_value`.
|
/// Show a radio button. It is selected if `*current_value == radio_value`.
|
||||||
/// If clicked, `radio_value` is assigned to `*curr_value`;
|
/// If clicked, `radio_value` is assigned to `*current_value`;
|
||||||
pub fn radio_value<Value: PartialEq>(
|
pub fn radio_value<Value: PartialEq>(
|
||||||
&mut self,
|
&mut self,
|
||||||
text: impl Into<String>,
|
text: impl Into<String>,
|
||||||
curr_value: &mut Value,
|
current_value: &mut Value,
|
||||||
radio_value: Value,
|
radio_value: Value,
|
||||||
) -> GuiResponse {
|
) -> GuiResponse {
|
||||||
let response = self.radio(text, *curr_value == radio_value);
|
let response = self.radio(text, *current_value == radio_value);
|
||||||
if response.clicked {
|
if response.clicked {
|
||||||
*curr_value = radio_value;
|
*current_value = radio_value;
|
||||||
}
|
}
|
||||||
response
|
response
|
||||||
}
|
}
|
||||||
|
@ -503,7 +503,7 @@ impl Ui {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # Addding Containers / Sub-uis:
|
/// # Adding Containers / Sub-uis:
|
||||||
impl Ui {
|
impl Ui {
|
||||||
pub fn collapsing<R>(
|
pub fn collapsing<R>(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -515,7 +515,7 @@ impl Ui {
|
||||||
|
|
||||||
/// Create a child ui at the current cursor.
|
/// Create a child ui at the current cursor.
|
||||||
/// `size` is the desired size.
|
/// `size` is the desired size.
|
||||||
/// Actual size may be much smaller if `avilable_size()` is not enough.
|
/// Actual size may be much smaller if `available_size()` is not enough.
|
||||||
/// Set `size` to `Vec::infinity()` to get as much space as possible.
|
/// Set `size` to `Vec::infinity()` to get as much space as possible.
|
||||||
/// Just because you ask for a lot of space does not mean you have to use it!
|
/// Just because you ask for a lot of space does not mean you have to use it!
|
||||||
/// After `add_contents` is called the contents of `bounding_size`
|
/// After `add_contents` is called the contents of `bounding_size`
|
||||||
|
|
Loading…
Reference in a new issue