// GetHeightForWidth void BCardLayout::GetHeightForWidth(float width, float* min, float* max, float* preferred) { _ValidateMinMax(); // init with useful values float minHeight = fMin.height; float maxHeight = fMax.height; float preferredHeight = fPreferred.height; // apply the items' constraints int32 count = CountItems(); for (int32 i = 0; i < count; i++) { BLayoutItem* item = ItemAt(i); if (item->HasHeightForWidth()) { float itemMinHeight; float itemMaxHeight; float itemPreferredHeight; item->GetHeightForWidth(width, &itemMinHeight, &itemMaxHeight, &itemPreferredHeight); minHeight = max_c(minHeight, itemMinHeight); maxHeight = min_c(maxHeight, itemMaxHeight); preferredHeight = min_c(preferredHeight, itemPreferredHeight); } } // adjust max and preferred, if necessary maxHeight = max_c(maxHeight, minHeight); preferredHeight = max_c(preferredHeight, minHeight); preferredHeight = min_c(preferredHeight, maxHeight); if (min) *min = minHeight; if (max) *max = maxHeight; if (preferred) *preferred = preferredHeight; }
bool BTwoDimensionalLayout::LocalLayouter::AddHeightForWidthConstraints( VerticalCompoundLayouter* compoundLayouter, Layouter* layouter, BLayoutContext* context) { if (context != fHorizontalLayoutContext) return false; if (fHeightForWidthConstraintsAdded) return false; LayoutInfo* hLayoutInfo = fHLayouter->GetLayoutInfo(); // add the children's height for width constraints int32 itemCount = fHeightForWidthItems.CountItems(); for (int32 i = 0; i < itemCount; i++) { BLayoutItem* item = (BLayoutItem*)fHeightForWidthItems.ItemAt(i); Dimensions itemDimensions; fLayout->GetItemDimensions(item, &itemDimensions); float minHeight, maxHeight, preferredHeight; item->GetHeightForWidth( hLayoutInfo->ElementRangeSize(itemDimensions.x, itemDimensions.width), &minHeight, &maxHeight, &preferredHeight); layouter->AddConstraints( itemDimensions.y, itemDimensions.height, minHeight, maxHeight, preferredHeight); } SetHeightForWidthConstraintsAdded(true); return true; }
void BSplitLayout::_InternalGetHeightForWidth(float width, bool realLayout, float* minHeight, float* maxHeight, float* preferredHeight) { if ((realLayout && fHeightForWidthVerticalLayouterWidth != width) || (!realLayout && fCachedHeightForWidthWidth != width)) { // The general strategy is to clone the vertical layouter, which only // knows the general min/max constraints, do a horizontal layout for the // given width, and add the children's height for width constraints to // the cloned vertical layouter. If this method is invoked internally, // we keep the cloned vertical layouter, for it will be used for doing // the layout. Otherwise we just drop it after we've got the height for // width info. // clone the vertical layouter and get the horizontal layout info to be used LayoutInfo* horizontalLayoutInfo = NULL; Layouter* verticalLayouter = fVerticalLayouter->CloneLayouter(); if (realLayout) { horizontalLayoutInfo = fHorizontalLayoutInfo; delete fHeightForWidthVerticalLayouter; fHeightForWidthVerticalLayouter = verticalLayouter; delete fVerticalLayoutInfo; fVerticalLayoutInfo = verticalLayouter->CreateLayoutInfo(); fHeightForWidthVerticalLayouterWidth = width; } else { if (fHeightForWidthHorizontalLayoutInfo == NULL) { delete fHeightForWidthHorizontalLayoutInfo; fHeightForWidthHorizontalLayoutInfo = fHorizontalLayouter->CreateLayoutInfo(); } horizontalLayoutInfo = fHeightForWidthHorizontalLayoutInfo; } // do the horizontal layout (already done when doing this for the real // layout) if (!realLayout) fHorizontalLayouter->Layout(horizontalLayoutInfo, width); // add the children's height for width constraints int32 count = fHeightForWidthItems.CountItems(); for (int32 i = 0; i < count; i++) { BLayoutItem* item = (BLayoutItem*)fHeightForWidthItems.ItemAt(i); int32 index = fVisibleItems.IndexOf(item); if (index >= 0) { float itemMinHeight, itemMaxHeight, itemPreferredHeight; item->GetHeightForWidth( horizontalLayoutInfo->ElementSize(index), &itemMinHeight, &itemMaxHeight, &itemPreferredHeight); verticalLayouter->AddConstraints(index, 1, itemMinHeight, itemMaxHeight, itemPreferredHeight); } } // get the height for width info fCachedHeightForWidthWidth = width; fCachedMinHeightForWidth = verticalLayouter->MinSize(); fCachedMaxHeightForWidth = verticalLayouter->MaxSize(); fCachedPreferredHeightForWidth = verticalLayouter->PreferredSize(); } if (minHeight) *minHeight = fCachedMinHeightForWidth; if (maxHeight) *maxHeight = fCachedMaxHeightForWidth; if (preferredHeight) *preferredHeight = fCachedPreferredHeightForWidth; }