ChildWindow change position when title changes.

  • 6 Replies
  • 379 Views
ChildWindow change position when title changes.
« on: 14 January 2019, 17:57:42 »
Hi

When i change the title of a child window the windows moves a bit inside the main (windows) form. I change title text because i am using more than one language.
This happening when height of child window is smaller than main window (570). However if the child window has the same height with form (600px) the the title tongle between visible and invisible.

Using github version

Code: [Select]
mWindow.create(sf::VideoMode(800, 600), "Sfml + Tgui example", style, contextSettings);
mWindow.setFramerateLimit(60);
mGui.setTarget(mWindow);


tgui::ChildWindow::Ptr pWindow = tgui::ChildWindow::create();
pWindow->setSize(800, 570);
pWindow->setPosition(0, 0);
pWindow->setKeepInParent(true);
pWindow->setTitleAlignment(tgui::ChildWindow::TitleAlignment::Center);
pWindow->getRenderer()->setTitleBarHeight(22);
pWindow->setTitle("Bill");

//-----------------------------------------------------------------------
pButtonLoad = tgui::Button::create();
pButtonLoad->setSize(150, 50);
pButtonLoad->setPosition(800 / 2 + 50, 600 / 2 - 20);
pButtonLoad->getRenderer()->setTextColor(sf::Color::Black);
pButtonLoad->setText("Load");
pButtonLoad->connect("MousePressed", [=]()
{
pWindow->setTitle("Billarhos");
});

*

texus

  • *****
  • 1463
    • View Profile
    • Texus's Blog
Re: ChildWindow change position when title changes.
« Reply #1 on: 14 January 2019, 20:06:39 »
The size of a ChildWindow is a bit special. While the size usually defines the total size of the widget, the size of the child window is it's "client size". So when you create a ChildWindow with width 800, it is actually 800 pixels + the border width on both sides (so the total width is 802 pixels). Since your window only has a width of 800 pixels, the child window doesn't actually fit inside your screen. The KeepInParent will attempt to keep the window inside the screen, but it is unable to do so (and whether it pushes the child window off the screen to the left or right is undefined as you noticed with it the window switching position).
It is surprising that something changes when calling setTitle, but doing so triggers a position recalculation for some reason which is where it goes wrong with the KeepInParent property set to true. Although I could probably fix this, it is an edge case that occurs in a situation which should never happen (forcing the widget inside a window where it can't fit), so this might not get fixed (or when it does get fixed there might be other calls that trigger the reposition).

Re: ChildWindow change position when title changes.
« Reply #2 on: 14 January 2019, 21:21:35 »
 If window is 800 and child window is 802 pixels then border sizes should be removed from the actual child window size.
« Last Edit: 14 January 2019, 21:25:37 by billarhos »

*

texus

  • *****
  • 1463
    • View Profile
    • Texus's Blog
Re: ChildWindow change position when title changes.
« Reply #3 on: 14 January 2019, 22:08:38 »
What do you mean exactly? That the window size should automatically be made smaller if it doesn't fit inside the window? Or that the child window size should always include the borders and title bar?

Re: ChildWindow change position when title changes.
« Reply #4 on: 14 January 2019, 22:26:37 »
Borders and title bar should be inside the windows size. You should not add the title bar size and the borders size to window size. If i want a 800x600 window then 800x600 should be. May be you can consider title bar and borders as two additional widgets. Just a thought. Give me some time to get to sleep. I come back tomorrow. I 'll dig up what happening with microsoft windows style and we can talk about it.

Re: ChildWindow change position when title changes.
« Reply #5 on: 15 January 2019, 09:46:33 »
Check some "dot net" windows forms. When you create a form with a size, created form is always less than the requested size. We are talking about normal windows. So the title bar and borders are inside the calculated size of window.

I removed "setKeepInParent" function and replaced it with "setPositionLocked" and that works for me since my actual size of new window is always same size of parent window.

What happening when "setKeepInParent" is declared and the form size is bigger than parent size?

Talking for myself, there is no need to change something with title bar height and window size. If your main thinking was to add the title bar size to form size is still ok with me now that i am aware of it.

 

*

texus

  • *****
  • 1463
    • View Profile
    • Texus's Blog
Re: ChildWindow change position when title changes.
« Reply #6 on: 15 January 2019, 18:08:41 »
Quote
What happening when "setKeepInParent" is declared and the form size is bigger than parent size?
When the position of the child window is updated (not only when it changes, but also on some other places that just call the function like setTitle), it will check if the child window is within the parent and move it if it partially lies outside the parent. Whether it moves it to the right or left just depend on which check is done first in the code. But since the code should always do the same thing, the position shouldn't jump, so I should probably still investigate this further as it indicates some place in the code where the position isn't updated even though it should.

Quote
Check some "dot net" windows forms. When you create a form with a size, created form is always less than the requested size. We are talking about normal windows. So the title bar and borders are inside the calculated size of window.
I'll have a look at how some other libraries. I'll probably change the behavior of setSize in TGUI 0.9 to include everything while a new setContentSize/setClientSize would be added that acts like the current setSize implementation.