[solved] listView and symbols

  • 7 Replies
  • 202 Views
*

che2a

  • *
  • 12
    • View Profile
[solved] listView and symbols
« on: 28 May 2020, 16:01:11 »
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

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

 
« Last Edit: 29 May 2020, 09:03:54 by che2a »

Re: listView and symbols
« Reply #1 on: 28 May 2020, 16:59:34 »
It has nothing to do with ListView.
Use wide string for any non-Ascii symbols:

Code: [Select]
#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

  • *
  • 12
    • View Profile
Re: listView and symbols
« Reply #2 on: 28 May 2020, 17:18:22 »
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
« Last Edit: 28 May 2020, 17:21:07 by che2a »

Re: listView and symbols
« Reply #3 on: 28 May 2020, 17:50:08 »
Do you use unicode character set in your project?
About the “Character set” option in Visual Studio

*

che2a

  • *
  • 12
    • View Profile
Re: listView and symbols
« Reply #4 on: 28 May 2020, 18:05:12 »
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

  • *****
  • 1569
    • View Profile
    • Texus's Blog
Re: listView and symbols
« Reply #5 on: 28 May 2020, 18:27:49 »
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

  • *****
  • 1569
    • View Profile
    • Texus's Blog
Re: listView and symbols
« Reply #6 on: 28 May 2020, 18:34:58 »
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:
sf::String str_annual_wages = std::to_string(drivers_vector[i]->contract->getAnnualWages()) + sf::String(L"\u20AC");

*

che2a

  • *
  • 12
    • View Profile
Re: listView and symbols
« Reply #7 on: 29 May 2020, 09:03:23 »
Yes, now it work
You teach me a good thing today :)

Thank you