Custom Preferences Pages

The editor Preferences window can be customized by adding custom pages with preferences for your tools. The following snippet shows how:

Custom Preferences Pages
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
    -- show the UI for the custom tool 1 preferences
    local function myTool1PrefsUI()
            if imgui.Button("Make it so") then
                    editor.preferences.myTool.someRandomValue = true
                    -- this is optional if you want to save preferences right away
                    -- this function is also called on editor shutdown/deactivate
                    editor.savePreferences()
            end
            if imgui.Button("Make it not so") then
                    editor.preferences.myTool.someRandomValue = false
                    editor.savePreferences()
            end
    end

    -- show the UI for the custom tool 2 preferences
    local function myTool2PrefsUI()
            -- some other UI here
            imgui.Text("Dummy text")
    end

    -- in this hook we're setting various preferences into our own data tables
    -- this is and optional hook
    local function onEditorAfterLoadPreferences()
            -- lets create our preferences table if not existent
            if not editor.preferences.myTool then editor.preferences.myTool = {} end
            local someValue = editor.preferences.myTool.someRandomValue or true -- if not existent, be true by default
            -- do something with the value
    end

    local function onEditorInitialized()
            -- add the pages to the preferences
            editor.addPreferencesPage("My Tool1", myTool1PrefsUI)
            editor.addPreferencesPage("My Tool2", myTool2PrefsUI)
    end

    M.onEditorInitialized = onEditorInitialized
    M.onEditorAfterLoadPreferences = onEditorAfterLoadPreferences

Also check the API for preferences-api

../../../_images/preferences.png