1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-27 15:13:12 -04:00

A Window can now be resizable in only one direction (#4155)

For instance: `Window::new(…).resizable([true, false])` is a window that
is only resizable in the horizontal direction.

This PR also removes a hack added in
https://github.com/emilk/egui/pull/3039 which is no longer needed since
https://github.com/emilk/egui/pull/4026
This commit is contained in:
Emil Ernerfeldt
2024-03-11 09:29:48 +01:00
committed by GitHub
parent a93c6cd5d2
commit 00a399b2f7
10 changed files with 91 additions and 64 deletions

View File

@@ -1,5 +1,7 @@
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
use crate::Vec2b;
/// A vector has a direction and length.
/// A [`Vec2`] is often used to represent a size.
///
@@ -86,6 +88,16 @@ impl From<&Vec2> for (f32, f32) {
}
}
impl From<Vec2b> for Vec2 {
#[inline(always)]
fn from(v: Vec2b) -> Self {
Self {
x: v.x as i32 as f32,
y: v.y as i32 as f32,
}
}
}
// ----------------------------------------------------------------------------
// Mint compatibility and convenience conversions

View File

@@ -19,6 +19,30 @@ impl Vec2b {
pub fn any(&self) -> bool {
self.x || self.y
}
/// Are both `x` and `y` true?
#[inline]
pub fn all(&self) -> bool {
self.x && self.y
}
#[inline]
pub fn and(&self, other: impl Into<Self>) -> Self {
let other = other.into();
Self {
x: self.x && other.x,
y: self.y && other.y,
}
}
#[inline]
pub fn or(&self, other: impl Into<Self>) -> Self {
let other = other.into();
Self {
x: self.x || other.x,
y: self.y || other.y,
}
}
}
impl From<bool> for Vec2b {