- [Code editor] Autocomplete now can be apply with enter key and mouse click.

This commit is contained in:
Tanasart 2023-09-29 07:13:17 +07:00
parent 017554d7a1
commit 3e20df73f5
7 changed files with 48 additions and 20 deletions

View file

@ -4,12 +4,13 @@
other.depth = min(depth - 1, other.depth);
ds_list_add(DIALOGS, self);
dialog_w = 320;
dialog_h = 320;
active = true;
dialog_w = 320;
dialog_h = 320;
_dialog_w = 320;
_dialog_h = 320;
dialog_x = 0;
dialog_y = 0;
dialog_x = 0;
dialog_y = 0;
title_height = 64;
padding = 24;
@ -35,6 +36,8 @@
dialog_drag_my = 0;
function doDrag() {
if(!active) return;
mouse_active = true;
if(!draggable) return;
@ -71,6 +74,7 @@
onResize = -1;
function doResize() {
if(!active) return;
if(!dialog_resizable) return;
if(dialog_resizing & 1 << 0 != 0) {
@ -121,6 +125,7 @@
#region focus
function checkFocus() {
if(!active) return;
var x0 = dialog_x - dialog_resizable * 6;
var x1 = dialog_x + dialog_w + dialog_resizable * 6;
var y0 = dialog_y - dialog_resizable * 6;
@ -135,6 +140,7 @@
}
function checkDepth() {
if(!active) return;
if(HOVER != self.id) return;
if(mouse_press(mb_any)) {
@ -145,6 +151,7 @@
}
function resetPosition() {
if(!active) return;
if(anchor == ANCHOR.none) {
dialog_x = xstart - dialog_w / 2;
dialog_y = ystart - dialog_h / 2;
@ -160,6 +167,7 @@
}
function checkMouse() {
if(!active) return;
if(!DIALOG_CLICK) {
//printIf(mouse_press(mb_any), $"Check {object_get_name(object_index)} : Click");
return;

View file

@ -1,5 +1,6 @@
/// @description init
if !ready exit;
if !ready exit;
if !active exit;
#region window control
if(sFOCUS) {

View file

@ -1,4 +1,6 @@
/// @description
event_inherited();
#region data
depth = -9999;
@ -13,6 +15,9 @@
prompt = "";
data = [];
destroy_on_escape = false;
destroy_on_click_out = false;
sc_content = new scrollPane(dialog_w, dialog_h, function(_y, _m) {
draw_clear_alpha(COLORS.panel_bg_clear, 0);
var hght = line_get_height(f_p0, 8);
@ -23,19 +28,19 @@
for(var i = 0; i < array_length(data); i++) {
var _dat = data[i];
//if(point_in_rectangle(_m[0], _m[1], 0, _ly + 1, _dw, _ly + hght - 1)) {
// selecting = i;
if(sHOVER && point_in_rectangle(_m[0], _m[1], 0, _ly + 1, _dw, _ly + hght - 1)) {
selecting = i;
// if(mouse_press(mb_left))
// applyAutoComplete(_dat[3]);
//}
if(mouse_press(mb_left))
applyAutoComplete(_dat[3]);
}
if(selecting == i) {
WIDGET_TAB_BLOCK = true;
draw_sprite_stretched_ext(THEME.textbox, 3, 0, _ly, _dw, hght, COLORS.dialog_menubox_highlight, 1);
if(keyboard_check_pressed(vk_tab))
if(keyboard_check_pressed(vk_tab) || keyboard_check_pressed(vk_enter))
applyAutoComplete(_dat[3]);
}

View file

@ -31,6 +31,7 @@ if(textbox != WIDGET_CURRENT) exit;
#region draw
draw_sprite_stretched(THEME.textbox, 3, dialog_x, dialog_y, dialog_w, dialog_h);
sc_content.setFocusHover(sFOCUS, sHOVER);
sc_content.draw(dialog_x, dialog_y);
draw_sprite_stretched(THEME.textbox, 1, dialog_x, dialog_y, dialog_w, dialog_h);
#endregion

View file

@ -12,7 +12,10 @@
"name": "widget",
"path": "folders/dialog/widget.yy",
},
"parentObjectId": null,
"parentObjectId": {
"name": "_p_dialog",
"path": "objects/_p_dialog/_p_dialog.yy",
},
"persistent": false,
"physicsAngularDamping": 0.1,
"physicsDensity": 0.5,

View file

@ -1,3 +1,5 @@
// feather ignore all
#region setup
function __addon_lua_setup(lua, context) {
__addon_lua_setup_functions(lua);

View file

@ -161,6 +161,16 @@ function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onMod
return ch == " " || ch == "\n";
} #endregion
static keyboardEnter = function() { #region
if(!keyboard_check_pressed(vk_enter))
return 0;
if(use_autocomplete && autocomplete_box.active)
return 0;
return 1 + ((shift_new_line && key_mod_press(SHIFT)) || (!shift_new_line && !key_mod_press(SHIFT)));
} #endregion
static onKey = function(key) { #region
if(key == vk_left) {
if(key_mod_press(SHIFT)) {
@ -367,8 +377,7 @@ function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onMod
if(keyboard_check_pressed(vk_escape)) {
} else if(keyboard_check_pressed(vk_tab)) {
} else if(( shift_new_line && keyboard_check_pressed(vk_enter) && key_mod_press(SHIFT)) ||
(!shift_new_line && keyboard_check_pressed(vk_enter) && !key_mod_press(SHIFT))) {
} else if(keyboardEnter() == 2) {
var ch = "\n";
if(cursor_select == -1) {
var str_before = string_copy(_input_text, 1, cursor);
@ -521,8 +530,7 @@ function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onMod
_input_text = _last_value;
cut_line();
deactivate();
} else if(( shift_new_line && keyboard_check_pressed(vk_enter) && !key_mod_press(SHIFT)) ||
(!shift_new_line && keyboard_check_pressed(vk_enter) && key_mod_press(SHIFT))) {
} else if(keyboardEnter() == 1) {
deactivate();
}
} #endregion
@ -628,14 +636,14 @@ function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onMod
}
}
if(target != -999) {
if(mouse_press(mb_left, active) || click_block == 1) {
if(target != -999 && mouse_press(mb_left, active) && HOVER != autocomplete_box.id) {
if(click_block == 1) {
cursor = target;
cursor_select = -1;
click_block = 0;
autocomplete_box.active = false;
} else if(mouse_click(mb_left, active) && cursor != target) {
} else if(cursor != target) {
if(cursor_select == -1)
cursor_select = cursor;
cursor = target;
@ -798,7 +806,7 @@ function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onMod
}
#endregion
if(!point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + hh) && mouse_press(mb_left)) {
if(!point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + hh) && mouse_press(mb_left) && HOVER != autocomplete_box.id) {
deactivate();
}
} else {