Automatic Layouting (horizontal, vertical, grid, ...)

Discussion regarding the development of CEGUI itself - as opposed to questions about CEGUI usage that should be in the help forums.

Moderators: CEGUI MVP, CEGUI Team

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Automatic Layouting (horizontal, vertical, grid, ...)

Postby CrazyEddie » Thu Aug 05, 2010 09:07

Kulik wrote:Well the one thing that is still undecided is whether it's OK to have the grid mapped to d_children....

I need to look into the implementation a bit closer and get back to you about this. Overall I'm someone who is happy to commit rough(ish) code now, and refine later if things become troublesome or a source of issues. Though I do, of course, appreciate the desire to get the best implementation early if possible.

Kulik wrote:I think introducing something like UBox would be better than 4 UDims, everything would be cleaner and more conscise. However UBox isn't the right name probably, but I can't think of anything better either :-( UMargin sounds sketchy as well...

Jamarr wrote:As far as the best term to define a rectangular area having left, top, right, bottom properties - I cannot think of a term more fitting than "box" ;) Also, as an incentive, the W3C calls it's margin, padding, border, and content areas the "Box Model."

Ok. I think we should go with UBox.

Kulik wrote:The problem with CEGUI::Size is, that it's 2 floats. I need two unsigned integers. But I guess I could probably round them or something...

Yeah. I think mostly it will be fine - who in their right mind would ask for 2.5 cells x 3.25 cells? :)

Kulik wrote:I've encountered a weird glitch that even though GridLayout set it's size correctly, ScrollablePane didn't update the scrollbar so you couldn't scroll all the way to the bottom. Can't reproduce it now though :-( Really weird...

It's probably a ScrollablePane bug related to calculations regarding when a scrollbar is needed; It'll probably only show up when a pixel-perfect situation arises, once I get into some devel work, I'll see if I can trigger it.

Kulik wrote:Yeah and why aren't CEGUI::FrameWindows changing their size when they rollup? I know it's not necessary for rendering or anything, but with layouts it would make sense (even though I must confess having frame windows inside frame windows isn't probably the best use case of them). I could create CollapsibleBoxes with just looknfeel.

We used to have FrameWindow do this, and it was nasty (IMO) and required other hacks (like making the Titlebar not be clipped by parents). So when the client area / inner rect fix went in, I swapped to using a different type of hack instead. I will agree that the situation is not ideal, to date I'd been trying to work with the existing implementations and avoid the need to redesign the FrameWindow, though that may be the best solution in the long term (I've mentioned it lots of times over the years - it's one of a few parts of the system I'm really not happy with).

CE.

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: Automatic Layouting (horizontal, vertical, grid, ...)

Postby Kulik » Fri Aug 06, 2010 13:23

ok, so this was commited and is present in revision 2578 of v-0-7 branch :)

IR3uL
Not too shy to talk
Not too shy to talk
Posts: 45
Joined: Wed Aug 25, 2010 00:32
Location: Buenos Aires - Argentina

Re: Automatic Layouting (horizontal, vertical, grid, ...)

Postby IR3uL » Wed Aug 25, 2010 00:48

Hi, first of all i want to thank you CE, CEGUI is simply awesome, i allways wanted to use it in a project and i finally did it. I also want to thank you for giving so much of your time to answer questions in the forum, i see you are really active and allways willing to help. Thanks to you too Kulik, i was starting to write a few lines of layouting code when i found yours. Ok, enough thanks for now =D. The reason i'm posting here is i can't get this layout thing working, whatever i do, the windows (tried with FWs and PBs, but all are Windows so this souldn't be an issue) get overlapped (I know i should be posting a screen but i'm not in my PC atm). I was going trough the code with a debugger but i can't see what's the problem. Kulik, Would you mind posting an example, or maybe a piece of the code from the editor you are coding? I'm doing as it's said in the Wiki, but for some reason is not working for me =/

I'm running the latest v0.7 branch from svn (i'm pretty sure it's revision 2604, as said... i'm not in my computer) and this is my log http://www.pasteall.org/15201

Also, i'm an spanish talker so i'm not sure my english is 100% right ;)

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: Automatic Layouting (horizontal, vertical, grid, ...)

Postby Kulik » Wed Aug 25, 2010 09:34

Could you please post a test case? I will run it and report back to you. The log looks fine.

