Guiliani  Version 2.4 revision 5970 (build 3)
CGUILayouterPercentage Class Reference

This is a layouter, which resizes and repositions an object with regard to its parent. More...

#include <GUILayouterPercentage.h>

Inheritance diagram for CGUILayouterPercentage:

Public Member Functions

 CGUILayouterPercentage (CGUIObject *const pObject=NULL, const eC_Value vXPosPercentage=eC_FromInt(-1), const eC_Value vYPosPercentage=eC_FromInt(-1), const eC_Value vWidthPercentage=eC_FromInt(-1), const eC_Value vHeightPercentage=eC_FromInt(-1))
 
virtual ~CGUILayouterPercentage ()
 Destructs an Anchor-Layouter.
 
virtual void DoLayout (eMovedEdges_t eMovedEdges)
 
virtual eC_Bool IsDependentOnParentSize ()
 
virtual void ReadFromStream ()
 
void SetLayoutParameters (const eC_Value &vXPosPercentage, const eC_Value &vYPosPercentage, const eC_Value &vWidthPercentage, const eC_Value &vHeightPercentage)
 
virtual void WriteToStream (const eC_Bool bWriteClassID=false)
 
- Public Member Functions inherited from CGUILayouter
virtual ~CGUILayouter ()
 Destructor. More...
 
CGUIObjectGetAssociatedObject () const
 
virtual void InitLayouter (eMovedEdges_t eMovedEdges)
 
virtual eC_Bool IsGroupLayouter () const
 
virtual void SetAssociatedObject (CGUIObject *const pObject)
 
- Public Member Functions inherited from CGUIStreamableObject
const eC_String & GetXMLTag () const
 
void SetXMLTag (const eC_String &kXMLTag)
 

Static Public Attributes

static const eC_UInt LAYOUTER_PERCENTAGE_CLASS_VERSION = 1
 Class version for streaming.
 
- Static Public Attributes inherited from CGUILayouter
static const eC_Char XMLTAG_LAYOUTERCLASSID [] = "LayouterClassID"
 XML tag to be used when writing a layouter class ID into a stream.
 
- Static Public Attributes inherited from CGUIStreamableObject
static const eC_Char XMLTAG_CLASSVERSION [] = "ClassVersion"
 

Additional Inherited Members

- Public Types inherited from CGUILayouter
enum  eMovedEdges_t {
  CHANGED_WIDTH, CHANGED_HEIGHT, CHANGED_RELXPOS, CHANGED_RELYPOS,
  CHANGED_EDGE_ALL
}
 Enumerate possible reasons for calling layout,. More...
 
- Protected Member Functions inherited from CGUILayouter
 CGUILayouter (CGUIObject *const pObject=NULL)
 
- Protected Member Functions inherited from CGUIStreamableObject
eC_UInt ReadStreamingHeader (const eC_UInt &uiClassVersion, const eC_UInt &uiClassMinVersion=0) const
 
void WriteStreamingFooter (const eC_Bool &bWriteClassID) const
 
void WriteStreamingHeader (const eC_Bool &bWriteClassID, const eC_Char *const pkClassIDTag, const eC_Int &iClassID, const eC_UInt &uiClassVersion) const
 

Detailed Description

This is a layouter, which resizes and repositions an object with regard to its parent.

This layouter class is useful for designing dynamic layouts, where objects shall e.g., resize themselves when their containing window gets resized.

A CGUILayouterPercentage will resize and reposition its associated object according to the size of its parent object. This allows for an easy way to let an object e.g., always span across the entire width of its parent, or to always cover the parent's lower right quadrant etc.

Example:

// This lets the object cover the entire width of the parent. Position and height remain unchanged.
pLayouter->SetLayoutParameters(eC_FromFloat(0), eC_FromFloat(0), eC_FromFloat(1), eC_FromFloat(0));
// This lets the object cover the lower right quadrant
pLayouter->SetLayoutParameters(eC_FromFloat(0.5), eC_FromFloat(0.5), eC_FromFloat(0.5), eC_FromFloat(0.5));
// This lets the object cover the lower 10 percent of the screen
pLayouter->SetLayoutParameters(eC_FromFloat(0), eC_FromFloat(0.9), eC_FromFloat(1), eC_FromFloat(0.1));

Constructor & Destructor Documentation

◆ CGUILayouterPercentage()

CGUILayouterPercentage::CGUILayouterPercentage ( CGUIObject *const  pObject = NULL,
const eC_Value  vXPosPercentage = eC_FromInt(-1),
const eC_Value  vYPosPercentage = eC_FromInt(-1),
const eC_Value  vWidthPercentage = eC_FromInt(-1),
const eC_Value  vHeightPercentage = eC_FromInt(-1) 
)

Constructor.

