mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 05:10:03 -04:00
Minor improvements
This commit is contained in:
@@ -409,7 +409,7 @@ impl Region {
|
||||
options: self.options,
|
||||
id: self.id,
|
||||
dir: self.dir,
|
||||
cursor: vec2((self.available_space.x - width) / 2.0, self.cursor.y),
|
||||
cursor: self.cursor + vec2((self.available_space.x - width) / 2.0, 0.0),
|
||||
align,
|
||||
bounding_size: vec2(0.0, 0.0),
|
||||
available_space: vec2(width, self.available_space.y),
|
||||
@@ -560,6 +560,31 @@ impl Region {
|
||||
})
|
||||
}
|
||||
|
||||
// Helper function
|
||||
pub fn floating_text(
|
||||
&mut self,
|
||||
pos: Vec2,
|
||||
text: &str,
|
||||
text_style: TextStyle,
|
||||
align: (Align, Align),
|
||||
text_color: Option<Color>,
|
||||
) {
|
||||
let font = &self.fonts()[text_style];
|
||||
let (text, text_size) = font.layout_multiline(text, std::f32::INFINITY);
|
||||
|
||||
let x = match align.0 {
|
||||
Align::Min => pos.x,
|
||||
Align::Center => pos.x - 0.5 * text_size.x,
|
||||
Align::Max => pos.x - text_size.x,
|
||||
};
|
||||
let y = match align.1 {
|
||||
Align::Min => pos.y,
|
||||
Align::Center => pos.y - 0.5 * text_size.y,
|
||||
Align::Max => pos.y - text_size.y,
|
||||
};
|
||||
self.add_text(vec2(x, y), text_style, text, text_color);
|
||||
}
|
||||
|
||||
pub fn add_text(
|
||||
&mut self,
|
||||
pos: Vec2,
|
||||
|
||||
@@ -134,6 +134,7 @@ impl Rect {
|
||||
pub fn min(&self) -> Vec2 {
|
||||
self.pos
|
||||
}
|
||||
|
||||
pub fn max(&self) -> Vec2 {
|
||||
self.pos + self.size
|
||||
}
|
||||
@@ -141,6 +142,12 @@ impl Rect {
|
||||
pub fn size(&self) -> Vec2 {
|
||||
self.size
|
||||
}
|
||||
pub fn width(&self) -> f32 {
|
||||
self.size.x
|
||||
}
|
||||
pub fn height(&self) -> f32 {
|
||||
self.size.y
|
||||
}
|
||||
|
||||
// Convenience functions:
|
||||
pub fn left_top(&self) -> Vec2 {
|
||||
|
||||
Reference in New Issue
Block a user