Skip to content

Commit

Permalink
add dropdown choice setting type
Browse files Browse the repository at this point in the history
  • Loading branch information
Bauumm committed Feb 5, 2024
1 parent abcec9e commit 4d09377
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions ui/overlay/settings/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local keyboard_navigation = require("ui.keyboard_navigation")
local transitions = require("ui.anim.transitions")
local quad = require("ui.elements.quad")
local flex = require("ui.layout.flex")
local collapse = require("ui.layout.collapse")
local label = require("ui.elements.label")
local config = require("config")
local scroll = require("ui.layout.scroll")
Expand Down Expand Up @@ -133,6 +134,51 @@ local function create_setting(name, property, value)
gui_setters[name] = function()
layout:init_bindings()
end
elseif property.options and #property.options > 0 then
-- multiple choice dropdown setting
local option_quads = {}
local dropdown
local button_label = label:new(value)
for i = 1, #property.options do
option_quads[i] = quad:new({
child_element = label:new(property.options[i]),
selectable = true,
click_handler = function()
button_label.raw_text = property.options[i]
button_label.changed = true
button_label:update_size()
config.set(name, property.options[i])
onchange()
if property.onchange then
property.onchange(button_label.raw_text)
end
button_label.parent:click()
dropdown:toggle(false)
end,
})
end
dropdown = collapse:new(flex:new(option_quads, { direction = "column" }))
layout = flex:new({
label:new(property.display_name .. ":"),
flex:new({
quad:new({
child_element = button_label,
selectable = true,
click_handler = function()
dropdown:toggle()
end,
}),
dropdown,
}, { direction = "column" }),
}, { align_items = "center" })
gui_setters[name] = function(text)
for i = 1, #property.options do
if property.options[i] == text then
option_quads[i]:click()
return
end
end
end
end
name_layout_map[name] = layout
all_setting_layouts[#all_setting_layouts + 1] = layout
Expand Down

0 comments on commit 4d09377

Please sign in to comment.