26 #define YUILogComponent "ui" 29 #include "YAlignment.h" 32 #include "Libyui_config.h" 43 YAlignmentType vertAlign )
51 alignment.hor = horAlign;
52 alignment.vert = vertAlign;
67 string backgroundPixmap;
76 YAlignmentType horAlign,
77 YAlignmentType vertAlign )
81 YUI_CHECK_NEW( priv );
94 return priv->alignment[ dim ];
100 return priv->leftMargin;
106 return priv->rightMargin;
112 return priv->topMargin;
118 return priv->bottomMargin;
124 priv->leftMargin = margin;
130 priv->rightMargin = margin;
136 priv->topMargin = margin;
142 priv->bottomMargin = margin;
148 return priv->minWidth;
154 return priv->minHeight;
160 priv->minWidth = width;
166 priv->minHeight = height;
172 return priv->backgroundPixmap;
222 yuiError() <<
"No child in " <<
this << endl;
228 newSize.hor = newWidth;
229 newSize.vert = newHeight;
242 YUIDimension dim = YD_HORIZ;
255 newChildSize[ dim ] = newSize[ dim ] - totalMargin[ dim ];
259 newChildSize[ dim ] = childPreferredSize;
262 else if ( newSize[ dim ] >= childPreferredSize )
265 newChildSize[ dim ] = childPreferredSize;
269 if ( totalMargin[ dim ] > 0 )
274 int remaining = newSize[ dim ] - childPreferredSize;
275 offset [ dim ] = remaining * offset[ dim ] / totalMargin[ dim ];
276 totalMargin[ dim ] = remaining;
282 newChildSize[ dim ] = newSize[ dim ];
284 totalMargin [ dim ] = 0;
291 newChildPos[ dim ] = ( newSize[ dim ] - newChildSize[ dim ] - totalMargin[ dim ] ) / 2;
294 case YAlignUnchanged:
296 newChildPos[ dim ] = 0;
300 newChildPos[ dim ] = newSize[ dim ] - newChildSize[ dim ] - totalMargin[ dim ];
304 newChildPos[ dim ] += offset[ dim ];
317 yuiDebug() <<
"setSize( alignment, " << newWidth <<
", " << newHeight <<
")" << endl;
318 yuiDebug() <<
"setSize( child, " << newChildSize.hor <<
", " << newChildSize.vert <<
")" << endl;
319 yuiDebug() <<
"moveChild( " << newChildPos.hor <<
", " << newChildPos.vert <<
")" << endl;
335 string pixmap = pixmapFileName;
337 if ( pixmap.length() > 0 &&
343 YPath pix( THEMEDIR, pixmap );
348 priv->backgroundPixmap = pixmap;
354 static const char *YAlignment_classes[3][5] =
356 {
"YAlignment_Left",
"YAlignment_HCenter",
"YAlignment_Right",
"YMarginBox",
"YMinWidth"},
357 {
"YAlignment_Top",
"YAlignment_VCenter",
"YAlignment_Bottom",
"YMarginBox",
"YMinHeight"},
358 {0,
"YAlignment_HVCenter", 0,
"YAlignment",
"YMinSize"},
364 if ( priv->alignment.hor == YAlignBegin ) { vIndex = 0; hIndex = 0; }
365 else if ( priv->alignment.hor == YAlignEnd ) { vIndex = 0; hIndex = 2; }
366 else if ( priv->alignment.hor == YAlignCenter )
368 vIndex = 0; hIndex = 1;
369 if ( priv->alignment.vert == YAlignCenter )
372 else if ( priv->alignment.vert == YAlignBegin ) { vIndex = 1; hIndex = 0; }
373 else if ( priv->alignment.vert == YAlignEnd ) { vIndex = 1; hIndex = 2; }
374 else if ( priv->alignment.vert == YAlignCenter ) { vIndex = 1; hIndex = 1; }
376 if ( priv->alignment.hor == YAlignUnchanged &&
377 priv->alignment.vert == YAlignUnchanged )
379 if ( priv->leftMargin > 0 ||
380 priv->rightMargin > 0 ||
381 priv->topMargin > 0 ||
382 priv->bottomMargin > 0 )
384 vIndex = 0; hIndex = 3;
387 if ( priv->minWidth > 0 || priv->minHeight > 0 )
389 if ( priv->minWidth == 0 ) { vIndex = 1; hIndex = 4; }
390 else if ( priv->minHeight == 0 ) { vIndex = 0; hIndex = 4; }
391 else { vIndex = 2; hIndex = 4; }
394 return YAlignment_classes[vIndex][hIndex];
std::string backgroundPixmap() const
Return the name of the background pixmap or an empty string, if there is none.
std::string path()
Returns the full path of the file if found; if not found just the filename given in constructor...
int minWidth() const
Return the minimum width of this alignment or 0 if none is set.
int minHeight() const
Return the minimum height of this alignment or 0 if none is set.
virtual bool stretchable(YUIDimension dim) const
Return this widget's stretchability.
virtual int preferredHeight()
Preferred height of the widget.
virtual void moveChild(YWidget *child, int newx, int newy)=0
Move a child widget to a new position.
YAlignment(YWidget *parent, YAlignmentType horAlign, YAlignmentType vertAlign)
Constructor.
virtual void addChild(YWidget *child)
Add a child widget.
void setMinHeight(int height)
Set the minimum height to return for preferredHeight().
virtual void setSize(int newWidth, int newHeight)
Set the current size and move the child widget according to its alignment.
void setMinWidth(int width)
Set the minimum width to return for preferredWidth().
YAlignmentType alignment(YUIDimension dim) const
Return the alignment in the specified dimension.
virtual const char * widgetClass() const
Return a descriptive name of this widget class for logging, debugging etc.
void setRightMargin(int margin)
Set the right margin in pixels.
virtual int preferredWidth()
Preferred width of the widget.
void setBottomMargin(int margin)
Set the bottom margin in pixels.
int topMargin() const
Return the top margin in pixels, the distance between the top edge of this alignment and the top edge...
virtual void setBackgroundPixmap(const std::string &pixmapFileName)
Set a background pixmap.
int bottomMargin() const
Return the bottom margin in pixels, the distance between the bottom edge of this alignment and the bo...
void setTopMargin(int margin)
Set the top margin in pixels.
int totalMargins(YUIDimension dim) const
Return the sum of all margins in the specified dimension.
int leftMargin() const
Return the left margin in pixels, the distance between the left edge of this alignment and the left e...
YAlignmentPrivate(YAlignmentType horAlign, YAlignmentType vertAlign)
Constructor.
int rightMargin() const
Return the right margin in pixels, the distance between the right edge of this alignment and the righ...
virtual ~YAlignment()
Destructor.
void setLeftMargin(int margin)
Set the left margin in pixels.