eliminate txti layer

This commit is contained in:
Ryan Fleury
2024-06-26 11:09:58 -07:00
parent 6e2353d302
commit 1229a50c68
10 changed files with 3 additions and 1422 deletions
-182
View File
@@ -12479,188 +12479,6 @@ df_do_txt_controls(TXT_TextInfo *info, String8 data, U64 line_count_per_page, Tx
return change;
}
internal B32
df_do_txti_controls(TXTI_Handle handle, U64 line_count_per_page, TxtPt *cursor, TxtPt *mark, S64 *preferred_column)
{
Temp scratch = scratch_begin(0, 0);
B32 change = 0;
UI_EventList *events = ui_events();
TXTI_BufferInfo buffer_info = txti_buffer_info_from_handle(scratch.arena, handle);
for(UI_EventNode *n = events->first, *next = 0; n != 0; n = next)
{
next = n->next;
B32 taken = 0;
if(n->v.kind != UI_EventKind_Navigate && n->v.kind != UI_EventKind_Edit)
{
continue;
}
String8 line = txti_string_from_handle_line_num(scratch.arena, handle, cursor->line);
UI_TxtOp single_line_op = ui_single_line_txt_op_from_event(scratch.arena, &n->v, line, *cursor, *mark);
//- rjf: invalid single-line op or endpoint units => try multiline
if(n->v.delta_unit == UI_EventDeltaUnit_Whole || single_line_op.flags & UI_TxtOpFlag_Invalid)
{
U64 line_count = buffer_info.total_line_count;
String8 prev_line = txti_string_from_handle_line_num(scratch.arena, handle, cursor->line-1);
String8 next_line = txti_string_from_handle_line_num(scratch.arena, handle, cursor->line+1);
Vec2S32 delta = n->v.delta_2s32;
//- rjf: wrap lines right
if(n->v.delta_unit != UI_EventDeltaUnit_Whole && delta.x > 0 && cursor->column == line.size+1 && cursor->line+1 <= line_count)
{
cursor->line += 1;
cursor->column = 1;
*preferred_column = 1;
change = 1;
taken = 1;
}
//- rjf: wrap lines left
if(n->v.delta_unit != UI_EventDeltaUnit_Whole && delta.x < 0 && cursor->column == 1 && cursor->line-1 >= 1)
{
cursor->line -= 1;
cursor->column = prev_line.size+1;
*preferred_column = prev_line.size+1;
change = 1;
taken = 1;
}
//- rjf: movement down (plain)
if(n->v.delta_unit == UI_EventDeltaUnit_Char && delta.y > 0 && cursor->line+1 <= line_count)
{
cursor->line += 1;
cursor->column = Min(*preferred_column, next_line.size+1);
change = 1;
taken = 1;
}
//- rjf: movement up (plain)
if(n->v.delta_unit == UI_EventDeltaUnit_Char && delta.y < 0 && cursor->line-1 >= 1)
{
cursor->line -= 1;
cursor->column = Min(*preferred_column, prev_line.size+1);
change = 1;
taken = 1;
}
//- rjf: movement down (chunk)
if(n->v.delta_unit == UI_EventDeltaUnit_Word && delta.y > 0 && cursor->line+1 <= line_count)
{
for(S64 line_num = cursor->line+1; line_num <= line_count; line_num += 1)
{
String8 line = txti_string_from_handle_line_num(scratch.arena, handle, line_num);
U64 line_size = line.size;
if(line_size == 0)
{
cursor->line = line_num;
cursor->column = 1;
break;
}
else if(line_num == line_count)
{
cursor->line = line_num;
cursor->column = line_size+1;
}
}
change = 1;
taken = 1;
}
//- rjf: movement up (chunk)
if(n->v.delta_unit == UI_EventDeltaUnit_Word && delta.y < 0 && cursor->line-1 >= 1)
{
for(S64 line_num = cursor->line-1; line_num > 0; line_num -= 1)
{
String8 line = txti_string_from_handle_line_num(scratch.arena, handle, line_num);
U64 line_size = line.size;
if(line_size == 0)
{
cursor->line = line_num;
cursor->column = 1;
break;
}
else if(line_num == 1)
{
cursor->line = line_num;
cursor->column = 1;
}
}
change = 1;
taken = 1;
}
//- rjf: movement down (page)
if(n->v.delta_unit == UI_EventDeltaUnit_Page && delta.y > 0)
{
cursor->line += line_count_per_page;
cursor->column = 1;
cursor->line = Clamp(1, cursor->line, line_count);
change = 1;
taken = 1;
}
//- rjf: movement up (page)
if(n->v.delta_unit == UI_EventDeltaUnit_Page && delta.y < 0)
{
cursor->line -= line_count_per_page;
cursor->column = 1;
cursor->line = Clamp(1, cursor->line, line_count);
change = 1;
taken = 1;
}
//- rjf: movement to endpoint (+)
if(n->v.delta_unit == UI_EventDeltaUnit_Whole && (delta.y > 0 || delta.x > 0))
{
*cursor = txt_pt(line_count, buffer_info.last_line_size);
change = 1;
taken = 1;
}
//- rjf: movement to endpoint (-)
if(n->v.delta_unit == UI_EventDeltaUnit_Whole && (delta.y < 0 || delta.x < 0))
{
*cursor = txt_pt(1, 1);
change = 1;
taken = 1;
}
//- rjf: stick mark to cursor, when we don't want to keep it in the same spot
if(!(n->v.flags & UI_EventFlag_KeepMark))
{
*mark = *cursor;
}
}
//- rjf: valid single-line op => do single-line op
else
{
*cursor = single_line_op.cursor;
*mark = single_line_op.mark;
*preferred_column = cursor->column;
change = 1;
taken = 1;
}
//- rjf: copy
if(n->v.flags & UI_EventFlag_Copy)
{
String8 text = txti_string_from_handle_txt_rng(scratch.arena, handle, txt_rng(*cursor, *mark));
os_set_clipboard_text(text);
taken = 1;
}
//- rjf: consume
if(taken)
{
ui_eat_event(events, n);
}
}
scratch_end(scratch);
return change;
}
////////////////////////////////
//~ rjf: UI Widgets: Fancy Labels
-1
View File
@@ -1084,7 +1084,6 @@ internal DF_CodeSliceSignal df_code_slice(DF_Window *ws, DF_CtrlCtx *ctrl_ctx, E
internal DF_CodeSliceSignal df_code_slicef(DF_Window *ws, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, DF_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *preferred_column, char *fmt, ...);
internal B32 df_do_txt_controls(TXT_TextInfo *info, String8 data, U64 line_count_per_page, TxtPt *cursor, TxtPt *mark, S64 *preferred_column);
internal B32 df_do_txti_controls(TXTI_Handle handle, U64 line_count_per_page, TxtPt *cursor, TxtPt *mark, S64 *preferred_column);
////////////////////////////////
//~ rjf: UI Widgets: Fancy Labels