- Add horizontal view for larger scrollbox.

This commit is contained in:
Tanasart 2024-07-15 16:44:07 +07:00
parent e51e4a8054
commit b36013dc57
8 changed files with 105 additions and 79 deletions

Binary file not shown.

View file

@ -4,6 +4,7 @@ event_inherited();
#region
max_h = 640;
horizon = true;
font = f_p0
align = fa_center;
text_pad = ui(8);
@ -63,7 +64,7 @@ event_inherited();
var hght = line_get_height(font) + item_pad;
var sh = ui(40);
var ww = 0;
var ww = 0, tw;
var hh = 0;
var lw = 0;
@ -75,32 +76,45 @@ event_inherited();
draw_set_text(font, fa_left, fa_top);
for( var i = 0, n = array_length(data); i < n; i++ ) {
var _dat = data[i];
var txt = is_instanceof(_dat, scrollItem)? _dat.name : _dat;
var _val = data[i];
var txt = is_instanceof(_val, scrollItem)? _val.name : _val;
var _spr = is_instanceof(_val, scrollItem) && _val.spr;
if(_dat == -1 || i == n - 1) {
if(_emp) {
array_push(widths, 0);
} else {
array_push(widths, lw);
ww += lw;
hh = max(hh, lh);
if(horizon) {
if(_val == -1 || i == n - 1) {
if(_emp) {
array_push(widths, 0);
} else {
array_push(widths, lw);
ww += lw;
hh = max(hh, lh);
}
lw = 0;
lh = item_pad;
continue;
}
lw = 0;
lh = item_pad;
} else if(_val == -1) {
lh += ui(8);
continue;
}
_emp = false;
lw = max(lw, string_width(txt) + text_pad * 2);
tw = string_width(txt) + _spr * (hght + text_pad * 2);
lw = max(lw, tw + text_pad * 2);
lh += hght;
}
dialog_w = max(scrollbox.w, ww);
dialog_h = min(max_h, sh + hh);
if(horizon) {
dialog_w = max(scrollbox.w, ww) + text_pad * 2;
dialog_h = min(max_h, sh + hh);
} else {
dialog_w = max(scrollbox.w, lw);
dialog_h = min(max_h, sh + lh);
}
sc_content.resize(dialog_w, dialog_h - ui(40));
sc_content.resize(dialog_w - text_pad * 2, dialog_h - ui(40));
resetPosition();
}
@ -117,23 +131,32 @@ event_inherited();
var _col = 0;
for( var i = 0, n = array_length(data); i < n; i++ ) {
var _dw = widths[_col];
var _dw = horizon? widths[_col] : sc_content.surface_w;
var _val = data[i];
if(data[i] == -1 || i == n -1) {
_lx += _dw;
_ly = _y;
_col++;
if(horizon) {
if(_val == -1 || i == n -1) {
_lx += _dw;
_ly = _y;
_col++;
_h = max(_h, _lh);
_lh = 0;
_lw = 0;
_h = max(_h, _lh);
_lh = 0;
_lw = 0;
continue;
}
if(_dw == 0) continue;
} else if(_val == -1) {
draw_sprite_stretched(THEME.menu_separator, 0, ui(8), _ly, _dw - ui(16), ui(6));
_ly += ui(8);
_h += ui(8);
continue;
}
if(_dw == 0) continue;
var txt = is_instanceof(_val, scrollItem)? _val.name : _val;
var _spr = is_instanceof(_val, scrollItem) && _val.spr;
var _tol = is_instanceof(_val, scrollItem) && _val.tooltip != "";
@ -142,8 +165,11 @@ event_inherited();
var subitem = string_starts_with(txt, ">");
txt = string_trim_start(txt, ["-", ">", " "]);
var _hov = false;
if(clickable) {
if(sc_content.hover && point_in_rectangle(_m[0], _m[1], _lx, _ly, _lx + _dw, _ly + hght - 1)) {
_hov = true;
selecting = i;
hovering = data[i];
@ -153,20 +179,22 @@ event_inherited();
if(selecting == i) {
draw_sprite_stretched_ext(THEME.textbox, 3, _lx, _ly, _dw, hght, COLORS.dialog_menubox_highlight, 1);
if(sc_content.active && (mouse_press(mb_left) || keyboard_check_pressed(vk_enter))) {
if(sc_content.active && (mouse_press(mb_left, _hov) || keyboard_check_pressed(vk_enter))) {
initVal = array_find(scrollbox.data, _val);
instance_destroy();
}
}
}
align = fa_left;
draw_set_text(font, align, fa_center, subitem? COLORS._main_text_sub : COLORS._main_text);
if(align == fa_center) {
var _xc = _spr? hght + (_dw - hght) / 2 : _dw / 2;
draw_text_add(_lx + _xc, _ly + hght / 2, txt);
} else if(align == fa_left)
draw_text_add(_lx + text_pad + _spr * hght, _ly + hght / 2, txt);
draw_text_add(text_pad + _lx + _spr * (text_pad * 2 + hght), _ly + hght / 2, txt);
if(_spr) draw_sprite_ext(_val.spr, _val.spr_ind, _lx + ui(8) + hght / 2, _ly + hght / 2, 1, 1, 0, _val.spr_blend, 1);

View file

@ -4,11 +4,16 @@
WIDGET_CURRENT = tb_search;
tb_search.setFocusHover(true, true);
tb_search.draw(dialog_x + ui(8), dialog_y + ui(8), dialog_w - ui(16), ui(24), search_string);
tb_search.draw(dialog_x + ui(8), dialog_y + ui(8), dialog_w - ui(16) - ui(24 + 4), ui(24), search_string);
tb_search.sprite_index = 0;
sc_content.setFocusHover(sFOCUS, sHOVER);
sc_content.draw(dialog_x, dialog_y + ui(40));
sc_content.draw(dialog_x + text_pad, dialog_y + ui(40));
draw_sprite_stretched(THEME.textbox, 1, dialog_x, dialog_y, dialog_w, dialog_h);
if(buttonInstant(THEME.button_hide, dialog_x + dialog_w - ui(8) - ui(24), dialog_y + ui(8), ui(24), ui(24), mouse_ui, sFOCUS, sHOVER, "", THEME.scrollbox_direction, horizon) == 2) {
horizon = !horizon;
setSize();
}
#endregion

View file

@ -2,7 +2,7 @@
if(winMan_isMinimized()) exit;
_MOUSE_BLOCK = MOUSE_BLOCK;
MOUSE_BLOCK = false;
if(MOUSE_BLOCK) MOUSE_BLOCK--;
if(APP_SURF_OVERRIDE) {
APP_SURF = surface_verify(APP_SURF, WIN_W, WIN_H);

View file

@ -2,25 +2,25 @@
"$GMObject":"",
"%Name":"o_main",
"eventList":[
{"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":0,"eventType":0,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":1,"eventType":2,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":0,"eventType":3,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":1,"eventType":3,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":1,"eventType":5,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":2,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":3,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":4,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":20,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":60,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":62,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":68,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":69,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":70,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":75,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":64,"eventType":8,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":75,"eventType":8,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":1,"eventType":9,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":1,"eventType":10,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":0,"eventType":0,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":1,"eventType":2,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":0,"eventType":3,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":1,"eventType":3,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":1,"eventType":5,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":2,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":3,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":4,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":20,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":60,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":62,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":68,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":69,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":70,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":75,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":64,"eventType":8,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":75,"eventType":8,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":1,"eventType":9,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":1,"eventType":10,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
],
"managed":true,
"name":"o_main",

View file

@ -16,15 +16,11 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_RM(_x, _y, _group) con
shape_types_str = [];
var _ind = 0;
for( var i = 0, n = array_length(shape_types); i < n; i++ ) {
if(shape_types[i] == -1)
shape_types_str[i] = -1;
else
shape_types_str[i] = new scrollItem(shape_types[i], s_node_shape_3d, _ind++, COLORS._main_icon_light);
}
for( var i = 0, n = array_length(shape_types); i < n; i++ )
shape_types_str[i] = shape_types[i] == -1? -1 : new scrollItem(shape_types[i], s_node_shape_3d, _ind++, COLORS._main_icon_light);
inputs[| 1] = nodeValue("Shape", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1)
.setDisplay(VALUE_DISPLAY.enum_scroll, shape_types_str);
.setDisplay(VALUE_DISPLAY.enum_scroll, { data: shape_types_str, horizontal: true, text_pad: ui(16) });
inputs[| 2] = nodeValue("Position", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0, 0 ])
.setDisplay(VALUE_DISPLAY.vector);

View file

@ -38,26 +38,23 @@ function Node_Shape(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) con
inputs[| 1] = nodeValue("Background", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
shape_types = [ "Rectangle", "Diamond", "Trapezoid", "Parallelogram",
-1,
"Ellipse", "Arc", "Donut", "Crescent", "Disk Segment", "Pie",
-1,
"Regular polygon", "Star", "Cross", "Rounded Cross",
-1,
"Teardrop", "Leaf", "Heart", "Arrow", "Gear",
];
shape_types = [
"Rectangle", "Diamond", "Trapezoid", "Parallelogram",
-1,
"Ellipse", "Arc", "Donut", "Crescent", "Disk Segment", "Pie",
-1,
"Regular polygon", "Star", "Cross", "Rounded Cross",
-1,
"Teardrop", "Leaf", "Heart", "Arrow", "Gear",
];
shape_types_str = [];
var _ind = 0;
for( var i = 0, n = array_length(shape_types); i < n; i++ ) {
if(shape_types[i] == -1)
shape_types_str[i] = -1;
else
shape_types_str[i] = new scrollItem(shape_types[i], s_node_shape_type, _ind++);
}
for( var i = 0, n = array_length(shape_types); i < n; i++ )
shape_types_str[i] = shape_types[i] == -1? -1 : new scrollItem(shape_types[i], s_node_shape_type, _ind++);
inputs[| 2] = nodeValue("Shape", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
.setDisplay(VALUE_DISPLAY.enum_scroll, shape_types_str);
.setDisplay(VALUE_DISPLAY.enum_scroll, { data: shape_types_str, horizontal: true, text_pad: ui(16) });
inputs[| 3] = nodeValue("Position", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, DEF_AREA_REF)
.setUnitRef(onSurfaceSize, VALUE_UNIT.reference)

View file

@ -694,12 +694,12 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
if(!is_struct(display_data)) display_data = { data: display_data };
var choices = __txt_junction_data(instanceof(node), connect_type, index, display_data.data);
editWidget = new scrollBox(choices, function(val) {
if(val == -1) return;
return setValueInspector(toNumber(val));
} );
if(struct_has(display_data, "update_hover"))
editWidget.update_hover = display_data.update_hover;
editWidget = new scrollBox(choices, function(val) /*=>*/ { if(val == -1) return; return setValueInspector(toNumber(val)); } );
if(struct_has(display_data, "update_hover")) editWidget.update_hover = display_data.update_hover;
if(struct_has(display_data, "horizontal")) editWidget.horizontal = display_data.horizontal;
if(struct_has(display_data, "item_pad")) editWidget.item_pad = display_data.item_pad;
if(struct_has(display_data, "text_pad")) editWidget.text_pad = display_data.text_pad;
rejectConnect();
key_inter = CURVE_TYPE.cut;