-
Notifications
You must be signed in to change notification settings - Fork 7
Variable
Refaltor77 edited this page Mar 29, 2026
·
1 revision
Conditional variable system for platform-specific and state-dependent layouts.
use refaltor\ui\components\Variable;$var = Variable::create("$is_using_gamepad")
->set('$action_text', "Press A")
->set('$btn_size', [200, 40]);$var = Variable::when("$pocket_screen", [
'$panel_width' => 200,
'$panel_height' => 150,
]);$var->requires("$condition"); // Set condition
$var->set('$name', $value); // Set single variable
$var->setValues(['$a' => 1, '$b' => 2]); // Set multiple$panel->addVariable($variable);
$panel->addVariables([$var1, $var2, $var3]);| Variable | True when |
|---|---|
$is_using_gamepad |
Gamepad connected |
$touch |
Touch input |
$pocket_screen |
Small screen (phone) |
$desktop_screen |
Desktop screen |
$is_holographic |
HoloLens / VR |
$trial_screen |
Trial/demo mode |
$is_pregame |
In menus (not in world) |
$is_living_room_mode |
Console living room |
$is_secondary_client |
Split screen guest |
$win10_edition |
Windows 10 |
$education_edition |
Education Edition |
$panel = Panel::create("adaptive_panel")
->setCustomSize(['$panel_w', '$panel_h'])
->addVariable(
Variable::when('$pocket_screen', [
'$panel_w' => 200,
'$panel_h' => 150,
'$font' => Label::FONT_SMALL,
])
)
->addVariable(
Variable::when('$desktop_screen', [
'$panel_w' => 400,
'$panel_h' => 300,
'$font' => Label::FONT_LARGE,
])
)
->addVariable(
Variable::when('$is_holographic', [
'$panel_w' => 500,
'$panel_h' => 400,
'$font' => Label::FONT_EXTRA_LARGE,
])
);$panel = Panel::create("input_hint")
->setSize(280, 40)
->addVariable(Variable::when('$is_using_gamepad', ['$hint' => "Press A"]))
->addVariable(Variable::when('$touch', ['$hint' => "Tap here"]))
->addVariable(Variable::when('(not $is_using_gamepad and not $touch)', ['$hint' => "Click here"]));
$panel->addChild(
Label::create("hint_label", '$hint')
->setShadow()
->setAnchorFrom(Element::ANCHOR_CENTER)
->setAnchorTo(Element::ANCHOR_CENTER)
);