[Scrollbox] Fix searching sometime show unmatched objects.

This commit is contained in:
Tanasart 2024-12-27 15:06:50 +07:00
parent 8c0b0c8b30
commit cae78fb658
10 changed files with 45 additions and 40 deletions

View file

@ -36,7 +36,7 @@ event_inherited();
right_free = !mouse_click(mb_right); right_free = !mouse_click(mb_right);
is_global = PANEL_GRAPH.getCurrentContext() == noone; is_global = PANEL_GRAPH.getCurrentContext() == noone;
tooltip_surface = -1; tooltip_surface = -1;
content_hoverable = true; content_hoverable = true;
canvas = false; canvas = false;

View file

@ -20,15 +20,12 @@ event_inherited();
search_string = ""; search_string = "";
KEYBOARD_STRING = ""; KEYBOARD_STRING = "";
tb_search = new textBox(TEXTBOX_INPUT.text, function(str) { tb_search = new textBox(TEXTBOX_INPUT.text, function(s) /*=>*/ { search_string = string(s); filterSearch(); })
search_string = string(str); .setFont(f_p2)
filterSearch(); .setAutoUpdate();
});
tb_search.font = f_p2;
tb_search.color = COLORS._main_text_sub;
tb_search.align = fa_left; tb_search.align = fa_left;
tb_search.auto_update = true; WIDGET_CURRENT = tb_search;
WIDGET_CURRENT = tb_search;
anchor = ANCHOR.top | ANCHOR.left; anchor = ANCHOR.top | ANCHOR.left;
@ -49,9 +46,10 @@ event_inherited();
data = []; data = [];
for( var i = 0, n = array_length(scrollbox.data); i < n; i++ ) { for( var i = 0, n = array_length(scrollbox.data); i < n; i++ ) {
var val = scrollbox.data[i]; var val = scrollbox.data[i];
if(val == -1) continue; if(val == -1) continue;
if(string_pos(string_lower(search_string), string_lower(val)) > 0)
var _txt = is(val, scrollItem)? val.name : val;
if(string_pos(string_lower(search_string), string_lower(_txt)) > 0)
array_push(data, val); array_push(data, val);
} }

View file

