Exemple #1
0
        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)
                };

                // 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);

            // 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),
            });

            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);

            // 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)
            {
                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);
        }
Exemple #2
0
        public SelectedObjectPanel(View3DWidget view3DWidget, BedConfig sceneContext, ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            this.HAnchor      = HAnchor.Stretch;
            this.VAnchor      = VAnchor.Top | VAnchor.Fit;
            this.Padding      = 0;
            this.view3DWidget = view3DWidget;
            this.theme        = theme;
            this.sceneContext = sceneContext;

            this.ContentPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit,
            };

            var scrollable = new ScrollableWidget(true)
            {
                Name    = "editorPanel",
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch,
            };

            scrollable.AddChild(this.ContentPanel);
            scrollable.ScrollArea.HAnchor = HAnchor.Stretch;

            this.AddChild(scrollable);

            var toolbar = new LeftClipFlowLayoutWidget()
            {
                BackgroundColor = theme.TabBodyBackground,
                Padding         = theme.ToolbarPadding,
                HAnchor         = HAnchor.Fit,
                VAnchor         = VAnchor.Fit
            };

            var scene = sceneContext.Scene;

            // put in a make permanent button
            var icon        = AggContext.StaticData.LoadIcon("fa-check_16.png", 16, 16, theme.InvertIcons).SetPreMultiply();
            var applyButton = new IconButton(icon, theme)
            {
                Margin      = theme.ButtonSpacing,
                ToolTipText = "Apply operation and make permanent".Localize(),
                Enabled     = scene.SelectedItem?.CanApply == true
            };

            applyButton.Click += (s, e) =>
            {
                this.item.Apply(view3DWidget.Scene.UndoBuffer);
                scene.SelectedItem = null;
            };
            scene.SelectionChanged += (s, e) => applyButton.Enabled = scene.SelectedItem?.CanApply == true;
            toolbar.AddChild(applyButton);

            // put in a remove button
            var removeButton = new IconButton(AggContext.StaticData.LoadIcon("close.png", 16, 16, theme.InvertIcons), theme)
            {
                Margin      = theme.ButtonSpacing,
                ToolTipText = "Remove operation from parts".Localize()
            };

            removeButton.Click += (s, e) =>
            {
                var rootSelection = scene.SelectedItemRoot;

                item.Remove(view3DWidget.Scene.UndoBuffer);

                scene.SelectedItem = null;

                if (item != rootSelection)
                {
                    scene.SelectedItem = rootSelection;
                }
            };
            toolbar.AddChild(removeButton);

            var overflowButton = new OverflowBar.OverflowMenuButton(theme);

            overflowButton.Enabled  = scene.SelectedItem != null;
            scene.SelectionChanged += (s, e) => overflowButton.Enabled = scene.SelectedItem != null;

            overflowButton.PopupBorderColor    = ApplicationController.Instance.MenuTheme.GetBorderColor(120);
            overflowButton.DynamicPopupContent = () =>
            {
                return(ApplicationController.Instance.GetActionMenuForSceneItem(item, sceneContext.Scene));
            };
            toolbar.AddChild(overflowButton);

            editorPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit,
                Name    = "editorPanel",
                Padding = new BorderDouble(right: theme.DefaultContainerPadding + 1)
            };

            // Wrap editorPanel with scrollable container
            var scrollableWidget = new ScrollableWidget(true)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            };

            scrollableWidget.AddChild(editorPanel);
            scrollableWidget.ScrollArea.HAnchor = HAnchor.Stretch;
            scrollableWidget.Padding            = new BorderDouble(right: theme.DefaultContainerPadding * .8);

            editorSectionWidget = new ResizableSectionWidget("Editor", sceneContext.ViewState.SelectedObjectEditorHeight, scrollableWidget, theme, serializationKey: UserSettingsKey.EditorPanelExpanded, rightAlignedContent: toolbar, defaultExpansion: true)
            {
                VAnchor = VAnchor.Fit,
            };
            editorSectionWidget.Resized += (s, e) =>
            {
                sceneContext.ViewState.SelectedObjectEditorHeight = editorSectionWidget.ResizeContainer.Height;
            };

            int topBottom = theme.DefaultContainerPadding / 2;

            editorSectionWidget.ResizeContainer.Padding = new BorderDouble(left: theme.DefaultContainerPadding, top: topBottom, bottom: topBottom + editorSectionWidget.ResizeContainer.SplitterHeight);

            this.ContentPanel.AddChild(editorSectionWidget);

            var colorSection = new SectionWidget(
                "Color".Localize(),
                new ColorSwatchSelector(scene, theme, buttonSize: 16, buttonSpacing: new BorderDouble(1, 1, 0, 0))
            {
                Margin = new BorderDouble(left: 10)
            },
                theme,
                serializationKey: UserSettingsKey.ColorPanelExpanded)
            {
                Name = "Color Panel",
            };

            this.ContentPanel.AddChild(colorSection);

            var materialsSection = new SectionWidget("Materials".Localize(), new MaterialControls(scene, theme), theme, serializationKey: UserSettingsKey.MaterialsPanelExpanded)
            {
                Name = "Materials Panel",
            };

            this.ContentPanel.AddChild(materialsSection);

            // Enforce panel padding in sidebar
            foreach (var sectionWidget in this.ContentPanel.Children <SectionWidget>())
            {
                // Special case for editorResizeWrapper due to ResizeContainer
                if (sectionWidget is ResizableSectionWidget resizableSectionWidget)
                {
                    // Apply padding to ResizeContainer not wrapper
                    //resizableSectionWidget.ResizeContainer.Padding = new BorderDouble(10, 10, 10, 0);
                }
                else
                {
                    sectionWidget.ContentPanel.Padding   = new BorderDouble(10, 10, 10, 0);
                    sectionWidget.ExpandableWhenDisabled = true;
                    sectionWidget.Enabled = false;
                }
            }
        }
Exemple #3
0
        public PartPreviewContent(ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            this.AnchorAll();

            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 = ActiveTheme.Instance.PrimaryBackgroundColor,
                BorderColor     = theme.MinimalShade,
                Border          = new BorderDouble(left: 1),
                NewTabPage      = () =>
                {
                    return(new StartTabPage(this, theme));
                }
            };
            tabControl.ActiveTabChanged += (s, e) =>
            {
                if (this.tabControl.ActiveTab?.TabContent is PartTabPage tabPage)
                {
                    var dragDropData = ApplicationController.Instance.DragDropData;

                    // Set reference on tab change
                    dragDropData.View3DWidget = tabPage.view3DWidget;
                    dragDropData.SceneContext = tabPage.sceneContext;
                }
            };

            // 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.ActiveTabColor;

            // Force common padding into top region
            tabControl.TabBar.Padding = theme.TabbarPadding.Clone(top: theme.TabbarPadding.Top * 2, bottom: 0);

            // add in a what's new button
            var seeWhatsNewButton = new LinkLabel("What's New...".Localize(), theme)
            {
                Name        = "What's New Link",
                ToolTipText = "See what's new in this version of MatterControl".Localize(),
                VAnchor     = VAnchor.Center,
                Margin      = new BorderDouble(10, 0),
                TextColor   = theme.Colors.PrimaryTextColor
            };

            seeWhatsNewButton.Click += (s, e) => UiThread.RunOnIdle(() =>
            {
                UserSettings.Instance.set(UserSettingsKey.LastReadWhatsNew, JsonConvert.SerializeObject(DateTime.Now));
                DialogWindow.Show(new HelpPage("What's New"));
            });

            tabControl.TabBar.ActionArea.AddChild(seeWhatsNewButton);

            // add in the update available button
            var updateAvailableButton = new LinkLabel("Update Available".Localize(), theme)
            {
                Visible = false,
            };

            // make the function inline so we don't have to create members for the buttons
            EventHandler SetLinkButtonsVisibility = (s, e) =>
            {
                if (UserSettings.Instance.HasLookedAtWhatsNew())
                {
                    // hide it
                    seeWhatsNewButton.Visible = false;
                }

                if (UpdateControlData.Instance.UpdateStatus == UpdateControlData.UpdateStatusStates.UpdateAvailable)
                {
                    updateAvailableButton.Visible = true;
                    // if we are going to show the update link hide the whats new link no matter what
                    seeWhatsNewButton.Visible = false;
                }
                else
                {
                    updateAvailableButton.Visible = false;
                }
            };

            UserSettings.Instance.Changed += SetLinkButtonsVisibility;
            Closed += (s, e) => UserSettings.Instance.Changed -= SetLinkButtonsVisibility;

            RunningInterval showUpdateInterval = null;

            updateAvailableButton.VisibleChanged += (s, e) =>
            {
                if (!updateAvailableButton.Visible)
                {
                    if (showUpdateInterval != null)
                    {
                        showUpdateInterval.Continue = false;
                        showUpdateInterval          = null;
                    }
                    return;
                }

                showUpdateInterval = UiThread.SetInterval(() =>
                {
                    double displayTime  = 1;
                    double pulseTime    = 1;
                    double totalSeconds = 0;
                    var textWidgets     = updateAvailableButton.Descendants <TextWidget>().Where((w) => w.Visible == true).ToArray();
                    Color startColor    = theme.Colors.PrimaryTextColor;
                    // Show a highlight on the button as the user did not click it
                    Animation flashBackground = null;
                    flashBackground           = new Animation()
                    {
                        DrawTarget      = updateAvailableButton,
                        FramesPerSecond = 10,
                        Update          = (s1, updateEvent) =>
                        {
                            totalSeconds += updateEvent.SecondsPassed;
                            if (totalSeconds < displayTime)
                            {
                                double blend = AttentionGetter.GetFadeInOutPulseRatio(totalSeconds, pulseTime);
                                var color    = new Color(startColor, (int)((1 - blend) * 255));
                                foreach (var textWidget in textWidgets)
                                {
                                    textWidget.TextColor = color;
                                }
                            }
                            else
                            {
                                foreach (var textWidget in textWidgets)
                                {
                                    textWidget.TextColor = startColor;
                                }
                                flashBackground.Stop();
                            }
                        }
                    };
                    flashBackground.Start();
                }, 120);
            };

            updateAvailableButton.Name = "Update Available Link";
            SetLinkButtonsVisibility(this, null);
            updateAvailableButton.ToolTipText = "There is a new update available for download".Localize();
            updateAvailableButton.VAnchor     = VAnchor.Center;
            updateAvailableButton.Margin      = new BorderDouble(10, 0);
            updateAvailableButton.Click      += (s, e) => UiThread.RunOnIdle(() =>
            {
                UiThread.RunOnIdle(() =>
                {
                    UpdateControlData.Instance.CheckForUpdate();
                    DialogWindow.Show <CheckForUpdatesPage>();
                });
            });

            tabControl.TabBar.ActionArea.AddChild(updateAvailableButton);

            UpdateControlData.Instance.UpdateStatusChanged.RegisterEvent(SetLinkButtonsVisibility, ref unregisterEvents);

            this.AddChild(tabControl);

            ActiveSliceSettings.SettingChanged.RegisterEvent((s, e) =>
            {
                if (e is StringEventArgs stringEvent &&
                    stringEvent.Data == SettingsKey.printer_name &&
                    printerTab != null)
                {
                    printerTab.Text = ActiveSliceSettings.Instance.GetValue(SettingsKey.printer_name);
                }
            }, ref unregisterEvents);

            ActiveSliceSettings.ActivePrinterChanged.RegisterEvent((s, e) =>
            {
                var activePrinter = ApplicationController.Instance.ActivePrinter;

                // If ActivePrinter has been nulled and a printer tab is open, close it
                var tab1 = tabControl.AllTabs.Skip(1).FirstOrDefault();
                if ((activePrinter == null || !activePrinter.Settings.PrinterSelected) &&
                    tab1?.TabContent is PrinterTabPage)
                {
                    tabControl.RemoveTab(tab1);
                }
                else
                {
                    this.CreatePrinterTab(activePrinter, theme);
                }
            }, ref unregisterEvents);

            ApplicationController.Instance.NotifyPrintersTabRightElement(extensionArea);

            // Show fixed start page
            tabControl.AddTab(
                new ChromeTab("Start".Localize(), tabControl, tabControl.NewTabPage(), theme, hasClose: false)
            {
                MinimumSize = new Vector2(0, theme.TabButtonHeight),
                Name        = "Start Tab",
                Padding     = new BorderDouble(15, 0)
            });

            // Add a tab for the current printer
            if (ActiveSliceSettings.Instance.PrinterSelected)
            {
                this.CreatePrinterTab(ApplicationController.Instance.ActivePrinter, theme);
            }

            // Restore active tabs
            foreach (var bed in ApplicationController.Instance.Workspaces)
            {
                this.CreatePartTab("New Part", bed, theme);
            }
        }
        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);
                });
            };

            tabControl.ActiveTabChanged += (s, e) =>
            {
                if (this.tabControl.ActiveTab?.TabContent is PartTabPage tabPage)
                {
                    var dragDropData = ApplicationController.Instance.DragDropData;

                    // Set reference on tab change
                    dragDropData.View3DWidget = tabPage.view3DWidget;
                    dragDropData.SceneContext = tabPage.sceneContext;

                    ApplicationController.Instance.PrinterTabSelected = true;
                }
                else
                {
                    ApplicationController.Instance.PrinterTabSelected = false;
                }

                ApplicationController.Instance.MainTabKey = tabControl.SelectedTabKey;
            };

            // 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);

            // add in a what's new button
            seeWhatsNewButton = new LinkLabel("What's New...".Localize(), theme)
            {
                Name        = "What's New Link",
                ToolTipText = "See what's new in this version of MatterControl".Localize(),
                VAnchor     = VAnchor.Center,
                Margin      = new BorderDouble(10, 0),
                TextColor   = theme.TextColor
            };
            seeWhatsNewButton.Click += (s, e) => UiThread.RunOnIdle(() =>
            {
                UserSettings.Instance.set(UserSettingsKey.LastReadWhatsNew, JsonConvert.SerializeObject(DateTime.Now));
                DialogWindow.Show(new HelpPage("What's New"));
            });

            tabControl.TabBar.ActionArea.AddChild(seeWhatsNewButton);

            // 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;

            RunningInterval showUpdateInterval = null;

            updateAvailableButton.VisibleChanged += (s, e) =>
            {
                if (!updateAvailableButton.Visible)
                {
                    if (showUpdateInterval != null)
                    {
                        UiThread.ClearInterval(showUpdateInterval);
                        showUpdateInterval = null;
                    }
                    return;
                }

                showUpdateInterval = UiThread.SetInterval(() =>
                {
                    double displayTime  = 1;
                    double pulseTime    = 1;
                    double totalSeconds = 0;
                    var textWidgets     = updateAvailableButton.Descendants <TextWidget>().Where((w) => w.Visible == true).ToArray();
                    Color startColor    = theme.TextColor;
                    // Show a highlight on the button as the user did not click it
                    Animation flashBackground = null;
                    flashBackground           = new Animation()
                    {
                        DrawTarget      = updateAvailableButton,
                        FramesPerSecond = 10,
                        Update          = (s1, updateEvent) =>
                        {
                            totalSeconds += updateEvent.SecondsPassed;
                            if (totalSeconds < displayTime)
                            {
                                double blend = AttentionGetter.GetFadeInOutPulseRatio(totalSeconds, pulseTime);
                                var color    = new Color(startColor, (int)((1 - blend) * 255));
                                foreach (var textWidget in textWidgets)
                                {
                                    textWidget.TextColor = color;
                                }
                            }
                            else
                            {
                                foreach (var textWidget in textWidgets)
                                {
                                    textWidget.TextColor = startColor;
                                }
                                flashBackground.Stop();
                            }
                        }
                    };
                    flashBackground.Start();
                }, 120);
            };

            SetLinkButtonsVisibility(this, null);
            updateAvailableButton.Click += (s, e) => UiThread.RunOnIdle(() =>
            {
                UpdateControlData.Instance.CheckForUpdate();
                DialogWindow.Show <CheckForUpdatesPage>();
            });

            tabControl.TabBar.ActionArea.AddChild(updateAvailableButton);

            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),
            });

            if (ApplicationController.Instance.Workspaces.Count == 0)
            {
                this.CreatePartTab().ConfigureAwait(false);
            }

            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 tabs
            foreach (var workspace in ApplicationController.Instance.Workspaces)
            {
                this.CreatePartTab(workspace);
            }

            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);

            var tasks = ApplicationController.Instance.Tasks;

            tasks.TasksChanged += (s, e) =>
            {
                RenderRunningTasks(theme, tasks);
            };

            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, tasks);

            // Register listeners
            PrinterSettings.AnyPrinterSettingChanged           += Printer_SettingChanged;
            ApplicationController.Instance.OpenPrintersChanged += OpenPrinters_Changed;

            UpdateControlData.Instance.UpdateStatusChanged.RegisterEvent((s, e) =>
            {
                SetLinkButtonsVisibility(s, new StringEventArgs("Unknown"));
            }, ref unregisterEvents);

            ApplicationController.Instance.MainView = this;
        }
        public SelectedObjectPanel(View3DWidget view3DWidget, BedConfig sceneContext, ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            this.HAnchor      = HAnchor.Stretch;
            this.VAnchor      = VAnchor.Top | VAnchor.Fit;
            this.Padding      = 0;
            this.view3DWidget = view3DWidget;
            this.theme        = theme;
            this.sceneContext = sceneContext;

            this.ContentPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit,
            };

            var scrollable = new ScrollableWidget(true)
            {
                Name    = "editorPanel",
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch,
            };

            scrollable.AddChild(this.ContentPanel);
            scrollable.ScrollArea.HAnchor = HAnchor.Stretch;

            this.AddChild(scrollable);

            var toolbar = new LeftClipFlowLayoutWidget()
            {
                BackgroundColor = theme.TabBodyBackground,
                Padding         = theme.ToolbarPadding,
                HAnchor         = HAnchor.Fit,
                VAnchor         = VAnchor.Fit
            };

            var scene = sceneContext.Scene;

            // put in a make permanent button
            var icon        = AggContext.StaticData.LoadIcon("fa-check_16.png", 16, 16, theme.InvertIcons).SetPreMultiply();
            var applyButton = new IconButton(icon, theme)
            {
                Margin      = theme.ButtonSpacing,
                ToolTipText = "Apply operation and make permanent".Localize()
            };

            applyButton.Click += (s, e) =>
            {
                this.item.Apply(view3DWidget.Scene.UndoBuffer);
                scene.SelectedItem = null;
            };
            scene.SelectionChanged += (s, e) => applyButton.Enabled = scene.SelectedItem?.CanApply == true;
            toolbar.AddChild(applyButton);

            // put in a remove button
            var removeButton = new IconButton(AggContext.StaticData.LoadIcon("close.png", 16, 16, theme.InvertIcons), theme)
            {
                Margin      = theme.ButtonSpacing,
                ToolTipText = "Remove operation from parts".Localize()
            };

            removeButton.Click += (s, e) =>
            {
                item.Remove(view3DWidget.Scene.UndoBuffer);
                scene.SelectedItem = null;
            };
            scene.SelectionChanged += (s, e) => removeButton.Enabled = scene.SelectedItem?.CanRemove == true;
            toolbar.AddChild(removeButton);

            var overflowButton = new OverflowBar.OverflowMenuButton(theme);

            overflowButton.PopupBorderColor    = ApplicationController.Instance.MenuTheme.GetBorderColor(120);
            overflowButton.DynamicPopupContent = () =>
            {
                var popupMenu = new PopupMenu(ApplicationController.Instance.MenuTheme);

                var menuItem = popupMenu.CreateMenuItem("Rename");
                menuItem.Click += (s, e) =>
                {
                    DialogWindow.Show(
                        new InputBoxPage(
                            "Rename Item".Localize(),
                            "Name".Localize(),
                            item.Name,
                            "Enter New Name Here".Localize(),
                            "Rename".Localize(),
                            (newName) =>
                    {
                        item.Name = newName;
                        editorSectionWidget.Text = newName;
                    }));
                };

                popupMenu.CreateHorizontalLine();

                if (true)                 //allowOperations)
                {
                    var selectedItemType = item.GetType();
                    var selectedItem     = item;

                    foreach (var nodeOperation in ApplicationController.Instance.Graph.Operations)
                    {
                        foreach (var type in nodeOperation.MappedTypes)
                        {
                            if (type.IsAssignableFrom(selectedItemType) &&
                                (nodeOperation.IsVisible?.Invoke(selectedItem) != false) &&
                                nodeOperation.IsEnabled?.Invoke(selectedItem) != false)
                            {
                                var button = popupMenu.CreateMenuItem(nodeOperation.Title, nodeOperation.IconCollector?.Invoke()?.CreateScaledImage(16, 16));
                                button.Click += (s, e) =>
                                {
                                    nodeOperation.Operation(selectedItem, sceneContext.Scene).ConfigureAwait(false);
                                };
                            }
                        }
                    }
                }

                return(popupMenu);
            };
            toolbar.AddChild(overflowButton);

            editorPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit,
                Padding = new BorderDouble(top: 10)
            };

            // Wrap editorPanel with scrollable container
            var scrollableWidget = new ScrollableWidget(true)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            };

            scrollableWidget.AddChild(editorPanel);
            scrollableWidget.ScrollArea.HAnchor = HAnchor.Stretch;

            editorSectionWidget = new ResizableSectionWidget("Editor", sceneContext.ViewState.SelectedObjectEditorHeight, scrollableWidget, theme, serializationKey: UserSettingsKey.EditorPanelExpanded, rightAlignedContent: toolbar, defaultExpansion: true)
            {
                VAnchor = VAnchor.Fit,
            };
            editorSectionWidget.Resized += (s, e) =>
            {
                sceneContext.ViewState.SelectedObjectEditorHeight = editorSectionWidget.ResizeContainer.Height;
            };

            this.ContentPanel.AddChild(editorSectionWidget);

            var colorSection = new SectionWidget(
                "Color".Localize(),
                new ColorSwatchSelector(scene, theme, buttonSize: 16, buttonSpacing: new BorderDouble(1, 1, 0, 0))
            {
                Margin = new BorderDouble(left: 10)
            },
                theme,
                serializationKey: UserSettingsKey.ColorPanelExpanded)
            {
                Name = "Color Panel",
            };

            this.ContentPanel.AddChild(colorSection);

            var materialsSection = new SectionWidget("Materials".Localize(), new MaterialControls(scene, theme), theme, serializationKey: UserSettingsKey.MaterialsPanelExpanded)
            {
                Name = "Materials Panel",
            };

            this.ContentPanel.AddChild(materialsSection);

            // Enforce panel padding in sidebar
            foreach (var sectionWidget in this.ContentPanel.Children <SectionWidget>())
            {
                // Special case for editorResizeWrapper due to ResizeContainer
                if (sectionWidget is ResizableSectionWidget resizableSectionWidget)
                {
                    // Apply padding to ResizeContainer not wrapper
                    resizableSectionWidget.ResizeContainer.Padding = new BorderDouble(10, 10, 10, 0);
                }
                else
                {
                    sectionWidget.ContentPanel.Padding   = new BorderDouble(10, 10, 10, 0);
                    sectionWidget.ExpandableWhenDisabled = true;
                    sectionWidget.Enabled = false;
                }
            }
        }