Layouting is really simple with sequential layouts (You basically just add the windows in the order they should show up and it works 8) ) and only a bit harder with a grid, are you using a sequential layout containter?

Maybe the layouting isn't triggered, in that case, just resize the parent window or any of the child windows and it should relayout immediately. Or call LayoutContainer::layout directly

This is a very rough, initial info about layouting containers, I will be updating this week http://www.cegui.org.uk/wiki/index.php/ ... Containers

BTW: The layout container must be added to a window, so you should have a parent FrameWindow for example, Vertical LC inside and windows inside the layout container. The relative sizes of child windows of LC are computed in relation to the sizes of the parent of LC. So for example setting layout container as your GUI sheet won't work.

IR3uL
Not too shy to talk
Not too shy to talk
Posts: 45
Joined: Wed Aug 25, 2010 00:32
Location: Buenos Aires - Argentina

Re: Automatic Layouting (horizontal, vertical, grid, ...)

Postby IR3uL » Wed Aug 25, 2010 14:28

Hi, basically i do as it's said in the link you posted. Try this in the FirstWindow sample, paste it before the return true statement:

Code: Select all

    VerticalLayoutContainer *vLayout = static_cast<VerticalLayoutContainer*>(winMgr.createWindow("VerticalLayoutContainer"));
    FrameWindow *frame = static_cast<FrameWindow*>(winMgr.createWindow("TaharezLook/FrameWindow", "blah"));
    vLayout->addChildWindow(frame);
    frame->setText("blah");
    frame->setSize(UVector2(UDim(1,0), UDim(0.1,0)));
   
    frame = static_cast<FrameWindow*>(winMgr.createWindow("TaharezLook/FrameWindow", "blah2"));
    vLayout->addChildWindow(frame);
    frame->setText("blah2");
    frame->setSize(UVector2(UDim(1,0), UDim(0.1,0)));

    wnd->addChildWindow(vLayout);


I noticed something when i enabled resizing of wnd. In the initial state, the windows look overlapped, but when i 'maximize' the parent FW the childs look as i want... what am i missing? =/

Btw, i also triggered the layout myself with no same result, so that's not the issue.

Overlapped pic: http://www.pasteall.org/pic/5310
Ok: http://www.pasteall.org/pic/5311

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: Automatic Layouting (horizontal, vertical, grid, ...)

Postby Kulik » Wed Aug 25, 2010 15:32

I think this is related to min size. Try to set min size of both child windows to UVector2(UDim(0,0), UDim(0, 0)) to confirm. This is indeed bug in my code :-) The layouting code uses getSize, this should already be constrained by min/max size... I will have to dig into it and hopefully I can create a patch before this gets released 8)

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Automatic Layouting (horizontal, vertical, grid, ...)

Postby CrazyEddie » Thu Aug 26, 2010 10:35

You might want to layout via Window::getPixelSize instead, if that does the job (which I think it will) since that takes into account min/max sizes :)

CE.

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: Automatic Layouting (horizontal, vertical, grid, ...)

Postby Kulik » Thu Aug 26, 2010 14:54

OK this patch seems to work for me...

http://harcov.czenet.com/kulik/CEGUI/minsize_fix.patch

Please confirm whether it works for you :)

IR3uL
Not too shy to talk
Not too shy to talk
Posts: 45
Joined: Wed Aug 25, 2010 00:32
Location: Buenos Aires - Argentina

Re: Automatic Layouting (horizontal, vertical, grid, ...)

Postby IR3uL » Thu Aug 26, 2010 18:16

You are the man! =D Works great. I'll make more tests and see if i can find something else. For the moment i noticed nested layouts doesn't work. Try this snipped:

