Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropdown widget v15 - With multiselect #135

Merged
merged 16 commits into from Dec 3, 2023

Conversation

Baertram
Copy link
Contributor

Added multiselection possibilities to the dropdown widget.
-> if multiselection is enabled the getFunc and setFunc are working with a table instead of single values!

Should be fully backwards comaptible with old dropdowns.

Widget's data table additions are:

    multiSelect = false, -- boolean or function returning a boolean. If set to true you can select multiple entries at the list (optional)
    multiSelectTextFormatter = SI_COMBO_BOX_DEFAULT_MULTISELECTION_TEXT_FORMATTER, -- or string id or function returning a string. If specified, this will be used with zo_strformat(multiSelectTextFormatter, numSelectedItems) to set the "selected item text". Only incombination with multiSelect = true (optional)
    multiSelectNoSelectionText = SI_COMBO_BOX_DEFAULT_NO_SELECTION_TEXT, -- or string id or function returning a string. Only incombination with multiSelect = true (optional)
    multiSelectType = "normal", -- String or function returning a string "normal" or "allowed". "normal" = a list with key = number index and value = String / "allowed" = a list with key = any String or number and value = boolean. If value == true then the entry will be added. Default = "normal". Only incombination with multiSelect = true (optional)
    multiSelectMaxSelections = 5, --Number or function returning a number of the maximum of selectable entries. If not specified there is no max selection. Only incombination with multiSelect = true (optional)

updateMultiSelectSelected
See addon FCOChangeStuff 1st dropdown at settings
--TODO 20231114 for debugging LibAddonMenu dropdwn.lua test for multiselection
        --settings._testMultiSelect = { "abc", "def" }
        {
            type = "dropdown",
            name = 'test multiselect',
            tooltip = 'test multiselect',
            choices = { "abc", "bcd", "cde", "def", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q" },
            --choicesValues = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
            choicesTooltips = { "abc TT", "bcd TT", "cde TT", "def TT", "","","","","","","","","","","", },
            scrollable = 10,
            getFunc = function() return settings._testMultiSelect end,
            setFunc = function(values)
                settings._testMultiSelect = values
            end,
            default = defaults._testMultiSelect,
            width="full",
            multiSelect = true,
            --multiSelectTextFormatter = SI_COMBO_BOX_DEFAULT_MULTISELECTION_TEXT_FORMATTER,
            --multiSelectNoSelectionText = SI_COMBO_BOX_DEFAULT_NO_SELECTION_TEXT,
            --multiSelectType = "normal",
            --multiSelectMaxSelections = 5,
        },
LibAddonMenu-2.0/controls/dropdown.lua Outdated Show resolved Hide resolved
LibAddonMenu-2.0/controls/dropdown.lua Outdated Show resolved Hide resolved
LibAddonMenu-2.0/controls/dropdown.lua Outdated Show resolved Hide resolved
LibAddonMenu-2.0/controls/dropdown.lua Outdated Show resolved Hide resolved
LibAddonMenu-2.0/controls/dropdown.lua Outdated Show resolved Hide resolved
LibAddonMenu-2.0/controls/dropdown.lua Outdated Show resolved Hide resolved
LibAddonMenu-2.0/controls/dropdown.lua Outdated Show resolved Hide resolved
LibAddonMenu-2.0/controls/dropdown.lua Outdated Show resolved Hide resolved
LibAddonMenu-2.0/controls/dropdown.lua Outdated Show resolved Hide resolved
LibAddonMenu-2.0/controls/dropdown.lua Outdated Show resolved Hide resolved
-Fixes and changes requested by sirinsidiator
todo: Change multiSelectType. Remove it and instead of "normal" or "allowed" always use "normal" internally and return the selected items (as table with key = choicesValues[i] or choices[i] / value = boolean -> Like "allowed" did) per function
dropdown:IsSelected() return table allowed
--Return table { [choicesValues[i] or choices[i]] = boolean, ... }
--Can be used at a setFunc e.g. to convert the SavedVariables (2nd param values) to that other table format
local function IsSelected(control, values)
-control ref for AdjustDimensions call
-useChoicesValues == true check
-OnMouseUp handler opens dropdown again (left click)
-callMultiSelectSetFunc(control, nil)
and fix for returning the 1 saved value if no muliselect enabled -> control:IsSelected
@Baertram
Copy link
Contributor Author

Baertram commented Dec 1, 2023

Tested ingame with changed code: choices, choicesValues, choicesTooltips, multi selection, single selection, maxMultiSelecion etc. Seems to work fine

@sirinsidiator sirinsidiator merged commit 404543c into sirinsidiator:master Dec 3, 2023
@Baertram Baertram deleted the dropdown_multiselect branch March 13, 2024 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants