Last active
August 16, 2022 15:21
-
-
Save 34j/48dc3590bc0b467b066dff76d2d4230f to your computer and use it in GitHub Desktop.
DaVinci Resolve UIManager.Tree with checkBoxes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --Licensed under CC0 1.0 https://creativecommons.org/publicdomain/zero/1.0/ | |
| --Add this file to C:\ProgramData\Blackmagic Design\DaVinci Resolve\Fusion\Scripts\Comp | |
| --tree:SetItemWidget is no available unfortunatelly, which means we cannot add custom widgets to TreeItems. | |
| --So we have to use this method. (only checkBoxes are supported) | |
| local ui = fu.UIManager | |
| local disp = bmd.UIDispatcher(ui) | |
| -- create a new window | |
| local win = disp:AddWindow({ | |
| ID = "Dialog", | |
| WindowTitle = "Generate Comp", | |
| ui:Tree { | |
| ID = "Tree", | |
| RootIsDecorated = false, | |
| Events = { CurrentItemChanged = true, ItemChanged = true, }, | |
| } | |
| }) | |
| local winItems = win:GetItems() | |
| local tree = winItems.Tree | |
| -- for performance ? | |
| tree.SortingEnabled = false | |
| tree.UpdatesEnabled = false | |
| -- add TreeItems to the Tree | |
| for i = 1, 50 do | |
| local treeItem = tree:NewItem() -- to create TreeItem, we need to call NewItem(). (ui.TreeItem is nil) | |
| treeItem.Text[0] = "Item " .. i | |
| treeItem.CheckState[0] = "Checked" -- without this, the checkbox is not shown. | |
| -- Make sure it is .CheckState[i] = "Checked" (or "UnChecked"), not .CheckState = "Checked" (or "UnChecked"). | |
| -- It took me many hours to figure out this bug... | |
| treeItem.Flags = { | |
| ItemIsSelectable = true, | |
| ItemIsEnabled = true, | |
| ItemIsUserCheckable = true, -- without this, the checkbox cannot be edited | |
| } | |
| treeItem:SetData(0, "UserRole", tostring(i)) -- without this, the events will not be triggered | |
| tree:AddTopLevelItem(treeItem) -- add the TreeItem to the Tree | |
| end | |
| -- for performance ? | |
| tree.SortingEnabled = true | |
| tree.UpdatesEnabled = true | |
| -- print message when the checkboxes are clicked | |
| function win.On.Tree.ItemChanged(ev) | |
| if ev.item then | |
| local id = ev.item:GetData(0, "UserRole") | |
| print("Item " .. id .. " " .. ev.item.CheckState[0]) | |
| end | |
| end | |
| -- close the window | |
| function win.On.Dialog.Close(ev) | |
| disp:ExitLoop() | |
| end | |
| -- show the window | |
| win:Show() | |
| disp:RunLoop() | |
| win:Hide() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment