Merge pull request #48 from BerkieBb/main

feat(ox_lib/interface/menu): onClose keyPressed
This commit is contained in:
Luke authored and GitHub committed 2022-09-25 15:17:52 +02:00
commit 15863b8508
1 file changed
+9 -3
+9 -3
View File
@@ -46,7 +46,7 @@ lib.registerMenu(data, cb)
* Default: `false` * Default: `false`
* canClose: `boolean` * canClose: `boolean`
* If set to false the user won't be able to exit the menu without pressing one of the buttons. * If set to false the user won't be able to exit the menu without pressing one of the buttons.
* onClose: `function` * onClose: `function`(keyPressed?: `'Escape' | 'Backspace'`)
* Function that runs when the menu is exited via ESC/Backspace. * Function that runs when the menu is exited via ESC/Backspace.
* onSelected: `function`(selected: `number`: scrollIndex: `number`: args: `any`) * onSelected: `function`(selected: `number`: scrollIndex: `number`: args: `any`)
* Function being ran when the selected button in the menu changes. * Function being ran when the selected button in the menu changes.
@@ -190,8 +190,11 @@ lib.registerMenu({
onSelected = function(selected, scrollIndex, args) onSelected = function(selected, scrollIndex, args)
print(selected, scrollIndex, args) print(selected, scrollIndex, args)
end, end,
onClose = function() onClose = function(keyPressed)
print('Menu closed') print('Menu closed')
if keyPressed then
print(('Pressed %s to close the menu'):format(keyPressed))
end
end, end,
options = { options = {
{label = 'Simple button', description = 'It has a description!'}, {label = 'Simple button', description = 'It has a description!'},
@@ -225,8 +228,11 @@ lib.registerMenu({
onSelected: (selected, scrollIndex, args) => { onSelected: (selected, scrollIndex, args) => {
console.log(selected, scrollIndex, args) console.log(selected, scrollIndex, args)
}, },
onClose: () => { onClose: (keyPressed) => {
console.log('Menu closed') console.log('Menu closed')
if (keyPressed) {
console.log(`Pressed ${keyPressed} to close the menu`)
}
}, },
options: [ options: [
{label: 'Simple button', description: 'It has a description!'}, {label: 'Simple button', description: 'It has a description!'},