Jump to content

Label text breaks if font and text was changed in real time


Dreikblack
 Share

Go to solution Solved by Josh,

Recommended Posts

image.png.5130f5c08ee0e8b82b3bc30896d5431c.pngimage.png.e8926b23c608dbfd9666539e3376f1fe.png

#include "UltraEngine.h"

using namespace UltraEngine;

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

shared_ptr<Widget> label;

static bool EventCallback(const Event& e, shared_ptr<Object> extra)
{
    Print("Callback");
    return true;
}

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

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

    //Create a window
    window = CreateWindow("Ultra Engine", 0, 0, 300, 300, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);

    //Create a world
    world = CreateWorld();

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

    //Create a camera    
    auto camera = CreateCamera(world);
    camera->SetClearColor(0, 0, 0);

    initGui();

    ListenEvent(EVENT_DATA, NULL, EventCallback, label);
    auto color = Vec4(0.5, 0, 1, 0.5f);
    label->SetColor(color);

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        if (window->KeyDown(KEY_SPACE))
        {
            label->SetText("New Text");
            float fonstScale = 14.0 / (float)13;
            label->SetFontScale(0.9);
        }
        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

 

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...