2017-08-15 12:32:09 -07:00
|
|
|
|
/*
|
|
|
|
|
|
Copyright (c) 2017, Lars Brubaker, John Lewin
|
|
|
|
|
|
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-11-11 17:28:03 -08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Linq;
|
2017-08-15 12:32:09 -07:00
|
|
|
|
using MatterHackers.Agg;
|
2017-08-17 18:18:41 -07:00
|
|
|
|
using MatterHackers.Agg.Image;
|
2017-08-15 12:32:09 -07:00
|
|
|
|
using MatterHackers.Agg.UI;
|
|
|
|
|
|
using MatterHackers.Agg.VertexSource;
|
2017-11-11 17:28:03 -08:00
|
|
|
|
using MatterHackers.Localizations;
|
2017-08-15 12:32:09 -07:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.PartPreviewWindow
|
|
|
|
|
|
{
|
2017-11-11 17:28:03 -08:00
|
|
|
|
public class MainTab : GuiWidget, ITab
|
2017-08-15 12:32:09 -07:00
|
|
|
|
{
|
2017-11-11 17:28:03 -08:00
|
|
|
|
public event EventHandler CloseClicked;
|
|
|
|
|
|
|
|
|
|
|
|
private SimpleTabs parentTabControl;
|
|
|
|
|
|
|
2017-11-21 11:11:07 -08:00
|
|
|
|
public MainTab(string tabLabel, SimpleTabs parentTabControl, GuiWidget tabContent, ThemeConfig theme, string tabImageUrl = null)
|
2017-11-11 17:28:03 -08:00
|
|
|
|
{
|
|
|
|
|
|
this.HAnchor = HAnchor.Fit;
|
|
|
|
|
|
this.VAnchor = VAnchor.Fit | VAnchor.Bottom;
|
|
|
|
|
|
this.Padding = 0;
|
|
|
|
|
|
this.Margin = 0;
|
2017-11-21 11:11:07 -08:00
|
|
|
|
this.theme = theme;
|
2017-11-11 17:28:03 -08:00
|
|
|
|
|
|
|
|
|
|
this.TabContent = tabContent;
|
|
|
|
|
|
this.parentTabControl = parentTabControl;
|
|
|
|
|
|
|
|
|
|
|
|
this.AddChild(
|
|
|
|
|
|
new TabPill(tabLabel, ActiveTheme.Instance.PrimaryTextColor, tabImageUrl)
|
|
|
|
|
|
{
|
|
|
|
|
|
Margin = new BorderDouble(right: 16)
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var closeButton = ApplicationController.Instance.Theme.CreateSmallResetButton();
|
|
|
|
|
|
closeButton.HAnchor = HAnchor.Right;
|
|
|
|
|
|
closeButton.Margin = new BorderDouble(right: 7, top: 1);
|
|
|
|
|
|
closeButton.Name = "Close Tab Button";
|
|
|
|
|
|
closeButton.ToolTipText = "Close".Localize();
|
|
|
|
|
|
closeButton.Click += (sender, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle(() =>
|
|
|
|
|
|
{
|
2017-11-14 14:19:02 -08:00
|
|
|
|
this.parentTabControl.RemoveTab(this);
|
2017-11-11 17:28:03 -08:00
|
|
|
|
this.CloseClicked?.Invoke(this, null);
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
this.AddChild(closeButton);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-11-21 11:11:07 -08:00
|
|
|
|
private ThemeConfig theme;
|
2017-11-11 17:28:03 -08:00
|
|
|
|
|
2017-11-21 11:11:07 -08:00
|
|
|
|
public GuiWidget TabContent { get; }
|
2017-11-11 17:28:03 -08:00
|
|
|
|
|
|
|
|
|
|
private static int tabInsetDistance = 14 / 2;
|
|
|
|
|
|
|
|
|
|
|
|
internal MainTab NextTab { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
internal MainTab PreviousTab { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnDraw(Graphics2D graphics2D)
|
|
|
|
|
|
{
|
|
|
|
|
|
var rect = LocalBounds;
|
|
|
|
|
|
var centerY = rect.YCenter;
|
|
|
|
|
|
|
|
|
|
|
|
var siblings = this.Parent.Children.OfType<MainTab>().ToList();
|
|
|
|
|
|
|
|
|
|
|
|
int position = siblings.IndexOf(this);
|
|
|
|
|
|
|
|
|
|
|
|
//MainTab leftSibling = (position > 0) ? siblings[position - 1] : null;
|
|
|
|
|
|
//MainTab rightSibling = (position < siblings.Count - 1) ? siblings[position + 1] : null;
|
|
|
|
|
|
|
|
|
|
|
|
var activeTab = parentTabControl.ActiveTab;
|
|
|
|
|
|
|
|
|
|
|
|
bool isFirstTab = position == 0;
|
|
|
|
|
|
bool rightSiblingSelected = this.NextTab == activeTab;
|
|
|
|
|
|
|
|
|
|
|
|
// Tab - core
|
|
|
|
|
|
var tabShape = new VertexStorage();
|
|
|
|
|
|
tabShape.MoveTo(rect.Left, centerY);
|
|
|
|
|
|
tabShape.LineTo(rect.Left + tabInsetDistance, rect.Top);
|
|
|
|
|
|
tabShape.LineTo(rect.Right - tabInsetDistance, rect.Top);
|
|
|
|
|
|
tabShape.LineTo(rect.Right, centerY);
|
|
|
|
|
|
if (!rightSiblingSelected)
|
|
|
|
|
|
{
|
|
|
|
|
|
tabShape.LineTo(rect.Right, rect.Bottom);
|
|
|
|
|
|
}
|
|
|
|
|
|
tabShape.LineTo(rect.Right - tabInsetDistance, rect.Bottom);
|
|
|
|
|
|
tabShape.LineTo(rect.Left + tabInsetDistance, rect.Bottom);
|
|
|
|
|
|
|
|
|
|
|
|
if (isFirstTab)
|
|
|
|
|
|
{
|
|
|
|
|
|
tabShape.LineTo(rect.Left, rect.Bottom);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
graphics2D.Render(
|
|
|
|
|
|
tabShape,
|
2017-11-21 11:11:07 -08:00
|
|
|
|
(this == activeTab) ? theme.ActiveTabColor : theme.InactiveTabColor);
|
2017-11-11 17:28:03 -08:00
|
|
|
|
|
|
|
|
|
|
if (!isFirstTab)
|
|
|
|
|
|
{
|
|
|
|
|
|
DrawTabLowerLeft(
|
|
|
|
|
|
graphics2D,
|
|
|
|
|
|
rect,
|
2017-11-21 11:11:07 -08:00
|
|
|
|
(this.PreviousTab == activeTab || this == activeTab) ? theme.ActiveTabColor : theme.InactiveTabColor);
|
2017-11-11 17:28:03 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (rightSiblingSelected)
|
|
|
|
|
|
{
|
2017-11-21 11:11:07 -08:00
|
|
|
|
DrawTabLowerRight(graphics2D, rect, theme.ActiveTabColor);
|
2017-11-11 17:28:03 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
base.OnDraw(graphics2D);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void DrawTabLowerRight(Graphics2D graphics2D, RectangleDouble rect, Color color)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Tab - right nub
|
|
|
|
|
|
var tabRight = new VertexStorage();
|
|
|
|
|
|
tabRight.MoveTo(rect.Right, rect.YCenter);
|
|
|
|
|
|
tabRight.LineTo(rect.Right, rect.Bottom);
|
|
|
|
|
|
tabRight.LineTo(rect.Right - tabInsetDistance, rect.Bottom);
|
|
|
|
|
|
|
|
|
|
|
|
graphics2D.Render(tabRight, color);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void DrawTabLowerLeft(Graphics2D graphics2D, RectangleDouble rect, Color color)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Tab - left nub
|
|
|
|
|
|
var tabLeft = new VertexStorage();
|
|
|
|
|
|
tabLeft.MoveTo(rect.Left, rect.YCenter);
|
|
|
|
|
|
tabLeft.LineTo(rect.Left + tabInsetDistance, rect.Bottom);
|
|
|
|
|
|
tabLeft.LineTo(rect.Left, rect.Bottom);
|
|
|
|
|
|
|
|
|
|
|
|
graphics2D.Render(tabLeft, color);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-17 18:18:41 -07:00
|
|
|
|
private class TabPill : FlowLayoutWidget
|
|
|
|
|
|
{
|
|
|
|
|
|
private TextWidget label;
|
|
|
|
|
|
|
2017-10-31 11:43:25 -07:00
|
|
|
|
public TabPill(string tabTitle, Color textColor, string imageUrl = null)
|
2017-08-17 05:58:59 -07:00
|
|
|
|
{
|
2017-11-11 17:28:03 -08:00
|
|
|
|
this.Selectable = false;
|
|
|
|
|
|
this.Padding = new BorderDouble(10, 5, 10, 4);
|
2017-08-17 18:18:41 -07:00
|
|
|
|
|
2017-09-15 09:08:55 -07:00
|
|
|
|
if (!string.IsNullOrEmpty(imageUrl))
|
2017-08-17 18:18:41 -07:00
|
|
|
|
{
|
2017-11-11 17:28:03 -08:00
|
|
|
|
var imageWidget = new ImageWidget(new ImageBuffer(16, 16))
|
|
|
|
|
|
{
|
|
|
|
|
|
Margin = new BorderDouble(right: 6, bottom: 2),
|
|
|
|
|
|
VAnchor = VAnchor.Center
|
|
|
|
|
|
};
|
|
|
|
|
|
this.AddChild(imageWidget);
|
|
|
|
|
|
|
2017-09-15 09:08:55 -07:00
|
|
|
|
// Attempt to load image
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
// TODO: Must use caching
|
|
|
|
|
|
ApplicationController.Instance.DownloadToImageAsync(imageWidget.Image, imageUrl, false);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch { }
|
2017-08-17 18:18:41 -07:00
|
|
|
|
}
|
2017-11-11 17:28:03 -08:00
|
|
|
|
|
|
|
|
|
|
label = new TextWidget(tabTitle)
|
|
|
|
|
|
{
|
|
|
|
|
|
TextColor = textColor,
|
|
|
|
|
|
VAnchor = VAnchor.Center
|
|
|
|
|
|
};
|
|
|
|
|
|
this.AddChild(label);
|
2017-08-17 18:18:41 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-31 11:43:25 -07:00
|
|
|
|
public Color TextColor
|
2017-08-17 05:58:59 -07:00
|
|
|
|
{
|
2017-11-11 17:28:03 -08:00
|
|
|
|
get => label.TextColor;
|
2017-08-17 18:18:41 -07:00
|
|
|
|
set => label.TextColor = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override string Text
|
2017-08-17 05:58:59 -07:00
|
|
|
|
{
|
2017-08-17 18:18:41 -07:00
|
|
|
|
get => label.Text;
|
|
|
|
|
|
set => label.Text = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-08-15 12:32:09 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|