File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -366,6 +366,14 @@ static std::vector<GlyphVtx> layout_text(
366366 float line_height = static_cast <float >(face->size ->metrics .height >> 6 );
367367 float ascender = static_cast <float >(face->size ->metrics .ascender >> 6 );
368368
369+ // Tab width = 4 spaces; tabs snap to the next tab stop instead of drawing
370+ // the font's missing-glyph box.
371+ float space_adv = 0 .f ;
372+ if (FT_Load_Char (face, ' ' , FT_LOAD_DEFAULT ) == 0 )
373+ space_adv = static_cast <float >(face->glyph ->advance .x >> 6 );
374+ if (space_adv <= 0 .f ) space_adv = static_cast <float >(px) * 0 .25f ;
375+ const float tab_width = space_adv * 4 .0f ;
376+
369377 std::vector<GlyphVtx> out;
370378 out.reserve (str.size ());
371379
@@ -388,6 +396,12 @@ static std::vector<GlyphVtx> layout_text(
388396 FT_UInt prev = 0 ;
389397 for (wchar_t wc : line)
390398 {
399+ if (wc == L' \t ' )
400+ {
401+ line_w = (static_cast <float >(static_cast <int >(line_w / tab_width)) + 1 .f ) * tab_width;
402+ prev = 0 ;
403+ continue ;
404+ }
391405 FT_UInt gi = FT_Get_Char_Index (face, static_cast <uint32_t >(wc));
392406 if (prev && gi)
393407 {
@@ -411,9 +425,18 @@ static std::vector<GlyphVtx> layout_text(
411425 x = area.left ;
412426
413427 // --- Emit glyph vertices ---
428+ const float x_line_start = x;
414429 FT_UInt prev = 0 ;
415430 for (wchar_t wc : line)
416431 {
432+ if (wc == L' \t ' )
433+ {
434+ float rel = x - x_line_start;
435+ x = x_line_start + (static_cast <float >(static_cast <int >(rel / tab_width)) + 1 .f ) * tab_width;
436+ prev = 0 ;
437+ continue ;
438+ }
439+
417440 uint32_t char_code = static_cast <uint32_t >(wc);
418441 FT_UInt gi = FT_Get_Char_Index (face, char_code);
419442
Original file line number Diff line number Diff line change @@ -294,7 +294,6 @@ for (const auto& token : parsed) {
294294 auto line = std::make_shared<label>();
295295 line->text = std::string (word_view.substr (0 ,word_view.length ()-1 ));
296296 line->docking = dock::TOP ;
297- line->draw_helper = true ;
298297 add_child (line);
299298
300299
You can’t perform that action at this time.
0 commit comments