Skip to content

Commit

Permalink
Drop LibDropDown for 11.x built-in system
Browse files Browse the repository at this point in the history
It's a drop-in system for simple dropdowns, but any entry types other
than checkboxes and radio buttons are not supported by the simple menu.

A complex menu can be made using the generator callback.
  • Loading branch information
p3lim committed Jul 7, 2024
1 parent 1a0bfb8 commit 11ebcaa
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 32 deletions.
21 changes: 18 additions & 3 deletions LibEditMode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,15 @@ Depending on the setting type there are additional required and optional entries
### Dropdown
| key | value | type | required |
|:--------|:---------------------------------------------------------------------------------------------------------|:------|:---------|
| values | LibDropDown [LineData](https://github.com/p3lim-wow/LibDropDown/wiki/Menu#menuaddlinedata) configuration | table | yes |
| key | value | type | required |
|:----------|:----------------------------------------------------------------------------------------------------------------------|:---------|:---------|
| values | indexed table containing [DropdownOption](#dropdownoption)s | table | no |
| generator | [Dropdown `SetupMenu` "generator" (callback)](https://warcraft.wiki.gg/wiki/Patch_11.0.0/API_changes#New_menu_system) | function | no |
- Either `values` or `generator` is required, the former for simple menues and the latter for complex ones.
- They are not exclusive, but `generator` takes precedence (e.g. `values` will be available but not used).
- `generator` signature is `(dropdown, rootDescription, settingObject)` - `settingObject` being the addition to the default arguments.
- getters and setters are not handled using `generator`, and must be handled by the layout
### Slider
Expand All @@ -365,6 +371,15 @@ Table containing the following entries:
| text | text rendered on the button | string | yes |
| click | callback when button is clicked | function | yes |
## DropdownOption
Table containing the following entries:
| key | value | type | required |
|:--------|:-------------------------------------------------------------------|---------|:---------|
| text | text rendered in the dropdown | string | yes |
| isRadio | turns the dropdown entry into a Radio button, otherwise a Checkbox | boolean | no |
## SettingType
Convenient shorthand for `Enum.EditModeSettingDisplayType`.
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ This is a library addon for the popular MMORPG "World of Warcraft.
LibEditMode is a library that allows a developer to integrate their frames into the Edit Mode introduced in Dragonflight.

It has feature parity with the systems Blizzard added to the Edit Mode, but limits its re-use of methods to limit taint issues.
It depends on [LibDropDown](https://github.com/p3lim-wow/LibDropDown) to achieve this.

For details on how to implement this in your own addon, please see the wiki:
<https://github.com/p3lim-wow/LibEditMode/wiki>
Expand Down
56 changes: 28 additions & 28 deletions widgets/dropdown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,43 @@ if minor > MINOR then
return
end

local LDD, lddMinor = LibStub('LibDropDown', true)
if not LDD then
error('LibEditMode requires LibDropDown to function')
local function get(data)
return data.get(lib.activeLayoutName) == data.value
end

local function isChecked(a, getB, default)
return a == (getB(lib.activeLayoutName) or default)
local function set(data)
data.set(lib.activeLayoutName, data.value)
end

local dropdownMixin = {}
function dropdownMixin:Setup(data)
self.setting = data
self.Label:SetText(data.name)

self.Dropdown:Clear()

for _, info in next, data.values do
info.checked = GenerateClosure(isChecked, info.text, data.get, data.default)
info.func = GenerateClosure(self.OnSettingSelected, self, info.text)
info.keepShown = false
self.Dropdown:Add(info)

if info.checked() then
self.Dropdown:SetText(info.text)
end
end
end

function dropdownMixin:OnSettingSelected(value)
self.setting.set(lib.activeLayoutName, value)

if lddMinor >= 7 and lddMinor < 9 then
self.Dropdown:Refresh()
if data.generator then
-- let the user have full control
self.Dropdown:SetupMenu(function(owner, rootDescription)
pcall(data.generator, owner, rootDescription, data)
end)
elseif data.values then
self.Dropdown:SetupMenu(function(dropdown, rootDescription)

Check warning on line 26 in widgets/dropdown.lua

View workflow job for this annotation

GitHub Actions / lint

unused argument 'dropdown'
for _, value in next, data.values do
if value.isRadio then
rootDescription:CreateRadio(value.text, get, set, {
get = data.get,
set = data.set,
value = value.text,
})
else
rootDescription:CreateCheckbox(value.text, get, set, {
get = data.get,
set = data.set,
value = value.text
})
end
end
end)
end
self.Dropdown:SetText(value)
end

lib.internal:CreatePool(lib.SettingType.Dropdown, function()
Expand All @@ -52,11 +54,9 @@ lib.internal:CreatePool(lib.SettingType.Dropdown, function()
label:SetJustifyH('LEFT')
frame.Label = label

local dropdown = LDD:NewButton(frame)
local dropdown = CreateFrame('DropdownButton', nil, frame, 'WowStyle1DropdownTemplate')
dropdown:SetPoint('LEFT', label, 'RIGHT', 5, 0)
dropdown:SetSize(200, 30)
dropdown:SetJustifyH('LEFT')
dropdown:SetCheckAlignment('LEFT')
frame.Dropdown = dropdown

return frame
Expand Down

0 comments on commit 11ebcaa

Please sign in to comment.