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

Rich text for all widgets (#855)

Introduce `RichText` and `WidgetText`
This commit is contained in:
Emil Ernerfeldt
2021-11-01 21:30:10 +01:00
committed by GitHub
parent 9378cd5c6e
commit 09b8269326
30 changed files with 1121 additions and 712 deletions

View File

@@ -37,6 +37,9 @@ use emath::*;
/// },
/// );
/// ```
///
/// As you can see, constructing a `LayoutJob` is currently a lot of work.
/// It would be nice to have a helper macro for it!
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct LayoutJob {
@@ -118,6 +121,21 @@ impl LayoutJob {
}
}
#[inline]
pub fn single_section(text: String, format: TextFormat) -> Self {
Self {
sections: vec![LayoutSection {
leading_space: 0.0,
byte_range: 0..text.len(),
format,
}],
text,
wrap_width: f32::INFINITY,
break_on_newline: true,
..Default::default()
}
}
#[inline(always)]
pub fn is_empty(&self) -> bool {
self.sections.is_empty()
@@ -134,6 +152,15 @@ impl LayoutJob {
format,
});
}
/// The height of the tallest used font in the job.
pub fn font_height(&self, fonts: &crate::Fonts) -> f32 {
let mut max_height = 0.0_f32;
for section in &self.sections {
max_height = max_height.max(fonts.row_height(section.format.style));
}
max_height
}
}
impl std::hash::Hash for LayoutJob {