Пример #1
0
 public Widget[] FindWidgets(WidgetAlignment alignment)
 {
     return((from w in Widgets
             where w.Alignment == alignment
             orderby w.DisplayIndex
             select w).ToArray());
 }
Пример #2
0
 /// <summary>
 /// Creates a new Widget shown near a <see cref="Control"/> in the specified parent <see cref="Window"/>, using the specified positioning, and the specified alignment.
 /// </summary>
 /// <param name="parentWindow">The parent <see cref="Window"/>.</param>
 /// <param name="showNear">The target <see cref="Control"/>. Must be a child of the parent <see cref="Window"/>.</param>
 /// <param name="relativePosition">The positioning of the Widget relative to the target <see cref="Control"/>.</param>
 /// <param name="alignment">The alignment of the Widget relative to the target <see cref="Control"/>. Must be horizontal for vertical positioning and vice versa.</param>
 /// <param name="allowOverlap">Determines whether the Widget will overlap the parent <see cref="Window"/>, or be positioned outside of it.</param>
 /// <param name="autoPosition">Determines whether the positioning will be automatically changed if there is no space. For example, if the positioning is Above and there is insufficient space above the window, it will be set to Below, but never Left or Right.</param>
 public void Initialize(Window parentWindow, Control showNear, WidgetRelativePosition relativePosition,
     WidgetAlignment alignment, bool allowOverlap, bool autoPosition)
 {
     WindowStartupLocation = WindowStartupLocation.Manual;
     ParentWindow = parentWindow;
     ParentWindow.LocationChanged += (sender, e) => UpdatePosition();
     ShowNear = showNear;
     RelativePosition = relativePosition;
     Alignment = alignment;
     AllowOverlap = allowOverlap;
     AutoPosition = autoPosition;
     UpdatePosition();
 }
Пример #3
0
 /// <summary>
 /// Creates a new Widget shown near a <see cref="Control"/> in the specified parent <see cref="Window"/>, using the specified positioning, and the specified alignment.
 /// </summary>
 /// <param name="parentWindow">The parent <see cref="Window"/>.</param>
 /// <param name="showNear">The target <see cref="Control"/>. Must be a child of the parent <see cref="Window"/>.</param>
 /// <param name="relativePosition">The positioning of the Widget relative to the target <see cref="Control"/>.</param>
 /// <param name="alignment">The alignment of the Widget relative to the target <see cref="Control"/>. Must be horizontal for vertical positioning and vice versa.</param>
 /// <param name="allowOverlap">Determines whether the Widget will overlap the parent <see cref="Window"/>, or be positioned outside of it.</param>
 /// <param name="autoPosition">Determines whether the positioning will be automatically changed if there is no space. For example, if the positioning is Above and there is insufficient space above the window, it will be set to Below, but never Left or Right.</param>
 public void Initialize(Window parentWindow, Control showNear, WidgetRelativePosition relativePosition,
                        WidgetAlignment alignment, bool allowOverlap, bool autoPosition)
 {
     WindowStartupLocation         = WindowStartupLocation.Manual;
     ParentWindow                  = parentWindow;
     ParentWindow.LocationChanged += (sender, e) => UpdatePosition();
     ShowNear         = showNear;
     RelativePosition = relativePosition;
     Alignment        = alignment;
     AllowOverlap     = allowOverlap;
     AutoPosition     = autoPosition;
     UpdatePosition();
 }
Пример #4
0
 public VolumeWidget(Window parentWindow, Control showNear, WidgetRelativePosition relativePosition,
     WidgetAlignment alignment, bool allowOverlap, bool autoPosition)
     : this()
 {
     Initialize(parentWindow, showNear, relativePosition, alignment, allowOverlap, autoPosition);
 }
Пример #5
0
 public PluginsWidget(Window parentWindow, Control showNear, WidgetRelativePosition relativePosition,
                      WidgetAlignment alignment, bool allowOverlap, bool autoPosition)
     : this()
 {
     Initialize(parentWindow, showNear, relativePosition, alignment, allowOverlap, autoPosition);
 }
