How to Prevent Widget Autoscaling?
« on: 14 July 2017, 21:03:46 »
I've just started working with TGUI- it's realllly nice so far! The built-in menubar is particularly nice. But then, you probably already knew that.  ::)

I've been trying to figure out how to stop my menu bar from resizing to fit the % of the screen it originally matched.

Code: [Select]
    auto menuBar = tgui::MenuBar::create();
    menuBar->getRenderer()->setBackgroundColor(tgui::Color(240, 240, 240));
    menuBar->getRenderer()->setTextColor(tgui::Color(10, 10, 10));
    menuBar->setSize({ 500, 18 });

This, for example, produces exactly what I want. However, when I resize the window, the menuBar becomes much larger than 18pixels, and the text becomes blurred slightly as it stretches to fit.

I was reading the documentation and saw that in 0.7 there is a 'scale' method that looked like what I want. I'm currently using 0.8 though and didn't see anything like it. Should I downgrade, or is there an alternative?

Thanks!  :)



  • *****
  • 1342
    • View Profile
    • Texus's Blog
Re: How to Prevent Widget Autoscaling?
« Reply #1 on: 14 July 2017, 22:44:37 »
The scale function just calls setSize(getSize() * scaleFactor), which is not what you need. (I removed it from 0.8 because you can easily call setSize yourself)

What you are describing sounds like the view not being changed, if that is the case then it should affect all widgets and not just the MenuBar. Unless you call gui.setView when the window is resized, the view will remain unchanged and everything drawn to the screen will be stretched. (SFML has the exact same behavior by default, you also need to call window.setView if you want your own SFML drawings to not get stretched)

If that is not the problem then please provide some minimal and complete code that reproduces the issue so that I can try it here.

Re: How to Prevent Widget Autoscaling?
« Reply #2 on: 14 July 2017, 22:50:29 »
That was it! Thanks so much. :)