From dea37667add4e34f179fbc78c7e5d57eebb4a6a5 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Mon, 8 Jan 2018 15:45:15 -0800 Subject: [PATCH] Remove network image - Issue MatterHackers/MCCentral#2609 Remove network linked image --- PartPreviewWindow/MainTab.cs | 52 +++++++++++++++++-------- PartPreviewWindow/PartPreviewContent.cs | 2 +- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/PartPreviewWindow/MainTab.cs b/PartPreviewWindow/MainTab.cs index 59618e734..4fac1a836 100644 --- a/PartPreviewWindow/MainTab.cs +++ b/PartPreviewWindow/MainTab.cs @@ -49,7 +49,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow public GuiWidget TabContent { get; protected set; } - public SimpleTab(string tabLabel, SimpleTabs parentTabControl, GuiWidget tabContent, ThemeConfig theme, string tabImageUrl = null, bool hasClose = true, double pointSize = 12) + public SimpleTab(string tabLabel, SimpleTabs parentTabControl, GuiWidget tabContent, ThemeConfig theme, string tabImageUrl = null, bool hasClose = true, double pointSize = 12, ImageBuffer iconImage = null) { this.HAnchor = HAnchor.Fit; this.VAnchor = VAnchor.Fit | VAnchor.Bottom; @@ -60,11 +60,17 @@ namespace MatterHackers.MatterControl.PartPreviewWindow this.TabContent = tabContent; this.parentTabControl = parentTabControl; - this.AddChild( - tabPill = new TabPill(tabLabel, ActiveTheme.Instance.PrimaryTextColor, tabImageUrl, pointSize) - { - Margin = (hasClose) ? new BorderDouble(right: 16) : 0 - }); + if (iconImage != null) + { + tabPill = new TabPill(tabLabel, ActiveTheme.Instance.PrimaryTextColor, iconImage, pointSize); + } + else + { + tabPill = new TabPill(tabLabel, ActiveTheme.Instance.PrimaryTextColor, tabImageUrl, pointSize); + } + tabPill.Margin = (hasClose) ? new BorderDouble(right: 16) : 0; + + this.AddChild(tabPill); if (hasClose) { @@ -89,28 +95,37 @@ namespace MatterHackers.MatterControl.PartPreviewWindow protected class TabPill : FlowLayoutWidget { private TextWidget label; + private ImageWidget imageWidget; public TabPill(string tabTitle, Color textColor, string imageUrl = null, double pointSize = 12) + : this (tabTitle, textColor, string.IsNullOrEmpty(imageUrl) ? null : new ImageBuffer(16, 16), pointSize) + { + if (imageWidget != null + && !string.IsNullOrEmpty(imageUrl)) + { + try + { + // TODO: Use caching + // Attempt to load image + ApplicationController.Instance.DownloadToImageAsync(imageWidget.Image, imageUrl, false); + } + catch { } + } + } + + public TabPill(string tabTitle, Color textColor, ImageBuffer imageBuffer = null, double pointSize = 12) { this.Selectable = false; this.Padding = new BorderDouble(10, 5, 10, 4); - if (!string.IsNullOrEmpty(imageUrl)) + if (imageBuffer != null) { - var imageWidget = new ImageWidget(new ImageBuffer(16, 16)) + imageWidget = new ImageWidget(imageBuffer) { Margin = new BorderDouble(right: 6, bottom: 2), VAnchor = VAnchor.Center }; this.AddChild(imageWidget); - - // Attempt to load image - try - { - // TODO: Must use caching - ApplicationController.Instance.DownloadToImageAsync(imageWidget.Image, imageUrl, false); - } - catch { } } label = new TextWidget(tabTitle, pointSize: pointSize) @@ -173,6 +188,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { } + public ChromeTab(string tabLabel, SimpleTabs parentTabControl, GuiWidget tabContent, ThemeConfig theme, ImageBuffer imageBuffer) + : base(tabLabel, parentTabControl, tabContent, theme, iconImage: imageBuffer) + { + } + private static int tabInsetDistance = 14 / 2; internal ChromeTab NextTab { get; set; } diff --git a/PartPreviewWindow/PartPreviewContent.cs b/PartPreviewWindow/PartPreviewContent.cs index 77a03e1cf..df951a2f4 100644 --- a/PartPreviewWindow/PartPreviewContent.cs +++ b/PartPreviewWindow/PartPreviewContent.cs @@ -198,7 +198,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow tabControl, new PartTabPage(null, sceneContext, theme, "xxxxx"), theme, - "https://i.imgur.com/nkeYgfU.png") + AggContext.StaticData.LoadIcon("part.png")) { Name = "newPart" + tabControl.AllTabs.Count(), MinimumSize = new Vector2(120, theme.shortButtonHeight)