-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
68 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,33 @@ | ||
use crate::{context::Context, render_util::Rect}; | ||
use crate::{ | ||
component_wise::ComponentWise, | ||
context::Context, | ||
render_util::{Point, Rect}, | ||
}; | ||
use nexus::imgui::Ui; | ||
|
||
/// UI element bounds. | ||
pub trait Bounds { | ||
/// Calculates the bounding box of the element. | ||
fn bounding_box(&self, ui: &Ui, ctx: &Context, pos: [f32; 2]) -> Rect; | ||
/// Calculates the relative bounding box of the element. | ||
fn bounds(&self, ui: &Ui, ctx: &Context) -> Rect; | ||
|
||
/// Calculates the bounding box of the element with the given offset. | ||
fn bounds_with_offset(&self, ui: &Ui, ctx: &Context, offset: Point) -> Rect { | ||
let (start, end) = self.bounds(ui, ctx); | ||
(offset.add(start), offset.add(end)) | ||
} | ||
|
||
/// Calculates the combined bounding box of the elements. | ||
fn combined_bounds<'a>( | ||
iter: impl IntoIterator<Item = &'a Self>, | ||
ui: &Ui, | ||
ctx: &Context, | ||
pos: [f32; 2], | ||
) -> Rect | ||
fn combined_bounds<'a>(iter: impl IntoIterator<Item = &'a Self>, ui: &Ui, ctx: &Context) -> Rect | ||
where | ||
Self: 'a, | ||
{ | ||
iter.into_iter() | ||
.map(|el| el.bounding_box(ui, ctx, pos)) | ||
.map(|el| el.bounds(ui, ctx)) | ||
.reduce(|a, b| { | ||
let ([a1, a2], [a3, a4]) = a; | ||
let ([b1, b2], [b3, b4]) = b; | ||
([a1.min(b1), a2.min(b2)], [a3.max(b3), a4.max(b4)]) | ||
}) | ||
.unwrap_or((pos, pos)) | ||
.unwrap_or_default() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters