Jump to content

SetIcon does not change an icon of widget


Go to solution Solved by Josh,

Recommended Posts

Posted

Initially i tried to reproduced bug when while changing an icon it was blinking with purple but in test example first icons stays.

#include "UltraEngine.h"

using namespace UltraEngine;

shared_ptr<Window> window;
shared_ptr<Framebuffer> framebuffer;
shared_ptr<World> menuWold;
shared_ptr<Interface> ui;
shared_ptr<Camera> uiCamera;

shared_ptr<Widget> panel;
shared_ptr<Widget> btn;

bool isFirst = true;

void initGui()
{
    auto default_font = LoadFont("Fonts\\arial.ttf");
    ui = CreateInterface(menuWold, default_font, framebuffer->GetSize());
    ui->SetRenderLayers(2);
    ui->root->SetColor(0.0f, 0.0f, 0.0f, 0.0f);
    uiCamera = CreateCamera(menuWold, PROJECTION_ORTHOGRAPHIC);
    uiCamera->SetPosition((float)framebuffer->GetSize().x * 0.5f, (float)framebuffer->GetSize().y * 0.5f, 0);
    uiCamera->SetRenderLayers(2);
    uiCamera->SetClearMode(CLEAR_DEPTH);

    panel = CreatePanel(10, 50, 64, 64, ui->root, PANEL_DEFAULT);
    auto icon = LoadIcon("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Icons/help.svg");
    panel->SetIcon(icon);
    btn = CreateButton("Change an icon", 10, 10, 150, 20, ui->root);
}


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

    //Create a window
    window = CreateWindow("Ultra Engine", 0, 0, 200, 200, displays[0], WINDOW_DEFAULT);

    //Create a world
    menuWold = CreateWorld();

    //Create a framebuffer
    framebuffer = CreateFramebuffer(window);

    //Create light
    auto light = CreateBoxLight(menuWold);
    light->SetRange(-10, 10);
    light->SetRotation(15, 15, 0);
    light->SetColor(2);

    //Create camera
    auto camera = CreateCamera(menuWold);
    camera->SetClearColor(0.125);
    camera->SetPosition(0, 0, -3);
    camera->SetFov(70);

    initGui();

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        while (PeekEvent())
        {
            const Event ev = WaitEvent();
            if (ev.source == btn && ev.id == EVENT_WIDGETACTION)
            {
                isFirst = !isFirst;
                if (isFirst)
                {
                    auto icon = LoadIcon("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Icons/help.svg");
                    panel->SetIcon(icon);
                }
                else
                {
                    auto icon2 = LoadIcon("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Icons/new.svg");
                    panel->SetIcon(icon2);
                }
            }
            ui->ProcessEvent(ev);
        }
        menuWold->Update();
        menuWold->Render(framebuffer);
    }
    return 0;
}

 

  • 1 month later...
  • Solution
Posted

Fixed, this will work correctly in the next build of the library...

My job is to make tools you love, with the features you want, and performance you can't live without.

  • Josh locked this topic
Guest
This topic is now closed to further replies.
×
×
  • Create New...