IGUIElement::getAlignment() suggestion
Posted: Tue Dec 31, 2019 10:03 am
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
IGUIElement.h
I considered using a single function that took an index, but it was more confusing and the above solution was just as clean.
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) {}
};
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 );
}