mirror of
https://github.com/emilk/egui.git
synced 2026-06-28 15:33:14 -04:00
WIP: Working clip rects for glium
This commit is contained in:
@@ -63,6 +63,10 @@ impl Vec2 {
|
||||
vec2(self.x.ceil(), self.y.ceil())
|
||||
}
|
||||
|
||||
pub fn is_finite(&self) -> bool {
|
||||
self.x.is_finite() && self.y.is_finite()
|
||||
}
|
||||
|
||||
pub fn min(self, other: Vec2) -> Self {
|
||||
vec2(self.x.min(other.x), self.y.min(other.y))
|
||||
}
|
||||
@@ -195,6 +199,10 @@ impl Pos2 {
|
||||
pub fn ceil(self) -> Self {
|
||||
pos2(self.x.ceil(), self.y.ceil())
|
||||
}
|
||||
|
||||
pub fn is_finite(&self) -> bool {
|
||||
self.x.is_finite() && self.y.is_finite()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::AddAssign<Vec2> for Pos2 {
|
||||
@@ -342,6 +350,14 @@ impl Rect {
|
||||
self.max.y - self.min.y
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.max.x < self.min.x || self.max.y < self.min.y
|
||||
}
|
||||
|
||||
pub fn is_finite(&self) -> bool {
|
||||
self.min.is_finite() && self.max.is_finite()
|
||||
}
|
||||
|
||||
// Convenience functions (assumes origin is towards left top):
|
||||
|
||||
pub fn left_top(&self) -> Pos2 {
|
||||
|
||||
@@ -6,39 +6,49 @@ use crate::{font::TextFragment, layout::*, widgets::*, *};
|
||||
/// with a type of layout (horizontal or vertical).
|
||||
/// TODO: make Region a trait so we can have type-safe HorizontalRegion etc?
|
||||
pub struct Region {
|
||||
// TODO: remove pub(crate) from all members.
|
||||
//
|
||||
/// How we access input, output and memory
|
||||
pub(crate) ctx: Arc<Context>,
|
||||
|
||||
/// Where to put the graphics output of this Region
|
||||
pub(crate) layer: Layer,
|
||||
|
||||
pub(crate) style: Style,
|
||||
|
||||
/// Unique ID of this region.
|
||||
/// ID of this region.
|
||||
/// Generated based on id of parent region together with
|
||||
/// another source of child identity (e.g. window title).
|
||||
/// Acts like a namespace for child regions.
|
||||
/// Hopefully unique.
|
||||
pub(crate) id: Id,
|
||||
|
||||
/// The `rect` represents where in space the region is
|
||||
/// and its max size (original available_space).
|
||||
/// Note that the size may be infinite in one or both dimensions.
|
||||
/// The widgets will TRY to fit within the rect,
|
||||
/// but may overflow (which you will see in bounding_size).
|
||||
/// It will use the rect (which never changes) as a
|
||||
/// clip rect when painting the contents of the region.
|
||||
pub(crate) rect: Rect, // TODO: rename desired_rect
|
||||
|
||||
/// Bounding box of children.
|
||||
/// We keep track of our max-size along the orthogonal to self.dir
|
||||
/// Initially set to zero.
|
||||
/// TODO: make into `child_bounds: Rect`
|
||||
pub(crate) bounding_size: Vec2,
|
||||
|
||||
/// Overide default style in this region
|
||||
pub(crate) style: Style,
|
||||
|
||||
// Layout stuff follows. TODO: move to own type and abstract.
|
||||
/// Doesn't change.
|
||||
pub(crate) dir: Direction,
|
||||
|
||||
pub(crate) align: Align,
|
||||
|
||||
// The `rect` represents where in space the region is
|
||||
// and its max size (original available_space).
|
||||
// Note that the size may be infinite in one or both dimensions.
|
||||
// The widgets will TRY to fit within the rect,
|
||||
// but may overflow (which you will see in bounding_size).
|
||||
// It will use the rect (which never changes) as a
|
||||
// clip rect when painting the contents of the region.
|
||||
pub(crate) rect: Rect,
|
||||
|
||||
/// Where the next widget will be put.
|
||||
/// Progresses along self.dir.
|
||||
/// Initially set to rect.min()
|
||||
pub(crate) cursor: Pos2,
|
||||
|
||||
/// Bounding box of children.
|
||||
/// We keep track of our max-size along the orthogonal to self.dir
|
||||
/// Initially set to zero.
|
||||
pub(crate) bounding_size: Vec2,
|
||||
}
|
||||
|
||||
impl Region {
|
||||
|
||||
@@ -120,10 +120,10 @@ pub enum PaintCmd {
|
||||
outline: Option<Outline>,
|
||||
},
|
||||
Rect {
|
||||
rect: Rect,
|
||||
corner_radius: f32,
|
||||
fill_color: Option<Color>,
|
||||
outline: Option<Outline>,
|
||||
rect: Rect,
|
||||
},
|
||||
/// Paint a single line of text
|
||||
Text {
|
||||
|
||||
Reference in New Issue
Block a user