Пример #1
0
 void adjustStretchedGo(LayoutingType lt)
 {
     if (stretchedGO == null)
     {
         return;
     }
     if (lt == LayoutingType.Width)
     {
         int newW = Math.Max(
             this.ClientRectangle.Width - contentSize.Width - Spacing * (Children.Count - 1),
             stretchedGO.MinimumSize.Width);
         if (stretchedGO.MaximumSize.Width > 0)
         {
             newW = Math.Min(newW, stretchedGO.MaximumSize.Width);
         }
         if (newW != stretchedGO.Slot.Width)
         {
             stretchedGO.Slot.Width = newW;
             stretchedGO.IsDirty    = true;
                                 #if DEBUG_LAYOUTING
             Debug.WriteLine("\tAdjusting Width of " + stretchedGO.ToString());
                                 #endif
             stretchedGO.LayoutChanged -= OnChildLayoutChanges;
             stretchedGO.OnLayoutChanges(LayoutingType.Width);
             stretchedGO.LayoutChanged  += OnChildLayoutChanges;
             stretchedGO.LastSlots.Width = stretchedGO.Slot.Width;
         }
     }
     else
     {
         int newH = Math.Max(
             this.ClientRectangle.Height - contentSize.Height - Spacing * (Children.Count - 1),
             stretchedGO.MinimumSize.Height);
         if (stretchedGO.MaximumSize.Height > 0)
         {
             newH = Math.Min(newH, stretchedGO.MaximumSize.Height);
         }
         if (newH != stretchedGO.Slot.Height)
         {
             stretchedGO.Slot.Height = newH;
             stretchedGO.IsDirty     = true;
                                 #if DEBUG_LAYOUTING
             Debug.WriteLine("\tAdjusting Height of " + stretchedGO.ToString());
                                 #endif
             stretchedGO.LayoutChanged -= OnChildLayoutChanges;
             stretchedGO.OnLayoutChanges(LayoutingType.Height);
             stretchedGO.LayoutChanged   += OnChildLayoutChanges;
             stretchedGO.LastSlots.Height = stretchedGO.Slot.Height;
         }
     }
 }
Пример #2
0
        public override void OnChildLayoutChanges(object sender, LayoutingEventArgs arg)
        {
            GraphicObject go = sender as GraphicObject;

            //Debug.WriteLine ("child layout change: " + go.LastSlots.ToString() + " => " + go.Slot.ToString());
            switch (arg.LayoutType)
            {
            case LayoutingType.Width:
                if (Orientation == Orientation.Horizontal)
                {
                    if (go.Width == Measure.Stretched)
                    {
                        if (stretchedGO == null && Width != Measure.Fit)
                        {
                            stretchedGO = go;
                        }
                        else if (stretchedGO != go)
                        {
                            go.Slot.Width = 0;
                            go.Width      = Measure.Fit;
                            return;
                        }
                    }
                    else
                    {
                        contentSize.Width += go.Slot.Width - go.LastSlots.Width;
                    }

                    if (stretchedGO != null)
                    {
                        int newW = Math.Max(
                            this.ClientRectangle.Width - contentSize.Width - Spacing * (Children.Count - 1),
                            stretchedGO.MinimumSize.Width);
                        if (stretchedGO.MaximumSize.Width > 0)
                        {
                            newW = Math.Min(newW, stretchedGO.MaximumSize.Width);
                        }
                        if (newW != stretchedGO.Slot.Width)
                        {
                            stretchedGO.Slot.Width = newW;
                            stretchedGO.bmp        = null;
#if DEBUG_LAYOUTING
                            Debug.WriteLine("\tAdjusting Width of " + stretchedGO.ToString());
#endif
                            stretchedGO.LayoutChanged -= OnChildLayoutChanges;
                            stretchedGO.OnLayoutChanges(LayoutingType.Width);
                            stretchedGO.LayoutChanged  += OnChildLayoutChanges;
                            stretchedGO.LastSlots.Width = stretchedGO.Slot.Width;
                        }
                    }

                    if (Width == Measure.Fit)
                    {
                        this.RegisterForLayouting(LayoutingType.Width);
                    }

                    this.RegisterForLayouting(LayoutingType.ArrangeChildren);
                    return;
                }
                break;

            case LayoutingType.Height:
                if (Orientation == Orientation.Vertical)
                {
                    if (go.Height == Measure.Stretched)
                    {
                        if (stretchedGO == null && Height != Measure.Fit)
                        {
                            stretchedGO = go;
                        }
                        else if (stretchedGO != go)
                        {
                            go.Slot.Height = 0;
                            go.Height      = Measure.Fit;
                            return;
                        }
                    }
                    else
                    {
                        contentSize.Height += go.Slot.Height - go.LastSlots.Height;
                    }

                    if (stretchedGO != null)
                    {
                        int newH = Math.Max(
                            this.ClientRectangle.Height - contentSize.Height - Spacing * (Children.Count - 1),
                            stretchedGO.MinimumSize.Height);
                        if (stretchedGO.MaximumSize.Height > 0)
                        {
                            newH = Math.Min(newH, stretchedGO.MaximumSize.Height);
                        }
                        if (newH != stretchedGO.Slot.Height)
                        {
                            stretchedGO.Slot.Height = newH;
                            stretchedGO.bmp         = null;
#if DEBUG_LAYOUTING
                            Debug.WriteLine("\tAdjusting Height of " + stretchedGO.ToString());
#endif
                            stretchedGO.LayoutChanged -= OnChildLayoutChanges;
                            stretchedGO.OnLayoutChanges(LayoutingType.Height);
                            stretchedGO.LayoutChanged   += OnChildLayoutChanges;
                            stretchedGO.LastSlots.Height = stretchedGO.Slot.Height;
                        }
                    }

                    if (Height == Measure.Fit)
                    {
                        this.RegisterForLayouting(LayoutingType.Height);
                    }

                    this.RegisterForLayouting(LayoutingType.ArrangeChildren);
                    return;
                }
                break;
            }
            base.OnChildLayoutChanges(sender, arg);
        }