Merge lp://staging/~rafalcieslak256/millenniumduel/containers into lp://staging/millenniumduel

Proposed by Rafał Cieślak
Status: Merged
Merged at revision: 10
Proposed branch: lp://staging/~rafalcieslak256/millenniumduel/containers
Merge into: lp://staging/millenniumduel
Diff against target: 765 lines (+408/-108)
18 files modified
src/Box.cpp (+59/-0)
src/Box.hpp (+47/-0)
src/Fixed.cpp (+28/-30)
src/Fixed.hpp (+17/-16)
src/HBox.cpp (+61/-0)
src/HBox.hpp (+11/-0)
src/VBox.cpp (+60/-0)
src/VBox.hpp (+11/-0)
src/build (+1/-1)
src/button.cpp (+10/-4)
src/button.hpp (+5/-2)
src/display.cpp (+9/-10)
src/display.hpp (+6/-4)
src/drawable.cpp (+17/-7)
src/drawable.hpp (+33/-11)
src/label.cpp (+11/-4)
src/label.hpp (+4/-1)
src/main.cpp (+18/-18)
To merge this branch: bzr merge lp://staging/~rafalcieslak256/millenniumduel/containers
Reviewer Review Type Date Requested Status
Adam Malinowski Approve
Jakub Sękowski Approve
Review via email: mp+176052@code.staging.launchpad.net

Description of the change

This branch implements Container widgets (namely a custom VBox and a HBox).
[https://blueprints.launchpad.net/millenniumduel/+spec/millenniumduel-containers]

These widgets are meant to spread evenly widgets aligned horizontally or vertically.

They are kind of similar to GTK's boxes, but one should not assume any similarities.

This branch also significantly changes the way draw() is used. It is now called with a set of 4 values, representing coordinates of a rectangular area where the widget should draw itself.
This way all widgets can be drawn in variety of sizes.

All Drawables can also provide the minimal size they need for drawing (for example, a button cannot be too thin or its text will not fit). These can be learned by calling GetMinimalHeight and GetMinimalWidth.

Both boxes are used by appending widgets with Add(drawable). By default all items are shrinked to minimum, except for those that are added with BOX_EXPAND as a second argument to Add, these will be spread evenly.
One can set the space between boxes with SetSpacing, as well as the margin around the Box with SetMargin (both default to 0).

Of course, Boxes are also a Drawable, and therefore can be nested freely.

Another change introduced by this branch is that a View widget (renamed to Fixed) is now a Drawable.
The Display class requires now a Drawable to be the topmost widget, it does not have to be a Fixed (View).

The example in main() sets a VBox as the main menu, shrinking and expanding some of the buttons. The additional menu is left as it was, as a Fixed.

NOTE: This code does not fix bug #1198640.

To post a comment you must log in.
Revision history for this message
Jakub Sękowski (sequba) wrote :

Why items in Box are stored in a set? I would use list or vector instead. Ordering of items would be clear and member order (of struct BoxEntry) wouldn't be needed.

Revision history for this message
Rafał Cieślak (rafalcieslak256) wrote :

My idea is that one may wish to insert a widget *between* some that already exist. This might be done using a vector too, but inserting items there may look more tricky, as the indexes might change in the meantime. The solution I implemented binds a (potentially) number to each item, so that one can freely insert the items wherever wanted.

Also please note that the struct BoxEntry would still be needed, as it also keeps info about the current size of the widget, the Drawables themselves do not store it, and it has to be recalculated from time to time to ensure proper widget resizing.

Revision history for this message
Jakub Sękowski (sequba) wrote :

In my opinion, that's exactly what we need.

I'm still not fully convinced of set and that weird attribute "order", but it may indeed be more convenient to use it this way.

Approve.

review: Approve
Revision history for this message
Adam Malinowski (adayah) wrote :

I love the code you wrote. It's elegant and very powerful, and is going to save us a lot of effort.

However, I discovered a minor bug. When examined carefully, it turns out, that buttons' click sensivity areas are a bit offset upwards with respect to their drawings.
I think I can tell which part of code needs a correction. In functions HBox::on_clicked and VBox::on_clicked, the 'sum' variable should be initialized with:

int sum = margin;

instead of actual:

int sum = 0;

Very nice job!

review: Needs Fixing
22. By Rafał Cieślak

Fixed click detection allignment

Revision history for this message
Adam Malinowski (adayah) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches