suic::Size HeaderedContentControl::ArrangeOverride(const suic::Size& availableSize) { ClearVisualChildren(); suic::Rect finalRect(0, 0, availableSize.cx, availableSize.cy); if (_header) { finalRect.bottom = finalRect.top + _header->GetDesiredSize().cy; finalRect.left += _indent; finalRect.right = finalRect.left + _header->GetDesiredSize().cx; AddVisualChild(_header.get()); _header->Arrange(finalRect); finalRect.left = 0; finalRect.top = finalRect.bottom; finalRect.bottom = availableSize.cy; finalRect.right = availableSize.cx; } if (_content && _content->IsVisible()) { AddVisualChild(_content.get()); _content->Arrange(finalRect); } return availableSize; }
suic::Size TabControl::ArrangeOverride(const suic::Size& size) { ClearVisualChildren(); _headerPanel.ClearLogicalChildren(); int iItems = GetItems()->GetCount(); suic::Rect finalRect(0, 0, size.cx, size.cy); if (_isAverage && iItems > 0) { TabItemPtr tabItem; int iWid = size.cx / iItems; suic::Size itemSize(iWid, _headerHeight); for (int i = 0; i < iItems - 1; ++i) { tabItem = GetItems()->GetItem(i).get(); tabItem->SetDesiredSize(itemSize); } tabItem = GetItems()->GetItem(iItems - 1).get(); itemSize.cx = size.cx - iWid * (iItems - 1); tabItem->SetDesiredSize(itemSize); for (int i = 0; i < iItems; ++i) { tabItem = GetItems()->GetItem(i).get(); _headerPanel.AddLogicalChild(tabItem.get()); } finalRect.bottom = finalRect.top + _headerHeight; AddVisualChild(&_headerPanel); _headerPanel.Arrange(finalRect); finalRect.top = finalRect.bottom; finalRect.bottom = size.cy; } TabItemPtr focusTab(_focusItem); if (focusTab) { if (focusTab->GetTabContent()) { AddVisualChild(focusTab->GetTabContent()); focusTab->GetTabContent()->Arrange(finalRect); } } return size; }
suic::Size WrapPanel::ArrangeOverride(const suic::Size& size) { ClearVisualChildren(); suic::Rect rect; int iPerRowCount = size.cx / (_horizontalSpace + _itemWidth); int iRight = size.cx - GetBorderThickness().right - _horizontalSpace; int iBottom = size.cy - GetBorderThickness().bottom - _verticalSpace; if (iPerRowCount == 0) { ++iPerRowCount; } int iRowHei = iPerRowCount * (_verticalSpace + _itemHeight); int iRowWid = iPerRowCount * (_horizontalSpace + _itemWidth) - _horizontalSpace; int iRealCount = 0; rect.left = GetBorderThickness().left + _horizontalSpace; rect.top = GetBorderThickness().top + _verticalSpace; for (int i = 0; i < GetChildrenCount(); ++i) { suic::Element* pElem = GetChild(i); if (pElem->IsVisible()) { ++iRealCount; rect.right = rect.left + _itemWidth; rect.bottom = rect.top + _itemHeight; AddVisualChild(pElem); pElem->Arrange(rect); rect.left = rect.right + _horizontalSpace; if (rect.right >= iRowWid) { rect.left = GetBorderThickness().left + _horizontalSpace; rect.top = rect.bottom + _verticalSpace; } if (rect.bottom >= iBottom) { break; } } } return size; }
suic::Size ScrollViewer::ArrangeOverride(const suic::Size& availableSize) { ClearVisualChildren(); suic::ElementPtr cont(GetContent()); if (cont) { suic::Rect rect; rect.right = availableSize.cx; rect.bottom = availableSize.cy; _vScroll->SetVisible(false); _hScroll->SetVisible(false); suic::Size desiredSize = cont->GetDesiredSize(); // // 计算是否有滚动条 // _hScroll->UpdateScrollInfo(rect.right, desiredSize.cx, false); _vScroll->UpdateScrollInfo(rect.bottom, desiredSize.cy, false); ComputeScrollBar(rect.right, rect.bottom, desiredSize.cx, desiredSize.cy); suic::PanelPtr lay(cont); if (lay) { lay->SetHorizontalOffset(_hScroll->GetScrollSize()); lay->SetVerticalOffset(_vScroll->GetScrollSize()); } rect.left += _contentOffset.x; rect.top += _contentOffset.y; if (rect.bottom > rect.top) { AddVisualChild(cont.get()); cont->Arrange(rect); } } return availableSize; }
suic::Size TreeViewItem::ArrangeOverride(const suic::Size& finalSize) { // 先清除可视节点 ClearVisualChildren(); const int ITEMSPACE = 2; suic::Rect finalRect(0, 0, finalSize.cx, 0); // 布局扩展按钮 if (_expand->IsVisible()) { finalRect.right = finalRect.left + _expand->GetDesiredSize().cx; finalRect.top = (_header->GetDesiredSize().cy - _expand->GetDesiredSize().cy) / 2; finalRect.bottom = finalRect.top + _expand->GetDesiredSize().cy; AddVisualChild(_expand.get()); _expand->Arrange(finalRect); finalRect.left = finalRect.right + 12; } // 布局选择按钮 if (_check.IsVisible()) { finalRect.right = finalRect.left + _check.GetDesiredSize().cx; finalRect.top = (_header->GetDesiredSize().cy - _check.GetDesiredSize().cy) / 2; finalRect.bottom = finalRect.top + _check.GetDesiredSize().cy; AddVisualChild(&_check); _check.Arrange(finalRect); finalRect.left = finalRect.right; } if (_icon) { // 布局图标 suic::Rect rcIcon(_icon->GetContentBrounds()); } finalRect.right = finalRect.left + _header->GetDesiredSize().cx; finalRect.top = 0; finalRect.bottom = _header->GetDesiredSize().cy; AddVisualChild(_header.get()); _header->Arrange(finalRect); finalRect.top = finalRect.bottom; finalRect.left = GetIndent(); if (!IsCollapsed()) { for (int i = 0; i < GetItems()->GetCount(); ++i) { TreeViewItemPtr item(GetItems()->GetItem(i)); finalRect.right = finalRect.left + item->GetDesiredSize().cx; finalRect.bottom = finalRect.top + item->GetDesiredSize().cy; AddVisualChild(item.get()); item->Arrange(finalRect); finalRect.top = finalRect.bottom; } } return finalSize; }
suic::Size ScrollBar::ArrangeOverride(const suic::Size& size) { ClearVisualChildren(); bool bChanged = false; suic::Rect finalRect; suic::Rect downRect; if (GetOrientation() == CoreFlags::Horizontal) { UpdateScrollVisual(size.cx, false); finalRect.bottom = _decreaseBtn.GetDesiredSize().cy; } else { UpdateScrollVisual(size.cy, false); finalRect.right = _decreaseBtn.GetDesiredSize().cx; } suic::Rect rcThumb; if (!_rcTrack.Empty()) { suic::Point ptSelf = PointToScreen(suic::Point()); rcThumb = _rcTrack; rcThumb.Offset(-ptSelf.x, -ptSelf.y); } else { rcThumb = GetScrollThumbRect(size); } if (GetOrientation() == CoreFlags::Horizontal) { if (_increaseBtn.IsVisible()) { downRect.bottom = _increaseBtn.GetDesiredSize().cy; downRect.right = size.cx; downRect.left = size.cx - _increaseBtn.GetDesiredSize().cx; } /*if (size.cx < downRect.Width() + finalRect.Width()) { return size; }*/ } else { if (_increaseBtn.IsVisible()) { downRect.right = _increaseBtn.GetDesiredSize().cx; downRect.bottom = size.cy; downRect.top = size.cy - _increaseBtn.GetDesiredSize().cy; } /*if (size.cy < downRect.Height() + finalRect.Height()) { return size; }*/ } if (_decreaseBtn.IsVisible()) { finalRect.right = _decreaseBtn.GetDesiredSize().cx; finalRect.bottom = _decreaseBtn.GetDesiredSize().cy; AddVisualChild(&_decreaseBtn); _decreaseBtn.Arrange(finalRect); } if (!rcThumb.Empty()) { if (GetOrientation() == CoreFlags::Horizontal) { finalRect.left = finalRect.right; finalRect.right = rcThumb.left; if (!finalRect.Empty()) { AddVisualChild(&_decreasePage); _decreasePage.Arrange(finalRect); } finalRect.left = rcThumb.left; finalRect.right = rcThumb.right; AddVisualChild(&_thumb); _thumb.Arrange(finalRect); finalRect.left = rcThumb.right; finalRect.right = size.cx - downRect.Width(); AddVisualChild(&_increasePage); _increasePage.Arrange(finalRect); } else { finalRect.top = finalRect.bottom; finalRect.bottom = rcThumb.top; if (!finalRect.Empty()) { AddVisualChild(&_decreasePage); _decreasePage.Arrange(finalRect); } finalRect.top = rcThumb.top; finalRect.bottom = rcThumb.bottom; AddVisualChild(&_thumb); _thumb.Arrange(finalRect); finalRect.top = rcThumb.bottom; finalRect.bottom = size.cy - downRect.Height(); AddVisualChild(&_increasePage); _increasePage.Arrange(finalRect); } } if (!downRect.Empty()) { AddVisualChild(&_increaseBtn); _increaseBtn.Arrange(downRect); } return size; }