Jump to content

Menu Theme doesn't update.


reepblue
 Share

Go to solution Solved by Josh,

Recommended Posts

This example shows that if the theme of the UI is changed, the menu bar dropdown lists fail to update it's background. This might happen with other widgets if this functionality is shared with other widgets. 

#include "UltraEngine.h"

using namespace UltraEngine;

int main(int argc, const char* argv[])
{
    //Get the displays
    auto displays = GetDisplays();

    //Create window
    auto window = CreateWindow("Ultra Engine", 0, 0, 800, 600, displays[0]);

    //Create user interface
    auto ui = CreateInterface(window);

    //Create widget
    iVec2 sz = ui->root->ClientSize();
    auto button_dark = CreateButton("Dark Theme", sz.x / 4 - 75, sz.y / 4 - 15, 150, 30, ui->root);
    auto button_light = CreateButton("Light Theme", sz.x / 4 * 3 - 75, sz.y / 4 - 15, 150, 30, ui->root);

    //File menu
    auto mainmenu = CreateMenu("", ui->root);
    auto menu_file = CreateMenu("File", mainmenu);
    CreateMenu("New", menu_file);
    CreateMenu("", menu_file);
    auto menu_open = CreateMenu("Open", menu_file);
    auto menu_save = CreateMenu("Save", menu_file);
    auto menu_saveas = CreateMenu("Save as...", menu_file);
    CreateMenu("", menu_file);
    auto menu_recentfiles = CreateMenu("Recent files", menu_file);
    std::array<shared_ptr<Widget>, 10> menu_recentfile;
    for (int n = 0; n < menu_recentfile.size(); ++n)
    {
        menu_recentfile[n] = CreateMenu("Recent file " + String(n + 1), menu_recentfiles);
    }
    CreateMenu("", menu_file);
    auto menu_exit = CreateMenu("Exit", menu_file);

    //Edit menu
    auto menu_edit = CreateMenu("Edit", mainmenu);
    CreateMenu("Undo", menu_edit);
    CreateMenu("Redo", menu_edit);
    CreateMenu("", menu_edit);
    CreateMenu("Cut", menu_edit);
    CreateMenu("Copy", menu_edit);
    CreateMenu("Past", menu_edit);
    CreateMenu("", menu_edit);
    CreateMenu("Select all", menu_edit);
    CreateMenu("Select none", menu_edit);
    CreateMenu("Invert selection", menu_edit);

    //View menu
    auto menu_view = CreateMenu("View", mainmenu);
    auto menu_perspective = CreateMenu("Perspective", menu_view);
    auto menu_top = CreateMenu("XZ - Top", menu_view);
    auto menu_side = CreateMenu("XZ - Side", menu_view);
    auto menu_front = CreateMenu("XY - Front", menu_view);
    menu_perspective->SetState(true);

    //Tools menu
    auto menu_tools = CreateMenu("Tools", mainmenu);
    auto menu_options = CreateMenu("Options", menu_tools);

    //Help menu
    auto menu_help = CreateMenu("Help", mainmenu);
    auto menu_helpcontents = CreateMenu("Help Contents", menu_help);
    auto menu_about = CreateMenu("About", menu_help);

    //Text area
    auto textarea = CreateTextArea(8,sz.y/2,sz.x-16,sz.y/2-8,ui->root);
    textarea->SetText(LoadString("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Themes/dark.json"));

    while (true)
    {
        const Event ev = WaitEvent();
        switch (ev.id)
        {
        case EVENT_WIDGETACTION:
            if (ev.source == button_dark)
            {
                //Load dark color scheme
                ui->LoadColorScheme("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Themes/dark.json");
                textarea->SetText(LoadString("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Themes/dark.json"));
            }
            else if (ev.source == button_light)
            {
                //Load light color scheme
                ui->LoadColorScheme("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Themes/light.json");
                textarea->SetText(LoadString("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Themes/light.json"));
            }
            break;
        case EVENT_WINDOWCLOSE:
            if (ev.source == window)
            {
                return 0;
            }
            break;
        }
    }
    return 0;
}

image.thumb.png.bf8b1197dfe6f1afcc7f0e580aad06b8.png

  • Thanks 1

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...