Exemple #6
0
        public SelectedObjectPanel(View3DWidget view3DWidget, BedConfig sceneContext, ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            this.HAnchor      = HAnchor.Stretch;
            this.VAnchor      = VAnchor.Top | VAnchor.Fit;
            this.Padding      = 0;
            this.view3DWidget = view3DWidget;
            this.theme        = theme;
            this.sceneContext = sceneContext;

            var toolbar = new LeftClipFlowLayoutWidget()
            {
                BackgroundColor = theme.ActiveTabColor,
                Padding         = theme.ToolbarPadding,
                HAnchor         = HAnchor.Fit,
                VAnchor         = VAnchor.Fit
            };

            var scene = sceneContext.Scene;

            // put in a make permanent button
            var icon          = AggContext.StaticData.LoadIcon("noun_766157.png", 16, 16, theme.InvertIcons).SetPreMultiply();
            var flattenButton = new IconButton(icon, theme)
            {
                Margin      = theme.ButtonSpacing,
                ToolTipText = "Flatten".Localize(),
                Enabled     = scene.SelectedItem?.CanFlatten == true
            };

            flattenButton.Click += (s, e) =>
            {
                this.item.Flatten(view3DWidget.Scene.UndoBuffer);
                scene.SelectedItem = null;
            };
            toolbar.AddChild(flattenButton);

            // put in a remove button
            var removeButton = new IconButton(AggContext.StaticData.LoadIcon("remove.png", 16, 16, theme.InvertIcons), theme)
            {
                Margin      = theme.ButtonSpacing,
                ToolTipText = "Delete".Localize(),
                Enabled     = scene.SelectedItem != null
            };

            removeButton.Click += (s, e) =>
            {
                var rootSelection = scene.SelectedItemRoot;

                var removeItem = item;
                removeItem.Remove(view3DWidget.Scene.UndoBuffer);

                scene.SelectedItem = null;

                // Only restore the root selection if it wasn't the item removed
                if (removeItem != rootSelection)
                {
                    scene.SelectedItem = rootSelection;
                }
            };
            toolbar.AddChild(removeButton);

            var overflowButton = new OverflowBar.OverflowMenuButton(theme)
            {
                Enabled          = scene.SelectedItem != null,
                PopupBorderColor = ApplicationController.Instance.MenuTheme.GetBorderColor(120)
            };

            overflowButton.DynamicPopupContent = () =>
            {
                return(ApplicationController.Instance.GetActionMenuForSceneItem(item, sceneContext.Scene, false));
            };
            toolbar.AddChild(overflowButton);

            editorPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit,
                Name    = "editorPanel",
                Padding = new BorderDouble(right: theme.DefaultContainerPadding + 1)
            };

            // Wrap editorPanel with scrollable container
            var scrollableWidget = new ScrollableWidget(true)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            };

            scrollableWidget.AddChild(editorPanel);
            scrollableWidget.ScrollArea.HAnchor = HAnchor.Stretch;

            editorSectionWidget = new SectionWidget("Editor", scrollableWidget, theme, toolbar, expandingContent: false, defaultExpansion: true, setContentVAnchor: false)
            {
                VAnchor = VAnchor.Stretch
            };
            this.AddChild(editorSectionWidget);

            this.ContentPanel   = editorPanel;
            editorPanel.Padding = new BorderDouble(theme.DefaultContainerPadding, 0);

            scene.SelectionChanged += (s, e) =>
            {
                if (editorPanel.Children.FirstOrDefault()?.DescendantsAndSelf <SectionWidget>().FirstOrDefault() is SectionWidget firstSectionWidget)
                {
                    firstSectionWidget.Margin = firstSectionWidget.Margin.Clone(top: 0);
                }

                var selectedItem = scene.SelectedItem;

                flattenButton.Enabled  = selectedItem?.CanFlatten == true;
                removeButton.Enabled   = selectedItem != null;
                overflowButton.Enabled = selectedItem != null;
            };
        }