Пример #6
0
        void ResetWidgetLocation(MindMapLayoutArgs e, Topic topic, WidgetAlignment alignment, Rectangle rect)
        {
            var widgets = topic.FindWidgets(alignment);

            if (widgets.Length == 0)
            {
                return;
            }

            var dynamicWidgets = widgets.Where(w => !w.FitContainer).ToArray();

            if (alignment == WidgetAlignment.Left || alignment == WidgetAlignment.Right)
            {
                var totalHeight  = dynamicWidgets.Sum(w => w.Bounds.Height);
                var maxWidth     = dynamicWidgets.Length > 0 ? dynamicWidgets.Max(w => w.Bounds.Width) : 0;
                var widgetMargin = Math.Max(e.Chart.WidgetMargin, (rect.Height - totalHeight) / (dynamicWidgets.Length + 1));

                int y  = rect.Y + widgetMargin;
                int x  = rect.X + e.Chart.WidgetMargin;
                int dx = -1;
                int dy = y;
                foreach (var w in widgets)
                {
                    var rw = w.Bounds;

                    if (w.FitContainer)
                    {
                        rw.X      = x;
                        rw.Y      = rect.Y + e.Chart.WidgetMargin;
                        rw.Height = rect.Height - e.Chart.WidgetMargin * 2;
                        x        += rw.Width + e.Chart.WidgetMargin;
                    }
                    else
                    {
                        if (dx < 0)
                        {
                            dx = x;
                            x += maxWidth + e.Chart.WidgetMargin;
                        }
                        rw.X = dx + (maxWidth - w.Bounds.Width) / 2;
                        rw.Y = dy;
                        dy  += rw.Height + widgetMargin;
                    }

                    w.Bounds = rw;
                }
            }
            else if (alignment == WidgetAlignment.Top || alignment == WidgetAlignment.Bottom)
            {
                var totalWidth    = dynamicWidgets.Sum(w => w.Bounds.Width);
                var maxHeight     = dynamicWidgets.Length > 0 ? dynamicWidgets.Max(w => w.Bounds.Height) : 0;
                var widgetPadding = Math.Max(e.Chart.WidgetMargin, (rect.Width - totalWidth) / (dynamicWidgets.Length + 1));

                int y  = rect.Y + e.Chart.WidgetMargin;
                int x  = rect.X + widgetPadding;
                int dx = x;
                int dy = -1;
                foreach (var w in widgets)
                {
                    var rw = w.Bounds;

                    if (w.FitContainer)
                    {
                        rw.X     = rect.X + e.Chart.WidgetMargin;
                        rw.Y     = y;
                        rw.Width = rect.Width - e.Chart.WidgetMargin * 2;
                        y       += rw.Height + e.Chart.WidgetMargin;
                    }
                    else
                    {
                        if (dy < 0)
                        {
                            dy = y;
                            y += maxHeight + e.Chart.WidgetMargin;
                        }
                        rw.X = dx;
                        rw.Y = dy + (maxHeight - w.Bounds.Height) / 2;
                        dx  += rw.Width + widgetPadding;
                    }

                    w.Bounds = rw;
                }
            }
        }
Пример #7
0
        Rectangle CalculateWidgets(Topic topic, WidgetAlignment alignment, MindMapLayoutArgs e)
        {
            var widgets = topic.FindWidgets(alignment);

            if (widgets.Length == 0)
            {
                return(Rectangle.Empty);
            }

            var rect    = Rectangle.Empty;
            var fitSize = Size.Empty;

            foreach (var widget in widgets)
            {
                var rectW = new Rectangle(Point.Empty, widget.CalculateSize(e));
                rectW.Inflate(widget.Padding, widget.Padding);
                if (widget.CustomWidth.HasValue)
                {
                    rectW.Width = widget.CustomWidth.Value;
                }
                if (widget.CustomHeight.HasValue)
                {
                    rectW.Height = widget.CustomHeight.Value;
                }
                widget.Bounds = rectW;

                rectW.Width  += e.Chart.WidgetMargin;
                rectW.Height += e.Chart.WidgetMargin;

                //
                switch (alignment)
                {
                case WidgetAlignment.Left:
                case WidgetAlignment.Right:
                    if (widget.FitContainer)
                    {
                        fitSize.Width += rectW.Width;
                        fitSize.Height = Math.Max(fitSize.Height, rectW.Height);
                    }
                    else
                    {
                        rect.Width   = Math.Max(rect.Width, rectW.Width);
                        rect.Height += rectW.Height;
                    }
                    break;

                case WidgetAlignment.Top:
                case WidgetAlignment.Bottom:
                    if (widget.FitContainer)
                    {
                        fitSize.Height += rectW.Height;
                        fitSize.Width   = Math.Max(fitSize.Width, rectW.Width);
                    }
                    else
                    {
                        rect.Width += rectW.Width;
                        rect.Height = Math.Max(rect.Height, rectW.Height);
                    }
                    break;
                }
            }

            switch (alignment)
            {
            case WidgetAlignment.Left:
            case WidgetAlignment.Right:
                rect.Width += fitSize.Width;
                rect.Height = Math.Max(rect.Height, fitSize.Height);
                break;

            case WidgetAlignment.Top:
            case WidgetAlignment.Bottom:
                rect.Width   = Math.Max(rect.Width, fitSize.Width);
                rect.Height += fitSize.Height;
                break;
            }

            rect.Width  += e.Chart.WidgetMargin;
            rect.Height += e.Chart.WidgetMargin;

            return(rect);
        }