Text isn't positioning correctly with Button?
« on: 27 January 2015, 00:30:07 »

                m_resourcesInterface.tilesTab->load("widgets/White.conf");
                m_resourcesInterface.tilesTab->setSize(121, 31);
                m_resourcesInterface.tilesTab->setPosition(0, 0);
                m_resourcesInterface.tilesTab->setText("Tiles");
                m_resourcesInterface.tilesTab->setTextSize(22);
                m_resourcesGui.add(m_resourcesInterface.tilesTab);
 

Results in the text being off-centered, almost as if the origin to the text didn't get set right.

I clicked
  "Download TGUI v0.6.6 with precompiled Visual C++ 12 (2013) 32-bit libraries (for SFML 2.2)"

Of course, I'm using Visual Studio 2013, SFML 2.2 for Visual Studio 2013. The only other library at play is Boost.

Sorry, I'm not even sure if anyone else has ran into this problem.

I decided to see what would happen if I created the form in the form-builder and load from the file, and it actually just resulted in no text appearing at all, (even though the font is located in the directory it can be found)

Other info:

Windows 7 (x64)
Pre-2012 Integrated Intel Graphics Card <-(this is the source of evil sometimes)

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: Text isn't positioning correctly with Button?
« Reply #1 on: 27 January 2015, 00:50:30 »
Quote
Results in the text being off-centered, almost as if the origin to the text didn't get set right.
Not being perfectly centered is a known issue on my todo list, but it only differs a few pixels and isn't that bad so its an entirely different issue here.

I just tested the code you posted and it seems like the mistake is with setting the font. The button is only given a font when you call m_resourcesGui.add so at the time you set its text and size it has no font yet. Moving the add line to before the load call (right after it also works, it just has to be before the other functions) should solve the problem.

It seems like this bug exists in all widgets. I'm not planning on fixing it though (due to a redesign it was already fixed in v0.7-dev), you should just add the widget to its parent before calling text related functions. This order was expected by design (hence add function is automatically called in widget constructor when constructing like in example codes).

You might even want to use the following code instead:
m_resourcesInterface.tilesTab = tgui::Button::Ptr(m_resourcesGui);
m_resourcesInterface.tilesTab->load("widgets/White.conf");
// other functions like setText
// no need to call add function, already done in constructor


Quote
I decided to see what would happen if I created the form in the form-builder and load from the file, and it actually just resulted in no text appearing at all
Did you set a global font before loading the file?
If you did, could you send the file so I can check it?
« Last Edit: 27 January 2015, 02:33:38 by texus »

Re: Text isn't positioning correctly with Button?
« Reply #2 on: 27 January 2015, 06:21:39 »
Hey, um, if this is your definition of a few pixels hehe



I have tried using add, the constructor with
tgui::Button::Ptr
, messing with all sorts of orders. Actually, if I add it to the container before I set the widget up, for some reason the text doesn't appear, acting as if it didn't receive the global font assigned to the Gui.

Aye, I did. It's just a simple file.

Thanks!

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: Text isn't positioning correctly with Button?
« Reply #3 on: 27 January 2015, 12:34:14 »
Quote
if this is your definition of a few pixels hehe
That screenshot is exactly what I got too with your code, but changing the order of the add solved it.

Did you set a global font before creating the widget?

Could you write some simple code that starts with setting the global font, then calls the constructor of the button to initialize it and then loads the button, which still displays the wrong text position? That way I can test with the same code.

Quote
Aye, I did. It's just a simple file.
The text displays correctly here. Something is probably going wrong with setting the font and this thus most likely has the same cause as the issue with the uncentered text. So lets focus on that issue and then afterwards you can check if this is solved too or not.

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: Text isn't positioning correctly with Button?
« Reply #4 on: 27 January 2015, 15:14:02 »
Since the release of v0.7 is still far away and v0.6 is still going to be the preferred version for quite some time, I decided to patch this issue anyway. I can't fix every problem with ordering of setting font and calling other functions, but at least calling the add function after the widget is already set up should no longer give problems. The changes where made on the master branch on github.

Nevertheless, I still want to figure out why changing the order of the add is not working for you.

Re: Text isn't positioning correctly with Button?
« Reply #5 on: 27 January 2015, 16:43:15 »
Hmm, it's possible I'm doing something wrong with lifetime expectancy here, I don't know.

I went ahead and pulled 0.7-dev and built it, and I did find out one other thing.

I was calling

createMainInterface();
createResourcesInterface();
 

before

initGUIResources();
 

So now everything seems to be working grandly. Sorry about that, and I'm not sure if that would have fixed the v0.6 code or not. My bad, in my style of wrapping everything up, I didn't see the obvious error in front of me  :o