@ -22,15 +22,12 @@ event_inherited();
search_string = ""; search_string = "";
KEYBOARD_STRING = ""; KEYBOARD_STRING = "";
tb_search = new textBox(TEXTBOX_INPUT.text, function(str) { tb_search = new textBox(TEXTBOX_INPUT.text, function(s) /*=>*/ { search_string = string(s); filterSearch(); })
search_string = string(str); .setFont(f_p2)
filterSearch(); .setAutoUpdate();
});
tb_search.font = f_p2;
tb_search.color = COLORS._main_text_sub;
tb_search.align = fa_left; tb_search.align = fa_left;
tb_search.auto_update = true; WIDGET_CURRENT = tb_search;
WIDGET_CURRENT = tb_search;
anchor = ANCHOR.top | ANCHOR.left; anchor = ANCHOR.top | ANCHOR.left;
@ -50,9 +47,10 @@ event_inherited();
data = []; data = [];
for( var i = 0, n = array_length(scrollbox.data); i < n; i++ ) { for( var i = 0, n = array_length(scrollbox.data); i < n; i++ ) {
var val = scrollbox.data[i]; var val = scrollbox.data[i];
if(val == -1) continue; if(val == -1) continue;
if(string_pos(string_lower(search_string), string_lower(val)) > 0)
var _txt = is(val, scrollItem)? val.name : val;
if(string_pos(string_lower(search_string), string_lower(_txt)) > 0)
array_push(data, val); array_push(data, val);
} }
@ -61,7 +59,8 @@ event_inherited();
function setSize() { function setSize() {
var _tpad = horizon? text_pad : ui(8); var _hori = horizon && search_string == "";
var _tpad = _hori? text_pad : ui(8);
var hght = line_get_height(font) + item_pad; var hght = line_get_height(font) + item_pad;
var sh = ui(40); var sh = ui(40);
@ -81,7 +80,7 @@ event_inherited();
var txt = is_instanceof(_val, scrollItem)? _val.name : _val; var txt = is_instanceof(_val, scrollItem)? _val.name : _val;
var _spr = is_instanceof(_val, scrollItem) && _val.spr; var _spr = is_instanceof(_val, scrollItem) && _val.spr;
if(horizon) { if(_hori) {
if(_val == -1) { if(_val == -1) {
if(_emp) { if(_emp) {
array_push(widths, 0); array_push(widths, 0);
@ -111,9 +110,10 @@ event_inherited();
ww += lw; ww += lw;
hh = max(hh, lh); hh = max(hh, lh);
if(horizon) { if(_hori) {
dialog_w = max(scrollbox.w, ww) + _tpad * 2; dialog_w = max(scrollbox.w, ww) + _tpad * 2;
dialog_h = min(max_h, sh + hh); dialog_h = min(max_h, sh + hh);
} else { } else {
dialog_w = max(scrollbox.w, lw); dialog_w = max(scrollbox.w, lw);
dialog_h = min(max_h, sh + lh); dialog_h = min(max_h, sh + lh);
@ -135,13 +135,14 @@ event_inherited();
var _h = 0; var _h = 0;
var _col = 0; var _col = 0;
var hovering = ""; var hovering = "";
var _tpad = horizon? text_pad : ui(8); var _hori = horizon && search_string == "";
var _tpad = _hori? text_pad : ui(8);
for( var i = 0, n = array_length(data); i < n; i++ ) { for( var i = 0, n = array_length(data); i < n; i++ ) {
var _dw = horizon? widths[_col] : sc_content.surface_w; var _dw = _hori? widths[_col] : sc_content.surface_w;
var _val = data[i]; var _val = data[i];
if(horizon) { if(_hori) {
if(_val == -1) { if(_val == -1) {
_lx += _dw; _lx += _dw;
_ly = _y; _ly = _y;
@ -218,7 +219,7 @@ event_inherited();
_lh += hght; _lh += hght;
} }
if(!horizon) _h = _lh + ui(8); if(!_hori) _h = _lh + ui(8);
if(update_hover) { if(update_hover) {
UNDO_HOLDING = true; UNDO_HOLDING = true;

View file

@ -2,11 +2,17 @@
#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);
var _tpad = horizon? text_pad : ui(8); var _hori = horizon && search_string == "";
var _tpad = _hori? text_pad : ui(8);
var tbx = dialog_x + ui(8);
var tby = dialog_y + ui(8);
var tbw = dialog_w - ui(16);
if(search_string == "") tbw -= ui(24 + 4);
WIDGET_CURRENT = tb_search; WIDGET_CURRENT = tb_search;
tb_search.setFocusHover(true, true); tb_search.setFocusHover(true, true);
tb_search.draw(dialog_x + ui(8), dialog_y + ui(8), dialog_w - ui(16) - ui(24 + 4), ui(24), search_string); tb_search.draw(tbx, tby, tbw, ui(24), search_string);
tb_search.sprite_index = 0; tb_search.sprite_index = 0;
sc_content.setFocusHover(sFOCUS, sHOVER); sc_content.setFocusHover(sFOCUS, sHOVER);
@ -14,6 +20,7 @@
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);
if(search_string == "")
if(buttonInstant(THEME.button_hide, dialog_x + dialog_w - ui(8) - ui(24), dialog_y + ui(8), ui(24), ui(24), mouse_ui, sHOVER, sFOCUS, "", THEME.scrollbox_direction, horizon) == 2) { if(buttonInstant(THEME.button_hide, dialog_x + dialog_w - ui(8) - ui(24), dialog_y + ui(8), ui(24), ui(24), mouse_ui, sHOVER, sFOCUS, "", THEME.scrollbox_direction, horizon) == 2) {
horizon = !horizon; horizon = !horizon;
setSize(); setSize();

View file

@ -22,9 +22,8 @@ function textInput(_input, _onModify) : widget() constructor {
static onKey = function(key) {} static onKey = function(key) {}
static setAutoUpdate = function() /*=>*/ { auto_update = true; return self; } static setAutoUpdate = function( ) /*=>*/ { auto_update = true; return self; }
static setSideButton = function(b) /*=>*/ { self.side_button = b; return self; }
static setSideButton = function(_button) /*=>*/ { self.side_button = _button; return self; }
static breakCharacter = function(ch) /*=>*/ { return ch == " " || ch == "\n"; } static breakCharacter = function(ch) /*=>*/ { return ch == " " || ch == "\n"; }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 365 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 376 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 365 B

View file

@ -2,10 +2,10 @@
"$GMSprite":"", "$GMSprite":"",
"%Name":"s_node_shape_type", "%Name":"s_node_shape_type",
"bboxMode":0, "bboxMode":0,
"bbox_bottom":23, "bbox_bottom":22,
"bbox_left":0, "bbox_left":1,
"bbox_right":23, "bbox_right":22,
"bbox_top":0, "bbox_top":2,
"collisionKind":1, "collisionKind":1,
"collisionTolerance":0, "collisionTolerance":0,
"DynamicTexturePage":false, "DynamicTexturePage":false,
@ -16,7 +16,7 @@
{"$GMSpriteFrame":"","%Name":"14bfe2b8-bba9-422d-9309-159a2068a2b8","name":"14bfe2b8-bba9-422d-9309-159a2068a2b8","resourceType":"GMSpriteFrame","resourceVersion":"2.0",}, {"$GMSpriteFrame":"","%Name":"14bfe2b8-bba9-422d-9309-159a2068a2b8","name":"14bfe2b8-bba9-422d-9309-159a2068a2b8","resourceType":"GMSpriteFrame","resourceVersion":"2.0",},
{"$GMSpriteFrame":"","%Name":"6d6db666-0f53-414f-8e2e-75217cbcd027","name":"6d6db666-0f53-414f-8e2e-75217cbcd027","resourceType":"GMSpriteFrame","resourceVersion":"2.0",}, {"$GMSpriteFrame":"","%Name":"6d6db666-0f53-414f-8e2e-75217cbcd027","name":"6d6db666-0f53-414f-8e2e-75217cbcd027","resourceType":"GMSpriteFrame","resourceVersion":"2.0",},
{"$GMSpriteFrame":"","%Name":"b1ec2af5-bef8-4227-95ad-3e2460e6e676","name":"b1ec2af5-bef8-4227-95ad-3e2460e6e676","resourceType":"GMSpriteFrame","resourceVersion":"2.0",}, {"$GMSpriteFrame":"","%Name":"b1ec2af5-bef8-4227-95ad-3e2460e6e676","name":"b1ec2af5-bef8-4227-95ad-3e2460e6e676","resourceType":"GMSpriteFrame","resourceVersion":"2.0",},
{"$GMSpriteFrame":"","%Name":"9feaa65f-1a89-49fa-93ac-f242274a9aa9","name":"9feaa65f-1a89-49fa-93ac-f242274a9aa9","resourceType":"GMSpriteFrame","resourceVersion":"2.0",}, {"$GMSpriteFrame":"","%Name":"415ce85e-10e0-4d70-b0dc-5959cdde8622","name":"415ce85e-10e0-4d70-b0dc-5959cdde8622","resourceType":"GMSpriteFrame","resourceVersion":"2.0",},
{"$GMSpriteFrame":"","%Name":"b0761a58-4f3d-4174-8a91-3d14246ac152","name":"b0761a58-4f3d-4174-8a91-3d14246ac152","resourceType":"GMSpriteFrame","resourceVersion":"2.0",}, {"$GMSpriteFrame":"","%Name":"b0761a58-4f3d-4174-8a91-3d14246ac152","name":"b0761a58-4f3d-4174-8a91-3d14246ac152","resourceType":"GMSpriteFrame","resourceVersion":"2.0",},
{"$GMSpriteFrame":"","%Name":"8ea8d1e8-6255-4f98-9112-0092f61f32d0","name":"8ea8d1e8-6255-4f98-9112-0092f61f32d0","resourceType":"GMSpriteFrame","resourceVersion":"2.0",}, {"$GMSpriteFrame":"","%Name":"8ea8d1e8-6255-4f98-9112-0092f61f32d0","name":"8ea8d1e8-6255-4f98-9112-0092f61f32d0","resourceType":"GMSpriteFrame","resourceVersion":"2.0",},
{"$GMSpriteFrame":"","%Name":"9619ab69-4168-4599-a598-8c722310ef03","name":"9619ab69-4168-4599-a598-8c722310ef03","resourceType":"GMSpriteFrame","resourceVersion":"2.0",}, {"$GMSpriteFrame":"","%Name":"9619ab69-4168-4599-a598-8c722310ef03","name":"9619ab69-4168-4599-a598-8c722310ef03","resourceType":"GMSpriteFrame","resourceVersion":"2.0",},
@ -102,8 +102,8 @@
"0":{"$SpriteFrameKeyframe":"","Id":{"name":"b1ec2af5-bef8-4227-95ad-3e2460e6e676","path":"sprites/s_node_shape_type/s_node_shape_type.yy",},"resourceType":"SpriteFrameKeyframe","resourceVersion":"2.0",}, "0":{"$SpriteFrameKeyframe":"","Id":{"name":"b1ec2af5-bef8-4227-95ad-3e2460e6e676","path":"sprites/s_node_shape_type/s_node_shape_type.yy",},"resourceType":"SpriteFrameKeyframe","resourceVersion":"2.0",},
},"Disabled":false,"id":"06a0723a-12ad-4b68-be76-0f7211427afe","IsCreationKey":false,"Key":3.0,"Length":1.0,"resourceType":"Keyframe<SpriteFrameKeyframe>","resourceVersion":"2.0","Stretch":false,}, },"Disabled":false,"id":"06a0723a-12ad-4b68-be76-0f7211427afe","IsCreationKey":false,"Key":3.0,"Length":1.0,"resourceType":"Keyframe<SpriteFrameKeyframe>","resourceVersion":"2.0","Stretch":false,},
{"$Keyframe<SpriteFrameKeyframe>":"","Channels":{ {"$Keyframe<SpriteFrameKeyframe>":"","Channels":{
"0":{"$SpriteFrameKeyframe":"","Id":{"name":"9feaa65f-1a89-49fa-93ac-f242274a9aa9","path":"sprites/s_node_shape_type/s_node_shape_type.yy",},"resourceType":"SpriteFrameKeyframe","resourceVersion":"2.0",}, "0":{"$SpriteFrameKeyframe":"","Id":{"name":"415ce85e-10e0-4d70-b0dc-5959cdde8622","path":"sprites/s_node_shape_type/s_node_shape_type.yy",},"resourceType":"SpriteFrameKeyframe","resourceVersion":"2.0",},
},"Disabled":false,"id":"3b00f31e-441e-4f88-9a03-4cbfeeb7fd09","IsCreationKey":false,"Key":4.0,"Length":1.0,"resourceType":"Keyframe<SpriteFrameKeyframe>","resourceVersion":"2.0","Stretch":false,}, },"Disabled":false,"id":"acdfd6d0-fabe-43d0-8da5-c6abfc1c728d","IsCreationKey":false,"Key":4.0,"Length":1.0,"resourceType":"Keyframe<SpriteFrameKeyframe>","resourceVersion":"2.0","Stretch":false,},
{"$Keyframe<SpriteFrameKeyframe>":"","Channels":{ {"$Keyframe<SpriteFrameKeyframe>":"","Channels":{
"0":{"$SpriteFrameKeyframe":"","Id":{"name":"b0761a58-4f3d-4174-8a91-3d14246ac152","path":"sprites/s_node_shape_type/s_node_shape_type.yy",},"resourceType":"SpriteFrameKeyframe","resourceVersion":"2.0",}, "0":{"$SpriteFrameKeyframe":"","Id":{"name":"b0761a58-4f3d-4174-8a91-3d14246ac152","path":"sprites/s_node_shape_type/s_node_shape_type.yy",},"resourceType":"SpriteFrameKeyframe","resourceVersion":"2.0",},
},"Disabled":false,"id":"3a442dac-3cd2-4edb-ad51-c2c739494466","IsCreationKey":false,"Key":5.0,"Length":1.0,"resourceType":"Keyframe<SpriteFrameKeyframe>","resourceVersion":"2.0","Stretch":false,}, },"Disabled":false,"id":"3a442dac-3cd2-4edb-ad51-c2c739494466","IsCreationKey":false,"Key":5.0,"Length":1.0,"resourceType":"Keyframe<SpriteFrameKeyframe>","resourceVersion":"2.0","Stretch":false,},