mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 22:00:03 -04:00
Fix WidgetText::Text ignoring fallback font and overrides (#7361)
* closes https://github.com/emilk/egui/issues/7356
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use crate::atomics::ATOMS_SMALL_VEC_SIZE;
|
||||
use crate::{
|
||||
AtomKind, Atoms, Frame, Id, Image, IntoAtoms, Response, Sense, SizedAtom, SizedAtomKind, Ui,
|
||||
Widget,
|
||||
AtomKind, Atoms, FontSelection, Frame, Id, Image, IntoAtoms, Response, Sense, SizedAtom,
|
||||
SizedAtomKind, Ui, Widget,
|
||||
};
|
||||
use emath::{Align2, GuiRounding as _, NumExt as _, Rect, Vec2};
|
||||
use epaint::text::TextWrapMode;
|
||||
@@ -36,6 +36,7 @@ pub struct AtomLayout<'a> {
|
||||
pub(crate) frame: Frame,
|
||||
pub(crate) sense: Sense,
|
||||
fallback_text_color: Option<Color32>,
|
||||
fallback_font: Option<FontSelection>,
|
||||
min_size: Vec2,
|
||||
wrap_mode: Option<TextWrapMode>,
|
||||
align2: Option<Align2>,
|
||||
@@ -56,6 +57,7 @@ impl<'a> AtomLayout<'a> {
|
||||
frame: Frame::default(),
|
||||
sense: Sense::hover(),
|
||||
fallback_text_color: None,
|
||||
fallback_font: None,
|
||||
min_size: Vec2::ZERO,
|
||||
wrap_mode: None,
|
||||
align2: None,
|
||||
@@ -94,6 +96,13 @@ impl<'a> AtomLayout<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the fallback (default) font.
|
||||
#[inline]
|
||||
pub fn fallback_font(mut self, font: impl Into<FontSelection>) -> Self {
|
||||
self.fallback_font = Some(font.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the minimum size of the Widget.
|
||||
///
|
||||
/// This will find and expand atoms with `grow: true`.
|
||||
@@ -154,8 +163,11 @@ impl<'a> AtomLayout<'a> {
|
||||
min_size,
|
||||
wrap_mode,
|
||||
align2,
|
||||
fallback_font,
|
||||
} = self;
|
||||
|
||||
let fallback_font = fallback_font.unwrap_or_default();
|
||||
|
||||
let wrap_mode = wrap_mode.unwrap_or(ui.wrap_mode());
|
||||
|
||||
// If the TextWrapMode is not Extend, ensure there is some item marked as `shrink`.
|
||||
@@ -220,7 +232,12 @@ impl<'a> AtomLayout<'a> {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
let sized = item.into_sized(ui, available_inner_size, Some(wrap_mode));
|
||||
let sized = item.into_sized(
|
||||
ui,
|
||||
available_inner_size,
|
||||
Some(wrap_mode),
|
||||
fallback_font.clone(),
|
||||
);
|
||||
let size = sized.size;
|
||||
|
||||
desired_width += size.x;
|
||||
@@ -239,7 +256,12 @@ impl<'a> AtomLayout<'a> {
|
||||
available_inner_size.y,
|
||||
);
|
||||
|
||||
let sized = item.into_sized(ui, available_size_for_shrink_item, Some(wrap_mode));
|
||||
let sized = item.into_sized(
|
||||
ui,
|
||||
available_size_for_shrink_item,
|
||||
Some(wrap_mode),
|
||||
fallback_font,
|
||||
);
|
||||
let size = sized.size;
|
||||
|
||||
desired_width += size.x;
|
||||
|
||||
Reference in New Issue
Block a user