clay recognize text size
This commit is contained in:
@@ -41,6 +41,8 @@ var clay_base = {
|
||||
size:null,
|
||||
background_color: null,
|
||||
clipped: false,
|
||||
text_break: 'word',
|
||||
text_align: 'left',
|
||||
};
|
||||
|
||||
var root_item;
|
||||
@@ -221,9 +223,10 @@ clay.text = function text(str, ...configs)
|
||||
var config = rectify_configs(configs);
|
||||
config.size ??= [0,0];
|
||||
config.font = graphics.get_font(config.font)
|
||||
var tsize = config.font.text_size(config.font, str, 0, config.size.x);
|
||||
var tsize = config.font.text_size(str, 0, config.size.x, config.text_break, config.text_align);
|
||||
tsize.x = Math.ceil(tsize.x)
|
||||
tsize.y = Math.ceil(tsize.y)
|
||||
log.console(json.encode(tsize))
|
||||
config.size = config.size.map((x,i) => Math.max(x, tsize[i]));
|
||||
config.text = str;
|
||||
add_item(config);
|
||||
@@ -245,7 +248,7 @@ clay.button = function button(str, action, config = {})
|
||||
{
|
||||
config.__proto__ = button_base;
|
||||
config.font = graphics.get_font(config.font)
|
||||
config.size = confit.font.text_size(config.font, str, 0, 0)
|
||||
config.size = config.font.text_size(str, 0, 0, config.text_break, config.text_align)
|
||||
add_item(config);
|
||||
config.text = str;
|
||||
config.action = action;
|
||||
@@ -256,7 +259,7 @@ clay.textbox = function(str, on_change, ...configs) {
|
||||
config.on_change = on_change
|
||||
config.text = str
|
||||
config.font = graphics.get_font(config.font)
|
||||
var tsize = config.font.text_size(config.font, str, 0, 0)
|
||||
var tsize = config.font.text_size(str, 0, 0, config.text_break, config.text_align)
|
||||
config.size ??= [0,0]
|
||||
config.size = [Math.ceil(tsize.x), Math.ceil(tsize.y)]
|
||||
config.size = [Math.max(config.size[0], config.size[0]), Math.max(config.size[1], config.size[1])]
|
||||
|
||||
Reference in New Issue
Block a user