void NFrameBase::AutoSize() { if(!IsAutoSize() || layout_ != LayoutNone) return; Base::NSize autoSize = GetAutoSize(); SetSizeImpl(autoSize.Width, autoSize.Height, true); }
bool NFrameBase::SetSizeImpl(int width, int height, bool force) { if(!force && (IsAutoSize() || (layout_ >= LayoutSizeStart && parentFrame_ != NULL))) return false; int frameWidth = (minSize_.Width < 0) ? width : (width >= minSize_.Width ? width : minSize_.Width); int frameHeight = (minSize_.Height < 0) ? height : (height >= minSize_.Height ? height : minSize_.Height); frameWidth = (maxSize_.Width > 0 && frameWidth > maxSize_.Width) ? maxSize_.Width : frameWidth; frameHeight = (maxSize_.Height > 0 && frameHeight > maxSize_.Height) ? maxSize_.Height : frameHeight; if(frameRect_.Width() == frameWidth && frameRect_.Height() == frameHeight) return false; Invalidate(); frameRect_.SetSize(frameWidth, frameHeight); Invalidate(); OnSizeChanged(frameWidth, frameHeight); SizeEventData eventData; eventData.width = width; eventData.height = height; SizeEvent.Invoke(this, &eventData); // Relayout all children FrameList::const_iterator ite = childs_.begin(); while(ite != childs_.end()) { NFrameBase* const& child = *ite; child->ReLayout(); ++ ite; } return true; }
void NFrameBase::SetAutoSize(bool autosize) { if(autosize == IsAutoSize()) return; Util::Misc::CheckFlag(frameFlags_, NFrameBase::FlagAutoSize, autosize); if(autosize) AutoSize(); }
bool NFrameBase::AutoSize() { if(layout_ != LayoutNone) { ReLayout(); return true; } if(!IsAutoSize()) return false; Base::NSize autoSize = GetAutoSize(); return SetSizeImpl(autoSize.Width, autoSize.Height, true); }
bool NFrameBase::SetMaxSize(int maxWidth, int maxHeight) { if(maxSize_.Width == maxWidth && maxSize_.Height == maxHeight) return false; maxSize_.Width = maxWidth; maxSize_.Height = maxHeight; if(IsAutoSize()) { return AutoSize(); } else if(frameRect_.Width() > maxSize_.Width || frameRect_.Height() > maxSize_.Height) { int width = frameRect_.Width() > maxSize_.Width ? maxSize_.Width : frameRect_.Width(); int height = frameRect_.Height() > maxSize_.Height ? maxSize_.Height : frameRect_.Height(); return SetSizeImpl(width, height, true); } return false; }
Vec3 Button::Measure() { if (IsAutoSize()) { const Vec3 labelSize = label->Measure(); double iconPart = 0; if (icon) { // The icon's width may vary depending on the height, so set the // height now and measure the new width. icon->AdjustHeight(labelSize.y); iconPart = icon->Measure().x + iconGap; } return Vec3( labelSize.x + paddingLeft + paddingRight + iconPart, labelSize.y + paddingTop + paddingBottom, 0); } else { return SUPER::Measure(); } }
bool NFrameBase::SetSizeImpl(int width, int height, bool force) { if(!force && (IsAutoSize() || layout_ >= LayoutSizeStart)) return false; int frameWidth = (minSize_.Width < 0) ? width : (width >= minSize_.Width ? width : minSize_.Width); int frameHeight = (minSize_.Height < 0) ? height : (height >= minSize_.Height ? height : minSize_.Height); if(frameRect_.Width() == width && frameRect_.Height() == height) return false; Invalidate(); frameRect_.SetSize(frameWidth, frameHeight); Invalidate(); // Relayout all children FrameList::const_iterator ite = childs_.begin(); while(ite != childs_.end()) { NFrameBase* const& child = *ite; child->ReLayout(); ++ ite; } return true; }
void NFrameBase::ReLayout() { if(layout_ == LayoutNone || !IsLayoutable()) return; int width = 0; int height = 0; if(GetParent() != NULL) { Base::NRect rcParent = GetParent()->GetRect(); width = rcParent.Width(); height = rcParent.Height(); } else if(window_ != NULL) { Base::NRect rcWnd; window_->GetRect(rcWnd); width = rcWnd.Width(); height = rcWnd.Height(); } else { return; } Base::NSize size = IsAutoSize() ? GetAutoSize() : frameRect_.GetSize(); Base::NRect rcNew(frameRect_.Left, frameRect_.Top, frameRect_.Left + size.Width, frameRect_.Top + size.Height); if(layout_ & LayoutHFill) { rcNew.Left = margin_.Left; rcNew.Right = width - margin_.Right; } else if(layout_ & LayoutHCenter) { size.Width = (minSize_.Width <= 0 || size.Width > minSize_.Width) ? size.Width : minSize_.Width; size.Width = (maxSize_.Width <= 0 || size.Width < maxSize_.Width) ? size.Width : maxSize_.Width; rcNew.Left = (width - margin_.Width() - size.Width) / 2; rcNew.Right = rcNew.Left + size.Width; } else if(layout_ & LayoutLeft) { rcNew.Left = margin_.Left; rcNew.Right = rcNew.Left + size.Width; } else if(layout_ & LayoutRight) { rcNew.Right = width - margin_.Right; rcNew.Left = rcNew.Right - size.Width; } if(layout_ & LayoutVFill) { rcNew.Top = margin_.Top; rcNew.Bottom = height - margin_.Bottom; } else if(layout_ & LayoutVCenter) { size.Height = (minSize_.Height <= 0 || size.Height > minSize_.Height) ? size.Height : minSize_.Height; size.Height = (maxSize_.Height <= 0 || size.Height < maxSize_.Height) ? size.Height : maxSize_.Height; rcNew.Top = (height - margin_.Height() - size.Height) / 2; rcNew.Bottom = rcNew.Top + size.Height; } else if(layout_ & LayoutTop) { rcNew.Top = margin_.Top; rcNew.Bottom = rcNew.Top + size.Height; } else if(layout_ & LayoutBottom) { rcNew.Bottom = height - margin_.Bottom; rcNew.Top = rcNew.Bottom - size.Height; } SetPosImpl(rcNew.Left, rcNew.Top, true); SetSizeImpl(rcNew.Width(), rcNew.Height(), true); }