Files
0ad/binaries/data/mods/mod/gui/common/utilities.js
T
phosit 36b9fd7b42 Return a promise from setButtonCaptionsAndVisibility
Now It's not hardcoded what is done if a button is pressed. The caller
can decide that.
Previously one had to call this function and then overwrite the on Press
attribute of each button.

Rename "Visibitily" to "Visibility" in setButtonCaptionsAndVisibility.
2024-10-17 20:47:54 +02:00

35 lines
876 B
JavaScript

function distributeButtonsHorizontally(button, captions)
{
const y1 = "100%-46";
const y2 = "100%-18";
switch (captions.length)
{
case 1:
button[0].size = "18 " + y1 + " 100%-18 " + y2;
break;
case 2:
button[0].size = "18 " + y1 + " 50%-5 " + y2;
button[1].size = "50%+5 " + y1 + " 100%-18 " + y2;
break;
case 3:
button[0].size = "18 " + y1 + " 33%-5 " + y2;
button[1].size = "33%+5 " + y1 + " 66%-5 " + y2;
button[2].size = "66%+5 " + y1 + " 100%-18 " + y2;
break;
}
}
function setButtonCaptionsAndVisibility(buttons, captions, cancelHotkey, name)
{
return new Promise(resolve => {
captions.forEach((caption, i) => {
buttons[i] = Engine.GetGUIObjectByName(name + (i + 1));
buttons[i].caption = caption;
buttons[i].hidden = false;
buttons[i].onPress = resolve.bind(null, i);
});
cancelHotkey.onPress = buttons[0].onPress;
});
}