UIElement:focused_element

Returns a focused element within this one (including itself). Only elements which can receive input are eligible.

This method does not incur a tree traversal.

Usage

ui_element:focused_element(player_index)

Arguments

Name Type Description
player_index number Player whose focus is being considered.

Returns

Name Type Description
element UIElement | nil Focused descendent which can receive input.

Examples

local menu = crystal.HorizontalList:new();

local buy_items = menu:add_child(crystal.VerticalList:new());
local sword = buy_items:add_child(crystal.Image:new(crystal.assets.get("sword.png")));
local shield = buy_items:add_child(crystal.Image:new(crystal.assets.get("shield.png")));

local sell_items = menu:add_child(crystal.VerticalList:new());
local helmet = sell_items:add_child(crystal.Image:new(crystal.assets.get("helmet.png")));
local armor = sell_items:add_child(crystal.Image:new(crystal.assets.get("armor.png")));

sword:set_focusable(true);
shield:set_focusable(true);
helmet:set_focusable(true);
armor:set_focusable(true);

menu:focus_tree(1);
assert(menu:focused_element(1) == sword);

This site uses Just the Docs, a documentation theme for Jekyll.