Fix some node draw string extremely small.

This commit is contained in:
Tanasart 2023-03-24 16:12:44 +07:00
parent 99315c5872
commit a7d56baffa
10 changed files with 48 additions and 50 deletions

View file

@ -21,3 +21,10 @@ function draw_text_ext_add(_x, _y, _text, _sep, _w) {
draw_text_ext(_x, _y, _text, _sep, _w); draw_text_ext(_x, _y, _text, _sep, _w);
BLEND_NORMAL; BLEND_NORMAL;
} }
function draw_text_bbox(bbox, text) {
var ss = min(bbox.w / string_width(text), bbox.h / string_height(text));
ss = max(0.5, ss);
draw_text_cut(bbox.xc, bbox.yc, text, bbox.w, ss);
}

View file

@ -401,14 +401,14 @@ function Node(_x, _y, _group = PANEL_GRAPH.getCurrentContext()) : __Node_Base(_x
var y0 = yy + 20 * draw_name + draw_padding * _s; var y0 = yy + 20 * draw_name + draw_padding * _s;
var y1 = yy + (h - draw_padding) * _s; var y1 = yy + (h - draw_padding) * _s;
return { x0: x0, return { x0 : x0,
x1 : x1, x1 : x1,
y0: y0, y0 : y0,
y1 : y1, y1 : y1,
xc: (x0 + x1) / 2, xc : (x0 + x1) / 2,
yc: (y0 + y1) / 2, yc : (y0 + y1) / 2,
w: x1 - x0, w : x1 - x0,
h: y1 - y0 h : y1 - y0
}; };
} }

View file

@ -12,10 +12,10 @@ function Node_String(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) co
} }
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text); var str = inputs[| 0].getValue();
var str = inputs[| 0].getValue();
var bbox = drawGetBbox(xx, yy, _s); var bbox = drawGetBbox(xx, yy, _s);
var ss = string_scale(str, bbox.w, bbox.h);
draw_text_transformed(bbox.xc, bbox.yc, str, ss, ss, 0); draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text);
draw_text_bbox(bbox, str);
} }
} }

View file

@ -17,10 +17,10 @@ function Node_String_Get_Char(_x, _y, _group = noone) : Node_Processor(_x, _y, _
} }
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text);
var str = inputs[| 0].getValue(); var str = inputs[| 0].getValue();
var bbox = drawGetBbox(xx, yy, _s); var bbox = drawGetBbox(xx, yy, _s);
var ss = string_scale(str, bbox.w, bbox.h);
draw_text_transformed(bbox.xc, bbox.yc, str, ss, ss, 0); draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text);
draw_text_bbox(bbox, str);
} }
} }

View file

@ -25,10 +25,10 @@ function Node_String_Join(_x, _y, _group = noone) : Node(_x, _y, _group) constru
} }
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text);
var str = outputs[| 0].getValue(); var str = outputs[| 0].getValue();
var bbox = drawGetBbox(xx, yy, _s); var bbox = drawGetBbox(xx, yy, _s);
var ss = string_scale(str, bbox.w, bbox.h);
draw_text_transformed(bbox.xc, bbox.yc, str, ss, ss, 0); draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text);
draw_text_bbox(bbox, str);
} }
} }

View file

@ -20,10 +20,10 @@ function Node_String_Length(_x, _y, _group = noone) : Node_Processor(_x, _y, _gr
} }
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text);
var str = outputs[| 0].getValue(); var str = outputs[| 0].getValue();
var bbox = drawGetBbox(xx, yy, _s); var bbox = drawGetBbox(xx, yy, _s);
var ss = string_scale(str, bbox.w, bbox.h);
draw_text_transformed(bbox.xc, bbox.yc, str, ss, ss, 0); draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text);
draw_text_bbox(bbox, str);
} }
} }

View file

@ -15,10 +15,10 @@ function Node_String_Merge(_x, _y, _group = noone) : Node_Processor(_x, _y, _gro
} }
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text);
var str = inputs[| 0].getValue(); var str = inputs[| 0].getValue();
var bbox = drawGetBbox(xx, yy, _s); var bbox = drawGetBbox(xx, yy, _s);
var ss = string_scale(str, bbox.w, bbox.h);
draw_text_transformed(bbox.xc, bbox.yc, str, ss, ss, 0); draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text);
draw_text_bbox(bbox, str);
} }
} }

View file

@ -27,13 +27,9 @@ function Node_String_Regex_Search(_x, _y, _group = noone) : Node_Processor(_x, _
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
var str = outputs[| 0].getValue(); var str = outputs[| 0].getValue();
var bbox = drawGetBbox(xx, yy, _s);
if(is_array(str) && array_length(str))
str = str[0];
draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text); draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text);
var bbox = drawGetBbox(xx, yy, _s); draw_text_bbox(bbox, str);
var ss = string_scale(str, bbox.w, bbox.h);
draw_text_transformed(bbox.xc, bbox.yc, str, ss, ss, 0);
} }
} }

View file

@ -69,15 +69,9 @@ function Node_String_Trim(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
var str = outputs[| 0].getValue(); var str = outputs[| 0].getValue();
var hed = inputs[| 1].getValue(); var bbox = drawGetBbox(xx, yy, _s);
var tal = inputs[| 2].getValue();
if(is_array(str) && array_length(str))
str = str[0];
draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text); draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text);
var bbox = drawGetBbox(xx, yy, _s); draw_text_bbox(bbox, str);
var ss = string_scale(str, bbox.w, bbox.h);
draw_text_transformed(bbox.xc, bbox.yc, str, ss, ss, 0);
} }
} }

View file

@ -3,25 +3,26 @@ function draw_text_cut(x, y, str, w, scale = 1) {
} }
function string_cut(str, w, tail = "...", scale = 1) { function string_cut(str, w, tail = "...", scale = 1) {
var ww = 0; var ww = 0;
var ind = 1; var ind = 1;
var ss = ""; var ss = "";
var tw = string_width(tail); var _str = str;
var tw = string_width(tail) * scale;
if(string_width(str) <= w) return str; if(string_width(str) <= w) return str;
while(ind <= string_length(str)) { var amo = string_length(str);
var ch = string_char_at(str, ind); for( var i = 1; i <= amo; i++ ) {
var _w = string_width(ch) * scale; var ch = string_char_at(str, 1);
str = string_copy(str, 2, string_length(str) - 1);
if(ww + _w + tw >= w) {
ss += tail;
break;
} else
ss += ch;
var _w = string_width(ch) * scale;
ww += _w; ww += _w;
ind++; var _tl = string_width(str) * scale;
if(ww + tw > w)
return ww + _tl <= w? _str : ss + tail;
ss += ch;
} }
return ss; return ss;