public MainViewWidget(ThemeConfig theme) : base(FlowDirection.TopToBottom) { this.AnchorAll(); this.theme = theme; this.Name = "PartPreviewContent"; this.BackgroundColor = theme.BackgroundColor; // Push TouchScreenMode into GuiWidget GuiWidget.TouchScreenMode = UserSettings.Instance.IsTouchScreen; var extensionArea = new LeftClipFlowLayoutWidget() { BackgroundColor = theme.TabBarBackground, VAnchor = VAnchor.Stretch, Padding = new BorderDouble(left: 8) }; tabControl = new ChromeTabs(extensionArea, theme) { VAnchor = VAnchor.Stretch, HAnchor = HAnchor.Stretch, BackgroundColor = theme.BackgroundColor, BorderColor = theme.MinimalShade, Border = new BorderDouble(left: 1), }; tabControl.PlusClicked += (s, e) => UiThread.RunOnIdle(() => { this.CreatePartTab().ConfigureAwait(false); }); // Force the ActionArea to be as high as ButtonHeight tabControl.TabBar.ActionArea.MinimumSize = new Vector2(0, theme.ButtonHeight); tabControl.TabBar.BackgroundColor = theme.TabBarBackground; tabControl.TabBar.BorderColor = theme.BackgroundColor; // Force common padding into top region tabControl.TabBar.Padding = theme.TabbarPadding.Clone(top: theme.TabbarPadding.Top * 2, bottom: 0); if (Application.EnableNetworkTraffic) { // add in the update available button updateAvailableButton = new LinkLabel("Update Available".Localize(), theme) { Visible = false, Name = "Update Available Link", ToolTipText = "There is a new update available for download".Localize(), VAnchor = VAnchor.Center, Margin = new BorderDouble(10, 0) }; // Register listeners UserSettings.Instance.SettingChanged += SetLinkButtonsVisibility; SetLinkButtonsVisibility(this, null); updateAvailableButton.Click += (s, e) => UiThread.RunOnIdle(() => { UpdateControlData.Instance.CheckForUpdate(); DialogWindow.Show <CheckForUpdatesPage>(); }); tabControl.TabBar.ActionArea.AddChild(updateAvailableButton); UpdateControlData.Instance.UpdateStatusChanged.RegisterEvent((s, e) => { SetLinkButtonsVisibility(s, new StringEventArgs("Unknown")); }, ref unregisterEvents); } this.AddChild(tabControl); ApplicationController.Instance.NotifyPrintersTabRightElement(extensionArea); // Store tab tabControl.AddTab( new ChromeTab("Store", "Store".Localize(), tabControl, new StoreTabPage(theme), theme, hasClose: false) { MinimumSize = new Vector2(0, theme.TabButtonHeight), Name = "Store Tab", Padding = new BorderDouble(15, 0), }); // Library tab var libraryWidget = new LibraryWidget(this, theme) { BackgroundColor = theme.BackgroundColor }; tabControl.AddTab( new ChromeTab("Library", "Library".Localize(), tabControl, libraryWidget, theme, hasClose: false) { MinimumSize = new Vector2(0, theme.TabButtonHeight), Name = "Library Tab", Padding = new BorderDouble(15, 0), }); // Hardware tab tabControl.AddTab( new ChromeTab( "Hardware", "Hardware".Localize(), tabControl, new HardwareTabPage(theme) { BackgroundColor = theme.BackgroundColor }, theme, hasClose: false) { MinimumSize = new Vector2(0, theme.TabButtonHeight), Name = "Hardware Tab", Padding = new BorderDouble(15, 0), }); string tabKey = ApplicationController.Instance.MainTabKey; if (string.IsNullOrEmpty(tabKey)) { tabKey = "Hardware"; } // HACK: Restore to the first printer tab if PrinterTabSelected and tabKey not found. This allows sign in/out to remain on the printer tab across different users if (!tabControl.AllTabs.Any(t => t.Key == tabKey) && ApplicationController.Instance.PrinterTabSelected) { var key = tabControl.AllTabs.Where(t => t.TabContent is PrinterTabPage).FirstOrDefault()?.Key; if (key != null) { tabKey = key; } } var brandMenu = new BrandMenuButton(theme) { HAnchor = HAnchor.Fit, VAnchor = VAnchor.Fit, BackgroundColor = theme.TabBarBackground, Padding = theme.TabbarPadding.Clone(right: theme.DefaultContainerPadding) }; tabControl.TabBar.ActionArea.AddChild(brandMenu, 0); // Restore active workspace tabs foreach (var workspace in ApplicationController.Instance.Workspaces) { // Create and switch to new printer tab if (workspace.Printer?.Settings.PrinterSelected == true) { tabControl.ActiveTab = this.CreatePrinterTab(workspace, theme); } else { tabControl.ActiveTab = this.CreatePartTab(workspace); } tabControl.RefreshTabPointers(); } tabControl.SelectedTabKey = tabKey; statusBar = new Toolbar(theme) { HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Absolute, Padding = 1, Height = 22, BackgroundColor = theme.BackgroundColor, Border = new BorderDouble(top: 1), BorderColor = theme.BorderColor20, }; this.AddChild(statusBar); statusBar.ActionArea.VAnchor = VAnchor.Stretch; tasksContainer = new FlowLayoutWidget(FlowDirection.LeftToRight) { HAnchor = HAnchor.Fit, VAnchor = VAnchor.Stretch, BackgroundColor = theme.MinimalShade, Name = "runningTasksPanel" }; statusBar.AddChild(tasksContainer); stretchStatusPanel = new GuiWidget() { HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Stretch, Padding = new BorderDouble(right: 3), Margin = new BorderDouble(right: 2, top: 1, bottom: 1), Border = new BorderDouble(1), BackgroundColor = theme.MinimalShade.WithAlpha(10), BorderColor = theme.SlightShade, Width = 200 }; statusBar.AddChild(stretchStatusPanel); var panelBackgroundColor = theme.MinimalShade.WithAlpha(10); statusBar.AddChild( this.CreateThemeStatusPanel(theme, panelBackgroundColor)); statusBar.AddChild( this.CreateNetworkStatusPanel(theme)); this.RenderRunningTasks(theme, ApplicationController.Instance.Tasks); // Register listeners PrinterSettings.AnyPrinterSettingChanged += Printer_SettingChanged; ApplicationController.Instance.WorkspacesChanged += Workspaces_Changed; ApplicationController.Instance.Tasks.TasksChanged += Tasks_TasksChanged; tabControl.ActiveTabChanged += TabControl_ActiveTabChanged; ApplicationController.Instance.ShellFileOpened += this.Instance_OpenNewFile; ApplicationController.Instance.MainView = this; }
private void AddStandardUi(ThemeConfig theme) { var extensionArea = new LeftClipFlowLayoutWidget() { BackgroundColor = theme.TabBarBackground, VAnchor = VAnchor.Stretch, Padding = new BorderDouble(left: 8) }; SearchPanel searchPanel = null; bool searchPanelOpenOnMouseDown = false; var searchButton = theme.CreateSearchButton(); searchButton.Name = "App Search Button"; searchButton.MouseDown += (s, e) => { searchPanelOpenOnMouseDown = searchPanel != null; }; searchButton.Click += SearchButton_Click; extensionArea.AddChild(searchButton); async void SearchButton_Click(object sender, EventArgs e) { if (searchPanel == null && !searchPanelOpenOnMouseDown) { void ShowSearchPanel() { searchPanel = new SearchPanel(this.TabControl, searchButton, theme); searchPanel.Closed += SearchPanel_Closed; var systemWindow = this.Parents <SystemWindow>().FirstOrDefault(); systemWindow.ShowRightSplitPopup( new MatePoint(searchButton), new MatePoint(searchPanel), borderWidth: 0); } if (HelpIndex.IndexExists) { ShowSearchPanel(); } else { searchButton.Enabled = false; try { // Show popover var popover = new Popover(ArrowDirection.Up, 7, 5, 0) { TagColor = theme.AccentMimimalOverlay }; popover.AddChild(new TextWidget("Preparing help".Localize() + "...", pointSize: theme.DefaultFontSize - 1, textColor: theme.TextColor)); popover.ArrowOffset = (int)(popover.Width - (searchButton.Width / 2)); this.Parents <SystemWindow>().FirstOrDefault().ShowPopover( new MatePoint(searchButton) { Mate = new MateOptions(MateEdge.Right, MateEdge.Bottom), AltMate = new MateOptions(MateEdge.Right, MateEdge.Bottom), Offset = new RectangleDouble(12, 0, 12, 0) }, new MatePoint(popover) { Mate = new MateOptions(MateEdge.Right, MateEdge.Top), AltMate = new MateOptions(MateEdge.Left, MateEdge.Bottom) }); await Task.Run(async() => { // Start index generation await HelpIndex.RebuildIndex(); UiThread.RunOnIdle(() => { // Close popover popover.Close(); // Continue to original task ShowSearchPanel(); }); }); } catch { } searchButton.Enabled = true; } } else { searchPanel?.CloseOnIdle(); searchPanelOpenOnMouseDown = false; } } void SearchPanel_Closed(object sender, EventArgs e) { // Unregister searchPanel.Closed -= SearchPanel_Closed; // Release searchPanel = null; } tabControl = new ChromeTabs(extensionArea, theme) { VAnchor = VAnchor.Stretch, HAnchor = HAnchor.Stretch, BackgroundColor = theme.BackgroundColor, BorderColor = theme.MinimalShade, Border = new BorderDouble(left: 1), }; tabControl.PlusClicked += (s, e) => UiThread.RunOnIdle(() => { this.CreatePartTab().ConfigureAwait(false); }); // Force the ActionArea to be as high as ButtonHeight tabControl.TabBar.ActionArea.MinimumSize = new Vector2(0, theme.ButtonHeight); tabControl.TabBar.BackgroundColor = theme.TabBarBackground; tabControl.TabBar.BorderColor = theme.BackgroundColor; // Force common padding into top region tabControl.TabBar.Padding = theme.TabbarPadding.Clone(top: theme.TabbarPadding.Top * 2, bottom: 0); if (Application.EnableNetworkTraffic) { // add in the update available button updateAvailableButton = new LinkLabel("Update Available".Localize(), theme) { Visible = false, Name = "Update Available Link", ToolTipText = "There is a new update available for download".Localize(), VAnchor = VAnchor.Center, Margin = new BorderDouble(10, 0), TextColor = theme.PrimaryAccentColor }; // Register listeners UserSettings.Instance.SettingChanged += SetLinkButtonsVisibility; SetLinkButtonsVisibility(this, null); updateAvailableButton.Click += (s, e) => { UpdateControlData.Instance.CheckForUpdate(); DialogWindow.Show <CheckForUpdatesPage>(); }; tabControl.TabBar.ActionArea.AddChild(updateAvailableButton); UpdateControlData.Instance.UpdateStatusChanged.RegisterEvent((s, e) => { SetLinkButtonsVisibility(s, new StringEventArgs("Unknown")); }, ref unregisterEvents); } this.AddChild(tabControl); ApplicationController.Instance.NotifyPrintersTabRightElement(extensionArea); ChromeTab tab = null; // Upgrade tab if (!ApplicationController.Instance.IsMatterControlPro()) { tabControl.AddTab( tab = new ChromeTab("Upgrade", "Upgrade".Localize(), tabControl, new UpgradeToProTabPage(theme), theme, hasClose: false) { MinimumSize = new Vector2(0, theme.TabButtonHeight), Name = "Upgrade", Padding = new BorderDouble(15, 0), }); tab.AfterDraw += (s, e) => { e.Graphics2D.Circle(tab.LocalBounds.Right - 25 * DeviceScale, tab.LocalBounds.Bottom + tab.Height / 2 - 1 * DeviceScale, 5 * DeviceScale, theme.PrimaryAccentColor); }; } else { // Store tab tabControl.AddTab( tab = new ChromeTab("Store", "Store".Localize(), tabControl, new StoreTabPage(theme), theme, hasClose: false) { MinimumSize = new Vector2(0, theme.TabButtonHeight), Name = "Store Tab", Padding = new BorderDouble(15, 0), }); } EnableReduceWidth(tab, theme); // Library tab var libraryWidget = new LibraryWidget(this, theme) { BackgroundColor = theme.BackgroundColor }; tabControl.AddTab( tab = new ChromeTab("Library", "Library".Localize(), tabControl, libraryWidget, theme, hasClose: false) { MinimumSize = new Vector2(0, theme.TabButtonHeight), Name = "Library Tab", Padding = new BorderDouble(15, 0), }); EnableReduceWidth(tab, theme); // Hardware tab tabControl.AddTab( tab = new ChromeTab( "Hardware", "Hardware".Localize(), tabControl, new HardwareTabPage(theme) { BackgroundColor = theme.BackgroundColor }, theme, hasClose: false) { MinimumSize = new Vector2(0, theme.TabButtonHeight), Name = "Hardware Tab", Padding = new BorderDouble(15, 0), }); EnableReduceWidth(tab, theme); SetInitialTab(); var brandMenu = new BrandMenuButton(theme) { HAnchor = HAnchor.Fit, VAnchor = VAnchor.Fit, BackgroundColor = theme.TabBarBackground, Padding = theme.TabbarPadding.Clone(right: theme.DefaultContainerPadding) }; tabControl.TabBar.ActionArea.AddChild(brandMenu, 0); tabControl.TabBar.ActionArea.VAnchor = VAnchor.Absolute; tabControl.TabBar.ActionArea.Height = brandMenu.Height; // Restore active workspace tabs foreach (var workspace in ApplicationController.Instance.Workspaces) { ChromeTab newTab; // Create and switch to new printer tab if (workspace.Printer?.Settings.PrinterSelected == true) { newTab = this.CreatePrinterTab(workspace, theme); } else { newTab = this.CreatePartTab(workspace); } if (newTab.Key == ApplicationController.Instance.MainTabKey) { tabControl.ActiveTab = newTab; } tabControl.RefreshTabPointers(); } statusBar = new Toolbar(theme.TabbarPadding) { HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Absolute, Padding = 1, Height = 22 * GuiWidget.DeviceScale, BackgroundColor = theme.BackgroundColor, Border = new BorderDouble(top: 1), BorderColor = theme.BorderColor20, }; this.AddChild(statusBar); statusBar.ActionArea.VAnchor = VAnchor.Stretch; tasksContainer = new FlowLayoutWidget(FlowDirection.LeftToRight) { HAnchor = HAnchor.Fit, VAnchor = VAnchor.Stretch, BackgroundColor = theme.MinimalShade, Name = "runningTasksPanel" }; statusBar.AddChild(tasksContainer); stretchStatusPanel = new GuiWidget() { HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Stretch, Padding = new BorderDouble(right: 3), Margin = new BorderDouble(right: 2, top: 1, bottom: 1), Border = new BorderDouble(1), BackgroundColor = theme.MinimalShade.WithAlpha(10), BorderColor = theme.SlightShade, Width = 200 * GuiWidget.DeviceScale }; statusBar.AddChild(stretchStatusPanel); var panelBackgroundColor = theme.MinimalShade.WithAlpha(10); statusBar.AddChild(this.CreateThemeStatusPanel(theme, panelBackgroundColor)); statusBar.AddChild(this.CreateNetworkStatusPanel(theme)); this.RenderRunningTasks(theme, ApplicationController.Instance.Tasks); }