1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 06:10:06 -04:00

Change focused widget with arrow keys (#3272)

* Allow widget focus change with keyboard arrows

* remove set id function

* docs

* Emilk feedback round 1

* Fix compile error

* undo example

* Move out functions from range to memory.rs

* remove contains range

* Use docstrings

* code cleanup

* Improve candidate logic

* More tweaks

* Less `pub`

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
Timon
2023-08-30 10:28:21 +02:00
committed by GitHub
parent 70bfc7e09f
commit ea15987ad4
2 changed files with 197 additions and 34 deletions

View File

@@ -49,6 +49,12 @@ impl Rangef {
self.max - self.min
}
/// The center of the range
#[inline]
pub fn center(self) -> f32 {
0.5 * (self.min + self.max)
}
#[inline]
#[must_use]
pub fn contains(self, x: f32) -> bool {
@@ -90,6 +96,25 @@ impl Rangef {
max: self.max + amnt,
}
}
/// The overlap of two ranges, i.e. the range that is contained by both.
///
/// If the ranges do not overlap, returns a range with `span() < 0.0`.
///
/// ```
/// # use emath::Rangef;
/// assert_eq!(Rangef::new(0.0, 10.0).intersection(Rangef::new(5.0, 15.0)), Rangef::new(5.0, 10.0));
/// assert_eq!(Rangef::new(0.0, 10.0).intersection(Rangef::new(10.0, 20.0)), Rangef::new(10.0, 10.0));
/// assert!(Rangef::new(0.0, 10.0).intersection(Rangef::new(20.0, 30.0)).span() < 0.0);
/// ```
#[inline]
#[must_use]
pub fn intersection(self, other: Self) -> Self {
Self {
min: self.min.max(other.min),
max: self.max.min(other.max),
}
}
}
impl From<Rangef> for RangeInclusive<f32> {