Code: Select all

    VerticalLayoutContainer *vLayout = static_cast<VerticalLayoutContainer*>(wMgr.createWindow("VerticalLayoutContainer"));
    frame->addChildWindow(vLayout);
   
    PushButton *btn = static_cast<PushButton*>(wMgr.createWindow("TaharezLook/Button", "blah"));
    vLayout->addChildWindow(btn);
    btn->setMinSize(UVector2(cegui_absdim(100), cegui_absdim(40)));
    btn->setText("blah");
   
    btn = static_cast<PushButton*>(wMgr.createWindow("TaharezLook/Button", "blah2"));
    vLayout->addChildWindow(btn);
    btn->setMinSize(UVector2(cegui_absdim(100), cegui_absdim(40)));
    btn->setText("blah2");
   
    HorizontalLayoutContainer *hLayout = static_cast<HorizontalLayoutContainer*>(wMgr.createWindow("HorizontalLayoutContainer"));
    vLayout->addChildWindow(hLayout);
   
    btn = static_cast<PushButton*>(wMgr.createWindow("TaharezLook/Button", "blah3"));
    hLayout->addChildWindow(btn);
    btn->setMinSize(UVector2(cegui_absdim(100), cegui_absdim(40)));
    btn->setText("blah3");
   
    btn = static_cast<PushButton*>(wMgr.createWindow("TaharezLook/Button", "blah4"));
    hLayout->addChildWindow(btn);
    btn->setMinSize(UVector2(cegui_absdim(100), cegui_absdim(40)));
    btn->setText("blah4");
   
    btn = static_cast<PushButton*>(wMgr.createWindow("TaharezLook/Button", "blah5"));
    vLayout->addChildWindow(btn);
    btn->setMinSize(UVector2(cegui_absdim(100), cegui_absdim(40)));
    btn->setText("blah5");

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: Automatic Layouting (horizontal, vertical, grid, ...)

Postby Kulik » Thu Aug 26, 2010 18:47

Layout can't contain other layouts. It can contain layouted windows. So the easiest solution here is to create a DefaultWindow and layout it with Horizontal Layout Container. So you would have a Vertical Layout Container containing DefaultWindows that would contain Horizontal Layout Containers :-) I can't try it now but I tried it before and it worked fine.

Perhaps in the future more changes can be introduced to make this possible but I can't make this happen till the code freeze on Saturday.

IR3uL
Not too shy to talk
Not too shy to talk
Posts: 45
Joined: Wed Aug 25, 2010 00:32
Location: Buenos Aires - Argentina

Re: Automatic Layouting (horizontal, vertical, grid, ...)

Postby IR3uL » Thu Aug 26, 2010 19:13

I'll implement it that way. Thanks for the help :wink:

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: Automatic Layouting (horizontal, vertical, grid, ...)

Postby Kulik » Mon Aug 30, 2010 23:52

Just a note: I finally got around to try the snippet and it works for me (0.7.2 release), I tried to do other nested layout containers and it worked too...

Can you please post a screenshot of whats wrong?

TBH it wasn't intentional that it works but it does :lol:

IR3uL
Not too shy to talk
Not too shy to talk
Posts: 45
Joined: Wed Aug 25, 2010 00:32
Location: Buenos Aires - Argentina

Re: Automatic Layouting (horizontal, vertical, grid, ...)

Postby IR3uL » Tue Aug 31, 2010 16:59

Image

The 5th button appears when y hover one of the others (TBH myself, i don't remember if this had the same behavior before). When i call layout() in all LCs everything works great. Maybe you can change the function to be recursive and call layout() in all child LCs.

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: Automatic Layouting (horizontal, vertical, grid, ...)

Postby Kulik » Tue Aug 31, 2010 17:28

Sadly I can't reproduce this :-( I immediately see all 5 buttons. I will try some more.

layout() actually does work in recursion but it works inside-out, not like you suggested.

When size of the parent window changes or windows are added/removed, layout containers react and mark themselves for relayouting. When child layout container relayouts it's content, the parent layout container is marker for relayouting again. At the moment this might be a wasted effort because the parent is relayouted first and then marked for relayouting again when child LC relayouts. I think we might move layoutIfNecessary to update() instead of drawSelf().

This becomes a problem with nested containers.

btw: Have you looked into the grid layout container? Perhaps it would fit your use case better.

IR3uL
Not too shy to talk
Not too shy to talk
Posts: 45
Joined: Wed Aug 25, 2010 00:32
Location: Buenos Aires - Argentina

Re: Automatic Layouting (horizontal, vertical, grid, ...)

Postby IR3uL » Tue Aug 31, 2010 17:46

Yes, i have tried it too, but for my current project is kind of useless. I'm replacing the gui code in Cube 2 engine to use CEGUI, but i still want to use the "old-style" method to define a menu, plus a couple more cmds like vlayout/hlayout. It looks something like this

newgui GuiName [
guibutton "The button text" "command to execute"
] GuiTitle

As you can see, is really easy to define a new menu in a script (they are quake-like scripts). I think a grid layout might be harder to define/use.


Return to “CEGUI Library Development Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests