2017-06-10 18:40:57 -07:00
|
|
|
|
/*
|
2017-06-12 14:19:04 -07:00
|
|
|
|
Copyright (c) 2017, Lars Brubaker, John Lewin
|
2017-06-10 18:40:57 -07:00
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
|
|
list of conditions and the following disclaimer.
|
|
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
|
and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
|
|
|
The views and conclusions contained in the software and documentation are those
|
|
|
|
|
|
of the authors and should not be interpreted as representing official policies,
|
|
|
|
|
|
either expressed or implied, of the FreeBSD Project.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2017-06-12 20:32:52 -07:00
|
|
|
|
using System;
|
2017-06-12 14:19:04 -07:00
|
|
|
|
using System.Collections.Generic;
|
2017-06-13 14:32:09 -07:00
|
|
|
|
using System.Linq;
|
2017-06-10 18:40:57 -07:00
|
|
|
|
using MatterHackers.Agg;
|
2017-06-10 21:17:43 -07:00
|
|
|
|
using MatterHackers.Agg.Font;
|
2017-08-20 02:34:39 -07:00
|
|
|
|
using MatterHackers.Agg.Platform;
|
2017-06-10 21:17:43 -07:00
|
|
|
|
using MatterHackers.Agg.Transform;
|
2017-06-11 15:17:25 -07:00
|
|
|
|
using MatterHackers.Agg.UI;
|
2017-06-10 21:17:43 -07:00
|
|
|
|
using MatterHackers.Agg.VertexSource;
|
2017-06-11 15:17:25 -07:00
|
|
|
|
using MatterHackers.MatterControl.PartPreviewWindow;
|
2017-06-10 21:17:43 -07:00
|
|
|
|
using MatterHackers.VectorMath;
|
2017-06-10 18:40:57 -07:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.CustomWidgets
|
|
|
|
|
|
{
|
2017-08-24 11:50:15 -07:00
|
|
|
|
public enum DockSide { Left, Bottom, Right, Top };
|
|
|
|
|
|
|
2017-11-06 17:06:04 -08:00
|
|
|
|
public class DockingTabControl : FlowLayoutWidget
|
2017-06-10 18:40:57 -07:00
|
|
|
|
{
|
2017-08-24 11:50:15 -07:00
|
|
|
|
public int MinDockingWidth = 400 * (int)GuiWidget.DeviceScale;
|
|
|
|
|
|
protected GuiWidget widgetTodockTo;
|
2017-06-13 14:32:09 -07:00
|
|
|
|
private Dictionary<string, GuiWidget> allTabs = new Dictionary<string, GuiWidget>();
|
2017-08-24 11:50:15 -07:00
|
|
|
|
private List<PopupButton> settingsButtons = new List<PopupButton>();
|
2017-06-12 20:32:52 -07:00
|
|
|
|
|
2017-08-15 19:13:55 -07:00
|
|
|
|
private PrinterConfig printer;
|
2017-06-13 14:32:09 -07:00
|
|
|
|
|
2017-09-30 10:25:25 -07:00
|
|
|
|
private ThemeConfig theme;
|
2017-08-15 19:13:55 -07:00
|
|
|
|
public DockingTabControl(GuiWidget widgetTodockTo, DockSide dockSide, PrinterConfig printer)
|
2017-11-06 17:06:04 -08:00
|
|
|
|
: base (FlowDirection.TopToBottom)
|
2017-06-13 14:32:09 -07:00
|
|
|
|
{
|
2017-09-30 10:25:25 -07:00
|
|
|
|
this.theme = ApplicationController.Instance.Theme;
|
2017-08-15 19:13:55 -07:00
|
|
|
|
this.printer = printer;
|
2017-06-13 14:32:09 -07:00
|
|
|
|
this.widgetTodockTo = widgetTodockTo;
|
|
|
|
|
|
this.DockSide = dockSide;
|
2017-11-07 11:31:30 -08:00
|
|
|
|
|
|
|
|
|
|
// Add dummy widget to ensure OnLoad fires
|
|
|
|
|
|
this.AddChild(new GuiWidget(10, 10));
|
2017-06-13 14:32:09 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public event EventHandler PinStatusChanged;
|
|
|
|
|
|
|
2017-06-12 20:32:52 -07:00
|
|
|
|
public bool ControlIsPinned
|
|
|
|
|
|
{
|
2017-08-15 19:13:55 -07:00
|
|
|
|
get => printer.ViewState.SliceSettingsTabPinned;
|
2017-06-13 14:32:09 -07:00
|
|
|
|
set
|
|
|
|
|
|
{
|
2017-08-15 19:13:55 -07:00
|
|
|
|
if (this.ControlIsPinned != value)
|
|
|
|
|
|
{
|
|
|
|
|
|
printer.ViewState.SliceSettingsTabPinned = value;
|
|
|
|
|
|
PinStatusChanged?.Invoke(this, null);
|
|
|
|
|
|
}
|
2017-06-12 20:32:52 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-24 11:50:15 -07:00
|
|
|
|
public DockSide DockSide { get; set; }
|
|
|
|
|
|
|
2017-06-11 15:17:25 -07:00
|
|
|
|
public void AddPage(string name, GuiWidget widget)
|
|
|
|
|
|
{
|
2017-06-12 10:01:50 -07:00
|
|
|
|
allTabs.Add(name, widget);
|
2017-11-07 11:31:30 -08:00
|
|
|
|
|
|
|
|
|
|
if (formHasLoaded)
|
|
|
|
|
|
{
|
|
|
|
|
|
Rebuild();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-03 15:24:55 -08:00
|
|
|
|
public void RemovePage(string name)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (allTabs.ContainsKey(name))
|
|
|
|
|
|
{
|
|
|
|
|
|
allTabs.Remove(name);
|
|
|
|
|
|
this.Rebuild();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-11-07 11:31:30 -08:00
|
|
|
|
public override void OnLoad(EventArgs args)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnLoad(args);
|
|
|
|
|
|
this.Rebuild();
|
2017-06-12 10:01:50 -07:00
|
|
|
|
}
|
2017-06-11 15:17:25 -07:00
|
|
|
|
|
2017-06-13 14:32:09 -07:00
|
|
|
|
public override void Initialize()
|
2017-06-12 10:01:50 -07:00
|
|
|
|
{
|
2017-06-13 14:32:09 -07:00
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
2017-11-06 17:06:04 -08:00
|
|
|
|
this.VAnchor = VAnchor.Stretch;
|
|
|
|
|
|
this.HAnchor = HAnchor.Fit;
|
2017-06-13 14:32:09 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-25 13:45:42 -07:00
|
|
|
|
private GuiWidget CreatePinButton()
|
2017-08-24 11:50:15 -07:00
|
|
|
|
{
|
2017-10-14 23:18:06 -07:00
|
|
|
|
string imageFile = this.ControlIsPinned ? "Pushpin_16x.png" : "PushpinUnpin_16x.png";
|
|
|
|
|
|
var icon = AggContext.StaticData.LoadIcon(imageFile, 16, 16, IconColor.Theme);
|
2017-09-25 13:45:42 -07:00
|
|
|
|
|
2017-09-25 14:01:17 -07:00
|
|
|
|
var imageWidget = ApplicationController.Instance.Theme.ButtonFactory.GenerateIconButton(icon);
|
|
|
|
|
|
imageWidget.Name = "Pin Settings Button";
|
2017-08-24 11:50:15 -07:00
|
|
|
|
imageWidget.Click += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
this.ControlIsPinned = !this.ControlIsPinned;
|
2017-11-07 11:31:30 -08:00
|
|
|
|
this.printer.ViewState.DockWindowFloating = false;
|
2017-09-28 23:36:10 -07:00
|
|
|
|
UiThread.RunOnIdle(this.Rebuild);
|
2017-08-24 11:50:15 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return imageWidget;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-19 15:25:52 -07:00
|
|
|
|
public override double Width
|
|
|
|
|
|
{
|
|
|
|
|
|
get => this.PageWidth;
|
|
|
|
|
|
set => this.PageWidth = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-28 23:42:43 -07:00
|
|
|
|
// Clamped to MinDockingWidth or value
|
2017-08-24 11:50:15 -07:00
|
|
|
|
double PageWidth
|
|
|
|
|
|
{
|
2017-09-28 23:42:43 -07:00
|
|
|
|
get => Math.Max(MinDockingWidth, printer.ViewState.SliceSettingsWidth);
|
|
|
|
|
|
set => printer.ViewState.SliceSettingsWidth = Math.Max(MinDockingWidth, value);
|
2017-08-24 11:50:15 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-06-13 14:32:09 -07:00
|
|
|
|
private void Rebuild()
|
|
|
|
|
|
{
|
2017-08-24 11:50:15 -07:00
|
|
|
|
settingsButtons.Clear();
|
2017-06-13 14:32:09 -07:00
|
|
|
|
Focus();
|
|
|
|
|
|
foreach (var nameWidget in allTabs)
|
2017-06-11 15:17:25 -07:00
|
|
|
|
{
|
2017-06-12 10:01:50 -07:00
|
|
|
|
nameWidget.Value.Parent?.RemoveChild(nameWidget.Value);
|
|
|
|
|
|
nameWidget.Value.ClearRemovedFlag();
|
|
|
|
|
|
}
|
2017-06-11 15:17:25 -07:00
|
|
|
|
|
2017-11-06 17:06:04 -08:00
|
|
|
|
this.RemoveAllChildren();
|
2017-06-11 15:17:25 -07:00
|
|
|
|
|
2017-11-06 17:06:04 -08:00
|
|
|
|
TabControl tabControl = null;
|
2017-08-15 19:13:55 -07:00
|
|
|
|
if (this.ControlIsPinned)
|
2017-06-12 10:01:50 -07:00
|
|
|
|
{
|
2017-08-24 11:50:15 -07:00
|
|
|
|
var resizePage = new ResizeContainer(this)
|
2017-06-11 15:17:25 -07:00
|
|
|
|
{
|
2017-08-24 11:50:15 -07:00
|
|
|
|
Width = PageWidth,
|
2017-08-07 15:47:27 -07:00
|
|
|
|
VAnchor = VAnchor.Stretch,
|
2017-11-21 11:11:07 -08:00
|
|
|
|
SpliterBarColor = theme.SplitterBackground,
|
|
|
|
|
|
SplitterWidth = theme.SplitterWidth,
|
2017-06-11 15:17:25 -07:00
|
|
|
|
};
|
2017-06-12 14:19:04 -07:00
|
|
|
|
|
2017-11-21 11:11:07 -08:00
|
|
|
|
tabControl = theme.CreateTabControl();
|
2017-06-12 10:01:50 -07:00
|
|
|
|
resizePage.AddChild(tabControl);
|
|
|
|
|
|
|
2017-11-06 17:06:04 -08:00
|
|
|
|
this.AddChild(resizePage);
|
2017-06-12 10:01:50 -07:00
|
|
|
|
}
|
2017-06-11 15:17:25 -07:00
|
|
|
|
|
2017-08-15 15:11:37 -07:00
|
|
|
|
int tabIndex = 0;
|
2017-06-12 10:01:50 -07:00
|
|
|
|
foreach (var nameWidget in allTabs)
|
|
|
|
|
|
{
|
2017-06-12 20:32:52 -07:00
|
|
|
|
string tabTitle = nameWidget.Key;
|
|
|
|
|
|
|
2017-08-15 19:13:55 -07:00
|
|
|
|
if (this.ControlIsPinned)
|
2017-06-11 15:17:25 -07:00
|
|
|
|
{
|
2017-08-23 13:52:31 -07:00
|
|
|
|
var content = new DockingWindowContent(this, nameWidget.Value, tabTitle);
|
2017-06-12 14:19:04 -07:00
|
|
|
|
|
2017-06-12 20:32:52 -07:00
|
|
|
|
var tabPage = new TabPage(content, tabTitle);
|
2017-08-15 15:11:37 -07:00
|
|
|
|
var textTab = new TextTab(
|
2017-06-12 14:19:04 -07:00
|
|
|
|
tabPage,
|
2017-06-12 20:32:52 -07:00
|
|
|
|
tabTitle + " Tab",
|
2017-06-12 14:19:04 -07:00
|
|
|
|
12,
|
|
|
|
|
|
ActiveTheme.Instance.TabLabelSelected,
|
2017-10-31 11:43:25 -07:00
|
|
|
|
Color.Transparent,
|
2017-06-12 14:19:04 -07:00
|
|
|
|
ActiveTheme.Instance.TabLabelUnselected,
|
2017-10-31 11:43:25 -07:00
|
|
|
|
Color.Transparent,
|
2017-08-15 15:11:37 -07:00
|
|
|
|
useUnderlineStyling: true);
|
|
|
|
|
|
|
|
|
|
|
|
tabControl.AddTab(textTab);
|
|
|
|
|
|
|
|
|
|
|
|
int localTabIndex = tabIndex;
|
|
|
|
|
|
textTab.Click += (s, e) =>
|
|
|
|
|
|
{
|
2017-08-15 19:13:55 -07:00
|
|
|
|
printer.ViewState.SliceSettingsTabIndex = localTabIndex;
|
2017-08-15 15:11:37 -07:00
|
|
|
|
};
|
2017-06-12 10:01:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
else // control is floating
|
|
|
|
|
|
{
|
2017-08-14 19:09:37 -07:00
|
|
|
|
var printer = new TypeFacePrinter(tabTitle, 12 * GuiWidget.DeviceScale);
|
2017-06-12 14:19:04 -07:00
|
|
|
|
var rotatedLabel = new VertexSourceApplyTransform(
|
2017-08-14 19:09:37 -07:00
|
|
|
|
printer,
|
2017-06-12 14:19:04 -07:00
|
|
|
|
Affine.NewRotation(MathHelper.DegreesToRadians(-90)));
|
2017-06-12 10:01:50 -07:00
|
|
|
|
|
2017-08-14 19:09:37 -07:00
|
|
|
|
var textBounds = rotatedLabel.Bounds();
|
|
|
|
|
|
var bounds = new RectangleDouble(printer.TypeFaceStyle.DescentInPixels, textBounds.Bottom, printer.TypeFaceStyle.AscentInPixels, textBounds.Top);
|
2017-08-24 11:50:15 -07:00
|
|
|
|
rotatedLabel.Transform = ((Affine)rotatedLabel.Transform)
|
2017-08-14 19:09:37 -07:00
|
|
|
|
* Affine.NewTranslation(new Vector2(-printer.TypeFaceStyle.DescentInPixels, -bounds.Bottom));
|
2017-06-12 10:01:50 -07:00
|
|
|
|
|
2017-06-12 14:19:04 -07:00
|
|
|
|
var optionsText = new GuiWidget(bounds.Width, bounds.Height)
|
2017-06-12 10:01:50 -07:00
|
|
|
|
{
|
|
|
|
|
|
DoubleBuffer = true,
|
2017-06-16 23:02:26 -07:00
|
|
|
|
Margin = new BorderDouble(3, 6, 3, 0)
|
2017-06-12 10:01:50 -07:00
|
|
|
|
};
|
|
|
|
|
|
optionsText.AfterDraw += (s, e) =>
|
|
|
|
|
|
{
|
2017-06-12 14:19:04 -07:00
|
|
|
|
e.graphics2D.Render(rotatedLabel, ActiveTheme.Instance.PrimaryTextColor);
|
|
|
|
|
|
};
|
2017-06-11 15:17:25 -07:00
|
|
|
|
|
2017-06-12 14:19:04 -07:00
|
|
|
|
var settingsButton = new PopupButton(optionsText)
|
2017-06-12 10:01:50 -07:00
|
|
|
|
{
|
|
|
|
|
|
AlignToRightEdge = true,
|
2017-06-13 16:40:10 -07:00
|
|
|
|
Name = $"{tabTitle} Sidebar",
|
|
|
|
|
|
MakeScrollable = false,
|
2017-06-12 10:01:50 -07:00
|
|
|
|
};
|
2017-06-13 16:40:10 -07:00
|
|
|
|
|
2017-11-21 11:11:07 -08:00
|
|
|
|
var spliterColor = theme.SplitterBackground;
|
2017-08-23 13:52:31 -07:00
|
|
|
|
|
2017-08-24 11:50:15 -07:00
|
|
|
|
var resizeContainer = new ResizeContainer(this)
|
2017-06-12 14:19:04 -07:00
|
|
|
|
{
|
2017-08-24 11:50:15 -07:00
|
|
|
|
Width = PageWidth,
|
2017-08-23 13:52:31 -07:00
|
|
|
|
VAnchor = VAnchor.Stretch,
|
|
|
|
|
|
HAnchor = HAnchor.Right,
|
|
|
|
|
|
SpliterBarColor = spliterColor,
|
|
|
|
|
|
SplitterWidth = ApplicationController.Instance.Theme.SplitterWidth,
|
2017-06-12 14:19:04 -07:00
|
|
|
|
};
|
2017-08-23 13:52:31 -07:00
|
|
|
|
resizeContainer.AddChild(new DockingWindowContent(this, nameWidget.Value, tabTitle)
|
|
|
|
|
|
{
|
|
|
|
|
|
BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor,
|
2017-08-24 11:50:15 -07:00
|
|
|
|
Width = PageWidth
|
2017-08-23 13:52:31 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
2017-08-24 11:50:15 -07:00
|
|
|
|
settingsButtons.Add(settingsButton);
|
2017-08-23 13:52:31 -07:00
|
|
|
|
settingsButton.PopupContent = resizeContainer;
|
|
|
|
|
|
|
|
|
|
|
|
settingsButton.Click += (s, e) =>
|
|
|
|
|
|
{
|
2017-08-24 11:50:15 -07:00
|
|
|
|
resizeContainer.Width = PageWidth;
|
2017-08-23 13:52:31 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2017-06-13 14:32:09 -07:00
|
|
|
|
settingsButton.PopupLayoutEngine = new UnpinnedLayoutEngine(settingsButton.PopupContent, widgetTodockTo, DockSide);
|
2017-11-06 17:06:04 -08:00
|
|
|
|
this.AddChild(settingsButton);
|
2017-08-15 15:11:37 -07:00
|
|
|
|
|
|
|
|
|
|
int localTabIndex = tabIndex;
|
|
|
|
|
|
settingsButton.Click += (s, e) =>
|
|
|
|
|
|
{
|
2017-08-15 19:13:55 -07:00
|
|
|
|
this.printer.ViewState.SliceSettingsTabIndex = localTabIndex;
|
2017-11-07 11:31:30 -08:00
|
|
|
|
this.printer.ViewState.DockWindowFloating = true;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
settingsButton.PopupWindowClosed += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!ApplicationController.Instance.IsReloading)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.printer.ViewState.DockWindowFloating = false;
|
|
|
|
|
|
}
|
2017-08-15 15:11:37 -07:00
|
|
|
|
};
|
2017-11-07 11:31:30 -08:00
|
|
|
|
|
|
|
|
|
|
if (this.printer.ViewState.DockWindowFloating
|
|
|
|
|
|
&& localTabIndex == this.printer.ViewState.SliceSettingsTabIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!settingsButton.HasBeenClosed && settingsButton.Parent != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
settingsButton.ShowPopup();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2017-06-12 10:01:50 -07:00
|
|
|
|
}
|
2017-08-15 15:11:37 -07:00
|
|
|
|
|
|
|
|
|
|
tabIndex++;
|
2017-06-11 15:17:25 -07:00
|
|
|
|
}
|
2017-06-12 17:55:32 -07:00
|
|
|
|
|
2017-08-15 19:13:55 -07:00
|
|
|
|
if (this.ControlIsPinned)
|
2017-06-12 17:55:32 -07:00
|
|
|
|
{
|
|
|
|
|
|
tabControl.TabBar.AddChild(new HorizontalSpacer());
|
2017-09-30 10:25:25 -07:00
|
|
|
|
tabControl.TabBar.AddChild(this.CreatePinButton());
|
2017-06-12 17:55:32 -07:00
|
|
|
|
|
2017-09-30 10:25:25 -07:00
|
|
|
|
tabControl.TabBar.Padding = new BorderDouble(right: theme.ToolbarPadding.Right);
|
2017-08-15 15:11:37 -07:00
|
|
|
|
|
2017-08-15 19:13:55 -07:00
|
|
|
|
if (printer.ViewState.SliceSettingsTabIndex < tabControl.TabCount)
|
2017-08-15 15:11:37 -07:00
|
|
|
|
{
|
2017-08-15 19:13:55 -07:00
|
|
|
|
tabControl.SelectedTabIndex = printer.ViewState.SliceSettingsTabIndex;
|
2017-08-15 15:11:37 -07:00
|
|
|
|
}
|
2017-06-12 17:55:32 -07:00
|
|
|
|
}
|
2017-06-11 15:17:25 -07:00
|
|
|
|
}
|
2017-06-10 18:40:57 -07:00
|
|
|
|
|
2017-11-21 11:11:07 -08:00
|
|
|
|
|
2017-08-23 13:52:31 -07:00
|
|
|
|
private class DockingWindowContent : GuiWidget, IIgnoredPopupChild
|
2017-06-10 18:40:57 -07:00
|
|
|
|
{
|
2017-08-23 13:52:31 -07:00
|
|
|
|
internal DockingWindowContent(DockingTabControl dockingControl, GuiWidget child, string title)
|
2017-06-11 10:14:32 -07:00
|
|
|
|
{
|
2017-06-12 14:19:04 -07:00
|
|
|
|
var topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
2017-06-11 10:14:32 -07:00
|
|
|
|
{
|
2017-08-07 15:47:27 -07:00
|
|
|
|
VAnchor = VAnchor.Stretch,
|
|
|
|
|
|
HAnchor = HAnchor.Stretch
|
2017-06-11 10:14:32 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2017-06-13 12:28:04 -07:00
|
|
|
|
if (!dockingControl.ControlIsPinned)
|
2017-06-12 10:08:13 -07:00
|
|
|
|
{
|
2017-06-12 17:55:32 -07:00
|
|
|
|
var titleBar = new FlowLayoutWidget()
|
|
|
|
|
|
{
|
2017-08-07 15:47:27 -07:00
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Fit,
|
2017-06-12 17:55:32 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2017-06-12 14:19:04 -07:00
|
|
|
|
titleBar.AddChild(new TextWidget(title, textColor: ActiveTheme.Instance.PrimaryTextColor)
|
|
|
|
|
|
{
|
|
|
|
|
|
Margin = new BorderDouble(left: 12)
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2017-06-13 12:28:04 -07:00
|
|
|
|
titleBar.AddChild(new HorizontalSpacer());
|
2017-06-12 14:19:04 -07:00
|
|
|
|
|
2017-06-13 12:28:04 -07:00
|
|
|
|
titleBar.AddChild(dockingControl.CreatePinButton());
|
2017-06-12 17:55:32 -07:00
|
|
|
|
|
|
|
|
|
|
topToBottom.AddChild(titleBar);
|
|
|
|
|
|
}
|
2017-06-11 10:14:32 -07:00
|
|
|
|
|
|
|
|
|
|
topToBottom.AddChild(child);
|
2017-06-10 18:40:57 -07:00
|
|
|
|
|
2017-08-23 13:52:31 -07:00
|
|
|
|
HAnchor = HAnchor.Stretch;
|
|
|
|
|
|
VAnchor = VAnchor.Stretch;
|
|
|
|
|
|
|
2017-06-11 10:14:32 -07:00
|
|
|
|
AddChild(topToBottom);
|
|
|
|
|
|
}
|
2017-06-10 18:40:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-06-13 14:32:09 -07:00
|
|
|
|
|
|
|
|
|
|
public class UnpinnedLayoutEngine : IPopupLayoutEngine
|
|
|
|
|
|
{
|
|
|
|
|
|
protected GuiWidget widgetTodockTo;
|
|
|
|
|
|
private GuiWidget contentWidget;
|
|
|
|
|
|
private HashSet<GuiWidget> hookedParents = new HashSet<GuiWidget>();
|
|
|
|
|
|
private PopupWidget popupWidget;
|
|
|
|
|
|
|
|
|
|
|
|
public UnpinnedLayoutEngine(GuiWidget contentWidget, GuiWidget widgetTodockTo, DockSide dockSide)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.contentWidget = contentWidget;
|
|
|
|
|
|
this.widgetTodockTo = widgetTodockTo;
|
|
|
|
|
|
DockSide = dockSide;
|
2017-08-23 13:52:31 -07:00
|
|
|
|
contentWidget.BoundsChanged += widgetRelativeTo_PositionChanged;
|
2017-06-13 14:32:09 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-24 11:50:15 -07:00
|
|
|
|
public DockSide DockSide { get; set; }
|
2017-06-13 14:32:09 -07:00
|
|
|
|
public double MaxHeight { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
public void Closed()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Unbind callbacks on parents for position_changed if we're closing
|
|
|
|
|
|
foreach (GuiWidget widget in hookedParents)
|
|
|
|
|
|
{
|
|
|
|
|
|
widget.PositionChanged -= widgetRelativeTo_PositionChanged;
|
|
|
|
|
|
widget.BoundsChanged -= widgetRelativeTo_PositionChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-23 13:52:31 -07:00
|
|
|
|
hookedParents.Clear();
|
|
|
|
|
|
|
2017-06-13 14:32:09 -07:00
|
|
|
|
// Long lived originating item must be unregistered
|
|
|
|
|
|
widgetTodockTo.Closed -= widgetRelativeTo_Closed;
|
|
|
|
|
|
|
|
|
|
|
|
// Restore focus to originating widget on close
|
|
|
|
|
|
if (this.widgetTodockTo != null
|
|
|
|
|
|
&& !widgetTodockTo.HasBeenClosed)
|
|
|
|
|
|
{
|
|
|
|
|
|
// On menu close, select the first scrollable parent of the widgetRelativeTo
|
|
|
|
|
|
var scrollableParent = widgetTodockTo.Parents<ScrollableWidget>().FirstOrDefault();
|
|
|
|
|
|
if (scrollableParent != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
scrollableParent.Focus();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ShowPopup(PopupWidget popupWidget)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.popupWidget = popupWidget;
|
|
|
|
|
|
SystemWindow windowToAddTo = widgetTodockTo.Parents<SystemWindow>().FirstOrDefault();
|
|
|
|
|
|
windowToAddTo?.AddChild(popupWidget);
|
|
|
|
|
|
|
|
|
|
|
|
GuiWidget topParent = widgetTodockTo.Parent;
|
|
|
|
|
|
while (topParent.Parent != null
|
|
|
|
|
|
&& topParent as SystemWindow == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Regrettably we don't know who it is that is the window that will actually think it is moving relative to its parent
|
|
|
|
|
|
// but we need to know anytime our widgetRelativeTo has been moved by any change, so we hook them all.
|
|
|
|
|
|
if (!hookedParents.Contains(topParent))
|
|
|
|
|
|
{
|
|
|
|
|
|
hookedParents.Add(topParent);
|
|
|
|
|
|
topParent.PositionChanged += widgetRelativeTo_PositionChanged;
|
|
|
|
|
|
topParent.BoundsChanged += widgetRelativeTo_PositionChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
topParent = topParent.Parent;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
widgetRelativeTo_PositionChanged(widgetTodockTo, null);
|
|
|
|
|
|
widgetTodockTo.Closed += widgetRelativeTo_Closed;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void widgetRelativeTo_Closed(object sender, ClosedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
// If the owning widget closed, so should we
|
|
|
|
|
|
popupWidget.CloseMenu();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void widgetRelativeTo_PositionChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (widgetTodockTo != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
RectangleDouble bounds = widgetTodockTo.BoundsRelativeToParent;
|
|
|
|
|
|
|
|
|
|
|
|
GuiWidget topParent = widgetTodockTo.Parent;
|
|
|
|
|
|
while (topParent != null && topParent.Parent != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
topParent.ParentToChildTransform.transform(ref bounds);
|
|
|
|
|
|
topParent = topParent.Parent;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch (DockSide)
|
|
|
|
|
|
{
|
|
|
|
|
|
case DockSide.Left:
|
2017-06-18 10:27:55 -07:00
|
|
|
|
popupWidget.LocalBounds = new RectangleDouble(bounds.Left, bounds.Bottom, bounds.Left - contentWidget.Width, bounds.Top);
|
|
|
|
|
|
break;
|
2017-08-24 11:50:15 -07:00
|
|
|
|
|
2017-06-13 14:32:09 -07:00
|
|
|
|
case DockSide.Bottom:
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
case DockSide.Right:
|
2017-08-23 13:52:31 -07:00
|
|
|
|
popupWidget.HAnchor = HAnchor.Absolute;
|
2017-06-13 14:32:09 -07:00
|
|
|
|
popupWidget.LocalBounds = new RectangleDouble(bounds.Right - contentWidget.Width, bounds.Bottom, bounds.Right, bounds.Top);
|
|
|
|
|
|
break;
|
2017-08-24 11:50:15 -07:00
|
|
|
|
|
2017-06-13 14:32:09 -07:00
|
|
|
|
case DockSide.Top:
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
default:
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-06-11 15:17:25 -07:00
|
|
|
|
}
|