|
|
Home » U++ Library support » U++ Widgets - General questions or Mixed problems » Size of TopWindow is different then the size I set for it
Size of TopWindow is different then the size I set for it [message #48330] |
Fri, 23 June 2017 15:58 |
rafiwui
Messages: 105 Registered: June 2017 Location: Stuttgart, Germany
|
Experienced Member |
|
|
When I wanted to add some buttons to a window I encountered a problem:
They were not fully visible. I added them depending on the size returned by TopWindow::GetSize() so I thought they should fit.
Can someone tell me why the TopWIndow is not in the size I gave him?
Here is an example code snippet that should produce the problem properly:
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
GUI_APP_MAIN
{
TopWindow app;
app.SetRect(0, 0, 500, 200);
Button button1;
// Button 1 should be centered and with a bit of space on both sides and a bit of space to
// the top
button1.SetLabel("Test Button 1").LeftPosZ(10, 480).TopPosZ(10, 80);
Button button2;
// Button 2 should be centered and with a bit of space on both sides and a bit of space to
// the bottom. This time the size is measured from the size of the TopWindow and not
// hardcoded
button2.SetLabel("Test Button 2").LeftPosZ(10, app.GetSize().cx - 20).TopPosZ(110, 80);
app.Add(button1);
app.Add(button2);
app.Run();
}
And to be safe I added an image how the window looks when you run the code.
Greetings
Daniel
|
|
|
|
|
Re: Size of TopWindow is different then the size I set for it [message #48365 is a reply to message #48361] |
Mon, 26 June 2017 12:51 |
rafiwui
Messages: 105 Registered: June 2017 Location: Stuttgart, Germany
|
Experienced Member |
|
|
Ok so another problem came up: How can I prevent TopPosZ/LeftPosZ/etc. from being used inside of the layout files. Because whenever I build my application it is changed back to TopPosZ/LeftPosZ whenever I set it to TopPosZ/LeftPosZ manually.
Edit: It seems that it only switches back to TopPosZ/LeftPosZ if you enter the graphical designer. If I stay inside the text editor of the layout it stays TopPos/LeftPos.
Greetings
Daniel
[Updated on: Mon, 26 June 2017 13:02] Report message to a moderator
|
|
|
|
Re: Size of TopWindow is different then the size I set for it [message #48369 is a reply to message #48330] |
Mon, 26 June 2017 13:32 |
rafiwui
Messages: 105 Registered: June 2017 Location: Stuttgart, Germany
|
Experienced Member |
|
|
Yes it makes sense or I am doing sth else wrong, because my layout is not visible as a whole even if the size I give the rectangle and the size I give the layout are the same. I am not setting the layout as parent of my class. Maybe that leads to my problem:
class MyWindow : public TopWindow
{
// Menu bar is added here...
}
GUI_APP_MAIN
{
MyWindow app;
app.SetRect(0, 0, 300, 150);
WithMyLayout<TopWindow> layout;
SetLayout_MyLayout(app, layout, true, true);
app.Run();
}
Greetings
Daniel
[Updated on: Mon, 26 June 2017 14:03] Report message to a moderator
|
|
|
Re: Size of TopWindow is different then the size I set for it [message #48370 is a reply to message #48369] |
Mon, 26 June 2017 14:37 |
|
mirek
Messages: 14038 Registered: November 2005
|
Ultimate Member |
|
|
rafiwui wrote on Mon, 26 June 2017 13:32Yes it makes sense or I am doing sth else wrong, because my layout is not visible as a whole even if the size I give the rectangle and the size I give the layout are the same. I am not setting the layout as parent of my class. Maybe that leads to my problem:
class MyWindow : public TopWindow
{
// Menu bar is added here...
}
GUI_APP_MAIN
{
MyWindow app;
app.SetRect(0, 0, 300, 150);
WithMyLayout<TopWindow> layout;
SetLayout_MyLayout(app, layout, true, true);
app.Run();
}
Well, font zooming is there for a reason - your application should work with different GUI font!
I guess you should just do it right: Leave zooming active and actually zoom your own coordinates. E.g.
app.SetRect(0, 0, Zx(300), Zy(150));
Mirek
|
|
|
Re: Size of TopWindow is different then the size I set for it [message #48371 is a reply to message #48370] |
Mon, 26 June 2017 14:51 |
rafiwui
Messages: 105 Registered: June 2017 Location: Stuttgart, Germany
|
Experienced Member |
|
|
Ok thanks. I didn't know these functions.
Using Zx/Zy everywhere it is now better but there is still a bit of the layout missing at the bottom only. Is this caused by the menu bar and you have to add a bit of extra space to compensate the bar?
Greetings
Daniel
|
|
|
|
|
|
|
Re: Size of TopWindow is different then the size I set for it [message #48868 is a reply to message #48865] |
Mon, 16 October 2017 10:56 |
|
mirek
Messages: 14038 Registered: November 2005
|
Ultimate Member |
|
|
I see...
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
#define LAYOUTFILE <GuiTest/test.lay>
#include <CtrlCore/lay.h>
struct MyApp : WithTestLayout<TopWindow> {
MenuBar bar;
MyApp() {
AddFrame(bar);
bar.Set([=](Bar& bar) {
bar.Sub("File", [=](Bar& bar) {
bar.Add("Exit", [=] {
Break();
});
});
});
CtrlLayout(*this);
}
};
GUI_APP_MAIN {
MyApp().Execute();
}
Note that it is important to call CtrlLayout AFTER adding menu as CtrlLayuot actually adds frame dimensions to the whole requested window size.
[Updated on: Mon, 16 October 2017 10:56] Report message to a moderator
|
|
|
Re: Size of TopWindow is different then the size I set for it [message #48869 is a reply to message #48868] |
Mon, 16 October 2017 12:08 |
rafiwui
Messages: 105 Registered: June 2017 Location: Stuttgart, Germany
|
Experienced Member |
|
|
It seems to work a bit. When I place CtrlLayout at the end it seems that there is a slightly bigger view area. But I faced another problem because I call it like this:
TestWindow::TestWindow()
{
//CtrlLayout(*this);
Sizeable(true);
Title("Testing");
SetRect(0, 0, Zx(400), Zy(200));
// Create menu bar
AddFrame(m_menuBar);
m_menuBar.Set(THISBACK(OnMenuBar));
CtrlLayout(*this);
}
Doing it with this code still leads to a bit of a cut at the bottom of the view area. Even though the layout has the exact same size as the SetRect method is given.
TestWindow::TestWindow()
{
//CtrlLayout(*this);
Sizeable(true);
Title("Testing");
//SetRect(0, 0, Zx(400), Zy(200));
// Create menu bar
AddFrame(m_menuBar);
m_menuBar.Set(THISBACK(OnMenuBar));
CtrlLayout(*this);
}
Commenting out SetRect leads to not displaying anything but the empty view area. This is kind of strange so I would appreciate if you have any idea.
I also added the whole package as an attachment if you need further information of my code.
EDIT: Oh never mind I just remembered that I faced this problem before. It is caused by the AutoResizer because if you don't set a size at the beginning explicitly it has no original size to work with because TopWindow is instantiated with a size of 0 or similiar. Guess I have to rethink some stuff.
-
Attachment: Testing.7z
(Size: 2.11KB, Downloaded 199 times)
Greetings
Daniel
[Updated on: Mon, 16 October 2017 12:10] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Fri Sep 20 06:23:55 CEST 2024
Total time taken to generate the page: 0.04068 seconds
|
|
|