clay id handling
This commit is contained in:
@@ -45,6 +45,7 @@ var root_item;
|
||||
var root_config;
|
||||
var boxes = [];
|
||||
var clay = {}
|
||||
var focused_textbox = null
|
||||
|
||||
clay.behave = layout.behave;
|
||||
clay.contain = layout.contain;
|
||||
@@ -244,36 +245,48 @@ clay.button = function button(str, action, config = {})
|
||||
config.action = action;
|
||||
}
|
||||
|
||||
clay.textbox = function(str, on_change, ...configs) {
|
||||
var config = rectify_configs(configs)
|
||||
config.on_change = on_change
|
||||
config.text = str
|
||||
config.font = graphics.get_font(config.font)
|
||||
var tsize = graphics.font_text_size(config.font, str, 0, 0)
|
||||
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])]
|
||||
add_item(config)
|
||||
}
|
||||
|
||||
var point = use('point')
|
||||
|
||||
// mousepos given in hud coordinates
|
||||
clay.draw_commands = function draw_commands(cmds, pos = {x:0, y:0}, mousepos = {x:0,y:0})
|
||||
clay.draw_commands = function draw_commands(cmds, pos = {x:0,y:0}, mousepos = {x:0,y:0})
|
||||
{
|
||||
cmds.hovered = null
|
||||
|
||||
for (var cmd of cmds) {
|
||||
var config = cmd.config;
|
||||
var boundingbox = geometry.rect_move(cmd.boundingbox,point.add(pos,config.offset));
|
||||
var content = geometry.rect_move(cmd.content,point.add(pos, config.offset));
|
||||
|
||||
if (config.hovered && geometry.rect_point_inside(boundingbox, mousepos)) {
|
||||
config.hovered.__proto__ = config;
|
||||
config = config.hovered;
|
||||
cmds.hovered = config;
|
||||
}
|
||||
var config = cmd.config
|
||||
var boundingbox = geometry.rect_move(cmd.boundingbox,point.add(pos,config.offset))
|
||||
var content = geometry.rect_move(cmd.content,point.add(pos, config.offset))
|
||||
if (config.hovered && geometry.rect_point_inside(boundingbox, mousepos))
|
||||
{
|
||||
config.hovered.__proto__ = config
|
||||
config = config.hovered
|
||||
cmds.hovered = cmd
|
||||
}
|
||||
|
||||
if (config.background_image)
|
||||
if (config.slice)
|
||||
draw.slice9(config.background_image, boundingbox, config.slice, config.background_color);
|
||||
draw.slice9(config.background_image, boundingbox, config.slice, config.background_color)
|
||||
else
|
||||
draw.image(config.background_image, boundingbox, 0, config.color);
|
||||
draw.image(config.background_image, boundingbox, 0, config.color)
|
||||
else if (config.background_color)
|
||||
draw.rectangle(boundingbox, config.background_color);
|
||||
draw.rectangle(boundingbox, config.background_color)
|
||||
|
||||
if (config.text)
|
||||
draw.text(config.text, content, config.font, config.color, config.size.width);
|
||||
draw.text(config.text, content, config.font, config.color, config.size.width)
|
||||
if (config.image)
|
||||
draw.image(config.image, content, 0, config.color);
|
||||
draw.image(config.image, content, 0, config.color)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user