mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-11-20 13:10:07 -08:00
text patches: checkpoint
This commit is contained in:
1 parent
cd82268a07
commit
bb85f6f692
22 files changed
+562
-565
No files matched your search
+18
-18
@@ -129,8 +129,8 @@ typedef struct UI_LineEditDrawData UI_LineEditDrawData;
|
||||
struct UI_LineEditDrawData
|
||||
{
|
||||
String8 edited_string;
|
||||
TxtPt cursor;
|
||||
TxtPt mark;
|
||||
U64 cursor;
|
||||
U64 mark;
|
||||
B32 trail;
|
||||
};
|
||||
|
||||
@@ -148,11 +148,11 @@ internal UI_BOX_CUSTOM_DRAW(ui_line_edit_draw)
|
||||
trail_color.w *= 0.25f;
|
||||
Vec2F32 text_position = ui_box_text_position(box);
|
||||
String8 edited_string = draw_data->edited_string;
|
||||
TxtPt cursor = draw_data->cursor;
|
||||
TxtPt mark = draw_data->mark;
|
||||
F32 cursor_pixel_off = fnt_dim_from_tag_size_string(font, font_size, 0, tab_size, str8_prefix(edited_string, cursor.column-1)).x;
|
||||
U64 cursor = draw_data->cursor;
|
||||
U64 mark = draw_data->mark;
|
||||
F32 cursor_pixel_off = fnt_dim_from_tag_size_string(font, font_size, 0, tab_size, str8_prefix(edited_string, cursor)).x;
|
||||
F32 cursor_pixel_off__animated = ui_anim(ui_key_from_stringf(box->key, "cursor_off_px"), cursor_pixel_off);
|
||||
F32 mark_pixel_off = fnt_dim_from_tag_size_string(font, font_size, 0, tab_size, str8_prefix(edited_string, mark.column-1)).x;
|
||||
F32 mark_pixel_off = fnt_dim_from_tag_size_string(font, font_size, 0, tab_size, str8_prefix(edited_string, mark)).x;
|
||||
F32 cursor_thickness = ClampBot(1.f, floor_f32(font_size/10.f));
|
||||
Rng2F32 cursor_rect =
|
||||
{
|
||||
@@ -196,7 +196,7 @@ internal UI_BOX_CUSTOM_DRAW(ui_line_edit_draw)
|
||||
}
|
||||
|
||||
internal UI_Signal
|
||||
ui_line_edit(TxtPt *cursor, TxtPt *mark, U8 *edit_buffer, U64 edit_buffer_size, U64 *edit_string_size_out, String8 pre_edit_value, String8 string)
|
||||
ui_line_edit(U64 *cursor, U64 *mark, U8 *edit_buffer, U64 edit_buffer_size, U64 *edit_string_size_out, String8 pre_edit_value, String8 string)
|
||||
{
|
||||
//- rjf: make key
|
||||
UI_Key key = ui_key_from_string(ui_active_seed_key(), string);
|
||||
@@ -241,9 +241,9 @@ ui_line_edit(TxtPt *cursor, TxtPt *mark, U8 *edit_buffer, U64 edit_buffer_size,
|
||||
UI_TxtOp op = ui_single_line_txt_op_from_event(scratch.arena, evt, edit_string, *cursor, *mark);
|
||||
|
||||
// rjf: perform replace range
|
||||
if(!txt_pt_match(op.range.min, op.range.max) || op.replace.size != 0)
|
||||
if(op.range.min != op.range.max || op.replace.size != 0)
|
||||
{
|
||||
String8 new_string = ui_push_string_replace_range(scratch.arena, edit_string, r1s64(op.range.min.column, op.range.max.column), op.replace);
|
||||
String8 new_string = ui_push_string_replace_range(scratch.arena, edit_string, op.range, op.replace);
|
||||
new_string.size = Min(edit_buffer_size, new_string.size);
|
||||
MemoryCopy(edit_buffer, new_string.str, new_string.size);
|
||||
edit_string_size_out[0] = new_string.size;
|
||||
@@ -269,7 +269,7 @@ ui_line_edit(TxtPt *cursor, TxtPt *mark, U8 *edit_buffer, U64 edit_buffer_size,
|
||||
}
|
||||
|
||||
//- rjf: build contents
|
||||
TxtPt mouse_pt = {0};
|
||||
U64 mouse_off = {0};
|
||||
F32 cursor_off = 0;
|
||||
UI_Parent(box)
|
||||
{
|
||||
@@ -289,14 +289,14 @@ ui_line_edit(TxtPt *cursor, TxtPt *mark, U8 *edit_buffer, U64 edit_buffer_size,
|
||||
ui_set_next_pref_width(ui_px(total_text_width+ui_top_font_size()*5, 1.f));
|
||||
UI_Box *editstr_box = ui_build_box_from_stringf(UI_BoxFlag_DrawText|UI_BoxFlag_DisableTextTrunc, "###editstr");
|
||||
UI_LineEditDrawData *draw_data = push_array(ui_build_arena(), UI_LineEditDrawData, 1);
|
||||
draw_data->edited_string = push_str8_copy(ui_build_arena(), edit_string);
|
||||
draw_data->edited_string = str8_copy(ui_build_arena(), edit_string);
|
||||
draw_data->cursor = *cursor;
|
||||
draw_data->mark = *mark;
|
||||
draw_data->trail = 1;
|
||||
ui_box_equip_display_string(editstr_box, edit_string);
|
||||
ui_box_equip_custom_draw(editstr_box, ui_line_edit_draw, draw_data);
|
||||
mouse_pt = txt_pt(1, 1+ui_box_char_pos_from_xy(editstr_box, ui_mouse()));
|
||||
cursor_off = fnt_dim_from_tag_size_string(ui_top_font(), ui_top_font_size(), 0, ui_top_tab_size(), str8_prefix(edit_string, cursor->column-1)).x;
|
||||
mouse_off = ui_box_char_pos_from_xy(editstr_box, ui_mouse());
|
||||
cursor_off = fnt_dim_from_tag_size_string(ui_top_font(), ui_top_font_size(), 0, ui_top_tab_size(), str8_prefix(edit_string, *cursor)).x;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,8 +310,8 @@ ui_line_edit(TxtPt *cursor, TxtPt *mark, U8 *edit_buffer, U64 edit_buffer_size,
|
||||
edit_string_size_out[0] = edit_string.size;
|
||||
ui_set_auto_focus_active_key(key);
|
||||
ui_kill_action();
|
||||
*cursor = txt_pt(1, edit_string.size+1);
|
||||
*mark = txt_pt(1, 1);
|
||||
*cursor = edit_string.size;
|
||||
*mark = 0;
|
||||
}
|
||||
if(is_focus_active && sig.f&UI_SignalFlag_KeyboardPressed)
|
||||
{
|
||||
@@ -322,9 +322,9 @@ ui_line_edit(TxtPt *cursor, TxtPt *mark, U8 *edit_buffer, U64 edit_buffer_size,
|
||||
{
|
||||
if(ui_pressed(sig))
|
||||
{
|
||||
*mark = mouse_pt;
|
||||
*mark = mouse_off;
|
||||
}
|
||||
*cursor = mouse_pt;
|
||||
*cursor = mouse_off;
|
||||
}
|
||||
|
||||
//- rjf: focus cursor
|
||||
@@ -349,7 +349,7 @@ ui_line_edit(TxtPt *cursor, TxtPt *mark, U8 *edit_buffer, U64 edit_buffer_size,
|
||||
}
|
||||
|
||||
internal UI_Signal
|
||||
ui_line_editf(TxtPt *cursor, TxtPt *mark, U8 *edit_buffer, U64 edit_buffer_size, U64 *edit_string_size_out, String8 pre_edit_value, char *fmt, ...)
|
||||
ui_line_editf(U64 *cursor, U64 *mark, U8 *edit_buffer, U64 edit_buffer_size, U64 *edit_string_size_out, String8 pre_edit_value, char *fmt, ...)
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
va_list args;
|
||||
|
||||
@@ -77,8 +77,8 @@ internal UI_Signal ui_button(String8 string);
|
||||
internal UI_Signal ui_buttonf(char *fmt, ...);
|
||||
internal UI_Signal ui_hover_label(String8 string);
|
||||
internal UI_Signal ui_hover_labelf(char *fmt, ...);
|
||||
internal UI_Signal ui_line_edit(TxtPt *cursor, TxtPt *mark, U8 *edit_buffer, U64 edit_buffer_size, U64 *edit_string_size_out, String8 pre_edit_value, String8 string);
|
||||
internal UI_Signal ui_line_editf(TxtPt *cursor, TxtPt *mark, U8 *edit_buffer, U64 edit_buffer_size, U64 *edit_string_size_out, String8 pre_edit_value, char *fmt, ...);
|
||||
internal UI_Signal ui_line_edit(U64 *cursor, U64 *mark, U8 *edit_buffer, U64 edit_buffer_size, U64 *edit_string_size_out, String8 pre_edit_value, String8 string);
|
||||
internal UI_Signal ui_line_editf(U64 *cursor, U64 *mark, U8 *edit_buffer, U64 edit_buffer_size, U64 *edit_string_size_out, String8 pre_edit_value, char *fmt, ...);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Images
|
||||
|
||||
+30
-44
@@ -142,11 +142,11 @@ ui_scanned_column_from_column(String8 string, S64 start_column, Side side)
|
||||
}
|
||||
|
||||
internal UI_TxtOp
|
||||
ui_single_line_txt_op_from_event(Arena *arena, UI_Event *event, String8 string, TxtPt cursor, TxtPt mark)
|
||||
ui_single_line_txt_op_from_event(Arena *arena, UI_Event *event, String8 string, U64 cursor, U64 mark)
|
||||
{
|
||||
TxtPt next_cursor = cursor;
|
||||
TxtPt next_mark = mark;
|
||||
TxtRng range = {0};
|
||||
U64 next_cursor = cursor;
|
||||
U64 next_mark = mark;
|
||||
Rng1U64 range = {0};
|
||||
String8 replace = {0};
|
||||
String8 copy = {0};
|
||||
UI_TxtOpFlags flags = 0;
|
||||
@@ -164,85 +164,78 @@ ui_single_line_txt_op_from_event(Arena *arena, UI_Event *event, String8 string,
|
||||
}break;
|
||||
case UI_EventDeltaUnit_Word:
|
||||
{
|
||||
delta.x = (S32)ui_scanned_column_from_column(string, cursor.column, delta.x > 0 ? Side_Max : Side_Min) - cursor.column;
|
||||
delta.x = (S32)(ui_scanned_column_from_column(string, (S64)cursor+1, delta.x > 0 ? Side_Max : Side_Min)-1 - (S64)cursor);
|
||||
}break;
|
||||
case UI_EventDeltaUnit_Line:
|
||||
case UI_EventDeltaUnit_Whole:
|
||||
case UI_EventDeltaUnit_Page:
|
||||
{
|
||||
S64 first_nonwhitespace_column = 1;
|
||||
U64 first_nonwhitespace_off = 0;
|
||||
for(U64 idx = 0; idx < string.size; idx += 1)
|
||||
{
|
||||
if(!char_is_space(string.str[idx]))
|
||||
{
|
||||
first_nonwhitespace_column = (S64)idx + 1;
|
||||
first_nonwhitespace_off = idx;
|
||||
break;
|
||||
}
|
||||
}
|
||||
S64 home_dest_column = (cursor.column == first_nonwhitespace_column) ? 1 : first_nonwhitespace_column;
|
||||
delta.x = (delta.x > 0) ? ((S64)string.size+1 - cursor.column) : (home_dest_column - cursor.column);
|
||||
U64 home_dest_off = (cursor == first_nonwhitespace_off) ? 0 : first_nonwhitespace_off;
|
||||
delta.x = (delta.x > 0) ? ((S64)string.size - (S64)cursor) : ((S64)home_dest_off - (S64)cursor);
|
||||
}break;
|
||||
}
|
||||
|
||||
//- rjf: zero delta
|
||||
if(!txt_pt_match(cursor, mark) && event->flags & UI_EventFlag_ZeroDeltaOnSelect)
|
||||
if(cursor != mark && event->flags & UI_EventFlag_ZeroDeltaOnSelect)
|
||||
{
|
||||
delta = v2s32(0, 0);
|
||||
}
|
||||
|
||||
//- rjf: form next cursor
|
||||
if(txt_pt_match(cursor, mark) || !(event->flags & UI_EventFlag_ZeroDeltaOnSelect))
|
||||
if(cursor == mark || !(event->flags & UI_EventFlag_ZeroDeltaOnSelect))
|
||||
{
|
||||
next_cursor.column += delta.x;
|
||||
next_cursor += delta.x;
|
||||
}
|
||||
|
||||
//- rjf: cap at line
|
||||
if(event->flags & UI_EventFlag_CapAtLine)
|
||||
{
|
||||
next_cursor.column = Clamp(1, next_cursor.column, (S64)(string.size+1));
|
||||
next_cursor = Clamp(0, next_cursor, string.size);
|
||||
}
|
||||
|
||||
//- rjf: in some cases, we want to pick a selection side based on the delta
|
||||
if(!txt_pt_match(cursor, mark) && event->flags & UI_EventFlag_PickSelectSide)
|
||||
if(cursor != mark && event->flags & UI_EventFlag_PickSelectSide)
|
||||
{
|
||||
if(original_delta.x < 0 || original_delta.y < 0)
|
||||
{
|
||||
next_cursor = next_mark = txt_pt_min(cursor, mark);
|
||||
next_cursor = next_mark = Min(cursor, mark);
|
||||
}
|
||||
else if(original_delta.x > 0 || original_delta.y > 0)
|
||||
{
|
||||
next_cursor = next_mark = txt_pt_max(cursor, mark);
|
||||
next_cursor = next_mark = Max(cursor, mark);
|
||||
}
|
||||
}
|
||||
|
||||
//- rjf: copying
|
||||
if(event->flags & UI_EventFlag_Copy)
|
||||
{
|
||||
if(cursor.line == mark.line)
|
||||
{
|
||||
copy = str8_substr(string, r1u64(cursor.column-1, mark.column-1));
|
||||
flags |= UI_TxtOpFlag_Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
flags |= UI_TxtOpFlag_Invalid;
|
||||
}
|
||||
copy = str8_substr(string, r1u64(cursor, mark));
|
||||
flags |= UI_TxtOpFlag_Copy;
|
||||
}
|
||||
|
||||
//- rjf: pasting
|
||||
if(event->flags & UI_EventFlag_Paste)
|
||||
{
|
||||
range = txt_rng(cursor, mark);
|
||||
range = r1u64(cursor, mark);
|
||||
replace = wm_get_clipboard_text(arena);
|
||||
next_cursor = next_mark = txt_pt(cursor.line, cursor.column+replace.size);
|
||||
next_cursor = next_mark = cursor + replace.size;
|
||||
}
|
||||
|
||||
//- rjf: deletion
|
||||
if(event->flags & UI_EventFlag_Delete)
|
||||
{
|
||||
TxtPt new_pos = txt_pt_min(next_cursor, next_mark);
|
||||
range = txt_rng(next_cursor, next_mark);
|
||||
replace = str8_lit("");
|
||||
U64 new_pos = Min(next_cursor, next_mark);
|
||||
range = r1u64(next_cursor, next_mark);
|
||||
replace = s("");
|
||||
next_cursor = next_mark = new_pos;
|
||||
}
|
||||
|
||||
@@ -255,19 +248,19 @@ ui_single_line_txt_op_from_event(Arena *arena, UI_Event *event, String8 string,
|
||||
//- rjf: insertion
|
||||
if(event->string.size != 0)
|
||||
{
|
||||
range = txt_rng(cursor, mark);
|
||||
replace = push_str8_copy(arena, event->string);
|
||||
next_cursor = next_mark = txt_pt(range.min.line, range.min.column + event->string.size);
|
||||
range = r1u64(cursor, mark);
|
||||
replace = str8_copy(arena, event->string);
|
||||
next_cursor = next_mark = range.min + event->string.size;
|
||||
}
|
||||
|
||||
//- rjf: determine if this event should be taken, based on bounds of cursor
|
||||
{
|
||||
if(next_cursor.column > string.size+replace.size+1 || 1 > next_cursor.column || event->delta_2s32.y != 0)
|
||||
if(next_cursor > string.size+replace.size || event->delta_2s32.y != 0)
|
||||
{
|
||||
flags |= UI_TxtOpFlag_Invalid;
|
||||
}
|
||||
next_cursor.column = Clamp(1, next_cursor.column, string.size+replace.size+1);
|
||||
next_mark.column = Clamp(1, next_mark.column, string.size+replace.size+1);
|
||||
next_cursor = Clamp(0, next_cursor, string.size+replace.size);
|
||||
next_mark = Clamp(0, next_mark, string.size+replace.size);
|
||||
}
|
||||
|
||||
//- rjf: build+fill
|
||||
@@ -284,15 +277,8 @@ ui_single_line_txt_op_from_event(Arena *arena, UI_Event *event, String8 string,
|
||||
}
|
||||
|
||||
internal String8
|
||||
ui_push_string_replace_range(Arena *arena, String8 string, Rng1S64 col_range, String8 replace)
|
||||
ui_push_string_replace_range(Arena *arena, String8 string, Rng1U64 range, String8 replace)
|
||||
{
|
||||
//- rjf: convert to offset range
|
||||
Rng1U64 range =
|
||||
{
|
||||
(U64)(col_range.min-1),
|
||||
(U64)(col_range.max-1),
|
||||
};
|
||||
|
||||
//- rjf: clamp range
|
||||
if(range.min > string.size)
|
||||
{
|
||||
|
||||
+5
-5
@@ -184,9 +184,9 @@ struct UI_TxtOp
|
||||
UI_TxtOpFlags flags;
|
||||
String8 replace;
|
||||
String8 copy;
|
||||
TxtRng range;
|
||||
TxtPt cursor;
|
||||
TxtPt mark;
|
||||
Rng1U64 range;
|
||||
U64 cursor;
|
||||
U64 mark;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
@@ -776,8 +776,8 @@ internal void ui_eat_event_node(UI_EventList *list, UI_EventNode *node);
|
||||
|
||||
internal B32 ui_char_is_scan_boundary(U8 c);
|
||||
internal S64 ui_scanned_column_from_column(String8 string, S64 start_column, Side side);
|
||||
internal UI_TxtOp ui_single_line_txt_op_from_event(Arena *arena, UI_Event *event, String8 string, TxtPt cursor, TxtPt mark);
|
||||
internal String8 ui_push_string_replace_range(Arena *arena, String8 string, Rng1S64 range, String8 replace);
|
||||
internal UI_TxtOp ui_single_line_txt_op_from_event(Arena *arena, UI_Event *event, String8 string, U64 cursor, U64 mark);
|
||||
internal String8 ui_push_string_replace_range(Arena *arena, String8 string, Rng1U64 range, String8 replace);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Size Type Functions
|
||||
|
||||
Reference in new issue
Block a user