Page 1 of 1

IGUIElement::getAlignment() suggestion

Posted: Tue Dec 31, 2019 10:03 am
by chronologicaldot
Not very important, but I ran across a case where I needed the alignment of a GUI element: It happens when you have one element that you want to add "transparently" (in a metaphorical sense) by having it wrap another element. To do that, it's easy enough to just grab the position of the inner element and make it that of the outer element while expanding the inner element to be glued to the outer one. Unfortunately, for the whole thing to work on resize, I need to get the alignment as well. I came up with my own little fix, which was to add a simple struct called AlignmentInfo to EGUIAlignment.h and add a setter and getter to IGUIElement.

EGUIAlignment.h

Code: Select all

 
// Preceded by GUIAlignmentNames [] ...
 
//! Convenient packaging of alignment info
struct AlignmentInfo
{
    EGUI_ALIGNMENT left;
    EGUI_ALIGNMENT right;
    EGUI_ALIGNMENT top;
    EGUI_ALIGNMENT bottom;
 
    AlignmentInfo() : left( EGUIA_UPPERLEFT ), right( EGUIA_UPPERLEFT ), top( EGUIA_UPPERLEFT ), bottom( EGUIA_UPPERLEFT ) {}
    AlignmentInfo( EGUI_ALIGNMENT l, EGUI_ALIGNMENT r, EGUI_ALIGNMENT t, EGUI_ALIGNMENT b ) : left(l), right(r), top(t), bottom(b) {}
};
 
IGUIElement.h

Code: Select all

 
// Preceded by setAlignment() {} ...
 
    //! Set the alignment with an info struct
    void setAlignment( AlignmentInfo info )
    {
        setAlignment( info.left, info.right, info.top, info.bottom );
    }
 
 
    //! Retrieve the alignment.
    AlignmentInfo  getAlignment() const
    {
        return AlignmentInfo( AlignLeft, AlignRight, AlignTop, AlignBottom );
    }
 
I considered using a single function that took an index, but it was more confusing and the above solution was just as clean.

Re: IGUIElement::getAlignment() suggestion

Posted: Tue Dec 31, 2019 6:39 pm
by CuteAlien
Hm, indeed no getter so far. We could add 4 functions getAlignmentLeft, getAlignmentRight, getAlignmentTop, getAlignmentBottom.
Setter/getter are then a bit asymmetric, but avoids adding a new struct.

Nicest c++ solution would probably be to use an inner class (or struct) in IGUIElement, but not sure how well those work with language wrappers.