Jump to content

UI Label Widget text ignores newline character


StOneDOes
 Share

Go to solution Solved by Josh,

Recommended Posts

The UI label widget appears to ignore the \n newline character, whereas the Text Area widget utilizes it correctly.

Is this the expected behaviour? Because for something like on-screen debug info I personally would prefer to have a single widget with all the text assigned to the one label, rather than having eg. 10 label widgets and having to set their positions.

Link to comment
Share on other sites

This is the intended behavior. The TextArea widget is intended for displaying multi-line text.

It might be possible in the future for labels to support multiple lines, but it needs to be done carefully because labels have a lot of alignment options in their style flags.

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

Link to comment
Share on other sites

Actually, I take that back. I already programmed it with multi-line support:

#include "UltraEngine.h"

using namespace UltraEngine;

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

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

    //Create User Interface
    auto ui = CreateInterface(window);

    //Create widget
    auto label1 = CreateLabel("First line\nSecond line\nThird line", 20, 20, 120, 60, ui->root, LABEL_BORDER | LABEL_CENTER | LABEL_MIDDLE );

    while (window->Closed() == false)
    {
        WaitEvent();
    }
    return 0;
}

However, when a 3D GUI is in use the line return is ignored:

#include "UltraEngine.h"

using namespace UltraEngine;

int main(int argc, const char* argv[])
{
    auto displays = GetDisplays();
    auto window = CreateWindow("Ultra Engine", 0, 0, 800, 600, displays[0]);
    auto framebuffer = CreateFramebuffer(window);

    auto world = CreateWorld();
    auto camera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
    camera->SetPosition(float(framebuffer->size.x) * 0.5f, float(framebuffer->size.y) * 0.5f, 0);

    auto font = LoadFont("Fonts/arial.ttf");
    auto ui = CreateInterface(world, font, framebuffer->size);
    auto label = CreateLabel("First line\nSecond line\nThird line", 20, 20, 120, 60, ui->root, LABEL_BORDER | LABEL_CENTER | LABEL_MIDDLE );

    while (window->Closed() == false)
    {
        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

So I need to adjust the sprite creation code to handle multi-line text and then everything should work the same in Vulkan.

  • Like 2

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

Link to comment
Share on other sites

  • 2 weeks later...
  • Solution

Here's an example of it working. I will have an update up shortly:

#include "UltraEngine.h"
#include "ComponentSystem.h"

using namespace UltraEngine;

#define UI3D

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

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

    //Create a world
    auto world = CreateWorld();
    world->SetAmbientLight(0);

    //Create a framebuffer
#ifdef UI3D
    auto framebuffer = CreateFramebuffer(window);
#endif

    //Create a camera
    auto camera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
#ifdef UI3D    
    camera->SetPosition(float(framebuffer->size.x) * 0.5f,float(framebuffer->size.y) * 0.5f);
#endif

    auto font = LoadFont("Fonts/arial.ttf");
    auto sprite = CreateSprite(world, font, "AAAAAAAAAAAAA", 26, TEXT_CENTER | TEXT_MIDDLE, 400000.0f);

    auto ss = CreateSprite(world, 100, 100);
    ss->SetColor(1, 0, 0);

#ifdef UI3D    
    auto ui = CreateInterface(world, font, framebuffer->size);
#else
    auto ui = CreateInterface(window);
#endif

    auto label = CreateLabel("test 1\ntest line 2\ntest 3", 20, 20, 200, 200, ui->background, LABEL_BORDER | LABEL_MIDDLE | LABEL_RIGHT );

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        Sleep(10);
#ifdef UI3D 
        world->Update();
        world->Render(framebuffer);
#endif
    }
    return 0;
}

 

  • Thanks 2

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

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