Exemple #7
0
        public SelectedObjectPanel(View3DWidget view3DWidget, ISceneContext sceneContext, ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            this.HAnchor      = HAnchor.Stretch;
            this.VAnchor      = VAnchor.Top | VAnchor.Fit;
            this.Padding      = 0;
            this.view3DWidget = view3DWidget;
            this.theme        = theme;
            this.sceneContext = sceneContext;

            var toolbar = new LeftClipFlowLayoutWidget()
            {
                BackgroundColor = theme.BackgroundColor,
                Padding         = theme.ToolbarPadding,
                HAnchor         = HAnchor.Fit,
                VAnchor         = VAnchor.Fit
            };

            scene = sceneContext.Scene;

            // put in a make permanent button
            var icon = AggContext.StaticData.LoadIcon("noun_766157.png", 16, 16, theme.InvertIcons).SetPreMultiply();

            flattenButton = new IconButton(icon, theme)
            {
                Margin      = theme.ButtonSpacing,
                ToolTipText = "Flatten".Localize(),
                Enabled     = true
            };
            flattenButton.Click += (s, e) =>
            {
                if (this.item.CanFlatten)
                {
                    var item = this.item;
                    using (new SelectionMaintainer(view3DWidget.Scene))
                    {
                        item.Flatten(view3DWidget.Scene.UndoBuffer);
                    }
                }
                else
                {
                    // try to ungroup it
                    sceneContext.Scene.UngroupSelection();
                }
            };
            toolbar.AddChild(flattenButton);

            // put in a remove button
            removeButton = new IconButton(AggContext.StaticData.LoadIcon("remove.png", 16, 16, theme.InvertIcons), theme)
            {
                Margin      = theme.ButtonSpacing,
                ToolTipText = "Delete".Localize(),
                Enabled     = scene.SelectedItem != null
            };
            removeButton.Click += (s, e) =>
            {
                var item = this.item;
                using (new SelectionMaintainer(view3DWidget.Scene))
                {
                    item.Remove(view3DWidget.Scene.UndoBuffer);
                }
            };
            toolbar.AddChild(removeButton);

            primaryActionsPanel = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.Fit,
                VAnchor = VAnchor.Center | VAnchor.Fit
            };

            toolbar.AddChild(primaryActionsPanel);

            overflowButton = new OverflowBar.OverflowMenuButton(theme)
            {
                Enabled = scene.SelectedItem != null,
            };
            overflowButton.DynamicPopupContent = () =>
            {
                var remainingOperations = ApplicationController.Instance.Graph.Operations.Values.Except(primaryActions);

                return(ApplicationController.Instance.GetActionMenuForSceneItem(item, sceneContext.Scene, false, remainingOperations));
            };
            toolbar.AddChild(overflowButton);

            editorPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit,
                Name    = "editorPanel",
                Padding = new BorderDouble(right: theme.DefaultContainerPadding + 1)
            };

            // Wrap editorPanel with scrollable container
            var scrollableWidget = new ScrollableWidget(true)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            };

            scrollableWidget.AddChild(editorPanel);
            scrollableWidget.ScrollArea.HAnchor = HAnchor.Stretch;

            editorSectionWidget = new SectionWidget(editorTitle, scrollableWidget, theme, toolbar, expandingContent: false, defaultExpansion: true, setContentVAnchor: false)
            {
                VAnchor = VAnchor.Stretch
            };
            this.AddChild(editorSectionWidget);

            this.ContentPanel   = editorPanel;
            editorPanel.Padding = new BorderDouble(theme.DefaultContainerPadding, 0);

            // Register listeners
            scene.SelectionChanged += Scene_SelectionChanged;
        }
        public SelectedObjectPanel(View3DWidget view3DWidget, ISceneContext sceneContext, ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            this.HAnchor      = HAnchor.Stretch;
            this.VAnchor      = VAnchor.Top | VAnchor.Fit;
            this.Padding      = 0;
            this.theme        = theme;
            this.sceneContext = sceneContext;

            var toolbar = new LeftClipFlowLayoutWidget()
            {
                BackgroundColor = theme.BackgroundColor,
                Padding         = theme.ToolbarPadding,
                HAnchor         = HAnchor.Fit,
                VAnchor         = VAnchor.Fit
            };

            scene = sceneContext.Scene;

            // put in the container for dynamic actions
            primaryActionsPanel = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.Fit,
                VAnchor = VAnchor.Center | VAnchor.Fit
            };

            toolbar.AddChild(primaryActionsPanel);

            // put in a make permanent button
            var icon = StaticData.Instance.LoadIcon("apply.png", 16, 16).SetToColor(theme.TextColor).SetPreMultiply();

            flattenButton = new IconButton(icon, theme)
            {
                Margin      = theme.ButtonSpacing,
                ToolTipText = "Apply".Localize(),
                Enabled     = true
            };
            flattenButton.Click += (s, e) =>
            {
                if (this.item.CanFlatten)
                {
                    var item = this.item;
                    using (new SelectionMaintainer(view3DWidget.Scene))
                    {
                        item.Flatten(view3DWidget.Scene.UndoBuffer);
                    }
                }
                else
                {
                    // try to ungroup it
                    sceneContext.Scene.UngroupSelection();
                }
            };
            toolbar.AddChild(flattenButton);

            // put in a remove button
            removeButton = new IconButton(StaticData.Instance.LoadIcon("cancel.png", 16, 16).SetToColor(theme.TextColor).SetPreMultiply(), theme)
            {
                Margin      = theme.ButtonSpacing,
                ToolTipText = "Cancel".Localize(),
                Enabled     = scene.SelectedItem != null
            };
            removeButton.Click += (s, e) =>
            {
                var item = this.item;
                using (new SelectionMaintainer(view3DWidget.Scene))
                {
                    item.Remove(view3DWidget.Scene.UndoBuffer);
                }
            };
            toolbar.AddChild(removeButton);

            overflowButton = new OverflowBar.OverflowMenuButton(theme)
            {
                Enabled = scene.SelectedItem != null,
            };
            overflowButton.ToolTipText         = "Selected Object Options".Localize();
            overflowButton.DynamicPopupContent = () =>
            {
                return(ApplicationController.Instance.GetModifyMenu(view3DWidget.sceneContext));
            };
            toolbar.AddChild(overflowButton);

            editorPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit,
                Name    = "editorPanel",
            };

            // Wrap editorPanel with scrollable container
            var scrollableWidget = new ScrollableWidget(true)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            };

            scrollableWidget.AddChild(editorPanel);
            scrollableWidget.ScrollArea.HAnchor = HAnchor.Stretch;

            editorSectionWidget = new SectionWidget(editorTitle, scrollableWidget, theme, toolbar, expandingContent: false, defaultExpansion: true, setContentVAnchor: false)
            {
                VAnchor = VAnchor.Stretch
            };
            this.AddChild(editorSectionWidget);

            this.ContentPanel = editorPanel;

            // Register listeners
            scene.SelectionChanged += Scene_SelectionChanged;
        }
Exemple #9
0
        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;
        }