[solved] listView and symbols

Started by che2a, 28 May 2020, 16:01:11

che2a

Hello, the ListView widget does not display the â,¬ symbol

I tried with sf::String::FromUtf8 and utf16 but it not works

How i can display symbols ?

Thank you

Code (cpp) Select

str_annual_wages = std::to_string(drivers_vector[i]->contract->getAnnualWages()) + "â,¬";

vect.push_back(sf::String::fromUtf8(str_annual_wages.begin(), str_annual_wages.end()));

// This is a part of my code, i use vectors to fill the listview columns


Kvaz1r

It has nothing to do with ListView.
Use wide string for any non-Ascii symbols:

#include <TGUI/TGUI.hpp>

class MyFrame
{
public:
    MyFrame()
    {
        window.create(sf::VideoMode(800, 600), "MCVE");
        gui.setTarget(window);

        auto listView = tgui::ListView::create();
        listView->setSize(window.getSize().x, window.getSize().y);

        listView->addColumn(L"Key");
        listView->addColumn(L"Value");
        sf::String test = "test";
        test += L"â,¬";
        listView->addItem({"0" ,test});

        gui.add(listView);
    }
    void main()
    {
        while (window.isOpen())
        {
            sf::Event event;
            while (window.pollEvent(event))
            {
                if (event.type == sf::Event::Closed)
                    window.close();
                gui.handleEvent(event);
            }
            window.clear();
            gui.draw();
            window.display();
        }
    }
    sf::RenderWindow window;
    tgui::Gui gui;
};

int main()
{
    MyFrame().main();
}

che2a

#2
Thank you but when i use L"â,¬"
I have error : converting to execution character set : Illegal byte sequence

When i use this symbol in sf::Text it is displayed correctly

Kvaz1r


che2a

I use Codeblocks , it never worked for me to use wide strings with L"â,¬"

I tried to change editor encoding settings but impossible i always have an error during the compilation

I would like to use visual studio but is not free...


texus

Unless you are an organization with more than 5 users, Visual Studio has a free community version.

Maybe you should try L"\u20AC".
Having unicode characters in your code can be tricky, because it will require the cpp files to have the right encoding (and your code thus won't compile if someone uses a different file encoding), so it might be better just to use the hex code instead.

texus

Using widestrings will require you to store the value in a std::wstring or sf::String immediately, so your code where you add it to the return of std::to_string won't compile.
You could use u8"\u20AC" if you want to store it in an std::string (but your code wouldn't work when compiling with c++20 or higher because that would return an std::u8string instead).
So the best option would probably be to put it in an sf::String immediately:
Code (cpp) Select
sf::String str_annual_wages = std::to_string(drivers_vector[i]->contract->getAnnualWages()) + sf::String(L"\u20AC");

che2a

Yes, now it work
You teach me a good thing today :)

Thank you