From 19f3682093f61f88907ed9a7813172b1abdf7478 Mon Sep 17 00:00:00 2001 From: Tanasart Date: Fri, 3 Jan 2025 10:11:13 +0700 Subject: [PATCH] textvox --- objects/o_dialog_add_node/Create_0.gml | 8 ++++---- objects/o_dialog_add_node/Draw_64.gml | 6 ++---- scripts/textBox/textBox.gml | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/objects/o_dialog_add_node/Create_0.gml b/objects/o_dialog_add_node/Create_0.gml index db5f36c56..edea7a446 100644 --- a/objects/o_dialog_add_node/Create_0.gml +++ b/objects/o_dialog_add_node/Create_0.gml @@ -971,10 +971,10 @@ event_inherited(); search_list = ds_list_create(); KEYBOARD_RESET - tb_search = new textBox(TEXTBOX_INPUT.text, function(str) /*=>*/ { search_string = string(str); searchNodes(); }); - tb_search.align = fa_left; - tb_search.auto_update = true; - WIDGET_CURRENT = tb_search; + tb_search = new textBox(TEXTBOX_INPUT.text, function(str) /*=>*/ { search_string = string(str); searchNodes(); }) + .setAlign(fa_left) + .setAutoupdate(); + WIDGET_CURRENT = tb_search; function searchNodes() { ds_list_clear(search_list); diff --git a/objects/o_dialog_add_node/Draw_64.gml b/objects/o_dialog_add_node/Draw_64.gml index 60a5b984f..5f6ccf560 100644 --- a/objects/o_dialog_add_node/Draw_64.gml +++ b/objects/o_dialog_add_node/Draw_64.gml @@ -1,10 +1,8 @@ /// @description init if !ready exit; -#region base UI - DIALOG_DRAW_BG - if(DIALOG_SHOW_FOCUS) DIALOG_DRAW_FOCUS -#endregion +DIALOG_DRAW_BG +if(DIALOG_SHOW_FOCUS) DIALOG_DRAW_FOCUS #region content WIDGET_CURRENT = tb_search; diff --git a/scripts/textBox/textBox.gml b/scripts/textBox/textBox.gml index e679e40a1..1af8db378 100644 --- a/scripts/textBox/textBox.gml +++ b/scripts/textBox/textBox.gml @@ -127,12 +127,14 @@ function textBox(_input, _onModify) : textInput(_input, _onModify) constructor { return self; } + static setAlign = function(align) { self.align = align; return self; } static setHide = function(hide) { self.hide = hide; return self; } static setFont = function(font) { self.font = font; return self; } static setLabel = function(label) { self.label = label; return self; } static setPrecision = function(precision) { self.precision = precision; return self; } static setPadding = function(padding) { self.padding = padding; return self; } static setEmpty = function() { no_empty = false; return self; } + static setAutoupdate = function() { auto_update = true; return self; } static activate = function(_def_str = _current_text) { WIDGET_CURRENT = self; @@ -176,6 +178,13 @@ function textBox(_input, _onModify) : textInput(_input, _onModify) constructor { cursor_select = -1; move_cursor(-1); + if(key_mod_press(CTRL)) { + while(cursor > 0) { + var ch = string_char_at(_input_text, cursor); + if(breakCharacter(ch)) break; + cursor--; + } + } } if(KEYBOARD_PRESSED == vk_right) { @@ -186,6 +195,13 @@ function textBox(_input, _onModify) : textInput(_input, _onModify) constructor { cursor_select = -1; move_cursor(1); + if(key_mod_press(CTRL)) { + while(cursor < string_length(_input_text)) { + var ch = string_char_at(_input_text, cursor); + if(breakCharacter(ch)) break; + cursor++; + } + } } }