Positioning rectangles


#1

I can see three rectangle positioning classes, all in different places!

JUCE/modules/juce_gui_basics/positioning/juce_RelativeRectangle.h
JUCE/modules/juce_graphics/geometry/juce_Rectangle.h
JUCE/modules/juce_graphics/placement/juce_RectanglePlacement.h

What's going on here? Are all of these still 'current'? Or is there some legacy business going on?

Is there any publicly available code that puts GUI positioning through its paces?  In the demo, things seem to be positioned by pixel (it would be  handy if the demo could demonstrate modern/current JUCE techniques for positioning GUI elements).

Could someone give a very basic rundown of what is available for GUI placement?

π


#2

Well, they're all entirely different things with different purposes.

Rectangle is just a rectangle.

RectanglePlacement is just some flags used to indicate how to lay out objects.

RelativeRectangle is a "smart" object that can handle expressions and stuff.. This one isn't "legacy" but it is something that I don't consider to have been a very good idea, and I'd recommend against using it, as I would probably like to get rid of it eventually.


#3

Thanks, could you possibly give a scenario/example of RectanglePlacement in action?  I can't quite see how it is meant to be used, or for what it is intended.


#4

Try searching the codebase - there are hundreds of examples of it being used.


#5

So there are. My bad, I didn't even think to look.

https://github.com/julianstorer/JUCE/blob/f1ad44e2bfd49acd19800342e944aaec7a3c04dd/examples/Demo/Source/Demos/WindowsDemo.cpp#L282 <-- looks like this line's a deadun btw

Maybe https://www.juce.com/doc/classRectangle under "See also:" could reference RectanglePlacement ...

Also for the detailed description, maybe something like the following would help a newcomer:

Helper class for positioning one rectangle inside another, e.g.

// justify 20x10 rect along bottom of viewport
RectanglePlacement placementObject { 
    RectanglePlacement::xMid  
  | RectanglePlacement::yBottom 
  | RectanglePlacement::doNotResize };
Rectangle<int> viewport{100,100},  r{20,10},  output = placementObject.appliedTo(r, viewport);
DBG(output.toString()); //40 90 20 10

That instantly gets to the heart of it.  The current description makes perfect sense if you already understand what the class is doing, but for a newcomer it's maybe a little tricky to grok.

I mean the thing is trivial once you see it. But if you've never seen that construct, and are just browsing API...

I frequently think about the idea of documenting an entire technology primarily with minimal examples. A bit like https://docs.python.org/3/tutorial/introduction.html but pushed even further i.e. Accompanying text starts to become the exception rather than the default.

I tutor maths for my day job, and I find the same kind of thing works really well. In fact I'm using JUCE to teach one boy C++, and he gets everything straightaway if I just give examples. But it's ten times more work to use English.

Using JUCE as a vehicle for teaching C++ is rather an interesting idea I think. Because graphics, audio, etc are at hand, so it brings it to life. Otherwise it's a bit dry working with console output. And the fact JUCE works on the three major desktop platforms means that you could teach a class and not worry about individual students constantly running into platform specific issues because they have different laptop OS.

mmm late night ramble.  But if you can't ramble on a forum, where?? :)

π


#6

Does this also apply to MarkerList which seems bound up with the RelativeRectangle stuff?


#7

Yeah, markerlist was part of that whole thing. Best avoided.