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

View file

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

View file

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

View file

@ -31,6 +31,7 @@ if(textbox != WIDGET_CURRENT) exit;
#region draw #region draw
draw_sprite_stretched(THEME.textbox, 3, dialog_x, dialog_y, dialog_w, dialog_h); 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); sc_content.draw(dialog_x, dialog_y);
draw_sprite_stretched(THEME.textbox, 1, dialog_x, dialog_y, dialog_w, dialog_h); draw_sprite_stretched(THEME.textbox, 1, dialog_x, dialog_y, dialog_w, dialog_h);
#endregion #endregion

View file

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

View file

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

View file

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