26 #define YUILogComponent "ui"
29 #include "YAlignment.h"
33 #include "Libyui_config.h"
44 YAlignmentType vertAlign )
52 alignment.hor = horAlign;
53 alignment.vert = vertAlign;
68 std::string backgroundPixmap;
77 YAlignmentType horAlign,
78 YAlignmentType vertAlign )
82 YUI_CHECK_NEW( priv );
95 return priv->alignment[ dim ];
101 return priv->leftMargin;
107 return priv->rightMargin;
113 return priv->topMargin;
119 return priv->bottomMargin;
125 priv->leftMargin = margin;
131 priv->rightMargin = margin;
137 priv->topMargin = margin;
143 priv->bottomMargin = margin;
149 return priv->minWidth;
155 return priv->minHeight;
161 priv->minWidth = width;
167 priv->minHeight = height;
173 return priv->backgroundPixmap;
203 return std::max(
minWidth(), preferredWidth );
215 return std::max(
minHeight(), preferredHeight );
223 yuiError() <<
"No child in " <<
this << std::endl;
229 newSize.hor = newWidth;
230 newSize.vert = newHeight;
243 YUIDimension dim = YD_HORIZ;
249 if ( newSize[ dim ] >= preferredSize )
256 newChildSize[ dim ] = newSize[ dim ] - totalMargin[ dim ];
260 newChildSize[ dim ] = childPreferredSize;
263 else if ( newSize[ dim ] >= childPreferredSize )
266 newChildSize[ dim ] = childPreferredSize;
270 if ( totalMargin[ dim ] > 0 )
275 int remaining = newSize[ dim ] - childPreferredSize;
276 offset [ dim ] = remaining * offset[ dim ] / totalMargin[ dim ];
277 totalMargin[ dim ] = remaining;
283 newChildSize[ dim ] = newSize[ dim ];
285 totalMargin [ dim ] = 0;
292 newChildPos[ dim ] = ( newSize[ dim ] - newChildSize[ dim ] - totalMargin[ dim ] ) / 2;
295 case YAlignUnchanged:
297 newChildPos[ dim ] = 0;
301 newChildPos[ dim ] = newSize[ dim ] - newChildSize[ dim ] - totalMargin[ dim ];
305 newChildPos[ dim ] += offset[ dim ];
318 yuiDebug() <<
"setSize( alignment, " << newWidth <<
", " << newHeight <<
")" << std::endl;
319 yuiDebug() <<
"setSize( child, " << newChildSize.hor <<
", " << newChildSize.vert <<
")" << std::endl;
320 yuiDebug() <<
"moveChild( " << newChildPos.hor <<
", " << newChildPos.vert <<
")" << std::endl;
336 std::string pixmap = pixmapFileName;
338 if ( pixmap.length() > 0 &&
344 YPath pix( THEMEDIR, pixmap );
349 priv->backgroundPixmap = pixmap;
355 static const char *YAlignment_classes[3][5] =
357 {
"YAlignment_Left",
"YAlignment_HCenter",
"YAlignment_Right",
"YMarginBox",
"YMinWidth"},
358 {
"YAlignment_Top",
"YAlignment_VCenter",
"YAlignment_Bottom",
"YMarginBox",
"YMinHeight"},
359 {0,
"YAlignment_HVCenter", 0,
"YAlignment",
"YMinSize"},
365 if ( priv->alignment.hor == YAlignBegin ) { vIndex = 0; hIndex = 0; }
366 else if ( priv->alignment.hor == YAlignEnd ) { vIndex = 0; hIndex = 2; }
367 else if ( priv->alignment.hor == YAlignCenter )
369 vIndex = 0; hIndex = 1;
370 if ( priv->alignment.vert == YAlignCenter )
373 else if ( priv->alignment.vert == YAlignBegin ) { vIndex = 1; hIndex = 0; }
374 else if ( priv->alignment.vert == YAlignEnd ) { vIndex = 1; hIndex = 2; }
375 else if ( priv->alignment.vert == YAlignCenter ) { vIndex = 1; hIndex = 1; }
377 if ( priv->alignment.hor == YAlignUnchanged &&
378 priv->alignment.vert == YAlignUnchanged )
380 if ( priv->leftMargin > 0 ||
381 priv->rightMargin > 0 ||
382 priv->topMargin > 0 ||
383 priv->bottomMargin > 0 )
385 vIndex = 0; hIndex = 3;
388 if ( priv->minWidth > 0 || priv->minHeight > 0 )
390 if ( priv->minWidth == 0 ) { vIndex = 1; hIndex = 4; }
391 else if ( priv->minHeight == 0 ) { vIndex = 0; hIndex = 4; }
392 else { vIndex = 2; hIndex = 4; }
395 return YAlignment_classes[vIndex][hIndex];