11use crate :: atomics:: ATOMS_SMALL_VEC_SIZE ;
22use crate :: {
3- AtomKind , Atoms , Frame , Id , Image , IntoAtoms , Response , Sense , SizedAtom , SizedAtomKind , Ui ,
4- Widget ,
3+ AtomKind , Atoms , FontSelection , Frame , Id , Image , IntoAtoms , Response , Sense , SizedAtom ,
4+ SizedAtomKind , Ui , Widget ,
55} ;
66use emath:: { Align2 , GuiRounding as _, NumExt as _, Rect , Vec2 } ;
77use epaint:: text:: TextWrapMode ;
@@ -36,6 +36,7 @@ pub struct AtomLayout<'a> {
3636 pub ( crate ) frame : Frame ,
3737 pub ( crate ) sense : Sense ,
3838 fallback_text_color : Option < Color32 > ,
39+ fallback_font : Option < FontSelection > ,
3940 min_size : Vec2 ,
4041 wrap_mode : Option < TextWrapMode > ,
4142 align2 : Option < Align2 > ,
@@ -56,6 +57,7 @@ impl<'a> AtomLayout<'a> {
5657 frame : Frame :: default ( ) ,
5758 sense : Sense :: hover ( ) ,
5859 fallback_text_color : None ,
60+ fallback_font : None ,
5961 min_size : Vec2 :: ZERO ,
6062 wrap_mode : None ,
6163 align2 : None ,
@@ -94,6 +96,13 @@ impl<'a> AtomLayout<'a> {
9496 self
9597 }
9698
99+ /// Set the fallback (default) font.
100+ #[ inline]
101+ pub fn fallback_font ( mut self , font : impl Into < FontSelection > ) -> Self {
102+ self . fallback_font = Some ( font. into ( ) ) ;
103+ self
104+ }
105+
97106 /// Set the minimum size of the Widget.
98107 ///
99108 /// This will find and expand atoms with `grow: true`.
@@ -154,8 +163,11 @@ impl<'a> AtomLayout<'a> {
154163 min_size,
155164 wrap_mode,
156165 align2,
166+ fallback_font,
157167 } = self ;
158168
169+ let fallback_font = fallback_font. unwrap_or_default ( ) ;
170+
159171 let wrap_mode = wrap_mode. unwrap_or ( ui. wrap_mode ( ) ) ;
160172
161173 // If the TextWrapMode is not Extend, ensure there is some item marked as `shrink`.
@@ -220,7 +232,12 @@ impl<'a> AtomLayout<'a> {
220232 continue ;
221233 }
222234 }
223- let sized = item. into_sized ( ui, available_inner_size, Some ( wrap_mode) ) ;
235+ let sized = item. into_sized (
236+ ui,
237+ available_inner_size,
238+ Some ( wrap_mode) ,
239+ fallback_font. clone ( ) ,
240+ ) ;
224241 let size = sized. size ;
225242
226243 desired_width += size. x ;
@@ -239,7 +256,12 @@ impl<'a> AtomLayout<'a> {
239256 available_inner_size. y ,
240257 ) ;
241258
242- let sized = item. into_sized ( ui, available_size_for_shrink_item, Some ( wrap_mode) ) ;
259+ let sized = item. into_sized (
260+ ui,
261+ available_size_for_shrink_item,
262+ Some ( wrap_mode) ,
263+ fallback_font,
264+ ) ;
243265 let size = sized. size ;
244266
245267 desired_width += size. x ;
0 commit comments