Parameters
pObjectPointer to the object to which the layouter is attached.
vXPosPercentageThe associated object's relative x position is calculated as vXPosPercentage * Parent-Width
vYPosPercentageThe associated object's relative y position is calculated as vYPosPercentage * Parent-Height
vWidthPercentageThe associated object's width is calculated as vWidthPercentage * Parent-Width
vHeightPercentageThe associated object's height is calculated as vHeightPercentage * Parent-Height

Member Function Documentation

◆ DoLayout()

void CGUILayouterPercentage::DoLayout ( eMovedEdges_t  eMovedEdges)
virtual

Called when the size of the parent of the associated object has changed.

This method must be re-implemented in derived classes to perform the actual layout change, typically adjustments to the associated object's dimension or position.

It is called by the framework every time the width or height of the parent of the associated object has changed. The framework first calls DoLayout() on the associated object itself and then on all children of the associated object in any depth in the hierarchy.

There are two valid types of layouters: Either: Implementations of DoLayout() shall only adjust the associated object and/or direct children of it. No other decendants of the associated object shall be changed in position or size! This is called a group layouter. CGUILayouterReposition and CGUILayouterGrid are examples of group layouters. Or: Implementations of DoLayout() shall only adjust the associated object depending on the layout of its parent object. No other objects shall be changed in position or size! This is called a child layouter. CGUILayouterAnchor is an example of a child layouter.

Implementing other types of layouters may compromise the framework architecture.

The two use cases may overlap: If a direct child of a group layouter composite object has a child layouter then while streaming in the composite object associated with the group layouter, the composite will first call DoLayout() on its layouter and then call InitLayouter() on the layouters of all direct children of that composite object. Therefore, the group layouter will re-initialize the child layouter. For an anchor layouter this implies that the child layouter will have no effect and should be removed. Still the child layouter's DoLayout() will be called after the parent layouter's DoLayout() later on for any change of the size of the parent so that the child layouter might change (override) the layouting of the group layouter concerning its child layout, for example if using hardcoded values for anchor distances.

Parameters
eMovedEdgesReason for layouter call

Implements CGUILayouter.

◆ IsDependentOnParentSize()

virtual eC_Bool CGUILayouterPercentage::IsDependentOnParentSize ( )
inlinevirtual

This function shall determine if the layouter shall initially be called due to resizing the parent of the associated object or if it shall initially be called by resizing the associated object. If it returns false the framework will call DoLayout() on this layouter of the object that is triggering the layout procedure, that is, the composite object on which the first (in the current call stack) SetWidth() or SetHeight() is called.

Returning false is the typical use case for a group layouter that does not consider the layout of the parent of the associated object. In this case the initially resized object starting the layout procedure is the 'group object' itself, therefore you can say changing the 'group object' starts the layout procedure in this case.

If it returns true, the first DoLayout() is called on a child of the initially resized object. This is the typical use case for a child layouter or a group layouter that is considering the layout of 'its' parent. Therefore, you can say changing the parent is starting the layout procedure in this case.

Returns
eC_Bool True if dependend, False otherwise

Implements CGUILayouter.

◆ ReadFromStream()

void CGUILayouterPercentage::ReadFromStream ( )
virtual

Reads attributes from the streaming file. Only for use with GUIFactoryManager.

See also
CGUIObject::ReadFromStream()

Reimplemented from CGUIStreamableObject.

◆ SetLayoutParameters()

void CGUILayouterPercentage::SetLayoutParameters ( const eC_Value &  vXPosPercentage,
const eC_Value &  vYPosPercentage,
const eC_Value &  vWidthPercentage,
const eC_Value &  vHeightPercentage 
)

Sets the layout parameters by which the object is scaled and positioned. Legal values are in the range of 0 to 1. The values will be used as factors by which the respective attributes get multiplied. A value of <=0 means that the corresponding attribute will not be affected by layouting.

Parameters
vXPosPercentageThe associated object's relative x position is calculated as vXPosPercentage * Parent-Width
vYPosPercentageThe associated object's relative y position is calculated as vYPosPercentage * Parent-Height
vWidthPercentageThe associated object's width is calculated as vWidthPercentage * Parent-Width
vHeightPercentageThe associated object's height is calculated as vHeightPercentage * Parent-Height

◆ WriteToStream()

void CGUILayouterPercentage::WriteToStream ( const eC_Bool  bWriteClassID = false)
virtual

Writes attributes to the streaming file. A CGUIStreamWriter has to be initialized.

Parameters
bWriteClassIDThis flag is used to switch writing of the class ID, leading and trailing tags. When implementing a new streamable object, check this flag. If it is true, first write the class ID, then continue with this object's attributes, and finally call the base class implementation with this flag set to false (this is the default).

Reimplemented from CGUIStreamableObject.


The documentation for this class was generated from the following files: