@@ -398,7 +398,7 @@ oc_ui_box* oc_ui_box_make_str8(oc_str8 string, oc_ui_flags flags)
398
398
399
399
box -> flags = flags ;
400
400
box -> string = oc_str8_push_copy (& ui -> frameArena , string );
401
- box -> glyphRun = 0 ;
401
+ box -> textLine = 0 ;
402
402
403
403
//NOTE: setup hierarchy
404
404
if (box -> frameCounter != ui -> frameCounter )
@@ -975,8 +975,14 @@ void oc_ui_styling_prepass(oc_ui_context* ui, oc_ui_box* box, oc_list* before, o
975
975
|| desiredSize [OC_UI_AXIS_Y ].kind == OC_UI_SIZE_TEXT )
976
976
{
977
977
oc_str32 codepoints = oc_utf8_push_to_codepoints (& ui -> frameArena , box -> string );
978
- box -> glyphRun = oc_text_shape (& ui -> frameArena , style -> font , 0 , codepoints , 0 , codepoints .len );
979
- textBox = oc_glyph_run_range_metrics (box -> glyphRun , style -> fontSize , 0 , codepoints .len ).logical ;
978
+ box -> textLine = oc_text_line_from_utf32 (& ui -> frameArena ,
979
+ codepoints ,
980
+ & (oc_text_attributes ){
981
+ .font = style -> font ,
982
+ .fontSize = style -> fontSize ,
983
+ .color = style -> color ,
984
+ });
985
+ textBox = oc_text_line_get_metrics_for_range (box -> textLine , 0 , codepoints .len ).logical ;
980
986
}
981
987
982
988
for (int i = 0 ; i < OC_UI_AXIS_COUNT ; i ++ )
@@ -1549,11 +1555,17 @@ void oc_ui_draw_box(oc_ui_box* box)
1549
1555
//TODO: might not want to recompute codepoints each time?
1550
1556
oc_ui_context * ui = oc_ui_get_context ();
1551
1557
oc_str32 codepoints = oc_utf8_push_to_codepoints (& ui -> frameArena , box -> string );
1552
- if (!box -> glyphRun )
1558
+ if (!box -> textLine )
1553
1559
{
1554
- box -> glyphRun = oc_text_shape (& ui -> frameArena , style -> font , 0 , codepoints , 0 , codepoints .len );
1560
+ box -> textLine = oc_text_line_from_utf32 (& ui -> frameArena ,
1561
+ codepoints ,
1562
+ & (oc_text_attributes ){
1563
+ .font = style -> font ,
1564
+ .fontSize = style -> fontSize ,
1565
+ .color = style -> color ,
1566
+ });
1555
1567
}
1556
- oc_rect textBox = oc_glyph_run_range_metrics (box -> glyphRun , style -> fontSize , 0 , codepoints .len ).logical ;
1568
+ oc_rect textBox = oc_text_line_get_metrics_for_range (box -> textLine , 0 , codepoints .len ).logical ;
1557
1569
1558
1570
f32 x = 0 ;
1559
1571
f32 y = 0 ;
@@ -1590,7 +1602,7 @@ void oc_ui_draw_box(oc_ui_box* box)
1590
1602
oc_set_color (style -> color );
1591
1603
1592
1604
oc_move_to (x , y );
1593
- oc_text_draw_run (box -> glyphRun , style -> fontSize );
1605
+ oc_text_line_draw (box -> textLine );
1594
1606
}
1595
1607
1596
1608
if (box -> flags & OC_UI_FLAG_CLIP )
@@ -3786,7 +3798,7 @@ i32 oc_ui_edit_find_word_end(oc_ui_context* ui, oc_str32 codepoints, i32 startCh
3786
3798
typedef struct oc_ui_text_box_render_info
3787
3799
{
3788
3800
oc_str32 codepoints ;
3789
- oc_glyph_run * glyphRun ;
3801
+ oc_text_line * textLine ;
3790
3802
3791
3803
} oc_ui_text_box_render_info ;
3792
3804
@@ -3807,7 +3819,7 @@ void oc_ui_text_box_render(oc_ui_box* box, void* data)
3807
3819
oc_font_metrics extents = oc_font_get_metrics (style -> font , style -> fontSize );
3808
3820
f32 lineHeight = extents .ascent + extents .descent ;
3809
3821
3810
- oc_rect beforeBox = oc_glyph_run_range_metrics (info -> glyphRun , style -> fontSize , 0 , firstDisplayedChar ).logical ;
3822
+ oc_rect beforeBox = oc_text_line_get_metrics_for_range (info -> textLine , 0 , firstDisplayedChar ).logical ;
3811
3823
3812
3824
f32 textX = box -> rect .x - beforeBox .w ;
3813
3825
f32 textTop = box -> rect .y + 0.5 * (box -> rect .h - lineHeight );
@@ -3818,15 +3830,15 @@ void oc_ui_text_box_render(oc_ui_box* box, void* data)
3818
3830
u32 selectStart = oc_min (ui -> editCursor , ui -> editMark );
3819
3831
u32 selectEnd = oc_max (ui -> editCursor , ui -> editMark );
3820
3832
3821
- oc_rect beforeSelectBox = oc_glyph_run_range_metrics (info -> glyphRun , style -> fontSize , 0 , selectStart ).logical ;
3833
+ oc_rect beforeSelectBox = oc_text_line_get_metrics_for_range (info -> textLine , 0 , selectStart ).logical ;
3822
3834
3823
3835
beforeSelectBox .x += textX ;
3824
3836
beforeSelectBox .y += textY ;
3825
3837
3826
3838
if (selectStart != selectEnd )
3827
3839
{
3828
- oc_rect selectBox = oc_glyph_run_range_metrics (info -> glyphRun , style -> fontSize , selectStart , selectEnd ).logical ;
3829
- oc_rect afterSelectBox = oc_glyph_run_range_metrics (info -> glyphRun , style -> fontSize , selectEnd , codepoints .len ).logical ;
3840
+ oc_rect selectBox = oc_text_line_get_metrics_for_range (info -> textLine , selectStart , selectEnd ).logical ;
3841
+ oc_rect afterSelectBox = oc_text_line_get_metrics_for_range (info -> textLine , selectEnd , codepoints .len ).logical ;
3830
3842
3831
3843
selectBox .x += textX ;
3832
3844
selectBox .y += textY ;
@@ -3837,7 +3849,7 @@ void oc_ui_text_box_render(oc_ui_box* box, void* data)
3837
3849
oc_set_color (style -> color );
3838
3850
3839
3851
oc_move_to (textX , textY );
3840
- oc_text_draw_run (info -> glyphRun , style -> fontSize );
3852
+ oc_text_line_draw (info -> textLine );
3841
3853
}
3842
3854
else
3843
3855
{
@@ -3850,14 +3862,14 @@ void oc_ui_text_box_render(oc_ui_box* box, void* data)
3850
3862
}
3851
3863
oc_set_color (style -> color );
3852
3864
oc_move_to (textX , textY );
3853
- oc_text_draw_run (info -> glyphRun , style -> fontSize );
3865
+ oc_text_line_draw (info -> textLine );
3854
3866
}
3855
3867
}
3856
3868
else
3857
3869
{
3858
3870
oc_set_color (style -> color );
3859
3871
oc_move_to (textX , textY );
3860
- oc_text_draw_run (info -> glyphRun , style -> fontSize );
3872
+ oc_text_line_draw (info -> textLine );
3861
3873
}
3862
3874
}
3863
3875
@@ -3912,7 +3924,13 @@ oc_ui_text_box_result oc_ui_text_box_str8(oc_str8 name, oc_arena* arena, oc_str8
3912
3924
oc_font_metrics extents = oc_font_get_metrics (font , fontSize );
3913
3925
3914
3926
oc_str32 codepoints = oc_utf8_push_to_codepoints (& ui -> frameArena , text );
3915
- oc_glyph_run * run = oc_text_shape (& ui -> frameArena , font , 0 , codepoints , 0 , codepoints .len );
3927
+ oc_text_line * line = oc_text_line_from_utf32 (& ui -> frameArena ,
3928
+ codepoints ,
3929
+ & (oc_text_attributes ){
3930
+ .font = font ,
3931
+ .fontSize = fontSize ,
3932
+ .color = textBox -> style .color ,
3933
+ });
3916
3934
3917
3935
oc_ui_sig sig = oc_ui_box_sig (frame );
3918
3936
@@ -3945,7 +3963,7 @@ oc_ui_text_box_result oc_ui_text_box_str8(oc_str8 name, oc_arena* arena, oc_str8
3945
3963
//TODO: update text API: use point to cursor on shaped text?
3946
3964
for (int i = ui -> editFirstDisplayedChar ; i < codepoints .len ; i ++ )
3947
3965
{
3948
- oc_rect bbox = oc_glyph_run_range_metrics ( run , fontSize , i , i + 1 ).logical ;
3966
+ oc_rect bbox = oc_text_line_get_metrics_for_range ( line , i , i + 1 ).logical ;
3949
3967
if (x < cursorX )
3950
3968
{
3951
3969
hoveredChar = i ;
@@ -4001,7 +4019,7 @@ oc_ui_text_box_result oc_ui_text_box_str8(oc_str8 name, oc_arena* arena, oc_str8
4001
4019
}
4002
4020
else if (ui -> editSelectionMode == OC_UI_EDIT_MOVE_LINE )
4003
4021
{
4004
- oc_rect bbox = oc_glyph_run_range_metrics ( run , fontSize , 0 , codepoints .len ).logical ;
4022
+ oc_rect bbox = oc_text_line_get_metrics_for_range ( line , 0 , codepoints .len ).logical ;
4005
4023
if (fabsf (bbox .w - cursorX ) < fabsf (cursorX ))
4006
4024
{
4007
4025
ui -> editCursor = codepoints .len ;
@@ -4018,8 +4036,8 @@ oc_ui_text_box_result oc_ui_text_box_str8(oc_str8 name, oc_arena* arena, oc_str8
4018
4036
if (oc_min (ui -> editCursor , ui -> editMark ) == oc_min (ui -> editWordSelectionInitialCursor , ui -> editWordSelectionInitialMark )
4019
4037
&& oc_max (ui -> editCursor , ui -> editMark ) == oc_max (ui -> editWordSelectionInitialCursor , ui -> editWordSelectionInitialMark ))
4020
4038
{
4021
- oc_rect editCursorPrefixBbox = oc_glyph_run_range_metrics ( run , fontSize , 0 , ui -> editCursor ).logical ;
4022
- oc_rect editMarkPrefixBbox = oc_glyph_run_range_metrics ( run , fontSize , 0 , ui -> editMark ).logical ;
4039
+ oc_rect editCursorPrefixBbox = oc_text_line_get_metrics_for_range ( line , 0 , ui -> editCursor ).logical ;
4040
+ oc_rect editMarkPrefixBbox = oc_text_line_get_metrics_for_range ( line , 0 , ui -> editMark ).logical ;
4023
4041
4024
4042
f32 editCursorX = editCursorPrefixBbox .w ;
4025
4043
f32 editMarkX = editMarkPrefixBbox .w ;
@@ -4154,12 +4172,12 @@ oc_ui_text_box_result oc_ui_text_box_str8(oc_str8 name, oc_arena* arena, oc_str8
4154
4172
else
4155
4173
{
4156
4174
i32 firstDisplayedChar = ui -> editFirstDisplayedChar ;
4157
- oc_rect firstToCursorBox = oc_glyph_run_range_metrics ( run , fontSize , firstDisplayedChar , ui -> editCursor ).logical ;
4175
+ oc_rect firstToCursorBox = oc_text_line_get_metrics_for_range ( line , firstDisplayedChar , ui -> editCursor ).logical ;
4158
4176
4159
4177
while (firstToCursorBox .w > textBox -> rect .w )
4160
4178
{
4161
4179
firstDisplayedChar ++ ;
4162
- firstToCursorBox = oc_glyph_run_range_metrics ( run , fontSize , firstDisplayedChar , ui -> editCursor ).logical ;
4180
+ firstToCursorBox = oc_text_line_get_metrics_for_range ( line , firstDisplayedChar , ui -> editCursor ).logical ;
4163
4181
}
4164
4182
4165
4183
ui -> editFirstDisplayedChar = firstDisplayedChar ;
@@ -4169,7 +4187,7 @@ oc_ui_text_box_result oc_ui_text_box_str8(oc_str8 name, oc_arena* arena, oc_str8
4169
4187
//NOTE: set renderer
4170
4188
oc_ui_text_box_render_info * info = oc_arena_push_type (& ui -> frameArena , oc_ui_text_box_render_info );
4171
4189
info -> codepoints = codepoints ;
4172
- info -> glyphRun = run ;
4190
+ info -> textLine = line ;
4173
4191
4174
4192
oc_ui_box_set_draw_proc (textBox , oc_ui_text_box_render , info );
4175
4193
}
@@ -4178,7 +4196,7 @@ oc_ui_text_box_result oc_ui_text_box_str8(oc_str8 name, oc_arena* arena, oc_str8
4178
4196
//NOTE: set renderer
4179
4197
oc_ui_text_box_render_info * info = oc_arena_push_type (& ui -> frameArena , oc_ui_text_box_render_info );
4180
4198
info -> codepoints = codepoints ;
4181
- info -> glyphRun = run ;
4199
+ info -> textLine = line ;
4182
4200
4183
4201
oc_ui_box_set_draw_proc (textBox , oc_ui_text_box_render , info );
4184
4202
}
0 commit comments