@@ -7,7 +7,7 @@ use std::rc::Rc;
77
88use glib:: translate:: { from_glib_full, ToGlibPtr } ;
99
10- use pango:: { AttrList , FontMapExt } ;
10+ use pango:: { AttrList , FontMapExt , TabAlign , TabArray } ;
1111use pango_sys:: pango_attr_insert_hyphens_new;
1212use pangocairo:: FontMap ;
1313
@@ -49,9 +49,12 @@ pub struct CairoTextLayout {
4949
5050pub struct CairoTextLayoutBuilder {
5151 text : Rc < dyn TextStorage > ,
52+
5253 defaults : util:: LayoutDefaults ,
5354 attributes : Vec < AttributeWithRange > ,
5455 last_range_start_pos : usize ,
56+
57+ tab_width : Option < f64 > ,
5558 width_constraint : f64 ,
5659 pango_layout : PangoLayout ,
5760}
@@ -193,6 +196,7 @@ impl Text for CairoText {
193196 defaults : util:: LayoutDefaults :: default ( ) ,
194197 attributes : Vec :: new ( ) ,
195198 last_range_start_pos : 0 ,
199+ tab_width : None ,
196200 width_constraint : f64:: INFINITY ,
197201 pango_layout,
198202 }
@@ -213,6 +217,11 @@ impl TextLayoutBuilder for CairoTextLayoutBuilder {
213217 self
214218 }
215219
220+ fn tab_width ( mut self , width : f64 ) -> Self {
221+ self . tab_width = Some ( width) ;
222+ self
223+ }
224+
216225 fn alignment ( self , alignment : TextAlignment ) -> Self {
217226 /*
218227 * NOTE: Pango has `auto_dir` enabled by default. This means that
@@ -277,6 +286,13 @@ impl TextLayoutBuilder for CairoTextLayoutBuilder {
277286 }
278287
279288 fn build ( self ) -> Result < Self :: Out , Error > {
289+ if let Some ( tab_width) = self . tab_width {
290+ let tab_width = ( tab_width * PANGO_SCALE ) as i32 ;
291+ let mut array = TabArray :: new ( 1 , false ) ;
292+ array. set_tab ( 0 , TabAlign :: Left , tab_width) ;
293+ self . pango_layout . set_tabs ( Some ( & array) ) ;
294+ }
295+
280296 let pango_attributes = AttrList :: new ( ) ;
281297 let add_attribute = |attribute| {
282298 if let Some ( attribute) = attribute {
0 commit comments