Esempio n. 1
0
        protected override int measureRawSize(LayoutingType lt)
        {
            int tmp = 0;

            //Wrapper can't fit in the opposite direction of the wrapper, this func is called only if Fit
            if (lt == LayoutingType.Width)
            {
                if (Orientation == Orientation.Vertical)
                {
                    Width = Measure.Stretched;
                    return(-1);
                }
                else if (RegisteredLayoutings.HasFlag(LayoutingType.Height))
                {
                    return(-1);
                }
                else
                {
                    int dy           = 0;
                    int largestChild = 0;
                    lock (Children) {
                        foreach (GraphicObject c in Children)
                        {
                            if (!c.Visible)
                            {
                                continue;
                            }
                            if (c.Height.Units == Unit.Percent &&
                                c.RegisteredLayoutings.HasFlag(LayoutingType.Height))
                            {
                                return(-1);
                            }
                            if (dy + c.Slot.Height > ClientRectangle.Height)
                            {
                                dy           = 0;
                                tmp         += largestChild + Spacing;
                                largestChild = c.Slot.Width;
                            }
                            else if (largestChild < c.Slot.Width)
                            {
                                largestChild = c.Slot.Width;
                            }

                            dy += c.Slot.Height + Spacing;
                        }
                        if (dy == 0)
                        {
                            tmp -= Spacing;
                        }
                        return(tmp + largestChild + 2 * Margin);
                    }
                }
            }
            else if (Orientation == Orientation.Horizontal)
            {
                Height = Measure.Stretched;
                return(-1);
            }
            else if (RegisteredLayoutings.HasFlag(LayoutingType.Width))
            {
                return(-1);
            }
            else
            {
                int dx           = 0;
                int tallestChild = 0;
                lock (Children) {
                    foreach (GraphicObject c in Children)
                    {
                        if (!c.Visible)
                        {
                            continue;
                        }
                        if (c.Width.Units == Unit.Percent &&
                            c.RegisteredLayoutings.HasFlag(LayoutingType.Width))
                        {
                            return(-1);
                        }
                        if (dx + c.Slot.Width > ClientRectangle.Width)
                        {
                            dx           = 0;
                            tmp         += tallestChild + Spacing;
                            tallestChild = c.Slot.Height;
                        }
                        else if (tallestChild < c.Slot.Height)
                        {
                            tallestChild = c.Slot.Height;
                        }

                        dx += c.Slot.Width + Spacing;
                    }
                    if (dx == 0)
                    {
                        tmp -= Spacing;
                    }
                    return(tmp + tallestChild + 2 * Margin);
                }
            }
        }
Esempio n. 2
0
		/// <summary> Update layout component only one at a time, this is where the computation of alignement
		/// and size take place.
		/// The redrawing will only be triggered if final slot size has changed </summary>
		/// <returns><c>true</c>, if layouting was possible, <c>false</c> if conditions were not
		/// met and LQI has to be re-queued</returns>
		public virtual bool UpdateLayout (LayoutingType layoutType)
		{
			//unset bit, it would be reset if LQI is re-queued
			registeredLayoutings &= (~layoutType);

			switch (layoutType) {
			case LayoutingType.X:
				if (Left == 0) {

					if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Width) ||
					    RegisteredLayoutings.HasFlag (LayoutingType.Width))
						return false;

					switch (HorizontalAlignment) {
					case HorizontalAlignment.Left:
						Slot.X = 0;
						break;
					case HorizontalAlignment.Right:
						Slot.X = Parent.ClientRectangle.Width - Slot.Width;
						break;
					case HorizontalAlignment.Center:
						Slot.X = Parent.ClientRectangle.Width / 2 - Slot.Width / 2;
						break;
					}
				} else
					Slot.X = Left;

				if (LastSlots.X == Slot.X)
					break;

				IsDirty = true;

				OnLayoutChanges (layoutType);

				LastSlots.X = Slot.X;
				break;
			case LayoutingType.Y:
				if (Top == 0) {

					if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Height) ||
					    RegisteredLayoutings.HasFlag (LayoutingType.Height))
						return false;

					switch (VerticalAlignment) {
					case VerticalAlignment.Top://this could be processed even if parent Height is not known
						Slot.Y = 0;
						break;
					case VerticalAlignment.Bottom:
						Slot.Y = Parent.ClientRectangle.Height - Slot.Height;
						break;
					case VerticalAlignment.Center:
						Slot.Y = Parent.ClientRectangle.Height / 2 - Slot.Height / 2;
						break;
					}
				} else
					Slot.Y = Top;

				if (LastSlots.Y == Slot.Y)
					break;

				IsDirty = true;

				OnLayoutChanges (layoutType);

				LastSlots.Y = Slot.Y;
				break;
			case LayoutingType.Width:
				if (Visible) {
					if (Width.IsFixed)
						Slot.Width = Width;
					else if (Width == Measure.Fit) {
						Slot.Width = measureRawSize (LayoutingType.Width);
					} else if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Width))
						return false;
					else if (Width == Measure.Stretched)
						Slot.Width = Parent.ClientRectangle.Width;
					else
						Slot.Width = (int)Math.Round ((double)(Parent.ClientRectangle.Width * Width) / 100.0);

					if (Slot.Width < 0)
						return false;

					//size constrain
					if (Slot.Width < MinimumSize.Width) {
						Slot.Width = MinimumSize.Width;
						//NotifyValueChanged ("WidthPolicy", Measure.Stretched);
					} else if (Slot.Width > MaximumSize.Width && MaximumSize.Width > 0) {
						Slot.Width = MaximumSize.Width;
						//NotifyValueChanged ("WidthPolicy", Measure.Stretched);
					}
				} else
					Slot.Width = 0;

				if (LastSlots.Width == Slot.Width)
					break;

				IsDirty = true;

				OnLayoutChanges (layoutType);

				LastSlots.Width = Slot.Width;
				break;
			case LayoutingType.Height:
				if (Visible) {
					if (Height.IsFixed)
						Slot.Height = Height;
					else if (Height == Measure.Fit) {
						Slot.Height = measureRawSize (LayoutingType.Height);
					} else if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Height))
						return false;
					else if (Height == Measure.Stretched)
						Slot.Height = Parent.ClientRectangle.Height;
					else
						Slot.Height = (int)Math.Round ((double)(Parent.ClientRectangle.Height * Height) / 100.0);

					if (Slot.Height < 0)
						return false;

					//size constrain
					if (Slot.Height < MinimumSize.Height) {
						Slot.Height = MinimumSize.Height;
						//NotifyValueChanged ("HeightPolicy", Measure.Stretched);
					} else if (Slot.Height > MaximumSize.Height && MaximumSize.Height > 0) {
						Slot.Height = MaximumSize.Height;
						//NotifyValueChanged ("HeightPolicy", Measure.Stretched);
					}
				} else
					Slot.Height = 0;

				if (LastSlots.Height == Slot.Height)
					break;

				IsDirty = true;

				OnLayoutChanges (layoutType);

				LastSlots.Height = Slot.Height;
				break;
			}

			//if no layouting remains in queue for item, registre for redraw
			if (this.registeredLayoutings == LayoutingType.None && IsDirty)
				CurrentInterface.EnqueueForRepaint (this);

			return true;
		}