1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 21:30:03 -04:00

Add a bunch on inline annotations

This commit is contained in:
Emil Ernerfeldt
2021-04-01 22:10:34 +02:00
parent d702e3078a
commit d7f9e2246c
7 changed files with 65 additions and 8 deletions

View File

@@ -359,6 +359,7 @@ impl Fonts {
impl std::ops::Index<TextStyle> for Fonts {
type Output = Font;
#[inline(always)]
fn index(&self, text_style: TextStyle) -> &Font {
&self.fonts[&text_style]
}

View File

@@ -72,30 +72,36 @@ pub struct Row {
}
impl Row {
#[inline]
pub fn sanity_check(&self) {
assert!(!self.x_offsets.is_empty());
assert!(self.x_offsets.len() == self.uv_rects.len() + 1);
}
/// Excludes the implicit `\n` after the `Row`, if any.
#[inline]
pub fn char_count_excluding_newline(&self) -> usize {
assert!(!self.x_offsets.is_empty());
self.x_offsets.len() - 1
}
/// Includes the implicit `\n` after the `Row`, if any.
#[inline]
pub fn char_count_including_newline(&self) -> usize {
self.char_count_excluding_newline() + (self.ends_with_newline as usize)
}
#[inline]
pub fn min_x(&self) -> f32 {
*self.x_offsets.first().unwrap()
}
#[inline]
pub fn max_x(&self) -> f32 {
*self.x_offsets.last().unwrap()
}
#[inline]
pub fn height(&self) -> f32 {
self.y_max - self.y_min
}
@@ -124,6 +130,7 @@ impl Row {
}
// Move down this much
#[inline(always)]
pub fn translate_y(&mut self, dy: f32) {
self.y_min += dy;
self.y_max += dy;