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];
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.
std::string backgroundPixmap() const
Return the name of the background pixmap or an empty string, if there is none.
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.