Example #1
0
        private void AddColumnAndChild(IconViewItem iconView)
        {
            if (rowButtonContainer == null)
            {
                rowButtonContainer = new FlowLayoutWidget(FlowDirection.LeftToRight)
                {
                    HAnchor = HAnchor.Stretch,
                    Padding = 0,
                    Margin  = new BorderDouble(bottom: 6)
                };
                this.AddChild(rowButtonContainer);
            }

            rowButtonContainer?.AddChild(iconView);

            if (cellIndex++ >= columnCount - 1)
            {
                rowButtonContainer = null;
                cellIndex          = 0;
            }
        }
Example #2
0
		public void TopToBottomContainerAppliesExpectedMargin()
		{
			int marginSize = 40;
			int dimensions = 300;

			GuiWidget outerContainer = new GuiWidget(dimensions, dimensions);

			FlowLayoutWidget topToBottomContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
			{
				HAnchor = HAnchor.ParentLeftRight,
				VAnchor = UI.VAnchor.ParentBottomTop,
			};
			outerContainer.AddChild(topToBottomContainer);

			GuiWidget childWidget = new GuiWidget()
			{
				HAnchor = HAnchor.ParentLeftRight,
				VAnchor = VAnchor.ParentBottomTop,
				Margin = new BorderDouble(marginSize),
				BackgroundColor = RGBA_Bytes.Red,
			};

			topToBottomContainer.AddChild(childWidget);
			topToBottomContainer.AnchorAll();
			topToBottomContainer.PerformLayout();

			outerContainer.DoubleBuffer = true;
			outerContainer.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
			outerContainer.OnDraw(outerContainer.NewGraphics2D());

			// For troubleshooting or visual validation
			//saveImagesForDebug = true;
			//OutputImages(outerContainer, outerContainer);

			var bounds = childWidget.BoundsRelativeToParent;
			Assert.IsTrue(bounds.Left == marginSize, "Left margin is incorrect");
			Assert.IsTrue(bounds.Right == dimensions - marginSize, "Right margin is incorrect");
			Assert.IsTrue(bounds.Top == dimensions - marginSize, "Top margin is incorrect");
			Assert.IsTrue(bounds.Bottom == marginSize, "Bottom margin is incorrect");
		}
Example #3
0
		public void EnsureFlowLayoutMinSizeFitsChildrenMinSize()
		{
			// This test is to prove that a flow layout widget always has it's min size set
			// to the enclosing bounds size of all it's childrens min size.
			// The code to be tested will expand the flow layouts min size as it's children's min size change.
			GuiWidget containerTest = new GuiWidget(640, 480);
			FlowLayoutWidget topToBottomFlowLayoutAll = new FlowLayoutWidget(FlowDirection.TopToBottom);
			containerTest.AddChild(topToBottomFlowLayoutAll);
			containerTest.DoubleBuffer = true;

			FlowLayoutWidget topLeftToRight = new FlowLayoutWidget(FlowDirection.LeftToRight);
			topToBottomFlowLayoutAll.AddChild(topLeftToRight);
			GuiWidget bottomLeftToRight = new FlowLayoutWidget(FlowDirection.LeftToRight);
			topToBottomFlowLayoutAll.AddChild(bottomLeftToRight);

			topLeftToRight.AddChild(new Button("top button"));

			FlowLayoutWidget bottomContentTopToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);
			bottomLeftToRight.AddChild(bottomContentTopToBottom);

			Button button1 = new Button("button1");
			Assert.IsTrue(button1.MinimumSize.x > 0, "Buttons should set their min size on construction.");
			bottomContentTopToBottom.AddChild(button1);
			//Assert.IsTrue(bottomContentTopToBottom.MinimumSize.x >= button1.MinimumSize.x, "There should be space for the button.");
			bottomContentTopToBottom.AddChild(new Button("button2"));
			Button wideButton = new Button("button3 Wide");
			bottomContentTopToBottom.AddChild(wideButton);
			//Assert.IsTrue(bottomContentTopToBottom.MinimumSize.x >= wideButton.MinimumSize.x, "These should be space for the button.");

			containerTest.BackgroundColor = RGBA_Bytes.White;
			containerTest.OnDrawBackground(containerTest.NewGraphics2D());
			containerTest.OnDraw(containerTest.NewGraphics2D());
			OutputImage(containerTest.BackBuffer, "zFlowLaoutsGetMinSize.tga");

			Assert.IsTrue(bottomLeftToRight.Width > 0, "This needs to have been expanded when the bottomContentTopToBottom grew.");
			Assert.IsTrue(bottomLeftToRight.MinimumSize.x >= bottomContentTopToBottom.MinimumSize.x, "These should be space for the next flowLayout.");
			Assert.IsTrue(containerTest.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one.");
		}
Example #4
0
        public FlowLayoutWidget CreateMenuItems(PopupMenu popupMenu, IEnumerable <NamedAction> menuActions)
        {
            // Create menu items in the DropList for each element in this.menuActions
            foreach (var menuAction in menuActions)
            {
                if (menuAction is ActionSeparator)
                {
                    popupMenu.CreateSeparator();
                }
                else
                {
                    if (menuAction is NamedActionGroup namedActionButtons)
                    {
                        var content = new FlowLayoutWidget()
                        {
                            HAnchor = HAnchor.Fit | HAnchor.Stretch
                        };

                        var textWidget = new TextWidget(menuAction.Title, pointSize: this.DefaultFontSize, textColor: this.TextColor)
                        {
                            // Padding = MenuPadding,
                            VAnchor = VAnchor.Center
                        };
                        content.AddChild(textWidget);

                        content.AddChild(new HorizontalSpacer());

                        foreach (var actionButton in namedActionButtons.Group)
                        {
                            var button = new TextButton(actionButton.Title, this)
                            {
                                Border      = new BorderDouble(1, 0, 0, 0),
                                BorderColor = this.MinimalShade,
                                HoverColor  = this.AccentMimimalOverlay,
                                Enabled     = actionButton.IsEnabled()
                            };

                            content.AddChild(button);

                            if (actionButton.IsEnabled())
                            {
                                button.Click += (s, e) =>
                                {
                                    actionButton.Action();
                                    popupMenu.Unfocus();
                                };
                            }
                        }

                        var menuItem = new PopupMenu.MenuItem(content, this)
                        {
                            HAnchor    = HAnchor.Fit | HAnchor.Stretch,
                            VAnchor    = VAnchor.Fit,
                            HoverColor = Color.Transparent,
                        };
                        popupMenu.AddChild(menuItem);
                        menuItem.Padding = new BorderDouble(menuItem.Padding.Left,
                                                            menuItem.Padding.Bottom,
                                                            0,
                                                            menuItem.Padding.Top);
                    }
                    else
                    {
                        PopupMenu.MenuItem menuItem;

                        if (menuAction is NamedBoolAction boolAction)
                        {
                            menuItem = popupMenu.CreateBoolMenuItem(menuAction.Title, boolAction.GetIsActive, boolAction.SetIsActive);
                        }
                        else
                        {
                            menuItem = popupMenu.CreateMenuItem(menuAction.Title, menuAction.Icon, menuAction.Shortcut);
                        }

                        menuItem.Name = $"{menuAction.Title} Menu Item";

                        menuItem.Enabled = menuAction is NamedActionGroup ||
                                           (menuAction.Action != null && menuAction.IsEnabled?.Invoke() != false);

                        menuItem.ClearRemovedFlag();

                        if (menuItem.Enabled)
                        {
                            menuItem.Click += (s, e) =>
                            {
                                menuAction.Action();
                            };
                        }
                    }
                }
            }

            return(popupMenu);
        }
Example #5
0
        public void SingleItemVisibleTest()
        {
            {
                ListBox containerListBox = new ListBox(new RectangleDouble(0, 0, 100, 100));
                ListBoxTextItem itemToAddToList = new ListBoxTextItem("test Item", "test data for item");
                itemToAddToList.Name = "list item";
                containerListBox.AddChild(itemToAddToList);
                containerListBox.DoubleBuffer = true;
                containerListBox.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
                containerListBox.OnDraw(containerListBox.BackBuffer.NewGraphics2D());

                ImageBuffer textImage = new ImageBuffer(80, 16, 32, new BlenderBGRA());
                textImage.NewGraphics2D().Clear(RGBA_Bytes.White);
                textImage.NewGraphics2D().DrawString("test Item", 1, 1);

                OutputImage(containerListBox.BackBuffer, "test.tga");
                OutputImage(textImage, "control.tga");

                double maxError = 20000000;
                Vector2 bestPosition;
                double leastSquares;
                containerListBox.BackBuffer.FindLeastSquaresMatch(textImage, out bestPosition, out leastSquares, maxError);

                Assert.IsTrue(leastSquares < maxError, "The list box need to be showing the item we added to it.");
            }

            {
                GuiWidget container = new GuiWidget(202, 302);
                container.DoubleBuffer = true;
                container.NewGraphics2D().Clear(RGBA_Bytes.White);
                FlowLayoutWidget leftToRightLayout = new FlowLayoutWidget();
                leftToRightLayout.AnchorAll();
                {
                    {
                        ListBox listBox = new ListBox(new RectangleDouble(0, 0, 200, 300));
                        //listBox.BackgroundColor = RGBA_Bytes.Red;
                        listBox.Name = "listBox";
                        listBox.VAnchor = UI.VAnchor.ParentTop;
                        listBox.ScrollArea.Margin = new BorderDouble(15);
                        leftToRightLayout.AddChild(listBox);

                        for (int i = 0; i < 1; i++)
                        {
                            ListBoxTextItem newItem = new ListBoxTextItem("hand" + i.ToString() + ".stl", "c:\\development\\hand" + i.ToString() + ".stl");
                            newItem.Name = "ListBoxItem" + i.ToString();
                            listBox.AddChild(newItem);
                        }
                    }
                }

                container.AddChild(leftToRightLayout);
                container.OnDraw(container.NewGraphics2D());

                ImageBuffer textImage = new ImageBuffer(80, 16, 32, new BlenderBGRA());
                textImage.NewGraphics2D().Clear(RGBA_Bytes.White);
                textImage.NewGraphics2D().DrawString("hand0.stl", 1, 1);

                OutputImage(container.BackBuffer, "control.tga");
                OutputImage(textImage, "test.tga");

                double maxError = 1000000;
                Vector2 bestPosition;
                double leastSquares;
                container.BackBuffer.FindLeastSquaresMatch(textImage, out bestPosition, out leastSquares, maxError);

                Assert.IsTrue(leastSquares < maxError, "The list box need to be showing the item we added to it.");
            }
        }
Example #6
0
		public void LeftRightWithAnchorLeftRightChildTest(BorderDouble controlPadding, BorderDouble buttonMargin)
		{
			double buttonSize = 40;
			GuiWidget containerControl = new GuiWidget(buttonSize * 8, buttonSize * 3);
			containerControl.Padding = controlPadding;
			containerControl.DoubleBuffer = true;

			RectangleDouble[] eightControlRectangles = new RectangleDouble[8];
			RGBA_Bytes[] eightColors = new RGBA_Bytes[] { RGBA_Bytes.Red, RGBA_Bytes.Orange, RGBA_Bytes.Yellow, RGBA_Bytes.YellowGreen, RGBA_Bytes.Green, RGBA_Bytes.Blue, RGBA_Bytes.Indigo, RGBA_Bytes.Violet };
			{
				double currentleft = controlPadding.Left + buttonMargin.Left;
				double buttonHeightWithMargin = buttonSize + buttonMargin.Height;
				double scalledWidth = (containerControl.Width - controlPadding.Width - buttonMargin.Width * 8 - buttonSize * 2) / 6;
				// the left unsized rect
				eightControlRectangles[0] = new RectangleDouble(
						currentleft,
						0,
						currentleft + buttonSize,
						buttonSize);

				// a bottom anchor
				currentleft += buttonSize + buttonMargin.Width;
				double bottomAnchorY = controlPadding.Bottom + buttonMargin.Bottom;
				eightControlRectangles[1] = new RectangleDouble(currentleft, bottomAnchorY, currentleft + scalledWidth, bottomAnchorY + buttonSize);

				// center anchor
				double centerYOfContainer = controlPadding.Bottom + (containerControl.Height - controlPadding.Height) / 2;
				currentleft += scalledWidth + buttonMargin.Width;
				eightControlRectangles[2] = new RectangleDouble(currentleft, centerYOfContainer - buttonHeightWithMargin / 2 + buttonMargin.Bottom, currentleft + scalledWidth, centerYOfContainer + buttonHeightWithMargin / 2 - buttonMargin.Top);

				// top anchor
				double topAnchorY = containerControl.Height - controlPadding.Top - buttonMargin.Top;
				currentleft += scalledWidth + buttonMargin.Width;
				eightControlRectangles[3] = new RectangleDouble(currentleft, topAnchorY - buttonSize, currentleft + scalledWidth, topAnchorY);

				// bottom center anchor
				currentleft += scalledWidth + buttonMargin.Width;
				eightControlRectangles[4] = new RectangleDouble(currentleft, bottomAnchorY, currentleft + scalledWidth, centerYOfContainer - buttonMargin.Top);

				// center top anchor
				currentleft += scalledWidth + buttonMargin.Width;
				eightControlRectangles[5] = new RectangleDouble(currentleft, centerYOfContainer + buttonMargin.Bottom, currentleft + scalledWidth, topAnchorY);

				// bottom top anchor
				currentleft += scalledWidth + buttonMargin.Width;
				eightControlRectangles[6] = new RectangleDouble(currentleft, bottomAnchorY, currentleft + scalledWidth, topAnchorY);

				// right anchor
				currentleft += scalledWidth + buttonMargin.Width;
				eightControlRectangles[7] = new RectangleDouble(currentleft, 0, currentleft + buttonSize, buttonSize);

				Graphics2D graphics = containerControl.NewGraphics2D();
				for (int i = 0; i < 8; i++)
				{
					graphics.FillRectangle(eightControlRectangles[i], eightColors[i]);
				}
			}

			GuiWidget containerTest = new GuiWidget(containerControl.Width, containerControl.Height);
			FlowLayoutWidget leftToRightFlowLayoutAll = new FlowLayoutWidget(FlowDirection.LeftToRight);
			containerTest.DoubleBuffer = true;
			{
				leftToRightFlowLayoutAll.AnchorAll();
				leftToRightFlowLayoutAll.Padding = controlPadding;
				{
					GuiWidget left = new GuiWidget(buttonSize, buttonSize);
					left.BackgroundColor = RGBA_Bytes.Red;
					left.Margin = buttonMargin;
					leftToRightFlowLayoutAll.AddChild(left);

					leftToRightFlowLayoutAll.AddChild(CreateLeftToRightMiddleWidget(buttonMargin, buttonSize, VAnchor.ParentBottom, RGBA_Bytes.Orange));
					leftToRightFlowLayoutAll.AddChild(CreateLeftToRightMiddleWidget(buttonMargin, buttonSize, VAnchor.ParentCenter, RGBA_Bytes.Yellow));
					leftToRightFlowLayoutAll.AddChild(CreateLeftToRightMiddleWidget(buttonMargin, buttonSize, VAnchor.ParentTop, RGBA_Bytes.YellowGreen));
					leftToRightFlowLayoutAll.AddChild(CreateLeftToRightMiddleWidget(buttonMargin, buttonSize, VAnchor.ParentBottomCenter, RGBA_Bytes.Green));
					leftToRightFlowLayoutAll.AddChild(CreateLeftToRightMiddleWidget(buttonMargin, buttonSize, VAnchor.ParentCenterTop, RGBA_Bytes.Blue));
					leftToRightFlowLayoutAll.AddChild(CreateLeftToRightMiddleWidget(buttonMargin, buttonSize, VAnchor.ParentBottomTop, RGBA_Bytes.Indigo));

					GuiWidget right = new GuiWidget(buttonSize, buttonSize);
					right.BackgroundColor = RGBA_Bytes.Violet;
					right.Margin = buttonMargin;
					leftToRightFlowLayoutAll.AddChild(right);
				}

				containerTest.AddChild(leftToRightFlowLayoutAll);
			}

			containerTest.OnDraw(containerTest.NewGraphics2D());
			OutputImages(containerControl, containerTest);

			for (int i = 0; i < 8; i++)
			{
				Assert.IsTrue(eightControlRectangles[i] == leftToRightFlowLayoutAll.Children[i].BoundsRelativeToParent);
			}

			Assert.IsTrue(containerControl.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one.");

			// we use a least squares match because the erase background that is setting the widgets is integer pixel based and the fill rectangle is not.
			Assert.IsTrue(containerControl.BackBuffer.FindLeastSquaresMatch(containerTest.BackBuffer, 0), "The test and control need to match.");
		}
Example #7
0
        protected void CreateGuiElements()
        {
            this.Cursor = Cursors.Hand;

            linkButtonFactory.fontSize  = 10;
            linkButtonFactory.textColor = RGBA_Bytes.White;

            WidgetTextColor       = RGBA_Bytes.Black;
            WidgetBackgroundColor = RGBA_Bytes.White;

            TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;

            SetDisplayAttributes();

            FlowLayoutWidget mainContainer = new FlowLayoutWidget(FlowDirection.LeftToRight);

            mainContainer.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
            mainContainer.VAnchor = VAnchor.ParentBottomTop;
            {
                partLabel = new TextWidget(this.ItemName.Replace('_', ' '), pointSize: 14);

                GuiWidget primaryContainer = new GuiWidget();
                primaryContainer.HAnchor = HAnchor.ParentLeftRight;
                primaryContainer.VAnchor = VAnchor.ParentBottomTop;
                primaryContainer.Name    = "Row Item " + partLabel.Text;

                FlowLayoutWidget primaryFlow = new FlowLayoutWidget(FlowDirection.LeftToRight);
                primaryFlow.HAnchor = HAnchor.ParentLeftRight;
                primaryFlow.VAnchor = VAnchor.ParentBottomTop;

                selectionCheckBoxContainer         = new GuiWidget();
                selectionCheckBoxContainer.VAnchor = VAnchor.ParentBottomTop;
                selectionCheckBoxContainer.Width   = 40;
                selectionCheckBoxContainer.Visible = false;
                selectionCheckBoxContainer.Margin  = new BorderDouble(left: 6);
                selectionCheckBox         = new CheckBox("");
                selectionCheckBox.Click  += selectionCheckBox_Click;
                selectionCheckBox.Name    = "Row Item Select Checkbox";
                selectionCheckBox.VAnchor = VAnchor.ParentCenter;
                selectionCheckBox.HAnchor = HAnchor.ParentCenter;
                selectionCheckBoxContainer.AddChild(selectionCheckBox);

                middleColumn         = new GuiWidget(0.0, 0.0);
                middleColumn.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
                middleColumn.VAnchor = Agg.UI.VAnchor.ParentBottomTop;
                middleColumn.Margin  = new BorderDouble(10, 3);
                {
                    partLabel.TextColor   = WidgetTextColor;
                    partLabel.MinimumSize = new Vector2(1, 18);
                    partLabel.VAnchor     = VAnchor.ParentCenter;
                    middleColumn.AddChild(partLabel);

                    middleColumn.MouseDown += (sender, e) =>
                    {
                        // Abort normal processing for view helpers
                        if (this.IsViewHelperItem)
                        {
                            return;
                        }

                        if (this.libraryDataView.EditMode)
                        {
                            if (this.IsSelectedItem)
                            {
                                libraryDataView.SelectedItems.Remove(this);
                            }
                            else
                            {
                                libraryDataView.SelectedItems.Add(this);
                            }
                        }
                        else
                        {
                            // we only have single selection
                            if (this.IsSelectedItem)
                            {
                                // It is aleady selected, do nothing.
                            }
                            else
                            {
                                libraryDataView.ClearSelectedItems();
                                libraryDataView.SelectedItems.Add(this);
                            }
                        }
                    };
                }
                primaryFlow.AddChild(selectionCheckBoxContainer);

                primaryFlow.AddChild(thumbnailWidget);
                primaryFlow.AddChild(middleColumn);

                primaryContainer.AddChild(primaryFlow);

                rightButtonOverlay         = GetItemActionButtons();
                rightButtonOverlay.Visible = false;

                mainContainer.AddChild(primaryContainer);
                mainContainer.AddChild(rightButtonOverlay);
            }
            this.AddChild(mainContainer);

            AddHandlers();
        }
Example #8
0
		public void TestVAnchorCenter()
		{
			FlowLayoutWidget searchPanel = new FlowLayoutWidget();
			searchPanel.BackgroundColor = new RGBA_Bytes(180, 180, 180);
			searchPanel.HAnchor = HAnchor.ParentLeftRight;
			searchPanel.Padding = new BorderDouble(3, 3);
			{
				TextEditWidget searchInput = new TextEditWidget("Test");
				searchInput.Margin = new BorderDouble(6, 0);
				searchInput.HAnchor = HAnchor.ParentLeftRight;
				searchInput.VAnchor = VAnchor.ParentCenter;

				Button searchButton = new Button("Search");
				searchButton.Margin = new BorderDouble(right: 9);

				searchPanel.AddChild(searchInput);
				Assert.IsTrue(searchInput.BoundsRelativeToParent.Bottom - searchPanel.BoundsRelativeToParent.Bottom == searchPanel.BoundsRelativeToParent.Top - searchInput.BoundsRelativeToParent.Top);
				searchPanel.AddChild(searchButton);
				Assert.IsTrue(searchInput.BoundsRelativeToParent.Bottom - searchPanel.BoundsRelativeToParent.Bottom == searchPanel.BoundsRelativeToParent.Top - searchInput.BoundsRelativeToParent.Top);
			}

			searchPanel.Close();
		}
Example #9
0
		private void LeftToRightAnchorLeftBottomTest(BorderDouble controlPadding, BorderDouble buttonMargin)
		{
			GuiWidget containerControl = new GuiWidget(300, 200);
			containerControl.DoubleBuffer = true;
			Button controlButton1 = new Button("buttonLeft");
			controlButton1.OriginRelativeParent = new VectorMath.Vector2(controlPadding.Left + buttonMargin.Left, controlButton1.OriginRelativeParent.y + controlPadding.Bottom + buttonMargin.Bottom);
			containerControl.AddChild(controlButton1);
			Button controlButton2 = new Button("buttonRight");
			controlButton2.OriginRelativeParent = new VectorMath.Vector2(controlPadding.Left + buttonMargin.Width + buttonMargin.Left + controlButton1.Width, controlButton2.OriginRelativeParent.y + controlPadding.Bottom + buttonMargin.Bottom);
			containerControl.AddChild(controlButton2);
			containerControl.OnDraw(containerControl.NewGraphics2D());

			GuiWidget containerTest = new GuiWidget(300, 200);
			FlowLayoutWidget flowLayout = new FlowLayoutWidget(FlowDirection.LeftToRight);
			flowLayout.AnchorAll();
			flowLayout.Padding = controlPadding;
			containerTest.DoubleBuffer = true;

			Button testButton1 = new Button("buttonLeft");
			testButton1.VAnchor = VAnchor.ParentBottom;
			testButton1.Margin = buttonMargin;
			flowLayout.AddChild(testButton1);

			Button testButton2 = new Button("buttonRight");
			testButton2.VAnchor = VAnchor.ParentBottom;
			testButton2.Margin = buttonMargin;
			flowLayout.AddChild(testButton2);

			containerTest.AddChild(flowLayout);

			containerTest.OnDraw(containerTest.NewGraphics2D());
			OutputImages(containerControl, containerTest);

			Assert.IsTrue(containerControl.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one.");
			Assert.IsTrue(containerControl.BackBuffer == containerTest.BackBuffer, "The Anchored widget should be in the correct place.");

			// make sure it can resize without breaking
			RectangleDouble bounds = containerTest.LocalBounds;
			RectangleDouble newBounds = bounds;
			newBounds.Right += 10;
			containerTest.LocalBounds = newBounds;
			Assert.IsTrue(containerControl.BackBuffer != containerTest.BackBuffer, "The Anchored widget should not be the same size.");
			containerTest.LocalBounds = bounds;
			containerTest.OnDraw(containerTest.NewGraphics2D());
			OutputImages(containerControl, containerTest);
			Assert.IsTrue(containerControl.BackBuffer == containerTest.BackBuffer, "The Anchored widget should be in the correct place.");
		}
Example #10
0
        public PrintingWindow(Action onCloseCallback, bool mockMode = false)
            : base(1280, 750)
        {
            this.BackgroundColor = new RGBA_Bytes(35, 40, 49);
            this.onCloseCallback = onCloseCallback;
            this.Title           = "Print Monitor".Localize();

            var topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                VAnchor = VAnchor.ParentBottomTop,
                HAnchor = HAnchor.ParentLeftRight
            };

            this.AddChild(topToBottom);

            var actionBar = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                VAnchor         = VAnchor.ParentTop | VAnchor.FitToChildren,
                HAnchor         = HAnchor.ParentLeftRight,
                BackgroundColor = new RGBA_Bytes(34, 38, 46),
                //DebugShowBounds = true
            };

            topToBottom.AddChild(actionBar);

            var logo = new ImageWidget(StaticData.Instance.LoadIcon(Path.Combine("Screensaver", "logo.png")));

            actionBar.AddChild(logo);

            actionBar.AddChild(new HorizontalSpacer());

            var pauseButton  = CreateButton("Pause".Localize().ToUpper());
            var resumeButton = CreateButton("Resume".Localize().ToUpper());

            pauseButton.Click += (s, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    //PrinterConnectionAndCommunication.Instance.RequestPause();
                    pauseButton.Visible  = false;
                    resumeButton.Visible = true;
                });
            };
            actionBar.AddChild(pauseButton);

            resumeButton.Visible = false;
            resumeButton.Click  += (s, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    //PrinterConnectionAndCommunication.Instance.Resume();
                    resumeButton.Visible = false;
                    pauseButton.Visible  = true;
                });
            };
            actionBar.AddChild(resumeButton);

            actionBar.AddChild(CreateVerticalLine());

            var cancelButton = CreateButton("Cancel".Localize().ToUpper());

            //cancelButton.Click += (sender, e) => UiThread.RunOnIdle(CancelButton_Click);
            actionBar.AddChild(cancelButton);

            actionBar.AddChild(CreateVerticalLine());

            var advancedButton = CreateButton("Advanced".Localize().ToUpper());

            actionBar.AddChild(advancedButton);

            var bodyContainer = new GuiWidget()
            {
                VAnchor         = VAnchor.ParentBottomTop,
                HAnchor         = HAnchor.ParentLeftRight,
                Padding         = new BorderDouble(50),
                BackgroundColor = new RGBA_Bytes(35, 40, 49),
            };

            topToBottom.AddChild(bodyContainer);

            var bodyRow = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                VAnchor = VAnchor.ParentBottomTop,
                HAnchor = HAnchor.ParentLeftRight,
                //BackgroundColor = new RGBA_Bytes(125, 255, 46, 20),
            };

            bodyContainer.AddChild(bodyRow);

            // Thumbnail section
            {
                ImageBuffer imageBuffer = null;

                string stlHashCode = PrinterConnectionAndCommunication.Instance.ActivePrintItem?.FileHashCode.ToString();
                if (!string.IsNullOrEmpty(stlHashCode) && stlHashCode != "0")
                {
                    imageBuffer = PartThumbnailWidget.LoadImageFromDisk(stlHashCode);
                    if (imageBuffer != null)
                    {
                        imageBuffer = ImageBuffer.CreateScaledImage(imageBuffer, 500, 500);
                    }
                }

                if (imageBuffer == null)
                {
                    imageBuffer = StaticData.Instance.LoadIcon(Path.Combine("Screensaver", "part_thumbnail.png"));
                }

                var partThumbnail = new ImageWidget(imageBuffer)
                {
                    VAnchor = VAnchor.ParentCenter,
                    Margin  = new BorderDouble(right: 50)
                };
                bodyRow.AddChild(partThumbnail);
            }

            bodyRow.AddChild(CreateVerticalLine());

            // Progress section
            {
                var expandingContainer = new HorizontalSpacer()
                {
                    VAnchor = VAnchor.FitToChildren | VAnchor.ParentCenter
                };
                bodyRow.AddChild(expandingContainer);

                var progressContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
                {
                    Margin  = new BorderDouble(50, 0),
                    VAnchor = VAnchor.ParentCenter | VAnchor.FitToChildren,
                    HAnchor = HAnchor.ParentCenter | HAnchor.FitToChildren,
                    //BackgroundColor = new RGBA_Bytes(125, 255, 46, 20),
                };
                expandingContainer.AddChild(progressContainer);

                progressDial = new ProgressDial()
                {
                    HAnchor = HAnchor.ParentCenter,
                    Height  = 200,
                    Width   = 200
                };
                progressContainer.AddChild(progressDial);

                var timeContainer = new FlowLayoutWidget()
                {
                    HAnchor = HAnchor.ParentLeftRight,
                    Margin  = new BorderDouble(50, 3)
                };
                progressContainer.AddChild(timeContainer);

                var timeImage = new ImageWidget(StaticData.Instance.LoadIcon(Path.Combine("Screensaver", "time.png")));
                timeContainer.AddChild(timeImage);

                timeWidget = new TextWidget("", pointSize: 16, textColor: ActiveTheme.Instance.PrimaryTextColor)
                {
                    AutoExpandBoundsToText = true,
                    Margin = new BorderDouble(10, 0)
                };

                timeContainer.AddChild(timeWidget);

                printerName = new TextWidget(ActiveSliceSettings.Instance.GetValue(SettingsKey.printer_name), pointSize: 16, textColor: ActiveTheme.Instance.PrimaryTextColor)
                {
                    AutoExpandBoundsToText = true,
                    HAnchor = HAnchor.ParentLeftRight,
                    Margin  = new BorderDouble(50, 3)
                };

                progressContainer.AddChild(printerName);

                partName = new TextWidget(PrinterConnectionAndCommunication.Instance.ActivePrintItem.GetFriendlyName(), pointSize: 16, textColor: ActiveTheme.Instance.PrimaryTextColor)
                {
                    AutoExpandBoundsToText = true,
                    HAnchor = HAnchor.ParentLeftRight,
                    Margin  = new BorderDouble(50, 3)
                };
                progressContainer.AddChild(partName);
            }

            bodyRow.AddChild(CreateVerticalLine());

            // ZControls
            {
                var widget = new ZAxisControls()
                {
                    Margin  = new BorderDouble(left: 50),
                    VAnchor = VAnchor.ParentCenter,
                    Width   = 120
                };
                bodyRow.AddChild(widget);
            }

            var footerBar = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                VAnchor         = VAnchor.ParentBottom | VAnchor.FitToChildren,
                HAnchor         = HAnchor.ParentCenter | HAnchor.FitToChildren,
                BackgroundColor = new RGBA_Bytes(35, 40, 49),
                Margin          = new BorderDouble(bottom: 30)
            };

            topToBottom.AddChild(footerBar);

            int extruderCount = mockMode ? 3 : ActiveSliceSettings.Instance.GetValue <int>(SettingsKey.extruder_count);

            var borderColor = bodyContainer.BackgroundColor.AdjustLightness(1.5).GetAsRGBA_Bytes();

            extruderStatusWidgets = Enumerable.Range(0, extruderCount).Select((i) => new ExtruderStatusWidget(i)
            {
                BorderColor = borderColor
            }).ToList();

            if (extruderCount == 1)
            {
                footerBar.AddChild(extruderStatusWidgets[0]);
            }
            else
            {
                var columnA = new FlowLayoutWidget(FlowDirection.TopToBottom);
                footerBar.AddChild(columnA);

                var columnB = new FlowLayoutWidget(FlowDirection.TopToBottom);
                footerBar.AddChild(columnB);

                // Add each status widget into the scene, placing into the appropriate column
                for (var i = 0; i < extruderCount; i++)
                {
                    var widget = extruderStatusWidgets[i];
                    if (i % 2 == 0)
                    {
                        widget.Margin = new BorderDouble(right: 20);
                        columnA.AddChild(widget);
                    }
                    else
                    {
                        columnB.AddChild(widget);
                    }
                }
            }

            UiThread.RunOnIdle(() =>
            {
                if (mockMode)
                {
                    MockProgress();
                }
                else
                {
                    CheckOnPrinter();
                }
            });

            PrinterConnectionAndCommunication.Instance.ExtruderTemperatureRead.RegisterEvent((s, e) =>
            {
                var eventArgs = e as TemperatureEventArgs;
                if (eventArgs != null && eventArgs.Index0Based < extruderStatusWidgets.Count)
                {
                    extruderStatusWidgets[eventArgs.Index0Based].UpdateTemperatures();
                }
            }, ref unregisterEvents);
        }
        public void SetActiveItem(ISceneContext sceneContext)
        {
            var selectedItem = sceneContext?.Scene?.SelectedItem;

            if (this.item == selectedItem)
            {
                return;
            }

            this.item = selectedItem;
            editorPanel.CloseChildren();

            // Allow caller to clean up with passing null for selectedItem
            if (item == null)
            {
                editorSectionWidget.Text = editorTitle;
                return;
            }

            var selectedItemType = selectedItem.GetType();

            primaryActionsPanel.RemoveChildren();

            IEnumerable <SceneOperation> primaryActions;

            if ((primaryActions = SceneOperations.GetPrimaryOperations(selectedItemType)) == null)
            {
                primaryActions = new List <SceneOperation>();
            }
            else
            {
                // Loop over primary actions creating a button for each
                foreach (var primaryAction in primaryActions)
                {
                    // TODO: Run visible/enable rules on actions, conditionally add/enable as appropriate
                    var button = new IconButton(primaryAction.Icon(theme), theme)
                    {
                        // Name = namedAction.Title + " Button",
                        ToolTipText     = primaryAction.Title,
                        Margin          = theme.ButtonSpacing,
                        BackgroundColor = theme.ToolbarButtonBackground,
                        HoverColor      = theme.ToolbarButtonHover,
                        MouseDownColor  = theme.ToolbarButtonDown,
                    };

                    button.Click += (s, e) =>
                    {
                        primaryAction.Action.Invoke(sceneContext);
                    };

                    primaryActionsPanel.AddChild(button);
                }
            }

            if (primaryActionsPanel.Children.Any())
            {
                // add in a separator from the apply and cancel buttons
                primaryActionsPanel.AddChild(new ToolbarSeparator(theme.GetBorderColor(50), theme.SeparatorMargin));
            }

            editorSectionWidget.Text = selectedItem.Name ?? selectedItemType.Name;

            HashSet <IObject3DEditor> mappedEditors = ApplicationController.Instance.Extensions.GetEditorsForType(selectedItemType);

            var undoBuffer = sceneContext.Scene.UndoBuffer;

            if (!(selectedItem.GetType().GetCustomAttributes(typeof(HideMeterialAndColor), true).FirstOrDefault() is HideMeterialAndColor))
            {
                // put in a color edit field
                var colorField = new ColorField(theme, selectedItem.Color);
                colorField.Initialize(0);
                colorField.ValueChanged += (s, e) =>
                {
                    if (selectedItem.Color != colorField.Color)
                    {
                        undoBuffer.AddAndDo(new ChangeColor(selectedItem, colorField.Color));
                    }
                };

                colorField.Content.MouseDown += (s, e) =>
                {
                    // make sure the render mode is set to shaded or outline
                    if (sceneContext.ViewState.RenderType != RenderOpenGl.RenderTypes.Shaded &&
                        sceneContext.ViewState.RenderType != RenderOpenGl.RenderTypes.Outlines)
                    {
                        // make sure the render mode is set to outline
                        sceneContext.ViewState.RenderType = RenderOpenGl.RenderTypes.Outlines;
                    }
                };

                // color row
                var row = new SettingsRow("Color".Localize(), null, colorField.Content, theme);

                // Special top border style for first item in editor
                row.Border = new BorderDouble(0, 1);

                editorPanel.AddChild(row);

                // put in a material edit field
                var materialField = new MaterialIndexField(sceneContext.Printer, theme, selectedItem.MaterialIndex);
                materialField.Initialize(0);
                materialField.ValueChanged += (s, e) =>
                {
                    if (selectedItem.MaterialIndex != materialField.MaterialIndex)
                    {
                        undoBuffer.AddAndDo(new ChangeMaterial(selectedItem, materialField.MaterialIndex));
                    }
                };

                materialField.Content.MouseDown += (s, e) =>
                {
                    if (sceneContext.ViewState.RenderType != RenderOpenGl.RenderTypes.Materials)
                    {
                        // make sure the render mode is set to material
                        sceneContext.ViewState.RenderType = RenderOpenGl.RenderTypes.Materials;
                    }
                };

                // material row
                editorPanel.AddChild(
                    new SettingsRow("Material".Localize(), null, materialField.Content, theme));
            }

            var rows = new SafeList <SettingsRow>();

            // put in the normal editor
            if (selectedItem is ComponentObject3D componentObject &&
                componentObject.Finalized)
            {
                var context = new PPEContext();
                PublicPropertyEditor.AddUnlockLinkIfRequired(selectedItem, editorPanel, theme);
                foreach (var selector in componentObject.SurfacedEditors)
                {
                    // if it is a reference to a sheet cell
                    if (selector.StartsWith("!"))
                    {
                        var firtSheet = componentObject.Descendants <SheetObject3D>().FirstOrDefault();
                        if (firtSheet != null)
                        {
                            var cellId = selector.Substring(1);
                            var cell   = firtSheet.SheetData[cellId];
                            if (cell != null)
                            {
                                // add an editor for the cell
                                var field = new DoubleField(theme);
                                field.Initialize(0);
                                double.TryParse(firtSheet.SheetData.EvaluateExpression(cellId), out double value);
                                field.DoubleValue = value;
                                field.ClearUndoHistory();

                                field.Content.Descendants <InternalNumberEdit>().First().MaxDecimalsPlaces = 3;
                                field.ValueChanged += (s, e) =>
                                {
                                    cell.Expression = field.Value;
                                    firtSheet.SheetData.Recalculate();
                                };

                                var row = new SettingsRow(cell.Name == null ? cellId : cell.Name, null, field.Content, theme);

                                editorPanel.AddChild(row);
                            }
                        }
                    }
                    else                     // parse it as a path to an object
                    {
                        // Get the named property via reflection
                        // Selector example:            '$.Children<CylinderObject3D>'
                        var match = pathResolver.Select(componentObject, selector).ToList();

                        //// - Add editor row for each
                        foreach (var instance in match)
                        {
                            if (instance is IObject3D object3D)
                            {
                                if (ApplicationController.Instance.Extensions.GetEditorsForType(object3D.GetType())?.FirstOrDefault() is IObject3DEditor editor)
                                {
                                    ShowObjectEditor((editor, object3D, object3D.Name), selectedItem);
                                }
                            }
                            else if (JsonPathContext.ReflectionValueSystem.LastMemberValue is ReflectionTarget reflectionTarget)
                            {
                                if (reflectionTarget.Source is IObject3D editedChild)
                                {
                                    context.item = editedChild;
                                }
                                else
                                {
                                    context.item = item;
                                }

                                var editableProperty = new EditableProperty(reflectionTarget.PropertyInfo, reflectionTarget.Source);

                                var editor = PublicPropertyEditor.CreatePropertyEditor(rows, editableProperty, undoBuffer, context, theme);
                                if (editor != null)
                                {
                                    editorPanel.AddChild(editor);
                                }

                                // Init with custom 'UpdateControls' hooks
                                (context.item as IPropertyGridModifier)?.UpdateControls(new PublicPropertyChange(context, "Update_Button"));
                            }
                        }
                    }
                }

                // Enforce panel padding
                foreach (var sectionWidget in editorPanel.Descendants <SectionWidget>())
                {
                    sectionWidget.Margin = 0;
                }
            }
Example #12
0
        public override void Initialize(int tabIndex)
        {
            var container = new FlowLayoutWidget();

            string[] xyzValueStrings = this.Value?.Split(',');
            if (xyzValueStrings == null ||
                xyzValueStrings.Length != 3)
            {
                xyzValueStrings = new string[] { "0", "0", "0" };
            }

            double.TryParse(xyzValueStrings[0], out double currentXValue);

            xEditWidget = new MHNumberEdit(currentXValue, theme, 'X', allowNegatives: true, allowDecimals: true, pixelWidth: VectorXYZEditWidth, tabIndex: tabIndex)
            {
                ToolTipText      = this.HelpText,
                TabIndex         = tabIndex,
                SelectAllOnFocus = true,
                Margin           = theme.ButtonSpacing
            };
            xEditWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
            {
                this.SetValue(
                    string.Format("{0},{1},{2}",
                                  xEditWidget.ActuallNumberEdit.Value.ToString(),
                                  yEditWidget.ActuallNumberEdit.Value.ToString(),
                                  zEditWidget.ActuallNumberEdit.Value.ToString()),
                    userInitiated: true);
            };

            container.AddChild(xEditWidget);

            double.TryParse(xyzValueStrings[1], out double currentYValue);

            yEditWidget = new MHNumberEdit(currentYValue, theme, 'Y', allowNegatives: true, allowDecimals: true, pixelWidth: VectorXYZEditWidth, tabIndex: tabIndex)
            {
                ToolTipText      = this.HelpText,
                TabIndex         = tabIndex + 1,
                SelectAllOnFocus = true,
                Margin           = theme.ButtonSpacing
            };
            yEditWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
            {
                this.SetValue(
                    string.Format("{0},{1},{2}",
                                  xEditWidget.ActuallNumberEdit.Value.ToString(),
                                  yEditWidget.ActuallNumberEdit.Value.ToString(),
                                  zEditWidget.ActuallNumberEdit.Value.ToString()),
                    userInitiated: true);
            };

            container.AddChild(yEditWidget);

            double.TryParse(xyzValueStrings[2], out double currentZValue);

            zEditWidget = new MHNumberEdit(currentZValue, theme, 'Z', allowNegatives: true, allowDecimals: true, pixelWidth: VectorXYZEditWidth, tabIndex: tabIndex)
            {
                ToolTipText      = this.HelpText,
                TabIndex         = tabIndex + 1,
                SelectAllOnFocus = true,
                Margin           = theme.ButtonSpacing
            };
            zEditWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
            {
                this.SetValue(
                    string.Format("{0},{1},{2}",
                                  xEditWidget.ActuallNumberEdit.Value.ToString(),
                                  yEditWidget.ActuallNumberEdit.Value.ToString(),
                                  zEditWidget.ActuallNumberEdit.Value.ToString()),
                    userInitiated: true);
            };

            container.AddChild(zEditWidget);

            this.Content = container;
        }
        protected override void AddChildElements()
        {
            actionBarButtonFactory.invertImageLocation = false;
            actionBarButtonFactory.borderWidth         = 1;
            if (ActiveTheme.Instance.IsDarkTheme)
            {
                actionBarButtonFactory.normalBorderColor = new RGBA_Bytes(77, 77, 77);
            }
            else
            {
                actionBarButtonFactory.normalBorderColor = new RGBA_Bytes(190, 190, 190);
            }
            actionBarButtonFactory.hoverBorderColor = new RGBA_Bytes(128, 128, 128);

            string connectString = "Connect".Localize().ToUpper();

            connectPrinterButton             = actionBarButtonFactory.Generate(connectString, "icon_power_32x32.png");
            connectPrinterButton.ToolTipText = "Connect to the currently selected printer".Localize();
            if (ApplicationController.Instance.WidescreenMode)
            {
                connectPrinterButton.Margin = new BorderDouble(0, 0, 3, 3);
            }
            else
            {
                connectPrinterButton.Margin = new BorderDouble(6, 0, 3, 3);
            }
            connectPrinterButton.VAnchor = VAnchor.ParentTop;
            connectPrinterButton.Cursor  = Cursors.Hand;

            string disconnectString = "Disconnect".Localize().ToUpper();

            disconnectPrinterButton             = actionBarButtonFactory.Generate(disconnectString, "icon_power_32x32.png");
            disconnectPrinterButton.ToolTipText = "Disconnect from current printer".Localize();
            if (ApplicationController.Instance.WidescreenMode)
            {
                disconnectPrinterButton.Margin = new BorderDouble(0, 0, 3, 3);
            }
            else
            {
                disconnectPrinterButton.Margin = new BorderDouble(6, 0, 3, 3);
            }
            disconnectPrinterButton.VAnchor = VAnchor.ParentTop;
            disconnectPrinterButton.Cursor  = Cursors.Hand;

            string resetConnectionText = "Reset\nConnection".Localize().ToUpper();

            resetConnectionButton = actionBarButtonFactory.Generate(resetConnectionText, "e_stop4.png");
            if (ApplicationController.Instance.WidescreenMode)
            {
                resetConnectionButton.Margin = new BorderDouble(0, 0, 3, 3);
            }
            else
            {
                resetConnectionButton.Margin = new BorderDouble(6, 0, 3, 3);
            }

            // Bind connect button states to active printer state
            this.SetConnectionButtonVisibleState();

            actionBarButtonFactory.invertImageLocation = true;

            this.AddChild(connectPrinterButton);
            this.AddChild(disconnectPrinterButton);

            FlowLayoutWidget printerSelectorAndEditButton = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.ParentLeftRight,
            };

            int rightMarginForWideScreenMode = ApplicationController.Instance.WidescreenMode ? 6 : 0;

            printerSelector = new PrinterSelector()
            {
                HAnchor = HAnchor.ParentLeftRight,
                Cursor  = Cursors.Hand,
                Margin  = new BorderDouble(0, 6, rightMarginForWideScreenMode, 3)
            };
            printerSelector.AddPrinter += (s, e) => WizardWindow.Show();
            printerSelector.MinimumSize = new Vector2(printerSelector.MinimumSize.x, connectPrinterButton.MinimumSize.y);
            printerSelectorAndEditButton.AddChild(printerSelector);

            Button editButton = TextImageButtonFactory.GetThemedEditButton();

            editButton.VAnchor = VAnchor.ParentCenter;
            editButton.Click  += UiNavigation.GoToEditPrinter_Click;
            printerSelectorAndEditButton.AddChild(editButton);
            this.AddChild(printerSelectorAndEditButton);

            this.AddChild(resetConnectionButton);
        }
Example #14
0
        public IconViewItem(ListViewItem item, int thumbWidth, int thumbHeight, ThemeConfig theme)
            : base(item, thumbWidth, thumbHeight, theme)
        {
            this.VAnchor = VAnchor.Fit;
            this.HAnchor = HAnchor.Fit;
            this.Padding = IconViewItem.ItemPadding;
            this.Margin  = new BorderDouble(6, 0, 0, 6);
            this.Border  = 1;

            int scaledWidth  = (int)(thumbWidth * GuiWidget.DeviceScale);
            int scaledHeight = (int)(thumbHeight * GuiWidget.DeviceScale);

            int maxWidth = scaledWidth - 4;

            if (thumbWidth < 75)
            {
                imageWidget = new ImageWidget(scaledWidth, scaledHeight)
                {
                    AutoResize      = false,
                    Name            = "List Item Thumbnail",
                    BackgroundColor = theme.ThumbnailBackground,
                    Margin          = 0,
                    Selectable      = false
                };
                this.AddChild(imageWidget);
            }
            else
            {
                var container = new FlowLayoutWidget(FlowDirection.TopToBottom)
                {
                    Selectable = false
                };
                this.AddChild(container);

                imageWidget = new ImageWidget(scaledWidth, scaledHeight)
                {
                    AutoResize      = false,
                    Name            = "List Item Thumbnail",
                    BackgroundColor = theme.ThumbnailBackground,
                    Margin          = 0,
                    Selectable      = false
                };
                container.AddChild(imageWidget);

                text = new TextWidget(item.Model.Name, 0, 0, 9, textColor: theme.TextColor)
                {
                    AutoExpandBoundsToText = false,
                    EllipsisIfClipped      = true,
                    HAnchor    = HAnchor.Center,
                    Margin     = new BorderDouble(0, 0, 0, 3),
                    Selectable = false
                };

                text.MaximumSize = new Vector2(maxWidth, 20);
                if (text.Printer.LocalBounds.Width > maxWidth)
                {
                    text.Width = maxWidth;
                    text.Text  = item.Model.Name;
                }

                container.AddChild(text);
            }
        }
        public JogControls(XYZColors colors)
        {
            moveButtonFactory.normalTextColor = RGBA_Bytes.Black;

            double distanceBetweenControls  = 12;
            double buttonSeparationDistance = 10;

            FlowLayoutWidget allControlsTopToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);

            allControlsTopToBottom.HAnchor |= Agg.UI.HAnchor.ParentLeftRight;

            {
                FlowLayoutWidget allControlsLeftToRight = new FlowLayoutWidget();

                FlowLayoutWidget xYZWithDistance = new FlowLayoutWidget(FlowDirection.TopToBottom);
                {
                    FlowLayoutWidget xYZControls = new FlowLayoutWidget();
                    {
                        GuiWidget xyGrid = CreateXYGridControl(colors, distanceBetweenControls, buttonSeparationDistance);
                        xYZControls.AddChild(xyGrid);

                        FlowLayoutWidget zButtons = CreateZButtons(XYZColors.zColor, buttonSeparationDistance, out zPlusControl, out zMinusControl);
                        zButtons.VAnchor = Agg.UI.VAnchor.ParentBottom;
                        xYZControls.AddChild(zButtons);
                        xYZWithDistance.AddChild(xYZControls);
                    }

                    this.KeyDown += (sender, e) =>
                    {
                        double moveAmountPositive  = AxisMoveAmount;
                        double moveAmountNegative  = -AxisMoveAmount;
                        int    eMoveAmountPositive = EAxisMoveAmount;
                        int    eMoveAmountNegative = -EAxisMoveAmount;

                        if (OsInformation.OperatingSystem == OSType.Windows)
                        {
                            if (e.KeyCode == Keys.Home && hotKeysEnabled)
                            {
                                PrinterConnectionAndCommunication.Instance.HomeAxis(PrinterConnectionAndCommunication.Axis.XYZ);
                            }
                            else if (e.KeyCode == Keys.Z && hotKeysEnabled)
                            {
                                PrinterConnectionAndCommunication.Instance.HomeAxis(PrinterConnectionAndCommunication.Axis.Z);
                            }
                            else if (e.KeyCode == Keys.Y && hotKeysEnabled)
                            {
                                PrinterConnectionAndCommunication.Instance.HomeAxis(PrinterConnectionAndCommunication.Axis.Y);
                            }
                            else if (e.KeyCode == Keys.X && hotKeysEnabled)
                            {
                                PrinterConnectionAndCommunication.Instance.HomeAxis(PrinterConnectionAndCommunication.Axis.X);
                            }
                            else if (e.KeyCode == Keys.Left && hotKeysEnabled)
                            {
                                PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.X, moveAmountNegative, MovementControls.XSpeed);
                            }
                            else if (e.KeyCode == Keys.Right && hotKeysEnabled)
                            {
                                PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.X, moveAmountPositive, MovementControls.XSpeed);
                            }
                            else if (e.KeyCode == Keys.Up && hotKeysEnabled)
                            {
                                PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.Y, moveAmountPositive, MovementControls.YSpeed);
                            }
                            else if (e.KeyCode == Keys.Down && hotKeysEnabled)
                            {
                                PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.Y, moveAmountNegative, MovementControls.YSpeed);
                            }
                            else if (e.KeyCode == Keys.PageUp && hotKeysEnabled)
                            {
                                PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.Z, moveAmountPositive, MovementControls.ZSpeed);
                            }
                            else if (e.KeyCode == Keys.PageDown && hotKeysEnabled)
                            {
                                PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.Z, moveAmountNegative, MovementControls.ZSpeed);
                            }
                            else if (e.KeyCode == Keys.E && hotKeysEnabled)
                            {
                                PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.E, eMoveAmountPositive, MovementControls.EFeedRate(0));
                            }
                            else if (e.KeyCode == Keys.R && hotKeysEnabled)
                            {
                                PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.E, eMoveAmountNegative, MovementControls.EFeedRate(0));
                            }
                        }
                        else if (OsInformation.OperatingSystem == OSType.Mac)
                        {
                            if (e.KeyCode == Keys.LButton && hotKeysEnabled)
                            {
                                PrinterConnectionAndCommunication.Instance.HomeAxis(PrinterConnectionAndCommunication.Axis.XYZ);
                            }
                            else if (e.KeyCode == Keys.Z && hotKeysEnabled)
                            {
                                PrinterConnectionAndCommunication.Instance.HomeAxis(PrinterConnectionAndCommunication.Axis.Z);
                            }
                            else if (e.KeyCode == Keys.Y && hotKeysEnabled)
                            {
                                PrinterConnectionAndCommunication.Instance.HomeAxis(PrinterConnectionAndCommunication.Axis.Y);
                            }
                            else if (e.KeyCode == Keys.X && hotKeysEnabled)
                            {
                                PrinterConnectionAndCommunication.Instance.HomeAxis(PrinterConnectionAndCommunication.Axis.X);
                            }
                            else if (e.KeyCode == Keys.Left && hotKeysEnabled)
                            {
                                PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.X, moveAmountNegative, MovementControls.XSpeed);
                            }
                            else if (e.KeyCode == Keys.Right && hotKeysEnabled)
                            {
                                PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.X, moveAmountPositive, MovementControls.XSpeed);
                            }
                            else if (e.KeyCode == Keys.Up && hotKeysEnabled)
                            {
                                PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.Y, moveAmountPositive, MovementControls.YSpeed);
                            }
                            else if (e.KeyCode == Keys.Down && hotKeysEnabled)
                            {
                                PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.Y, moveAmountNegative, MovementControls.YSpeed);
                            }
                            else if (e.KeyCode == (Keys.Back | Keys.Cancel) && hotKeysEnabled)
                            {
                                PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.Z, moveAmountPositive, MovementControls.ZSpeed);
                            }
                            else if (e.KeyCode == Keys.Clear && hotKeysEnabled)
                            {
                                PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.Z, moveAmountNegative, MovementControls.ZSpeed);
                            }
                            else if (e.KeyCode == Keys.E && hotKeysEnabled)
                            {
                                PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.E, eMoveAmountPositive, MovementControls.EFeedRate(0));
                            }
                            else if (e.KeyCode == Keys.R && hotKeysEnabled)
                            {
                                PrinterConnectionAndCommunication.Instance.MoveRelative(PrinterConnectionAndCommunication.Axis.E, eMoveAmountNegative, MovementControls.EFeedRate(0));
                            }
                        }
                    };

                    // add in some movement radio buttons
                    FlowLayoutWidget setMoveDistanceControl = new FlowLayoutWidget();
                    TextWidget       buttonsLabel           = new TextWidget("Distance:", textColor: RGBA_Bytes.White);
                    buttonsLabel.VAnchor = Agg.UI.VAnchor.ParentCenter;
                    //setMoveDistanceControl.AddChild(buttonsLabel);

                    {
                        TextImageButtonFactory buttonFactory = new TextImageButtonFactory();
                        buttonFactory.FixedHeight        = 20 * GuiWidget.DeviceScale;
                        buttonFactory.FixedWidth         = 30 * GuiWidget.DeviceScale;
                        buttonFactory.fontSize           = 8;
                        buttonFactory.Margin             = new BorderDouble(0);
                        buttonFactory.checkedBorderColor = ActiveTheme.Instance.PrimaryTextColor;

                        FlowLayoutWidget moveRadioButtons = new FlowLayoutWidget();

                        var radioList = new ObservableCollection <GuiWidget>();

                        pointZeroOneButton                      = buttonFactory.GenerateRadioButton("0.02");
                        pointZeroOneButton.VAnchor              = Agg.UI.VAnchor.ParentCenter;
                        pointZeroOneButton.CheckedStateChanged += (sender, e) => { if (((RadioButton)sender).Checked)
                                                                                   {
                                                                                       SetXYZMoveAmount(.02);
                                                                                   }
                        };
                        pointZeroOneButton.SiblingRadioButtonList = radioList;
                        moveRadioButtons.AddChild(pointZeroOneButton);

                        RadioButton pointOneButton = buttonFactory.GenerateRadioButton("0.1");
                        pointOneButton.VAnchor              = Agg.UI.VAnchor.ParentCenter;
                        pointOneButton.CheckedStateChanged += (sender, e) => { if (((RadioButton)sender).Checked)
                                                                               {
                                                                                   SetXYZMoveAmount(.1);
                                                                               }
                        };
                        pointOneButton.SiblingRadioButtonList = radioList;
                        moveRadioButtons.AddChild(pointOneButton);

                        RadioButton oneButton = buttonFactory.GenerateRadioButton("1");
                        oneButton.VAnchor              = Agg.UI.VAnchor.ParentCenter;
                        oneButton.CheckedStateChanged += (sender, e) => { if (((RadioButton)sender).Checked)
                                                                          {
                                                                              SetXYZMoveAmount(1);
                                                                          }
                        };
                        oneButton.SiblingRadioButtonList = radioList;
                        moveRadioButtons.AddChild(oneButton);

                        tooBigForBabyStepping = new DisableableWidget()
                        {
                            VAnchor = VAnchor.FitToChildren,
                            HAnchor = HAnchor.FitToChildren
                        };

                        var tooBigFlowLayout = new FlowLayoutWidget();
                        tooBigForBabyStepping.AddChild(tooBigFlowLayout);

                        tenButton                      = buttonFactory.GenerateRadioButton("10");
                        tenButton.VAnchor              = Agg.UI.VAnchor.ParentCenter;
                        tenButton.CheckedStateChanged += (sender, e) => { if (((RadioButton)sender).Checked)
                                                                          {
                                                                              SetXYZMoveAmount(10);
                                                                          }
                        };
                        tenButton.SiblingRadioButtonList = radioList;
                        tooBigFlowLayout.AddChild(tenButton);

                        oneHundredButton                      = buttonFactory.GenerateRadioButton("100");
                        oneHundredButton.VAnchor              = Agg.UI.VAnchor.ParentCenter;
                        oneHundredButton.CheckedStateChanged += (sender, e) => { if (((RadioButton)sender).Checked)
                                                                                 {
                                                                                     SetXYZMoveAmount(100);
                                                                                 }
                        };
                        oneHundredButton.SiblingRadioButtonList = radioList;
                        tooBigFlowLayout.AddChild(oneHundredButton);

                        moveRadioButtons.AddChild(tooBigForBabyStepping);

                        tenButton.Checked       = true;
                        moveRadioButtons.Margin = new BorderDouble(0, 3);

                        setMoveDistanceControl.AddChild(moveRadioButtons);

                        TextWidget mmLabel = new TextWidget("mm", textColor: ActiveTheme.Instance.PrimaryTextColor, pointSize: 8);
                        mmLabel.VAnchor = Agg.UI.VAnchor.ParentCenter;

                        tooBigFlowLayout.AddChild(mmLabel);
                    }

                    setMoveDistanceControl.HAnchor = Agg.UI.HAnchor.ParentLeft;
                    xYZWithDistance.AddChild(setMoveDistanceControl);
                }

                allControlsLeftToRight.AddChild(xYZWithDistance);

#if !__ANDROID__
                allControlsLeftToRight.AddChild(GetHotkeyControlContainer());
#endif
                GuiWidget barBetweenZAndE = new GuiWidget(2, 2);
                barBetweenZAndE.VAnchor         = Agg.UI.VAnchor.ParentBottomTop;
                barBetweenZAndE.BackgroundColor = RGBA_Bytes.White;
                barBetweenZAndE.Margin          = new BorderDouble(distanceBetweenControls, 5);
                allControlsLeftToRight.AddChild(barBetweenZAndE);

                FlowLayoutWidget eButtons = CreateEButtons(buttonSeparationDistance);
                disableableEButtons = new DisableableWidget()
                {
                    HAnchor = HAnchor.FitToChildren,
                    VAnchor = VAnchor.FitToChildren | VAnchor.ParentTop,
                };
                disableableEButtons.AddChild(eButtons);

                allControlsLeftToRight.AddChild(disableableEButtons);
                allControlsTopToBottom.AddChild(allControlsLeftToRight);
            }

            this.AddChild(allControlsTopToBottom);
            this.HAnchor = HAnchor.FitToChildren;
            this.VAnchor = VAnchor.FitToChildren;

            Margin = new BorderDouble(3);

            // this.HAnchor |= HAnchor.ParentLeftRight;
        }
        private FlowLayoutWidget CreateEButtons(double buttonSeparationDistance)
        {
            int extruderCount = ActiveSliceSettings.Instance.ExtruderCount();

            FlowLayoutWidget eButtons = new FlowLayoutWidget(FlowDirection.TopToBottom);

            {
                FlowLayoutWidget eMinusButtonAndText = new FlowLayoutWidget();
                BorderDouble     extrusionMargin     = new BorderDouble(4, 0, 4, 0);

                if (extruderCount == 1)
                {
                    ExtrudeButton eMinusControl = moveButtonFactory.Generate("E-", MovementControls.EFeedRate(0), 0);
                    eMinusControl.Margin      = extrusionMargin;
                    eMinusControl.ToolTipText = "Retract filament";
                    eMinusButtonAndText.AddChild(eMinusControl);
                    eMinusButtons.Add(eMinusControl);
                }
                else
                {
                    for (int i = 0; i < extruderCount; i++)
                    {
                        ExtrudeButton eMinusControl = moveButtonFactory.Generate(string.Format("E{0}-", i + 1), MovementControls.EFeedRate(0), i);
                        eMinusControl.ToolTipText = "Retract filament";
                        eMinusControl.Margin      = extrusionMargin;
                        eMinusButtonAndText.AddChild(eMinusControl);
                        eMinusButtons.Add(eMinusControl);
                    }
                }

                TextWidget eMinusControlLabel = new TextWidget(LocalizedString.Get("Retract"), pointSize: 11);
                eMinusControlLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                eMinusControlLabel.VAnchor   = Agg.UI.VAnchor.ParentCenter;
                eMinusButtonAndText.AddChild(eMinusControlLabel);
                eButtons.AddChild(eMinusButtonAndText);

                eMinusButtonAndText.HAnchor = HAnchor.FitToChildren;
                eMinusButtonAndText.VAnchor = VAnchor.FitToChildren;

                FlowLayoutWidget buttonSpacerContainer = new FlowLayoutWidget();
                for (int i = 0; i < extruderCount; i++)
                {
                    GuiWidget eSpacer     = new GuiWidget(2, buttonSeparationDistance);
                    double    buttonWidth = eMinusButtons[i].Width + 6;

                    eSpacer.Margin          = new BorderDouble((buttonWidth / 2), 0, ((buttonWidth) / 2), 0);
                    eSpacer.BackgroundColor = XYZColors.eColor;
                    buttonSpacerContainer.AddChild(eSpacer);
                }

                eButtons.AddChild(buttonSpacerContainer);

                buttonSpacerContainer.HAnchor = HAnchor.FitToChildren;
                buttonSpacerContainer.VAnchor = VAnchor.FitToChildren;

                FlowLayoutWidget ePlusButtonAndText = new FlowLayoutWidget();
                if (extruderCount == 1)
                {
                    ExtrudeButton ePlusControl = moveButtonFactory.Generate("E+", MovementControls.EFeedRate(0), 0);
                    ePlusControl.Margin      = extrusionMargin;
                    ePlusControl.ToolTipText = "Extrude filament";
                    ePlusButtonAndText.AddChild(ePlusControl);
                    ePlusButtons.Add(ePlusControl);
                }
                else
                {
                    for (int i = 0; i < extruderCount; i++)
                    {
                        ExtrudeButton ePlusControl = moveButtonFactory.Generate(string.Format("E{0}+", i + 1), MovementControls.EFeedRate(0), i);
                        ePlusControl.Margin      = extrusionMargin;
                        ePlusControl.ToolTipText = "Extrude filament";
                        ePlusButtonAndText.AddChild(ePlusControl);
                        ePlusButtons.Add(ePlusControl);
                    }
                }

                TextWidget ePlusControlLabel = new TextWidget(LocalizedString.Get("Extrude"), pointSize: 11);
                ePlusControlLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                ePlusControlLabel.VAnchor   = Agg.UI.VAnchor.ParentCenter;
                ePlusButtonAndText.AddChild(ePlusControlLabel);
                eButtons.AddChild(ePlusButtonAndText);
                ePlusButtonAndText.HAnchor = HAnchor.FitToChildren;
                ePlusButtonAndText.VAnchor = VAnchor.FitToChildren;
            }

            eButtons.AddChild(new GuiWidget(10, 6));

            // add in some movement radio buttons
            FlowLayoutWidget setMoveDistanceControl = new FlowLayoutWidget();
            TextWidget       buttonsLabel           = new TextWidget("Distance:", textColor: RGBA_Bytes.White);

            buttonsLabel.VAnchor = Agg.UI.VAnchor.ParentCenter;
            //setMoveDistanceControl.AddChild(buttonsLabel);

            {
                TextImageButtonFactory buttonFactory = new TextImageButtonFactory();
                buttonFactory.FixedHeight        = 20 * GuiWidget.DeviceScale;
                buttonFactory.FixedWidth         = 30 * GuiWidget.DeviceScale;
                buttonFactory.fontSize           = 8;
                buttonFactory.Margin             = new BorderDouble(0);
                buttonFactory.checkedBorderColor = ActiveTheme.Instance.PrimaryTextColor;

                FlowLayoutWidget moveRadioButtons = new FlowLayoutWidget();
                RadioButton      oneButton        = buttonFactory.GenerateRadioButton("1");
                oneButton.VAnchor              = Agg.UI.VAnchor.ParentCenter;
                oneButton.CheckedStateChanged += (sender, e) => { if (((RadioButton)sender).Checked)
                                                                  {
                                                                      SetEMoveAmount(1);
                                                                  }
                };
                moveRadioButtons.AddChild(oneButton);
                RadioButton tenButton = buttonFactory.GenerateRadioButton("10");
                tenButton.VAnchor              = Agg.UI.VAnchor.ParentCenter;
                tenButton.CheckedStateChanged += (sender, e) => { if (((RadioButton)sender).Checked)
                                                                  {
                                                                      SetEMoveAmount(10);
                                                                  }
                };
                moveRadioButtons.AddChild(tenButton);
                RadioButton oneHundredButton = buttonFactory.GenerateRadioButton("100");
                oneHundredButton.VAnchor              = Agg.UI.VAnchor.ParentCenter;
                oneHundredButton.CheckedStateChanged += (sender, e) => { if (((RadioButton)sender).Checked)
                                                                         {
                                                                             SetEMoveAmount(100);
                                                                         }
                };
                moveRadioButtons.AddChild(oneHundredButton);
                tenButton.Checked       = true;
                moveRadioButtons.Margin = new BorderDouble(0, 3);
                setMoveDistanceControl.AddChild(moveRadioButtons);
            }

            TextWidget mmLabel = new TextWidget("mm", textColor: ActiveTheme.Instance.PrimaryTextColor, pointSize: 8);

            mmLabel.VAnchor = Agg.UI.VAnchor.ParentCenter;
            setMoveDistanceControl.AddChild(mmLabel);
            setMoveDistanceControl.HAnchor = Agg.UI.HAnchor.ParentLeft;
            eButtons.AddChild(setMoveDistanceControl);

            eButtons.HAnchor = HAnchor.FitToChildren;
            eButtons.VAnchor = VAnchor.FitToChildren | VAnchor.ParentBottom;

            return(eButtons);
        }
Example #17
0
		internal void EnsureNestedAreMinimumSize()
		{
			{
				GuiWidget containerTest = new GuiWidget(640, 480);
				containerTest.DoubleBuffer = true;
				FlowLayoutWidget leftToRightLayout = new FlowLayoutWidget(FlowDirection.LeftToRight);
				containerTest.AddChild(leftToRightLayout);

				GuiWidget item1 = new GuiWidget(10, 11);
				GuiWidget item2 = new GuiWidget(20, 22);
				GuiWidget item3 = new GuiWidget(30, 33);
				item3.HAnchor = HAnchor.ParentLeftRight;

				leftToRightLayout.AddChild(item1);
				leftToRightLayout.AddChild(item2);
				leftToRightLayout.AddChild(item3);

				containerTest.OnDraw(containerTest.NewGraphics2D());
				Assert.IsTrue(leftToRightLayout.Width == 60);
				Assert.IsTrue(leftToRightLayout.MinimumSize.x == 0);
				Assert.IsTrue(leftToRightLayout.Height == 33);
				Assert.IsTrue(leftToRightLayout.MinimumSize.y == 0);
				Assert.IsTrue(item3.Width == 30);

				containerTest.Width = 650;
				containerTest.OnDraw(containerTest.NewGraphics2D());
				Assert.IsTrue(leftToRightLayout.Width == 60);
				Assert.IsTrue(leftToRightLayout.MinimumSize.x == 0);
				Assert.IsTrue(leftToRightLayout.Height == 33);
				Assert.IsTrue(leftToRightLayout.MinimumSize.y == 0);
				Assert.IsTrue(item3.Width == 30);
			}
		}
Example #18
0
        public SearchableTreePanel(ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            this.theme      = theme;
            this.TreeLoaded = false;

            var searchIcon = AggContext.StaticData.LoadIcon("icon_search_24x24.png", 16, 16, theme.InvertIcons).AjustAlpha(0.3);

            searchBox = new TextEditWithInlineCancel(theme)
            {
                Name    = "Search",
                HAnchor = HAnchor.Stretch,
                Margin  = new BorderDouble(6),
            };

            searchBox.ResetButton.Visible = false;

            var searchInput = searchBox.TextEditWidget;

            searchInput.BeforeDraw += (s, e) =>
            {
                if (!searchBox.ResetButton.Visible)
                {
                    e.Graphics2D.Render(
                        searchIcon,
                        searchInput.Width - searchIcon.Width - 5,
                        searchInput.LocalBounds.Bottom + searchInput.Height / 2 - searchIcon.Height / 2);
                }
            };

            searchBox.ResetButton.Click += (s, e) =>
            {
                this.ClearSearch();
            };

            searchBox.KeyDown += (s, e) =>
            {
                if (e.KeyCode == Keys.Escape)
                {
                    this.ClearSearch();
                    e.Handled = true;
                }
            };

            searchBox.TextEditWidget.ActualTextEditWidget.TextChanged += (s, e) =>
            {
                if (string.IsNullOrWhiteSpace(searchBox.Text))
                {
                    this.ClearSearch();
                }
                else
                {
                    this.PerformSearch(searchBox.Text);
                }
            };

            horizontalSplitter = new Splitter()
            {
                SplitterDistance   = Math.Max(UserSettings.Instance.LibraryViewWidth, 20),
                SplitterSize       = theme.SplitterWidth,
                SplitterBackground = theme.SplitterBackground
            };
            horizontalSplitter.AnchorAll();

            horizontalSplitter.DistanceChanged += (s, e) =>
            {
                UserSettings.Instance.LibraryViewWidth = Math.Max(horizontalSplitter.SplitterDistance, 20);
            };

            this.AddChild(horizontalSplitter);

            var leftPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            };

            leftPanel.AddChild(searchBox);

            treeView = new TreeView(theme)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch,
            };
            leftPanel.AddChild(treeView);

            horizontalSplitter.Panel1.AddChild(leftPanel);

            contentPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Fit,
                VAnchor = VAnchor.Fit,
                Margin  = new BorderDouble(left: 2)
            };
            treeView.AddChild(contentPanel);
        }
Example #19
0
		public void ChildHAnchorPriority()
		{
			// make sure a middle spacer grows and shrinks correctly
			{
				FlowLayoutWidget leftRightFlowLayout = new FlowLayoutWidget();
				Assert.IsTrue(leftRightFlowLayout.HAnchor == HAnchor.FitToChildren); // flow layout starts with FitToChildren
				leftRightFlowLayout.HAnchor |= HAnchor.ParentLeftRight; // add to the existing flags ParentLeftRight (starts with FitToChildren)
				// [<-><->] // attempting to make a visual descrition of what is happening
				Assert.IsTrue(leftRightFlowLayout.Width == 0); // nothing is forcing it to have a width so it doesn't
				GuiWidget leftWidget = new GuiWidget(10, 10); // we call it left widget as it will be the first one in the left to right flow layout
				leftRightFlowLayout.AddChild(leftWidget); // add in a child with a width of 10
				// [<->(10)<->] // the flow layout should now be forced to be 10 wide
				Assert.IsTrue(leftRightFlowLayout.Width == 10);

				GuiWidget middleSpacer = new GuiWidget(0, 10); // this widget will hold the space
				middleSpacer.HAnchor = HAnchor.ParentLeftRight; // by resizing to whatever width it can be
				leftRightFlowLayout.AddChild(middleSpacer);
				// [<->(10)(<->)<->]
				Assert.IsTrue(leftRightFlowLayout.Width == 10);
				Assert.IsTrue(middleSpacer.Width == 0);

				GuiWidget rightItem = new GuiWidget(10, 10);
				leftRightFlowLayout.AddChild(rightItem);
				// [<->(10)(<->)(10)<->]
				Assert.IsTrue(leftRightFlowLayout.Width == 20);

				GuiWidget container = new GuiWidget(40, 20);
				container.AddChild(leftRightFlowLayout);
				// (40[<->(10)(<->)(10)<->]) // the extra 20 must be put into the expandable (<->)
				Assert.IsTrue(container.Width == 40);
				Assert.IsTrue(leftRightFlowLayout.Width == 40);
				Assert.IsTrue(middleSpacer.Width == 20);

				container.Width = 50;
				// (50[<->(10)(<->)(10)<->]) // the extra 30 must be put into the expandable (<->)
				Assert.IsTrue(container.Width == 50);
				Assert.IsTrue(leftRightFlowLayout.Width == 50);
				Assert.IsTrue(middleSpacer.Width == 30);

				container.Width = 40;
				// (40[<->(10)(<->)(10)<->]) // the extra 20 must be put into the expandable (<->) by shrinking it
				Assert.IsTrue(container.Width == 40);
				Assert.IsTrue(leftRightFlowLayout.Width == 40);
				Assert.IsTrue(middleSpacer.Width == 20);

				Assert.IsTrue(container.MinimumSize.x == 40); // minimum size is set to the construction size for normal GuiWidgets
				container.MinimumSize = new Vector2(0, 0); // make sure we can make this smaller
				container.Width = 10;
				// (10[<->(10)(<->)(10)<->]) // the extra 20 must be put into the expandable (<->) by shrinking it
				Assert.IsTrue(container.Width == 10); // nothing should be keeping this big
				Assert.IsTrue(leftRightFlowLayout.Width == 20); // it can't get smaller than its contents
				Assert.IsTrue(middleSpacer.Width == 0);
			}

			// make sure the middle spacer works the same when in a flow layout
			{
				FlowLayoutWidget leftRightFlowLayout = new FlowLayoutWidget();
				leftRightFlowLayout.Name = "leftRightFlowLayout";
				Assert.IsTrue(leftRightFlowLayout.HAnchor == HAnchor.FitToChildren); // flow layout starts with FitToChildren
				leftRightFlowLayout.HAnchor |= HAnchor.ParentLeftRight; // add to the existing flags ParentLeftRight (starts with FitToChildren)
				// [<-><->] // attempting to make a visual descrition of what is happening
				Assert.IsTrue(leftRightFlowLayout.Width == 0); // nothing is forcing it to have a width so it doesn't
				GuiWidget leftWidget = new GuiWidget(10, 10); // we call it left widget as it will be the first one in the left to right flow layout
				leftWidget.Name = "leftWidget";
				leftRightFlowLayout.AddChild(leftWidget); // add in a child with a width of 10
				// [<->(10)<->] // the flow layout should now be forced to be 10 wide
				Assert.IsTrue(leftRightFlowLayout.Width == 10);

				FlowLayoutWidget middleFlowLayoutWrapper = new FlowLayoutWidget(); // we are going to wrap the implicitly middle items to test nested resizing
				middleFlowLayoutWrapper.Name = "middleFlowLayoutWrapper";
				middleFlowLayoutWrapper.HAnchor |= HAnchor.ParentLeftRight;
				GuiWidget middleSpacer = new GuiWidget(0, 10); // this widget will hold the space
				middleSpacer.Name = "middleSpacer";
				middleSpacer.HAnchor = HAnchor.ParentLeftRight; // by resizing to whatever width it can be
				middleFlowLayoutWrapper.AddChild(middleSpacer);
				// {<->(<->)<->}
				leftRightFlowLayout.AddChild(middleFlowLayoutWrapper);
				// [<->(10){<->(<->)<->}<->]
				Assert.IsTrue(leftRightFlowLayout.Width == 10);
				Assert.IsTrue(middleFlowLayoutWrapper.Width == 0);
				Assert.IsTrue(middleSpacer.Width == 0);

				GuiWidget rightWidget = new GuiWidget(10, 10);
				rightWidget.Name = "rightWidget";
				leftRightFlowLayout.AddChild(rightWidget);
				// [<->(10){<->(<->)<->}(10)<->]
				Assert.IsTrue(leftRightFlowLayout.Width == 20);

				GuiWidget container = new GuiWidget(40, 20);
				container.Name = "container";
				container.AddChild(leftRightFlowLayout);
				// (40[<->(10){<->(<->)<->}(10)<->]) // the extra 20 must be put into the expandable (<->)
				Assert.IsTrue(leftRightFlowLayout.Width == 40);
				Assert.IsTrue(middleFlowLayoutWrapper.Width == 20);
				Assert.IsTrue(middleSpacer.Width == 20);

				container.Width = 50;
				// (50[<->(10){<->(<->)<->}(10)<->]) // the extra 30 must be put into the expandable (<->)
				Assert.IsTrue(leftRightFlowLayout.Width == 50);
				Assert.IsTrue(middleSpacer.Width == 30);

				container.Width = 40;
				// (50[<->(10){<->(<->)<->}(10)<->]) // the extra 20 must be put into the expandable (<->) by shrinking it
				Assert.IsTrue(leftRightFlowLayout.Width == 40);
				Assert.IsTrue(middleSpacer.Width == 20);
			}

			// make sure a middle spacer grows and shrinks correctly when in another guiwidget (not a flow widget) that is LeftRight
			{
				FlowLayoutWidget leftRightFlowLayout = new FlowLayoutWidget();
				leftRightFlowLayout.Name = "leftRightFlowLayout";
				Assert.IsTrue(leftRightFlowLayout.HAnchor == HAnchor.FitToChildren); // flow layout starts with FitToChildren
				leftRightFlowLayout.HAnchor |= HAnchor.ParentLeftRight; // add to the existing flags ParentLeftRight (starts with FitToChildren)
				// [<-><->] // attempting to make a visual descrition of what is happening
				Assert.IsTrue(leftRightFlowLayout.Width == 0); // nothing is forcing it to have a width so it doesn't

				GuiWidget middleSpacer = new GuiWidget(0, 10); // this widget will hold the space
				middleSpacer.Name = "middleSpacer";
				middleSpacer.HAnchor = HAnchor.ParentLeftRight; // by resizing to whatever width it can be
				leftRightFlowLayout.AddChild(middleSpacer);
				// [<->(<->)<->]
				Assert.IsTrue(leftRightFlowLayout.Width == 0);
				Assert.IsTrue(middleSpacer.Width == 0);

				Assert.IsTrue(leftRightFlowLayout.Width == 0);

				GuiWidget containerOuter = new GuiWidget(40, 20);
				containerOuter.Name = "containerOuter";
				GuiWidget containerInner = new GuiWidget(0, 20);
				containerInner.HAnchor = HAnchor.ParentLeftRight | HAnchor.FitToChildren;
				containerInner.Name = "containerInner";
				containerOuter.AddChild(containerInner);
				Assert.IsTrue(containerInner.Width == 40);
				containerInner.AddChild(leftRightFlowLayout);
				// (40(<-[<->(<->)<->]->)) // the extra 20 must be put into the expandable (<->)
				Assert.IsTrue(containerInner.Width == 40);
				Assert.IsTrue(leftRightFlowLayout.Width == 40);
				Assert.IsTrue(middleSpacer.Width == 40);

				containerOuter.Width = 50;
				// (50(<-[<->(<->)<->]->) // the extra 30 must be put into the expandable (<->)
				Assert.IsTrue(containerInner.Width == 50);
				Assert.IsTrue(leftRightFlowLayout.Width == 50);
				Assert.IsTrue(middleSpacer.Width == 50);

				containerOuter.Width = 40;
				// (40(<-[<->(<->)<->]->) // the extra 20 must be put into the expandable (<->) by shrinking it
				Assert.IsTrue(containerInner.Width == 40);
				Assert.IsTrue(leftRightFlowLayout.Width == 40);
				Assert.IsTrue(middleSpacer.Width == 40);
			}

			// make sure a middle spacer grows and shrinks correctly when in another guiwidget (not a flow widget) that is LeftRight
			{
				FlowLayoutWidget leftRightFlowLayout = new FlowLayoutWidget();
				Assert.IsTrue(leftRightFlowLayout.HAnchor == HAnchor.FitToChildren); // flow layout starts with FitToChildren
				leftRightFlowLayout.HAnchor |= HAnchor.ParentLeftRight; // add to the existing flags ParentLeftRight (starts with FitToChildren)
				// [<-><->] // attempting to make a visual descrition of what is happening
				Assert.IsTrue(leftRightFlowLayout.Width == 0); // nothing is forcing it to have a width so it doesn't
				GuiWidget leftWidget = new GuiWidget(10, 10); // we call it left widget as it will be the first one in the left to right flow layout
				leftRightFlowLayout.AddChild(leftWidget); // add in a child with a width of 10
				// [<->(10)<->] // the flow layout should now be forced to be 10 wide
				Assert.IsTrue(leftRightFlowLayout.Width == 10);

				GuiWidget middleSpacer = new GuiWidget(0, 10); // this widget will hold the space
				middleSpacer.HAnchor = HAnchor.ParentLeftRight; // by resizing to whatever width it can be
				leftRightFlowLayout.AddChild(middleSpacer);
				// [<->(10)(<->)<->]
				Assert.IsTrue(leftRightFlowLayout.Width == 10);
				Assert.IsTrue(middleSpacer.Width == 0);

				GuiWidget rightItem = new GuiWidget(10, 10);
				leftRightFlowLayout.AddChild(rightItem);
				// [<->(10)(<->)(10)<->]
				Assert.IsTrue(leftRightFlowLayout.Width == 20);

				GuiWidget containerOuter = new GuiWidget(40, 20);
				containerOuter.Name = "containerOuter";
				GuiWidget containerInner = new GuiWidget(0, 20);
				containerInner.HAnchor = HAnchor.ParentLeftRight | HAnchor.FitToChildren;
				containerInner.Name = "containerInner";
				containerOuter.AddChild(containerInner);
				Assert.IsTrue(containerInner.Width == 40);
				containerInner.AddChild(leftRightFlowLayout);
				// (40(<-[<->(10)(<->)(10)<->]->)) // the extra 20 must be put into the expandable (<->)
				Assert.IsTrue(containerInner.Width == 40);
				Assert.IsTrue(leftRightFlowLayout.Width == 40);
				Assert.IsTrue(middleSpacer.Width == 20);

				containerOuter.Width = 50;
				// (50(<-[<->(10)(<->)(10)<->]->) // the extra 30 must be put into the expandable (<->)
				Assert.IsTrue(containerInner.Width == 50);
				Assert.IsTrue(leftRightFlowLayout.Width == 50);
				Assert.IsTrue(middleSpacer.Width == 30);

				containerOuter.Width = 40;
				// (40(<-[<->(10)(<->)(10)<->]->) // the extra 20 must be put into the expandable (<->) by shrinking it
				Assert.IsTrue(containerInner.Width == 40);
				Assert.IsTrue(leftRightFlowLayout.Width == 40);
				Assert.IsTrue(middleSpacer.Width == 20);
			}
		}
        private FlowLayoutWidget GetHomeButtonBar()
        {
            FlowLayoutWidget homeButtonBar = new FlowLayoutWidget();

            homeButtonBar.HAnchor = HAnchor.ParentLeftRight;
            homeButtonBar.Margin  = new BorderDouble(3, 0, 3, 6);
            homeButtonBar.Padding = new BorderDouble(0);

            textImageButtonFactory.borderWidth       = 1;
            textImageButtonFactory.normalBorderColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200);
            textImageButtonFactory.hoverBorderColor  = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200);

            ImageBuffer helpIconImage = StaticData.Instance.LoadIcon("icon_home_white_24x24.png", 24, 24);

            if (ActiveTheme.Instance.IsDarkTheme)
            {
                helpIconImage.InvertLightness();
            }
            ImageWidget homeIconImageWidget = new ImageWidget(helpIconImage);

            homeIconImageWidget.Margin = new BorderDouble(0, 0, 6, 0);
            homeIconImageWidget.OriginRelativeParent += new Vector2(0, 2) * GuiWidget.DeviceScale;
            RGBA_Bytes oldColor = this.textImageButtonFactory.normalFillColor;

            textImageButtonFactory.normalFillColor = new RGBA_Bytes(180, 180, 180);
            homeAllButton = textImageButtonFactory.Generate(LocalizedString.Get("ALL"));
            this.textImageButtonFactory.normalFillColor = oldColor;
            homeAllButton.ToolTipText = "Home X, Y and Z";
            homeAllButton.Margin      = new BorderDouble(0, 0, 6, 0);
            homeAllButton.Click      += new EventHandler(homeAll_Click);

            textImageButtonFactory.FixedWidth = (int)homeAllButton.Width * GuiWidget.DeviceScale;
            homeXButton             = textImageButtonFactory.Generate("X", centerText: true);
            homeXButton.ToolTipText = "Home X";
            homeXButton.Margin      = new BorderDouble(0, 0, 6, 0);
            homeXButton.Click      += new EventHandler(homeXButton_Click);

            homeYButton             = textImageButtonFactory.Generate("Y", centerText: true);
            homeYButton.ToolTipText = "Home Y";
            homeYButton.Margin      = new BorderDouble(0, 0, 6, 0);
            homeYButton.Click      += new EventHandler(homeYButton_Click);

            homeZButton             = textImageButtonFactory.Generate("Z", centerText: true);
            homeZButton.ToolTipText = "Home Z";
            homeZButton.Margin      = new BorderDouble(0, 0, 6, 0);
            homeZButton.Click      += new EventHandler(homeZButton_Click);

            textImageButtonFactory.normalFillColor = RGBA_Bytes.White;
            textImageButtonFactory.FixedWidth      = 0;

            disableMotors        = textImageButtonFactory.Generate("Release".Localize().ToUpper());
            disableMotors.Margin = new BorderDouble(0);
            disableMotors.Click += new EventHandler(disableMotors_Click);
            this.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;

            GuiWidget spacerReleaseShow = new GuiWidget(10 * GuiWidget.DeviceScale, 0);

            homeButtonBar.AddChild(homeIconImageWidget);
            homeButtonBar.AddChild(homeAllButton);
            homeButtonBar.AddChild(homeXButton);
            homeButtonBar.AddChild(homeYButton);
            homeButtonBar.AddChild(homeZButton);

            offsetStreamLabel = new TextWidget("", textColor: ActiveTheme.Instance.PrimaryTextColor, pointSize: 8);
            offsetStreamLabel.AutoExpandBoundsToText = true;
            offsetStreamLabel.VAnchor = VAnchor.ParentCenter;
            homeButtonBar.AddChild(offsetStreamLabel);

            homeButtonBar.AddChild(new HorizontalSpacer());
            homeButtonBar.AddChild(disableMotors);
            homeButtonBar.AddChild(spacerReleaseShow);

            PrinterConnectionAndCommunication.Instance.OffsetStreamChanged += OffsetStreamChanged;

            return(homeButtonBar);
        }
Example #21
0
		public void NestedLayoutTopToBottomWithResizeTest(BorderDouble controlPadding, BorderDouble buttonMargin)
		{
			GuiWidget containerTest = new GuiWidget(300, 200);
			containerTest.Padding = controlPadding;
			containerTest.DoubleBuffer = true;
			containerTest.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);

			FlowLayoutWidget allButtons = new FlowLayoutWidget(FlowDirection.TopToBottom);
			{
				FlowLayoutWidget topButtonBar = new FlowLayoutWidget();
				{
					Button button1 = new Button("button1");
					button1.Margin = buttonMargin;
					topButtonBar.AddChild(button1);
				}
				allButtons.AddChild(topButtonBar);

				FlowLayoutWidget bottomButtonBar = new FlowLayoutWidget();
				{
					Button button2 = new Button("wide button2");
					button2.Margin = buttonMargin;
					bottomButtonBar.AddChild(button2);
				}
				allButtons.AddChild(bottomButtonBar);
			}
			containerTest.AddChild(allButtons);
			containerTest.OnDraw(containerTest.NewGraphics2D());
			ImageBuffer controlImage = new ImageBuffer(containerTest.BackBuffer, new BlenderBGRA());

			OutputImage(controlImage, "image-control.tga");

			RectangleDouble oldBounds = containerTest.LocalBounds;
			RectangleDouble newBounds = oldBounds;
			newBounds.Right += 10;
			containerTest.LocalBounds = newBounds;
			containerTest.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
			containerTest.OnDraw(containerTest.NewGraphics2D());
			OutputImage(containerTest, "image-test.tga");

			containerTest.LocalBounds = oldBounds;
			containerTest.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
			containerTest.OnDraw(containerTest.NewGraphics2D());
			OutputImage(containerTest, "image-test.tga");

			Assert.IsTrue(containerTest.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one.");
			Assert.IsTrue(containerTest.BackBuffer == controlImage, "The control should contain the same image after being scaled away and back to the same size.");
		}
        public TemperatureWidgetBase(PrinterConfig printer, string textValue, ThemeConfig theme)
            : base(theme)
        {
            this.printer = printer;

            this.AlignToRightEdge = true;
            this.DrawArrow        = true;
            this.HAnchor          = HAnchor.Fit;
            this.VAnchor          = VAnchor.Fit | VAnchor.Center;
            this.Cursor           = Cursors.Hand;
            this.MakeScrollable   = false;
            this.AlignToRightEdge = true;

            ImageWidget = new ImageWidget(AggContext.StaticData.LoadIcon("hotend.png", theme.InvertIcons))
            {
                VAnchor = VAnchor.Center,
                Margin  = new BorderDouble(right: 5)
            };

            alwaysEnabled = new List <GuiWidget>();

            var container = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.Fit,
                VAnchor = VAnchor.Fit,
                Padding = new BorderDouble(10, 5, 0, 5)
            };

            this.AddChild(container);

            container.AddChild(this.ImageWidget);

            CurrentTempIndicator = new TextWidget(textValue, pointSize: 11)
            {
                TextColor = theme.TextColor,
                VAnchor   = VAnchor.Center,
                AutoExpandBoundsToText = true
            };
            container.AddChild(CurrentTempIndicator);

            container.AddChild(new TextWidget("/")
            {
                TextColor = theme.TextColor
            });

            goalTempIndicator = new TextWidget(textValue, pointSize: 11)
            {
                TextColor = theme.TextColor,
                VAnchor   = VAnchor.Center,
                AutoExpandBoundsToText = true
            };
            container.AddChild(goalTempIndicator);

            DirectionIndicator = new TextWidget(textValue, pointSize: 11)
            {
                TextColor = theme.TextColor,
                VAnchor   = VAnchor.Center,
                AutoExpandBoundsToText = true,
                Margin = new BorderDouble(left: 5)
            };
            container.AddChild(DirectionIndicator);

            // Register listeners
            printer.Connection.CommunicationStateChanged += Connection_CommunicationStateChanged;

            foreach (var child in this.Children)
            {
                child.Selectable = false;
            }
        }
Example #23
0
        public RenameItemWindow(string currentItemName, Action <RenameItemReturnInfo> functionToCallToRenameItem, string renameButtonString = null)
            : base(480, 180)
        {
            Title             = "MatterControl - Rename Item";
            AlwaysOnTopOfMain = true;

            this.functionToCallToCreateNamedFolder = functionToCallToRenameItem;

            FlowLayoutWidget topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);

            topToBottom.AnchorAll();
            topToBottom.Padding = new BorderDouble(3, 0, 3, 5);

            // Creates Header
            FlowLayoutWidget headerRow = new FlowLayoutWidget(FlowDirection.LeftToRight);

            headerRow.HAnchor = HAnchor.ParentLeftRight;
            headerRow.Margin  = new BorderDouble(0, 3, 0, 0);
            headerRow.Padding = new BorderDouble(0, 3, 0, 3);
            BackgroundColor   = ActiveTheme.Instance.PrimaryBackgroundColor;

            //Creates Text and adds into header
            {
                string renameItemLabel = "Rename Item:".Localize();
                elementHeader           = new TextWidget(renameItemLabel, pointSize: 14);
                elementHeader.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                elementHeader.HAnchor   = HAnchor.ParentLeftRight;
                elementHeader.VAnchor   = Agg.UI.VAnchor.ParentBottom;

                headerRow.AddChild(elementHeader);
                topToBottom.AddChild(headerRow);
                this.AddChild(topToBottom);
            }

            //Creates container in the middle of window
            FlowLayoutWidget middleRowContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
            {
                middleRowContainer.HAnchor         = HAnchor.ParentLeftRight;
                middleRowContainer.VAnchor         = VAnchor.ParentBottomTop;
                middleRowContainer.Padding         = new BorderDouble(5);
                middleRowContainer.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
            }

            string     fileNameLabel = "New Name".Localize();
            TextWidget textBoxHeader = new TextWidget(fileNameLabel, pointSize: 12);

            textBoxHeader.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            textBoxHeader.Margin    = new BorderDouble(5);
            textBoxHeader.HAnchor   = HAnchor.ParentLeft;

            //Adds text box and check box to the above container
            saveAsNameWidget         = new MHTextEditWidget(currentItemName, pixelWidth: 300, messageWhenEmptyAndNotSelected: "Enter New Name Here".Localize());
            saveAsNameWidget.HAnchor = HAnchor.ParentLeftRight;
            saveAsNameWidget.Margin  = new BorderDouble(5);

            middleRowContainer.AddChild(textBoxHeader);
            middleRowContainer.AddChild(saveAsNameWidget);
            middleRowContainer.AddChild(new HorizontalSpacer());
            topToBottom.AddChild(middleRowContainer);

            //Creates button container on the bottom of window
            FlowLayoutWidget buttonRow = new FlowLayoutWidget(FlowDirection.LeftToRight);

            {
                BackgroundColor   = ActiveTheme.Instance.PrimaryBackgroundColor;
                buttonRow.HAnchor = HAnchor.ParentLeftRight;
                buttonRow.Padding = new BorderDouble(0, 3);
            }

            if (renameButtonString == null)
            {
                renameButtonString = "Rename".Localize();
            }
            renameItemButton         = textImageButtonFactory.Generate(renameButtonString, centerText: true);
            renameItemButton.Name    = "Rename Button";
            renameItemButton.Visible = true;
            renameItemButton.Cursor  = Cursors.Hand;
            buttonRow.AddChild(renameItemButton);

            renameItemButton.Click += new EventHandler(renameItemButton_Click);
            saveAsNameWidget.ActualTextEditWidget.EnterPressed += new KeyEventHandler(ActualTextEditWidget_EnterPressed);

            //Adds Create and Close Button to button container
            buttonRow.AddChild(new HorizontalSpacer());

            Button cancelButton = textImageButtonFactory.Generate("Cancel".Localize(), centerText: true);

            cancelButton.Visible = true;
            cancelButton.Cursor  = Cursors.Hand;
            buttonRow.AddChild(cancelButton);
            cancelButton.Click += (sender, e) =>
            {
                CloseOnIdle();
            };

            topToBottom.AddChild(buttonRow);

            ShowAsSystemWindow();
        }
        private FlowLayoutWidget GetDisplayControl()
        {
            FlowLayoutWidget buttonRow = new FlowLayoutWidget();

            buttonRow.HAnchor = HAnchor.ParentLeftRight;
            buttonRow.Margin  = new BorderDouble(top: 4);

            TextWidget settingsLabel = new TextWidget("Display Mode".Localize());

            settingsLabel.AutoExpandBoundsToText = true;
            settingsLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            settingsLabel.VAnchor   = VAnchor.ParentTop;

            Button displayControlRestartButton = textImageButtonFactory.Generate("Restart");

            displayControlRestartButton.VAnchor = Agg.UI.VAnchor.ParentCenter;
            displayControlRestartButton.Visible = false;
            displayControlRestartButton.Margin  = new BorderDouble(right: 6);
            displayControlRestartButton.Click  += (sender, e) =>
            {
                if (PrinterConnectionAndCommunication.Instance.PrinterIsPrinting)
                {
                    StyledMessageBox.ShowMessageBox(null, cannotRestartWhilePrintIsActiveMessage, cannotRestartWhileActive);
                }
                else
                {
                    RestartApplication();
                }
            };

            FlowLayoutWidget optionsContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);

            optionsContainer.Margin = new BorderDouble(bottom: 6);

            StyledDropDownList interfaceOptionsDropList = new StyledDropDownList("Development", maxHeight: 200);

            interfaceOptionsDropList.HAnchor = HAnchor.ParentLeftRight;

            optionsContainer.AddChild(interfaceOptionsDropList);
            optionsContainer.Width = 200;

            MenuItem responsizeOptionsDropDownItem  = interfaceOptionsDropList.AddItem("Normal".Localize(), "responsive");
            MenuItem touchscreenOptionsDropDownItem = interfaceOptionsDropList.AddItem("Touchscreen".Localize(), "touchscreen");

            List <string> acceptableUpdateFeedTypeValues = new List <string>()
            {
                "responsive", "touchscreen"
            };
            string currentDisplayModeType = UserSettings.Instance.get("ApplicationDisplayMode");

            if (acceptableUpdateFeedTypeValues.IndexOf(currentDisplayModeType) == -1)
            {
                UserSettings.Instance.set("ApplicationDisplayMode", "responsive");
            }

            interfaceOptionsDropList.SelectedValue     = UserSettings.Instance.get("ApplicationDisplayMode");
            interfaceOptionsDropList.SelectionChanged += (sender, e) =>
            {
                string releaseCode = ((StyledDropDownList)sender).SelectedValue;
                if (releaseCode != UserSettings.Instance.get("ApplicationDisplayMode"))
                {
                    UserSettings.Instance.set("ApplicationDisplayMode", releaseCode);
                    displayControlRestartButton.Visible = true;
                }
            };

            buttonRow.AddChild(settingsLabel);
            buttonRow.AddChild(new HorizontalSpacer());
            buttonRow.AddChild(displayControlRestartButton);
            buttonRow.AddChild(optionsContainer);
            return(buttonRow);
        }
Example #25
0
        private GuiWidget CreateActionBar(bool smallScreen)
        {
            var actionBar = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                VAnchor         = VAnchor.ParentTop | VAnchor.FitToChildren,
                HAnchor         = HAnchor.ParentLeftRight,
                BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor,
            };

            var mcLogo = StaticData.Instance.LoadImage(Path.Combine("Images", "Screensaver", "logo.png"));

            if (!ActiveTheme.Instance.IsDarkTheme)
            {
                mcLogo.InvertLightness();
            }
            actionBar.AddChild(new ImageWidget(mcLogo));

            actionBar.AddChild(new HorizontalSpacer());

            // put in the pause button
            var pauseButton = CreateButton("Pause".Localize().ToUpper(), smallScreen);

            pauseButton.Click += (s, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    PrinterConnectionAndCommunication.Instance.RequestPause();
                });
            };
            pauseButton.Enabled = PrinterConnectionAndCommunication.Instance.PrinterIsPrinting &&
                                  !PrinterConnectionAndCommunication.Instance.PrinterIsPaused;

            actionBar.AddChild(pauseButton);

            // put in the resume button
            var resumeButton = CreateButton("Resume".Localize().ToUpper(), smallScreen);

            resumeButton.Visible = false;
            resumeButton.Click  += (s, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    if (PrinterConnectionAndCommunication.Instance.PrinterIsPaused)
                    {
                        PrinterConnectionAndCommunication.Instance.Resume();
                    }
                });
            };
            actionBar.AddChild(resumeButton);

            actionBar.AddChild(CreateVerticalLine());

            // put in cancel button
            var cancelButton = CreateButton("Cancel".Localize().ToUpper(), smallScreen);

            cancelButton.Click += (s, e) =>
            {
                bool canceled = ApplicationController.Instance.ConditionalCancelPrint();
                if (canceled)
                {
                    this.Close();
                }
            };
            cancelButton.Enabled = PrinterConnectionAndCommunication.Instance.PrinterIsPrinting || PrinterConnectionAndCommunication.Instance.PrinterIsPaused;
            actionBar.AddChild(cancelButton);

            actionBar.AddChild(CreateVerticalLine());

            // put in the reset button
            var resetButton = CreateButton("Reset".Localize().ToUpper(), smallScreen, true, StaticData.Instance.LoadIcon("e_stop4.png", 32, 32));

            resetButton.Visible = ActiveSliceSettings.Instance.GetValue <bool>(SettingsKey.show_reset_connection);
            resetButton.Click  += (s, e) =>
            {
                UiThread.RunOnIdle(PrinterConnectionAndCommunication.Instance.RebootBoard);
            };
            actionBar.AddChild(resetButton);

            actionBar.AddChild(CreateVerticalLine());

            var advancedButton = CreateButton("Advanced".Localize().ToUpper(), smallScreen);

            actionBar.AddChild(advancedButton);
            advancedButton.Click += (s, e) =>
            {
                bool inBasicMode = bodyContainer.Children[0] is BasicBody;
                if (inBasicMode)
                {
                    bodyContainer.RemoveChild(basicBody);

                    bodyContainer.AddChild(new ManualPrinterControls()
                    {
                        VAnchor = VAnchor.ParentBottomTop,
                        HAnchor = HAnchor.ParentLeftRight
                    });

                    advancedButton.BackgroundColor = ActiveTheme.Instance.PrimaryAccentColor;
                }
                else
                {
                    bodyContainer.CloseAllChildren();

                    basicBody.ClearRemovedFlag();
                    bodyContainer.AddChild(basicBody);

                    advancedButton.BackgroundColor = RGBA_Bytes.Transparent;
                }
            };

            PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent((s, e) =>
            {
                pauseButton.Enabled = PrinterConnectionAndCommunication.Instance.PrinterIsPrinting &&
                                      !PrinterConnectionAndCommunication.Instance.PrinterIsPaused;

                if (PrinterConnectionAndCommunication.Instance.PrinterIsPaused)
                {
                    resumeButton.Visible = true;
                    pauseButton.Visible  = false;
                }
                else
                {
                    resumeButton.Visible = false;
                    pauseButton.Visible  = true;
                }

                // Close if not Preparing, Printing or Paused
                switch (PrinterConnectionAndCommunication.Instance.CommunicationState)
                {
                case PrinterConnectionAndCommunication.CommunicationStates.PreparingToPrint:
                case PrinterConnectionAndCommunication.CommunicationStates.Printing:
                case PrinterConnectionAndCommunication.CommunicationStates.Paused:
                    break;

                default:
                    this.CloseOnIdle();
                    break;
                }
            }, ref unregisterEvents);

            PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent((s, e) =>
            {
                cancelButton.Enabled = PrinterConnectionAndCommunication.Instance.PrinterIsPrinting || PrinterConnectionAndCommunication.Instance.PrinterIsPaused;
            }, ref unregisterEvents);

            return(actionBar);
        }
        private FlowLayoutWidget GetThumbnailRenderingControl()
        {
            FlowLayoutWidget buttonRow = new FlowLayoutWidget();

            buttonRow.HAnchor = HAnchor.ParentLeftRight;
            buttonRow.Margin  = new BorderDouble(top: 4);

            TextWidget settingsLabel = new TextWidget("Thumbnail Rendering".Localize());

            settingsLabel.AutoExpandBoundsToText = true;
            settingsLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            settingsLabel.VAnchor   = VAnchor.ParentTop;

            FlowLayoutWidget optionsContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);

            optionsContainer.Margin = new BorderDouble(bottom: 6);

            StyledDropDownList interfaceOptionsDropList = new StyledDropDownList("Development", maxHeight: 200);

            interfaceOptionsDropList.HAnchor = HAnchor.ParentLeftRight;

            optionsContainer.AddChild(interfaceOptionsDropList);
            optionsContainer.Width = 200;

            interfaceOptionsDropList.AddItem("Flat".Localize(), "orthographic");
            interfaceOptionsDropList.AddItem("3D".Localize(), "raytraced");

            List <string> acceptableUpdateFeedTypeValues = new List <string>()
            {
                "orthographic", "raytraced"
            };
            string currentThumbnailRenderingMode = UserSettings.Instance.get("ThumbnailRenderingMode");

            if (acceptableUpdateFeedTypeValues.IndexOf(currentThumbnailRenderingMode) == -1)
            {
                UserSettings.Instance.set("ThumbnailRenderingMode", "orthographic");
            }

            interfaceOptionsDropList.SelectedValue     = UserSettings.Instance.get("ThumbnailRenderingMode");
            interfaceOptionsDropList.SelectionChanged += (sender, e) =>
            {
                string thumbnailRenderingMode = ((StyledDropDownList)sender).SelectedValue;
                if (thumbnailRenderingMode != UserSettings.Instance.get("ThumbnailRenderingMode"))
                {
                    UserSettings.Instance.set("ThumbnailRenderingMode", thumbnailRenderingMode);

                    // Ask if the user would like to rebuild all their thumbnails
                    Action <bool> removeThumbnails = (bool shouldRebuildThumbnails) =>
                    {
                        if (shouldRebuildThumbnails)
                        {
                            string directoryToRemove = PartThumbnailWidget.ThumbnailPath();
                            try
                            {
                                if (Directory.Exists(directoryToRemove))
                                {
                                    Directory.Delete(directoryToRemove, true);
                                }
                            }
                            catch (Exception)
                            {
                                GuiWidget.BreakInDebugger();
                            }
                        }

                        ApplicationController.Instance.ReloadAll(null, null);
                    };

                    UiThread.RunOnIdle(() =>
                    {
                        StyledMessageBox.ShowMessageBox(removeThumbnails, rebuildThumbnailsMessage, rebuildThumbnailsTitle, StyledMessageBox.MessageType.YES_NO, "Rebuild".Localize());
                    });
                }
            };

            buttonRow.AddChild(settingsLabel);
            buttonRow.AddChild(new HorizontalSpacer());
            buttonRow.AddChild(optionsContainer);
            return(buttonRow);
        }
Example #27
0
        private FlowLayoutWidget NewPulldownContainer()
        {
            dropDownList = CreateDropdown();

            var container = new FlowLayoutWidget()
            {
                HAnchor = createAsFit ? HAnchor.Fit : HAnchor.MaxFitOrStretch,
                Name    = "Preset Pulldown Container"
            };

            editButton = new IconButton(StaticData.Instance.LoadIcon("icon_edit.png", 16, 16, theme.InvertIcons), theme)
            {
                ToolTipText = "Edit Selected Setting".Localize(),
                Enabled     = dropDownList.SelectedIndex != -1,
                VAnchor     = VAnchor.Center,
                Margin      = new BorderDouble(left: 6)
            };

            editButton.Click += (sender, e) =>
            {
                if (layerType == NamedSettingsLayers.Material)
                {
                    if (ApplicationController.Instance.EditMaterialPresetsPage == null)
                    {
                        string presetsID = printer.Settings.ActiveMaterialKey;
                        if (string.IsNullOrEmpty(presetsID))
                        {
                            return;
                        }

                        var layerToEdit = printer.Settings.MaterialLayers.Where(layer => layer.LayerID == presetsID).FirstOrDefault();

                        var presetsContext = new PresetsContext(printer.Settings.MaterialLayers, layerToEdit)
                        {
                            LayerType   = NamedSettingsLayers.Material,
                            SetAsActive = (materialKey) => printer.Settings.ActiveMaterialKey = materialKey,
                            DeleteLayer = () =>
                            {
                                printer.Settings.ActiveMaterialKey = "";
                                printer.Settings.MaterialLayers.Remove(layerToEdit);
                                printer.Settings.Save();
                            }
                        };

                        var editMaterialPresetsPage = new SlicePresetsPage(printer, presetsContext);
                        editMaterialPresetsPage.Closed += (s, e2) =>
                        {
                            ApplicationController.Instance.EditMaterialPresetsPage = null;
                        };

                        ApplicationController.Instance.EditMaterialPresetsPage = editMaterialPresetsPage;
                        DialogWindow.Show(editMaterialPresetsPage);
                    }
                    else
                    {
                        ApplicationController.Instance.EditMaterialPresetsPage.DialogWindow.BringToFront();
                    }
                }

                if (layerType == NamedSettingsLayers.Quality)
                {
                    if (ApplicationController.Instance.EditQualityPresetsWindow == null)
                    {
                        string presetsID = printer.Settings.ActiveQualityKey;
                        if (string.IsNullOrEmpty(presetsID))
                        {
                            return;
                        }

                        var layerToEdit = printer.Settings.QualityLayers.Where(layer => layer.LayerID == presetsID).FirstOrDefault();

                        var presetsContext = new PresetsContext(printer.Settings.QualityLayers, layerToEdit)
                        {
                            LayerType   = NamedSettingsLayers.Quality,
                            SetAsActive = (qualityKey) => printer.Settings.ActiveQualityKey = qualityKey,
                            DeleteLayer = () =>
                            {
                                printer.Settings.QualityLayers.Remove(layerToEdit);
                                printer.Settings.Save();

                                // Clear QualityKey after removing layer to ensure listeners see update
                                printer.Settings.ActiveQualityKey = "";
                            }
                        };

                        var editQualityPresetsWindow = new SlicePresetsPage(printer, presetsContext);
                        editQualityPresetsWindow.Closed += (s, e2) =>
                        {
                            ApplicationController.Instance.EditQualityPresetsWindow = null;
                        };

                        ApplicationController.Instance.EditQualityPresetsWindow = editQualityPresetsWindow;
                        DialogWindow.Show(editQualityPresetsWindow);
                    }
                    else
                    {
                        ApplicationController.Instance.EditQualityPresetsWindow.DialogWindow.BringToFront();
                    }
                }
            };

            container.AddChild(dropDownList);
            container.AddChild(editButton);

            return(container);
        }
Example #28
0
        public MaterialControls(InteractiveScene scene, ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            this.theme   = theme;
            this.scene   = scene;
            this.HAnchor = HAnchor.Stretch;
            this.VAnchor = VAnchor.Fit;

            materialButtons.Clear();
            int extruderCount = 4;

            for (int extruderIndex = -1; extruderIndex < extruderCount; extruderIndex++)
            {
                var name = $"{"Material".Localize()} {extruderIndex +1}";
                if (extruderIndex == -1)
                {
                    name = "Default".Localize();
                }

                var buttonView = new FlowLayoutWidget()
                {
                    HAnchor = HAnchor.Fit,
                    VAnchor = VAnchor.Fit
                };

                var scaledButtonSize = 16 * GuiWidget.DeviceScale;

                buttonView.AddChild(new ColorButton(extruderIndex == -1 ? Color.Black : MaterialRendering.Color(extruderIndex))
                {
                    Margin  = new BorderDouble(right: 5),
                    Width   = scaledButtonSize,
                    Height  = scaledButtonSize,
                    VAnchor = VAnchor.Center,
                });

                buttonView.AddChild(new TextWidget(name, pointSize: theme.DefaultFontSize, textColor: theme.Colors.PrimaryTextColor)
                {
                    VAnchor = VAnchor.Center
                });

                var radioButtonView = new RadioButtonView(buttonView)
                {
                    TextColor = theme.Colors.PrimaryTextColor
                };
                radioButtonView.RadioCircle.Margin = radioButtonView.RadioCircle.Margin.Clone(right: 5);

                var radioButton = new RadioButton(radioButtonView)
                {
                    HAnchor   = HAnchor.Stretch,
                    VAnchor   = VAnchor.Fit,
                    TextColor = theme.Colors.PrimaryTextColor
                };
                materialButtons.Add(radioButton);
                this.AddChild(radioButton);

                int extruderIndexCanPassToClick = extruderIndex;
                radioButton.Click += (sender, e) =>
                {
                    var selectedItem = scene.SelectedItem;
                    if (selectedItem != null)
                    {
                        selectedItem.MaterialIndex = extruderIndexCanPassToClick;
                        scene.Invalidate(new InvalidateArgs(null, InvalidateType.Material));
                    }
                };
            }

            scene.SelectionChanged += Scene_SelectionChanged;
        }
Example #29
0
		public void ParentTopBottomAndFitToChildren()
		{
			// Make sure normal nested layouts works as expected. First inner added then outer
			{
				GuiWidget parent = new GuiWidget(100, 200);

				GuiWidget childOuter = new GuiWidget(31, 32);
				childOuter.VAnchor = VAnchor.FitToChildren | VAnchor.ParentBottomTop;
				Assert.IsTrue(childOuter.LocalBounds == new RectangleDouble(0, 0, 31, 32));

				GuiWidget childInner = new GuiWidget(41, 42);
				childOuter.AddChild(childInner);

				Assert.IsTrue(childOuter.LocalBounds == new RectangleDouble(0, 0, 31, 42));

				parent.AddChild(childOuter);

				Assert.IsTrue(childOuter.LocalBounds == new RectangleDouble(0, 0, 31, 200));
			}

			// Make sure vertical flow layout nested works with both top bottom and children
			{
				GuiWidget parent = new GuiWidget(100, 200);
				parent.Name = "Parent";

				FlowLayoutWidget childOuter = new FlowLayoutWidget(FlowDirection.TopToBottom);
				childOuter.Name = "childOuter";
				childOuter.VAnchor = VAnchor.FitToChildren | VAnchor.ParentBottomTop;
				Assert.IsTrue(childOuter.LocalBounds == new RectangleDouble(0, 0, 0, 0));

				GuiWidget childInner = new GuiWidget(41, 42);
				childInner.Name = "childInner";
				childOuter.AddChild(childInner);

				Assert.IsTrue(childOuter.LocalBounds == new RectangleDouble(0, 0, 41, 42));

				parent.AddChild(childOuter);

				Assert.IsTrue(childOuter.LocalBounds == new RectangleDouble(0, 0, 41, 200));
			}

			// Make sure horizontal flow layout nested works with both top bottom and children
			{
				GuiWidget parent = new GuiWidget(100, 200);
				parent.Name = "Parent";

				FlowLayoutWidget childOuter = new FlowLayoutWidget(FlowDirection.TopToBottom);
				childOuter.Name = "childOuter";
				childOuter.HAnchor = HAnchor.FitToChildren | HAnchor.ParentLeftRight;
				Assert.IsTrue(childOuter.LocalBounds == new RectangleDouble(0, 0, 0, 0));

				GuiWidget childInner = new GuiWidget(41, 42);
				childInner.Name = "childInner";
				childOuter.AddChild(childInner);

				Assert.IsTrue(childOuter.LocalBounds == new RectangleDouble(0, 0, 41, 42));

				parent.AddChild(childOuter);

				Assert.IsTrue(childOuter.LocalBounds == new RectangleDouble(0, 0, 100, 42));
			}

			// Make sure normal nested layouts works as expected. First outer than inner added
			{
				GuiWidget parent = new GuiWidget(100, 200);

				GuiWidget childOuter = new GuiWidget(31, 32);
				childOuter.VAnchor = VAnchor.FitToChildren | VAnchor.ParentBottomTop;
				Assert.IsTrue(childOuter.LocalBounds == new RectangleDouble(0, 0, 31, 32));

				parent.AddChild(childOuter);

				Assert.IsTrue(childOuter.LocalBounds == new RectangleDouble(0, 0, 31, 200));

				GuiWidget childInner = new GuiWidget(41, 42);
				childOuter.AddChild(childInner);

				Assert.IsTrue(childOuter.LocalBounds == new RectangleDouble(0, 0, 31, 200));
			}
		}
Example #30
0
        public MarlinEEPromPage(PrinterConfig printer)
            : base(printer)
        {
            AlwaysOnTopOfMain = true;
            this.WindowTitle  = "Marlin Firmware EEPROM Settings".Localize();

            currentEePromSettings             = new EePromMarlinSettings(printer.Connection);
            currentEePromSettings.eventAdded += SetUiToPrinterSettings;

            // the center content
            var conterContent = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                VAnchor = VAnchor.Fit | VAnchor.Top,
                HAnchor = HAnchor.Stretch
            };

            // add a scroll container
            var settingsAreaScrollBox = new ScrollableWidget(true);

            settingsAreaScrollBox.ScrollArea.HAnchor |= HAnchor.Stretch;
            settingsAreaScrollBox.AnchorAll();
            contentRow.AddChild(settingsAreaScrollBox);

            settingsAreaScrollBox.AddChild(conterContent);

            conterContent.AddChild(Create4FieldSet("Steps per mm".Localize() + ":",
                                                   "X:", ref stepsPerMmX,
                                                   "Y:", ref stepsPerMmY,
                                                   "Z:", ref stepsPerMmZ,
                                                   "E:", ref stepsPerMmE));

            conterContent.AddChild(Create4FieldSet("Maximum feedrates [mm/s]".Localize() + ":",
                                                   "X:", ref maxFeedrateMmPerSX,
                                                   "Y:", ref maxFeedrateMmPerSY,
                                                   "Z:", ref maxFeedrateMmPerSZ,
                                                   "E:", ref maxFeedrateMmPerSE));

            conterContent.AddChild(Create4FieldSet("Maximum Acceleration [mm/s²]".Localize() + ":",
                                                   "X:", ref maxAccelerationMmPerSSqrdX,
                                                   "Y:", ref maxAccelerationMmPerSSqrdY,
                                                   "Z:", ref maxAccelerationMmPerSSqrdZ,
                                                   "E:", ref maxAccelerationMmPerSSqrdE));

            conterContent.AddChild(CreateField("Acceleration Printing".Localize() + ":", ref accelerationPrintingMoves));
            conterContent.AddChild(CreateField("Acceleration Travel".Localize() + ":", ref accelerationTravelMoves));
            conterContent.AddChild(CreateField("Retract Acceleration".Localize() + ":", ref accelerationRetraction));

            conterContent.AddChild(Create3FieldSet("PID Settings".Localize() + ":",
                                                   "P:", ref pidP,
                                                   "I:", ref pidI,
                                                   "D:", ref pidD));

            conterContent.AddChild(Create3FieldSet("Bed PID Settings".Localize() + ":",
                                                   "P:", ref bedPidP,
                                                   "I:", ref bedPidI,
                                                   "D:", ref bedPidD));

            conterContent.AddChild(Create3FieldSet("Homing Offset".Localize() + ":",
                                                   "X:", ref homingOffsetX,
                                                   "Y:", ref homingOffsetY,
                                                   "Z:", ref homingOffsetZ));

            conterContent.AddChild(CreateField("Min feedrate [mm/s]".Localize() + ":", ref minFeedrate));
            conterContent.AddChild(CreateField("Min travel feedrate [mm/s]".Localize() + ":", ref minTravelFeedrate));
            conterContent.AddChild(CreateField("Minimum segment time [ms]".Localize() + ":", ref minSegmentTime));
            conterContent.AddChild(CreateField("Maximum X-Y jerk [mm/s]".Localize() + ":", ref maxXYJerk));
            conterContent.AddChild(CreateField("Maximum Z jerk [mm/s]".Localize() + ":", ref maxZJerk));
            conterContent.AddChild(CreateField("Maximum E jerk [mm/s]".Localize() + ":", ref maxEJerk));

            // the bottom button bar
            var buttonSave = theme.CreateDialogButton("Save to EEProm".Localize());

            buttonSave.Click += (s, e) =>
            {
                SaveSettingsToActive();
                currentEePromSettings.SaveToEeProm();
                this.DialogWindow.Close();
            };
            this.AddPageAction(buttonSave);

            var exportButton = theme.CreateDialogButton("Export".Localize());

            exportButton.Click += (s, e) =>
            {
                UiThread.RunOnIdle(this.ExportSettings, .1);
            };
            this.AddPageAction(exportButton);

            printer.Connection.LineReceived += currentEePromSettings.Add;

            // and ask the printer to send the settings
            currentEePromSettings.Update();

            if (headerRow is OverflowBar overflowBar)
            {
                overflowBar.ExtendOverflowMenu = (popupMenu) =>
                {
                    var menuItem = popupMenu.CreateMenuItem("Import".Localize());
                    menuItem.Name   = "Import Menu Item";
                    menuItem.Click += (s, e) =>
                    {
                        UiThread.RunOnIdle(() =>
                        {
                            AggContext.FileDialogs.OpenFileDialog(
                                new OpenFileDialogParams("EEPROM Settings|*.ini")
                            {
                                ActionButtonLabel = "Import EEPROM Settings".Localize(),
                                Title             = "Import EEPROM".Localize(),
                            },
                                (openParams) =>
                            {
                                if (!string.IsNullOrEmpty(openParams.FileName))
                                {
                                    currentEePromSettings.Import(openParams.FileName);
                                    SetUiToPrinterSettings(null, null);
                                }
                            });
                        }, .1);
                    };

                    // put in the export button
                    menuItem        = popupMenu.CreateMenuItem("Export".Localize());
                    menuItem.Name   = "Export Menu Item";
                    menuItem.Click += (s, e) =>
                    {
                        UiThread.RunOnIdle(this.ExportSettings, .1);
                    };

                    popupMenu.CreateSeparator();

                    menuItem        = popupMenu.CreateMenuItem("Reset to Factory Defaults".Localize());
                    menuItem.Click += (s, e) =>
                    {
                        currentEePromSettings.SetPrinterToFactorySettings();
                        currentEePromSettings.Update();
                    };
                };
            }

            foreach (GuiWidget widget in leftStuffToSize)
            {
                widget.Width = maxWidthOfLeftStuff;
            }
        }
Example #31
0
		public void TopBottomWithAnchorBottomTopChildTest(BorderDouble controlPadding, BorderDouble buttonMargin)
		{
			double buttonSize = 40;
			GuiWidget containerControl = new GuiWidget(buttonSize * 3, buttonSize * 8);
			containerControl.Padding = controlPadding;
			containerControl.DoubleBuffer = true;

			RectangleDouble[] eightControlRectangles = new RectangleDouble[8];
			RGBA_Bytes[] eightColors = new RGBA_Bytes[] { RGBA_Bytes.Red, RGBA_Bytes.Orange, RGBA_Bytes.Yellow, RGBA_Bytes.YellowGreen, RGBA_Bytes.Green, RGBA_Bytes.Blue, RGBA_Bytes.Indigo, RGBA_Bytes.Violet };
			{
				double currentBottom = containerControl.Height - controlPadding.Top - buttonMargin.Top - buttonSize;
				double buttonWidthWithMargin = buttonSize + buttonMargin.Width;
				double scalledHeight = (containerControl.Height - controlPadding.Height - buttonMargin.Height * 8 - buttonSize * 2) / 6;
				// the bottom unsized rect
				eightControlRectangles[0] = new RectangleDouble(
						0,
						currentBottom,
						buttonSize,
						currentBottom + buttonSize);

				// left anchor
				currentBottom -= scalledHeight + buttonMargin.Height;
				double leftAnchorX = controlPadding.Left + buttonMargin.Left;
				eightControlRectangles[1] = new RectangleDouble(leftAnchorX, currentBottom, leftAnchorX + buttonSize, currentBottom + scalledHeight);

				// center anchor
				double centerXOfContainer = controlPadding.Left + (containerControl.Width - controlPadding.Width) / 2;
				currentBottom -= scalledHeight + buttonMargin.Height;
				eightControlRectangles[2] = new RectangleDouble(centerXOfContainer - buttonWidthWithMargin / 2 + buttonMargin.Left, currentBottom, centerXOfContainer + buttonWidthWithMargin / 2 - buttonMargin.Right, currentBottom + scalledHeight);

				// right anchor
				double rightAnchorX = containerControl.Width - controlPadding.Right - buttonMargin.Right;
				currentBottom -= scalledHeight + buttonMargin.Height;
				eightControlRectangles[3] = new RectangleDouble(rightAnchorX - buttonSize, currentBottom, rightAnchorX, currentBottom + scalledHeight);

				// left center anchor
				currentBottom -= scalledHeight + buttonMargin.Height;
				eightControlRectangles[4] = new RectangleDouble(leftAnchorX, currentBottom, centerXOfContainer - buttonMargin.Right, currentBottom + scalledHeight);

				// center right anchor
				currentBottom -= scalledHeight + buttonMargin.Height;
				eightControlRectangles[5] = new RectangleDouble(centerXOfContainer + buttonMargin.Left, currentBottom, rightAnchorX, currentBottom + scalledHeight);

				// left right anchor
				currentBottom -= scalledHeight + buttonMargin.Height;
				eightControlRectangles[6] = new RectangleDouble(leftAnchorX, currentBottom, rightAnchorX, currentBottom + scalledHeight);

				// top anchor
				currentBottom -= buttonSize + buttonMargin.Height;
				eightControlRectangles[7] = new RectangleDouble(0, currentBottom, buttonSize, currentBottom + buttonSize);

				Graphics2D graphics = containerControl.NewGraphics2D();
				for (int i = 0; i < 8; i++)
				{
					graphics.FillRectangle(eightControlRectangles[i], eightColors[i]);
				}
			}

			GuiWidget containerTest = new GuiWidget(containerControl.Width, containerControl.Height);
			FlowLayoutWidget bottomToTopFlowLayoutAll = new FlowLayoutWidget(FlowDirection.TopToBottom);
			containerTest.DoubleBuffer = true;
			{
				bottomToTopFlowLayoutAll.AnchorAll();
				bottomToTopFlowLayoutAll.Padding = controlPadding;
				{
					GuiWidget top = new GuiWidget(buttonSize, buttonSize);
					top.BackgroundColor = RGBA_Bytes.Red;
					top.Margin = buttonMargin;
					bottomToTopFlowLayoutAll.AddChild(top);

					bottomToTopFlowLayoutAll.AddChild(CreateBottomToTopMiddleWidget(buttonMargin, buttonSize, HAnchor.ParentLeft, RGBA_Bytes.Orange));
					bottomToTopFlowLayoutAll.AddChild(CreateBottomToTopMiddleWidget(buttonMargin, buttonSize, HAnchor.ParentCenter, RGBA_Bytes.Yellow));
					bottomToTopFlowLayoutAll.AddChild(CreateBottomToTopMiddleWidget(buttonMargin, buttonSize, HAnchor.ParentRight, RGBA_Bytes.YellowGreen));
					bottomToTopFlowLayoutAll.AddChild(CreateBottomToTopMiddleWidget(buttonMargin, buttonSize, HAnchor.ParentLeftCenter, RGBA_Bytes.Green));
					bottomToTopFlowLayoutAll.AddChild(CreateBottomToTopMiddleWidget(buttonMargin, buttonSize, HAnchor.ParentCenterRight, RGBA_Bytes.Blue));
					bottomToTopFlowLayoutAll.AddChild(CreateBottomToTopMiddleWidget(buttonMargin, buttonSize, HAnchor.ParentLeftRight, RGBA_Bytes.Indigo));

					GuiWidget bottom = new GuiWidget(buttonSize, buttonSize);
					bottom.BackgroundColor = RGBA_Bytes.Violet;
					bottom.Margin = buttonMargin;
					bottomToTopFlowLayoutAll.AddChild(bottom);
				}

				containerTest.AddChild(bottomToTopFlowLayoutAll);
			}

			containerTest.OnDraw(containerTest.NewGraphics2D());
			OutputImages(containerControl, containerTest);

			for (int i = 0; i < 8; i++)
			{
				Assert.IsTrue(eightControlRectangles[i].Equals(bottomToTopFlowLayoutAll.Children[i].BoundsRelativeToParent, .001));
			}

			Assert.IsTrue(containerControl.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one.");

			// we use a least squares match because the erase background that is setting the widgets is integer pixel based and the fill rectangle is not.
			Assert.IsTrue(containerControl.BackBuffer.FindLeastSquaresMatch(containerTest.BackBuffer, 0), "The test and control need to match.");
		}
Example #32
0
        public override void Initialize(int tabIndex)
        {
            var theme = ApplicationController.Instance.Theme;

            // Enum keyed on name to friendly name
            var enumItems = Enum.GetNames(property.PropertyType).Select(enumName =>
            {
                return(new
                {
                    Key = enumName,
                    Value = enumName.Replace('_', ' ')
                });
            });

            var iconsRow = new FlowLayoutWidget();

            int index           = 0;
            var radioButtonSize = new Vector2(iconsAttribute.Width, iconsAttribute.Height);

            foreach (var enumItem in enumItems)
            {
                var         localIndex = index;
                ImageBuffer iconImage  = null;
                var         iconPath   = iconsAttribute.IconPaths[localIndex];
                if (!string.IsNullOrWhiteSpace(iconPath))
                {
                    if (iconsAttribute.Width > 0)
                    {
                        iconImage = AggContext.StaticData.LoadIcon(iconPath, iconsAttribute.Width, iconsAttribute.Height);
                    }
                    else
                    {
                        iconImage = AggContext.StaticData.LoadIcon(iconPath);
                    }

                    var radioButton = new RadioIconButton(iconImage, theme)
                    {
                        ToolTipText = enumItem.Key
                    };

                    radioButtonSize = new Vector2(radioButton.Width, radioButton.Height);

                    // set it if checked
                    if (enumItem.Value == this.InitialValue)
                    {
                        radioButton.Checked = true;
                    }

                    iconsRow.AddChild(radioButton);

                    var localItem = enumItem;
                    radioButton.CheckedStateChanged += (s, e) =>
                    {
                        if (radioButton.Checked)
                        {
                            this.SetValue(localItem.Key, true);
                        }
                    };
                }
                else if (iconsAttribute.Width > 0)
                {
                    // hold the space of the empty icon
                    iconsRow.AddChild(new GuiWidget(radioButtonSize.X, radioButtonSize.Y));
                }

                index++;
            }

            this.Content = iconsRow;
        }
Example #33
0
		public void ChildVisibilityChangeCauseResize()
		{
			//Test whether toggling the visibility of children changes the flow layout
			GuiWidget containerTest = new GuiWidget(640, 480);
			FlowLayoutWidget topToBottomFlowLayoutAll = new FlowLayoutWidget(FlowDirection.TopToBottom);
			containerTest.AddChild(topToBottomFlowLayoutAll);

			GuiWidget item1 = new GuiWidget(1, 20);
			GuiWidget item2 = new GuiWidget(1, 30);
			GuiWidget item3 = new GuiWidget(1, 40);

			topToBottomFlowLayoutAll.AddChild(item1);
			Assert.IsTrue(topToBottomFlowLayoutAll.Height == 20);
			topToBottomFlowLayoutAll.AddChild(item2);
			Assert.IsTrue(topToBottomFlowLayoutAll.Height == 50);
			topToBottomFlowLayoutAll.AddChild(item3);
			Assert.IsTrue(topToBottomFlowLayoutAll.Height == 90);

			item2.Visible = false;

			Assert.IsTrue(topToBottomFlowLayoutAll.Height == 60);
		}
Example #34
0
        public EditManualMovementSpeedsWindow(string windowTitle, string movementSpeedsString, Action <string> functionToCallOnSave)
            : base(260, 300)
        {
            AlwaysOnTopOfMain = true;
            Title             = LocalizedString.Get(windowTitle);

            FlowLayoutWidget topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);

            topToBottom.AnchorAll();
            topToBottom.Padding = new BorderDouble(3, 0, 3, 5);

            FlowLayoutWidget headerRow = new FlowLayoutWidget(FlowDirection.LeftToRight);

            headerRow.HAnchor = HAnchor.ParentLeftRight;
            headerRow.Margin  = new BorderDouble(0, 3, 0, 0);
            headerRow.Padding = new BorderDouble(0, 3, 0, 3);

            {
                string     movementSpeedsLabel = LocalizedString.Get("Movement Speeds Presets".Localize());
                TextWidget elementHeader       = new TextWidget(string.Format("{0}:", movementSpeedsLabel), pointSize: 14);
                elementHeader.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                elementHeader.HAnchor   = HAnchor.ParentLeftRight;
                elementHeader.VAnchor   = Agg.UI.VAnchor.ParentBottom;

                headerRow.AddChild(elementHeader);
            }

            topToBottom.AddChild(headerRow);

            FlowLayoutWidget presetsFormContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);

            //ListBox printerListContainer = new ListBox();
            {
                presetsFormContainer.HAnchor         = HAnchor.ParentLeftRight;
                presetsFormContainer.VAnchor         = VAnchor.ParentBottomTop;
                presetsFormContainer.Padding         = new BorderDouble(3);
                presetsFormContainer.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
            }

            topToBottom.AddChild(presetsFormContainer);

            this.functionToCallOnSave = functionToCallOnSave;
            BackgroundColor           = ActiveTheme.Instance.PrimaryBackgroundColor;

            double oldHeight = textImageButtonFactory.FixedHeight;

            textImageButtonFactory.FixedHeight = 30 * GuiWidget.DeviceScale;

            TextWidget tempTypeLabel = new TextWidget(windowTitle, textColor: ActiveTheme.Instance.PrimaryTextColor, pointSize: 10);

            tempTypeLabel.Margin  = new BorderDouble(3);
            tempTypeLabel.HAnchor = HAnchor.ParentLeft;
            presetsFormContainer.AddChild(tempTypeLabel);

            FlowLayoutWidget leftRightLabels = new FlowLayoutWidget();

            leftRightLabels.Padding  = new BorderDouble(3, 6);
            leftRightLabels.HAnchor |= Agg.UI.HAnchor.ParentLeftRight;

            GuiWidget hLabelSpacer = new GuiWidget();

            hLabelSpacer.HAnchor = HAnchor.ParentLeftRight;

            GuiWidget tempLabelContainer = new GuiWidget();

            tempLabelContainer.Width  = 76;
            tempLabelContainer.Height = 16;
            tempLabelContainer.Margin = new BorderDouble(3, 0);

            TextWidget tempLabel = new TextWidget("mm/s".Localize(), textColor: ActiveTheme.Instance.PrimaryTextColor, pointSize: 10);

            tempLabel.HAnchor = HAnchor.ParentLeft;
            tempLabel.VAnchor = VAnchor.ParentCenter;

            tempLabelContainer.AddChild(tempLabel);

            leftRightLabels.AddChild(hLabelSpacer);
            leftRightLabels.AddChild(tempLabelContainer);

            presetsFormContainer.AddChild(leftRightLabels);

            // put in the movement edit controls
            string[] settingsArray = movementSpeedsString.Split(',');
            int      preset_count  = 1;
            int      tab_index     = 0;

            for (int i = 0; i < settingsArray.Count() - 1; i += 2)
            {
                FlowLayoutWidget leftRightEdit = new FlowLayoutWidget();
                leftRightEdit.Padding  = new BorderDouble(3);
                leftRightEdit.HAnchor |= Agg.UI.HAnchor.ParentLeftRight;
                TextWidget axisLabel;
                if (settingsArray[i].StartsWith("e"))
                {
                    axisLabel = new TextWidget(string.Format("{0}(s)", "Extruder".Localize()), textColor: ActiveTheme.Instance.PrimaryTextColor);
                }
                else
                {
                    axisLabel = new TextWidget(string.Format("{0} {1}", "Axis".Localize(), settingsArray[i].ToUpper()), textColor: ActiveTheme.Instance.PrimaryTextColor);
                }
                axisLabel.VAnchor = VAnchor.ParentCenter;
                leftRightEdit.AddChild(axisLabel);

                leftRightEdit.AddChild(new HorizontalSpacer());

                axisLabels.Add(settingsArray[i]);

                double movementSpeed = 0;
                double.TryParse(settingsArray[i + 1], out movementSpeed);
                movementSpeed = movementSpeed / 60.0;                   // Convert from mm/min to mm/s
                MHNumberEdit valueEdit = new MHNumberEdit(movementSpeed, minValue: 0, pixelWidth: 60, tabIndex: tab_index++, allowDecimals: true);
                valueEdit.Margin = new BorderDouble(3);
                leftRightEdit.AddChild(valueEdit);
                valueEditors.Add(valueEdit);

                //leftRightEdit.AddChild(textImageButtonFactory.Generate("Delete".Localize()));
                presetsFormContainer.AddChild(leftRightEdit);
                preset_count += 1;
            }

            textImageButtonFactory.FixedHeight = oldHeight;

            ShowAsSystemWindow();
            MinimumSize = new Vector2(260, 300);

            Button savePresetsButton = textImageButtonFactory.Generate("Save".Localize());

            savePresetsButton.Click += save_Click;

            Button cancelPresetsButton = textImageButtonFactory.Generate("Cancel".Localize());

            cancelPresetsButton.Click += (sender, e) =>
            {
                UiThread.RunOnIdle(Close);
            };

            FlowLayoutWidget buttonRow = new FlowLayoutWidget();

            buttonRow.HAnchor = HAnchor.ParentLeftRight;
            buttonRow.Padding = new BorderDouble(0, 3);

            GuiWidget hButtonSpacer = new GuiWidget();

            hButtonSpacer.HAnchor = HAnchor.ParentLeftRight;

            buttonRow.AddChild(savePresetsButton);
            buttonRow.AddChild(hButtonSpacer);
            buttonRow.AddChild(cancelPresetsButton);

            topToBottom.AddChild(buttonRow);

            AddChild(topToBottom);
        }
Example #35
0
		public void EnsureCorrectSizeOnChildrenVisibleChange()
		{
			// just one column changes correctly
			{
				FlowLayoutWidget testColumn = new FlowLayoutWidget(FlowDirection.TopToBottom);
				testColumn.Name = "testColumn";

				GuiWidget item1 = new GuiWidget(10, 10);
				item1.Name = "item1";
				testColumn.AddChild(item1);

				Assert.IsTrue(testColumn.Height == 10);

				GuiWidget item2 = new GuiWidget(11, 11);
				item2.Name = "item2";
				testColumn.AddChild(item2);

				Assert.IsTrue(testColumn.Height == 21);

				GuiWidget item3 = new GuiWidget(12, 12);
				item3.Name = "item3";
				testColumn.AddChild(item3);

				Assert.IsTrue(testColumn.Height == 33);

				item2.Visible = false;

				Assert.IsTrue(testColumn.Height == 22);

				item2.Visible = true;

				Assert.IsTrue(testColumn.Height == 33);
			}

			// nested columns change correctly
			{
				GuiWidget.DefaultEnforceIntegerBounds = true;
				CheckBox hideCheckBox;
				FlowLayoutWidget leftColumn;
				FlowLayoutWidget topLeftStuff;
				GuiWidget everything = new GuiWidget(500, 500);
				GuiWidget firstItem;
				GuiWidget thingToHide;
				{
					FlowLayoutWidget twoColumns = new FlowLayoutWidget();
					twoColumns.Name = "twoColumns";
					twoColumns.VAnchor = UI.VAnchor.ParentTop;

					{
						leftColumn = new FlowLayoutWidget(FlowDirection.TopToBottom);
						leftColumn.Name = "leftColumn";
						{
							topLeftStuff = new FlowLayoutWidget(FlowDirection.TopToBottom);
							topLeftStuff.Name = "topLeftStuff";
							firstItem = new TextWidget("Top of Top Stuff");
							topLeftStuff.AddChild(firstItem);
							thingToHide = new Button("thing to hide");
							topLeftStuff.AddChild(thingToHide);
							topLeftStuff.AddChild(new TextWidget("Bottom of Top Stuff"));

							leftColumn.AddChild(topLeftStuff);
							//leftColumn.DebugShowBounds = true;
						}

						twoColumns.AddChild(leftColumn);
					}

					{
						FlowLayoutWidget rightColumn = new FlowLayoutWidget(FlowDirection.TopToBottom);
						rightColumn.Name = "rightColumn";
						hideCheckBox = new CheckBox("Hide Stuff");
						rightColumn.AddChild(hideCheckBox);
						hideCheckBox.CheckedStateChanged += (sender, e) =>
						{
							if (hideCheckBox.Checked)
							{
								thingToHide.Visible = false;
							}
							else
							{
								thingToHide.Visible = true;
							}
						};

						twoColumns.AddChild(rightColumn);
					}

					everything.AddChild(twoColumns);

					Assert.IsTrue(firstItem.OriginRelativeParent.y == 54);
					//Assert.IsTrue(firstItem.OriginRelativeParent.y - topLeftStuff.LocalBounds.Bottom == 54);
					Assert.IsTrue(twoColumns.BoundsRelativeToParent.Top == 500);
					Assert.IsTrue(leftColumn.BoundsRelativeToParent.Top == 67);
					Assert.IsTrue(leftColumn.BoundsRelativeToParent.Bottom == 0);
					Assert.IsTrue(leftColumn.OriginRelativeParent.y == 0);
					Assert.IsTrue(topLeftStuff.BoundsRelativeToParent.Top == 67);
					Assert.IsTrue(topLeftStuff.Height == 67);
					Assert.IsTrue(leftColumn.Height == 67);

					hideCheckBox.Checked = true;

					Assert.IsTrue(firstItem.OriginRelativeParent.y == 21);
					Assert.IsTrue(leftColumn.OriginRelativeParent.y == 0);
					Assert.IsTrue(leftColumn.BoundsRelativeToParent.Bottom == 0);
					Assert.IsTrue(topLeftStuff.Height == 34);
					Assert.IsTrue(leftColumn.Height == 34);
				}
				GuiWidget.DefaultEnforceIntegerBounds = false;
			}
		}
        private void RefreshStatus()
        {
            CriteriaRow.ResetAll();

            // Clear the main container
            contentRow.CloseAllChildren();

            // Regen and refresh the troubleshooting criteria
            TextWidget printerNameLabel = new TextWidget(string.Format("{0}:", "Connection Troubleshooting".Localize()), 0, 0, labelFontSize);

            printerNameLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            printerNameLabel.Margin    = new BorderDouble(bottom: 10);

#if __ANDROID__
            IUsbSerialPort serialPort = FrostedSerialPort.LoadSerialDriver();

#if ANDROID7
            // Filter out the built-in 002 device and select the first item from the list
            // On the T7 Android device, there is a non-printer device always registered at usb/002/002 that must be ignored
            UsbDevice usbPrintDevice = usbManager.DeviceList.Values.Where(d => d.DeviceName != "/dev/bus/usb/002/002").FirstOrDefault();
#else
            UsbDevice usbPrintDevice = usbManager.DeviceList.Values.FirstOrDefault();
#endif

            UsbStatus usbStatus = new UsbStatus()
            {
                IsDriverLoadable   = (serialPort != null),
                HasUsbDevice       = true,
                HasUsbPermission   = false,
                AnyUsbDeviceExists = usbPrintDevice != null
            };

            if (!usbStatus.IsDriverLoadable)
            {
                usbStatus.HasUsbDevice = usbPrintDevice != null;

                if (usbStatus.HasUsbDevice)
                {
                    // TODO: Testing specifically for UsbClass.Comm seems fragile but no better alternative exists without more research
                    usbStatus.UsbDetails = new UsbDeviceDetails()
                    {
                        ProductID   = usbPrintDevice.ProductId,
                        VendorID    = usbPrintDevice.VendorId,
                        DriverClass = usbManager.DeviceList.Values.First().DeviceClass == Android.Hardware.Usb.UsbClass.Comm ? "cdcDriverType" : "ftdiDriverType"
                    };
                    usbStatus.Summary = string.Format("No USB device definition found. Click the 'Fix' button to add an override for your device ", usbStatus.UsbDetails.VendorID, usbStatus.UsbDetails.ProductID);
                }
            }

            usbStatus.HasUsbPermission = usbStatus.IsDriverLoadable && FrostedSerialPort.HasPermissionToDevice(serialPort);

            contentRow.AddChild(printerNameLabel);

            contentRow.AddChild(new CriteriaRow(
                                    "USB Connection",
                                    "Retry",
                                    "No USB device found. Check and reseat cables and try again",
                                    usbStatus.AnyUsbDeviceExists,
                                    () => UiThread.RunOnIdle(RefreshStatus)));

            contentRow.AddChild(new CriteriaRow(
                                    "USB Driver",
                                    "Fix",
                                    usbStatus.Summary,
                                    usbStatus.IsDriverLoadable,
                                    () => {
                string overridePath         = Path.Combine(ApplicationDataStorage.ApplicationUserDataPath, "data", "usboverride.local");
                UsbDeviceDetails usbDetails = usbStatus.UsbDetails;
                File.AppendAllText(overridePath, string.Format("{0},{1},{2}\r\n", usbDetails.VendorID, usbDetails.ProductID, usbDetails.DriverClass));

                UiThread.RunOnIdle(() => RefreshStatus());
            }));

            contentRow.AddChild(new CriteriaRow(
                                    "USB Permission",
                                    "Request Permission",
                                    "Click the 'Request Permission' button to gain Android access rights",
                                    usbStatus.HasUsbPermission,
                                    () => {
                if (checkForPermissionTimer == null)
                {
                    checkForPermissionTimer = new System.Threading.Timer((state) => {
                        if (FrostedSerialPort.HasPermissionToDevice(serialPort))
                        {
                            UiThread.RunOnIdle(this.RefreshStatus);
                            checkForPermissionTimer.Dispose();
                        }
                    }, null, 200, 200);
                }

                FrostedSerialPort.RequestPermissionToDevice(serialPort);
            }));
#endif
            connectToPrinterRow = new CriteriaRow(
                "Connect to Printer",
                "Connect",
                "Click the 'Connect' button to retry the original connection attempt",
                false,
                () => PrinterConnectionAndCommunication.Instance.ConnectToActivePrinter());

            contentRow.AddChild(connectToPrinterRow);

            if (CriteriaRow.ActiveErrorItem != null)
            {
                FlowLayoutWidget errorText = new FlowLayoutWidget()
                {
                    Padding = new BorderDouble(0, 15)
                };

                errorText.AddChild(new TextWidget(CriteriaRow.ActiveErrorItem.ErrorText)
                {
                    TextColor = ActiveTheme.Instance.PrimaryAccentColor
                });

                contentRow.AddChild(errorText);
            }
        }
Example #37
0
		public void ChangingChildFlowWidgetVisiblityUpdatesParentFlow()
		{
			//  ___________________________________________________
			//  |       containerControl 300                      |
			//  | _______________________________________________ |
			//  | |     Flow1 ParentWidth  300                  | |
			//  | | __________________________________________  | |
			//  | | |   Flow2 FitToChildren 250              |  | |
			//  | | | ____________________________ _________ |  | |
			//  | | | | Flow 3 FitToChildren 200 | |Size2  | |  | |
			//  | | | | ________________________ | |50     | |  | |
			//  | | | | | Size1 200            | | |       | |  | |
			//  | | | | |______________________| | |       | |  | |
			//  | | | |__________________________| |_______| |  | |
			//  | | |________________________________________|  | |
			//  | |_____________________________________________| |
			//  |_________________________________________________|
			//

			GuiWidget containerControl = new GuiWidget(300, 200);
			containerControl.Name = "containerControl";

			FlowLayoutWidget flow1 = new FlowLayoutWidget(FlowDirection.LeftToRight);
			flow1.Name = "flow1";
			flow1.HAnchor = HAnchor.ParentLeftRight;
			flow1.Padding = new BorderDouble(3, 3);
			containerControl.AddChild(flow1);

			FlowLayoutWidget flow2 = new FlowLayoutWidget();
			flow2.Name = "flow2";
			flow1.AddChild(flow2);

			GuiWidget flow3 = new FlowLayoutWidget();
			flow3.Name = "flow3";
			flow2.AddChild(flow3);

			GuiWidget size1 = new GuiWidget(200, 20);
			size1.Name = "size2";
			flow3.AddChild(size1);

			GuiWidget size2 = new GuiWidget(50, 20);
			size2.Name = "size1";
			flow2.AddChild(size2);


			Assert.IsTrue(flow1.Width == containerControl.Width);
			Assert.IsTrue(flow3.Width == size1.Width);
			Assert.IsTrue(flow2.Width == size2.Width + flow3.Width);

			size1.Visible = false;
			//  ___________________________________________________
			//  |       containerControl 300                      |
			//  | _______________________________________________ |
			//  | |   Flow1 ParentWidth  300                    | |
			//  | | _____________                               | |
			//  | | | Flow2 50  |                               | |
			//  | | | _________ |                               | |
			//  | | | |Size2  | |                               | |
			//  | | | |50     | |                               | |
			//  | | | |       | |                               | |
			//  | | | |_______| |                               | |
			//  | | |___________|                               | |
			//  | |_____________________________________________| |
			//  |_________________________________________________|
			//

			Assert.IsTrue(flow1.Width == containerControl.Width);
			Assert.IsTrue(flow2.Width == size2.Width);
		}
Example #38
0
        internal ControlContentExtruder(PrinterConfig printer, int extruderIndex, ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            this.HAnchor = HAnchor.Stretch;
            this.printer = printer;

            GuiWidget macroButtons = null;

            // We do not yet support loading filament into extruders other than 0, fix it when time.
            if (extruderIndex == 0)
            {
                // add in load and unload buttons
                macroButtons = new FlowLayoutWidget()
                {
                    Padding = theme.ToolbarPadding,
                };

                var loadFilament = new GCodeMacro()
                {
                    GCode = AggContext.StaticData.ReadAllText(Path.Combine("SliceSettings", "load_filament.txt"))
                };

                var loadButton = new TextButton("Load".Localize(), theme)
                {
                    BackgroundColor = theme.SlightShade,
                    Margin          = theme.ButtonSpacing,
                    ToolTipText     = "Load filament".Localize()
                };
                loadButton.Name   = "Load Filament Button";
                loadButton.Click += (s, e) => loadFilament.Run(printer.Connection);
                macroButtons.AddChild(loadButton);

                var unloadFilament = new GCodeMacro()
                {
                    GCode = AggContext.StaticData.ReadAllText(Path.Combine("SliceSettings", "unload_filament.txt"))
                };

                var unloadButton = new TextButton("Unload".Localize(), theme)
                {
                    BackgroundColor = theme.SlightShade,
                    Margin          = theme.ButtonSpacing,
                    ToolTipText     = "Unload filament".Localize()
                };
                unloadButton.Click += (s, e) => unloadFilament.Run(printer.Connection);
                macroButtons.AddChild(unloadButton);

                this.AddChild(new SettingsItem("Filament".Localize(), macroButtons, theme, enforceGutter: false));
            }

            // Add the Extrude buttons
            var buttonContainer = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.Fit,
                VAnchor = VAnchor.Fit,
                Padding = theme.ToolbarPadding,
            };

            var retractButton = new TextButton("Retract".Localize(), theme)
            {
                BackgroundColor = theme.SlightShade,
                Margin          = theme.ButtonSpacing,
                ToolTipText     = "Retract filament".Localize()
            };

            retractButton.Click += (s, e) =>
            {
                printer.Connection.MoveExtruderRelative(moveAmount * -1, printer.Settings.EFeedRate(extruderIndex), extruderIndex);
            };
            buttonContainer.AddChild(retractButton);

            int extruderButtonTopMargin = macroButtons == null ? 8 : 0;

            var extrudeButton = new TextButton("Extrude".Localize(), theme)
            {
                BackgroundColor = theme.SlightShade,
                Margin          = theme.ButtonSpacing,
                Name            = "Extrude Button",
                ToolTipText     = "Extrude filament".Localize()
            };

            extrudeButton.Click += (s, e) =>
            {
                printer.Connection.MoveExtruderRelative(moveAmount, printer.Settings.EFeedRate(extruderIndex), extruderIndex);
            };
            buttonContainer.AddChild(extrudeButton);

            this.AddChild(new SettingsItem(
                              macroButtons == null ? "Filament".Localize() : "",   // Don't put the name if we put in a macro button (it has the name)
                              buttonContainer,
                              theme,
                              enforceGutter: false));

            var moveButtonsContainer = new FlowLayoutWidget()
            {
                VAnchor = VAnchor.Fit | VAnchor.Center,
                HAnchor = HAnchor.Fit,
                Padding = theme.ToolbarPadding,
            };

            var oneButton = theme.CreateMicroRadioButton("1");

            oneButton.CheckedStateChanged += (s, e) =>
            {
                if (oneButton.Checked)
                {
                    moveAmount = 1;
                }
            };
            moveButtonsContainer.AddChild(oneButton);

            var tenButton = theme.CreateMicroRadioButton("10");

            tenButton.CheckedStateChanged += (s, e) =>
            {
                if (tenButton.Checked)
                {
                    moveAmount = 10;
                }
            };
            moveButtonsContainer.AddChild(tenButton);

            var oneHundredButton = theme.CreateMicroRadioButton("100");

            oneHundredButton.CheckedStateChanged += (s, e) =>
            {
                if (oneHundredButton.Checked)
                {
                    moveAmount = 100;
                }
            };
            moveButtonsContainer.AddChild(oneHundredButton);

            switch (moveAmount)
            {
            case 1:
                oneButton.Checked = true;
                break;

            case 10:
                tenButton.Checked = true;
                break;

            case 100:
                oneHundredButton.Checked = true;
                break;
            }

            moveButtonsContainer.AddChild(new TextWidget("mm", textColor: theme.Colors.PrimaryTextColor, pointSize: 8)
            {
                VAnchor = VAnchor.Center,
                Margin  = new BorderDouble(3, 0)
            });

            this.AddChild(new SettingsItem("Distance".Localize(), moveButtonsContainer, theme, enforceGutter: false));
        }
Example #39
0
		public void NestedLayoutTopToBottomTest(BorderDouble controlPadding, BorderDouble buttonMargin)
		{
			GuiWidget containerControl = new GuiWidget(300, 200);
			containerControl.DoubleBuffer = true;
			containerControl.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
			{
				Button topButtonC = new Button("top button");
				Button bottomButtonC = new Button("bottom wide button");
				topButtonC.LocalBounds = new RectangleDouble(0, 0, bottomButtonC.LocalBounds.Width, 40);
				topButtonC.OriginRelativeParent = new Vector2(bottomButtonC.OriginRelativeParent.x + buttonMargin.Left, containerControl.Height - controlPadding.Top - topButtonC.Height - buttonMargin.Top);
				containerControl.AddChild(topButtonC);
				bottomButtonC.OriginRelativeParent = new Vector2(bottomButtonC.OriginRelativeParent.x + buttonMargin.Left, topButtonC.OriginRelativeParent.y - buttonMargin.Height - bottomButtonC.Height);
				containerControl.AddChild(bottomButtonC);
			}
			containerControl.OnDraw(containerControl.NewGraphics2D());

			GuiWidget containerTest = new GuiWidget(300, 200);
			containerTest.DoubleBuffer = true;
			containerTest.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);

			FlowLayoutWidget allButtons = new FlowLayoutWidget(FlowDirection.TopToBottom);
			allButtons.AnchorAll();
			Button topButtonT;
			Button bottomButtonT;
			FlowLayoutWidget topButtonBar;
			FlowLayoutWidget bottomButtonBar;
			allButtons.Padding = controlPadding;
			{
				bottomButtonT = new Button("bottom wide button");

				topButtonBar = new FlowLayoutWidget();
				{
					topButtonT = new Button("top button");
					topButtonT.LocalBounds = new RectangleDouble(0, 0, bottomButtonT.LocalBounds.Width, 40);
					topButtonT.Margin = buttonMargin;
					topButtonBar.AddChild(topButtonT);
				}
				allButtons.AddChild(topButtonBar);

				bottomButtonBar = new FlowLayoutWidget();
				{
					bottomButtonT.Margin = buttonMargin;
					bottomButtonBar.AddChild(bottomButtonT);
				}
				allButtons.AddChild(bottomButtonBar);
			}
			containerTest.AddChild(allButtons);
			containerTest.OnDraw(containerTest.NewGraphics2D());

			OutputImages(containerControl, containerTest);

			Assert.IsTrue(containerTest.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one.");
			Assert.IsTrue(containerTest.BackBuffer.Equals(containerControl.BackBuffer, 1), "The test should contain the same image as the control.");
		}
Example #40
0
		public void FlowTopBottomAnchorChildrenLeftRightTest(BorderDouble controlPadding, BorderDouble buttonMargin)
		{
			GuiWidget containerControl = new GuiWidget(300, 500);
			containerControl.DoubleBuffer = true;
			Button controlButtonWide = new Button("Button Wide Text");
			containerControl.AddChild(controlButtonWide);
			Button controlButton1 = new Button("button1");
			controlButton1.OriginRelativeParent = new VectorMath.Vector2(controlPadding.Left + buttonMargin.Left + controlButton1.OriginRelativeParent.x, controlPadding.Bottom + buttonMargin.Bottom);
			controlButtonWide.OriginRelativeParent = new VectorMath.Vector2(controlPadding.Left + buttonMargin.Left + controlButtonWide.OriginRelativeParent.x, controlButton1.BoundsRelativeToParent.Top + buttonMargin.Height);
			controlButton1.LocalBounds = controlButtonWide.LocalBounds;
			containerControl.AddChild(controlButton1);
			containerControl.OnDraw(containerControl.NewGraphics2D());

			GuiWidget containerTest = new GuiWidget(300, 500);
			FlowLayoutWidget flowLayout = new FlowLayoutWidget(FlowDirection.TopToBottom);
			flowLayout.Padding = controlPadding;
			containerTest.DoubleBuffer = true;

			Button testButtonWide = new Button("Button Wide Text");
			testButtonWide.HAnchor = HAnchor.ParentLeft;
			testButtonWide.Margin = buttonMargin;
			flowLayout.AddChild(testButtonWide);

			double correctHeightOfFlowLayout = testButtonWide.Height + flowLayout.Padding.Height + testButtonWide.Margin.Height;
			Assert.AreEqual(flowLayout.Height, correctHeightOfFlowLayout, .001);

			Button testButton1 = new Button("button1");
			testButton1.Margin = buttonMargin;
			testButton1.HAnchor = HAnchor.ParentLeft | HAnchor.ParentRight;
			flowLayout.AddChild(testButton1);

			correctHeightOfFlowLayout += testButton1.Height + testButton1.Margin.Height;
			Assert.AreEqual(flowLayout.Height, correctHeightOfFlowLayout, .001);

			flowLayout.HAnchor = HAnchor.ParentLeft;
			flowLayout.VAnchor = VAnchor.ParentBottom;
			containerTest.AddChild(flowLayout);

			Vector2 controlButton1Pos = controlButton1.OriginRelativeParent;
			Vector2 testButton1Pos = testButton1.TransformToScreenSpace(Vector2.Zero);

			containerTest.OnDraw(containerTest.NewGraphics2D());
			OutputImages(containerControl, containerTest);

			Assert.IsTrue(containerControl.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one.");
			Assert.IsTrue(containerControl.BackBuffer.Equals(containerTest.BackBuffer, 1), "The Anchored widget should be in the correct place.");

			// make sure it can resize without breaking
			RectangleDouble bounds = containerTest.LocalBounds;
			RectangleDouble newBounds = bounds;
			newBounds.Right += 10;
			containerTest.LocalBounds = newBounds;
			Assert.IsTrue(containerControl.BackBuffer != containerTest.BackBuffer, "The Anchored widget should not be the same size.");
			containerTest.LocalBounds = bounds;
			containerTest.OnDraw(containerTest.NewGraphics2D());
			OutputImages(containerControl, containerTest);
			Assert.IsTrue(containerControl.BackBuffer.Equals(containerTest.BackBuffer, 1), "The Anchored widget should be in the correct place.");
		}
Example #41
0
		public void NestedFitToChildrenParentWidth()
		{
			// child of flow layout is ParentLeftRight
			{
				//  _________________________________________
				//  |            containerControl            |
				//  | _____________________________________  |
				//  | |    Max_FitToChildren_ParentWidth   | |
				//  | | ________________________ ________  | |
				//  | | |                      | |       | | |
				//  | | |    ParentLeftRight   | | 10x10 | | |
				//  | | |______________________| |_______| | |
				//  | |____________________________________| |
				//  |________________________________________|
				//

				GuiWidget containerControl = new GuiWidget(300, 200); // containerControl = 0, 0, 300, 200
				containerControl.DoubleBuffer = true;
				FlowLayoutWidget flowWidget = new FlowLayoutWidget()
				{
					HAnchor = HAnchor.Max_FitToChildren_ParentWidth,
				};
				containerControl.AddChild(flowWidget); // flowWidget = 0, 0, 300, 0
				GuiWidget fitToChildrenOrParent = new GuiWidget(20, 20)
				{
					HAnchor = HAnchor.ParentLeftRight,
				};
				flowWidget.AddChild(fitToChildrenOrParent); // flowWidget = 0, 0, 300, 20  fitToChildrenOrParent = 0, 0, 300, 20
				GuiWidget fixed10x10 = new GuiWidget(10, 10);
				flowWidget.AddChild(fixed10x10); // flowWidget = 0, 0, 300, 20  fitToChildrenOrParent = 0, 0, 290, 20
				containerControl.OnDraw(containerControl.NewGraphics2D());

				//OutputImage(containerControl, "countainer");

				Assert.IsTrue(flowWidget.Width == containerControl.Width);
				Assert.IsTrue(fitToChildrenOrParent.Width + fixed10x10.Width == containerControl.Width);

				containerControl.Width = 350;
				Assert.IsTrue(flowWidget.Width == containerControl.Width);
				Assert.IsTrue(fitToChildrenOrParent.Width + fixed10x10.Width == containerControl.Width);

				containerControl.Width = 310;
				Assert.IsTrue(flowWidget.Width == containerControl.Width);
				Assert.IsTrue(fitToChildrenOrParent.Width + fixed10x10.Width == containerControl.Width);
			}

			// child of flow layout is Max_FitToChildren_ParentWidth
			{
				//  ___________________________________________________
				//  |            containerControl                      |
				//  | _______________________________________________  |
				//  | |    Max_FitToChildren_ParentWidth             | |
				//  | | _________________________________   _______  | |
				//  | | |                                | |       | | |
				//  | | | Max_FitToChildren_ParentWidth  | | 10x10 | | |
				//  | | |________________________________| |_______| | |
				//  | |______________________________________________| |
				//  |__________________________________________________|
				//

				GuiWidget containerControl = new GuiWidget(300, 200); // containerControl = 0, 0, 300, 200
				containerControl.DoubleBuffer = true;
				FlowLayoutWidget flowWidget = new FlowLayoutWidget()
				{
					HAnchor = HAnchor.Max_FitToChildren_ParentWidth,
				};
				containerControl.AddChild(flowWidget);
				GuiWidget fitToChildrenOrParent = new GuiWidget(20, 20)
				{
					Name = "fitToChildrenOrParent",
					HAnchor = HAnchor.Max_FitToChildren_ParentWidth,
				};
				flowWidget.AddChild(fitToChildrenOrParent); // flowWidget = 0, 0, 300, 20  fitToChildrenOrParent = 0, 0, 300, 20
				GuiWidget fixed10x10 = new GuiWidget(10, 10);
				flowWidget.AddChild(fixed10x10); // flowWidget = 0, 0, 300, 20  fitToChildrenOrParent = 0, 0, 290, 20
				containerControl.OnDraw(containerControl.NewGraphics2D());

				//OutputImage(containerControl, "countainer");

				Assert.IsTrue(flowWidget.Width == containerControl.Width);
				Assert.IsTrue(fitToChildrenOrParent.Width + fixed10x10.Width == containerControl.Width);

				containerControl.Width = 350;
				Assert.IsTrue(flowWidget.Width == containerControl.Width);
				Assert.IsTrue(fitToChildrenOrParent.Width + fixed10x10.Width == containerControl.Width);

				containerControl.Width = 310;
				Assert.IsTrue(flowWidget.Width == containerControl.Width);
				Assert.IsTrue(fitToChildrenOrParent.Width + fixed10x10.Width == containerControl.Width);
			}
		}
Example #42
0
		public void NestedFlowWidgetsRightToLeftTest(BorderDouble controlPadding, BorderDouble buttonMargin)
		{
			GuiWidget containerControl = new GuiWidget(500, 300);
			containerControl.Padding = controlPadding;
			containerControl.DoubleBuffer = true;

			{
				Button buttonRight = new Button("buttonRight");
				Button buttonLeft = new Button("buttonLeft");
				buttonRight.OriginRelativeParent = new VectorMath.Vector2(containerControl.LocalBounds.Right - controlPadding.Right - buttonMargin.Right - buttonRight.Width, buttonRight.OriginRelativeParent.y + controlPadding.Bottom + buttonMargin.Bottom);
				buttonLeft.OriginRelativeParent = new VectorMath.Vector2(buttonRight.BoundsRelativeToParent.Left - buttonMargin.Width - buttonLeft.Width, buttonLeft.OriginRelativeParent.y + controlPadding.Bottom + buttonMargin.Bottom);
				containerControl.AddChild(buttonRight);
				containerControl.AddChild(buttonLeft);
				containerControl.OnDraw(containerControl.NewGraphics2D());
			}

			GuiWidget containerTest = new GuiWidget(500, 300);
			containerTest.DoubleBuffer = true;
			{
				FlowLayoutWidget rightToLeftFlowLayoutAll = new FlowLayoutWidget(FlowDirection.RightToLeft);
				rightToLeftFlowLayoutAll.AnchorAll();
				rightToLeftFlowLayoutAll.Padding = controlPadding;
				{
					FlowLayoutWidget rightToLeftFlowLayoutRight = new FlowLayoutWidget(FlowDirection.RightToLeft);
					Button buttonRight = new Button("buttonRight");
					buttonRight.Margin = buttonMargin;
					rightToLeftFlowLayoutRight.AddChild(buttonRight);
					rightToLeftFlowLayoutRight.SetBoundsToEncloseChildren();
					rightToLeftFlowLayoutRight.VAnchor = VAnchor.ParentBottom;
					rightToLeftFlowLayoutAll.AddChild(rightToLeftFlowLayoutRight);
				}

				{
					FlowLayoutWidget rightToLeftFlowLayoutLeft = new FlowLayoutWidget(FlowDirection.RightToLeft);
					Button buttonLeft = new Button("buttonLeft");
					buttonLeft.Margin = buttonMargin;
					rightToLeftFlowLayoutLeft.AddChild(buttonLeft);
					rightToLeftFlowLayoutLeft.SetBoundsToEncloseChildren();
					rightToLeftFlowLayoutLeft.VAnchor = VAnchor.ParentBottom;
					rightToLeftFlowLayoutAll.AddChild(rightToLeftFlowLayoutLeft);
				}

				containerTest.AddChild(rightToLeftFlowLayoutAll);
			}

			containerTest.OnDraw(containerTest.NewGraphics2D());
			OutputImages(containerControl, containerTest);

			Assert.IsTrue(containerControl.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one.");
			// we use a least squares match because the erase background that is setting the widgets is integer pixel based and the fill rectangle is not.
			Assert.IsTrue(containerControl.BackBuffer.FindLeastSquaresMatch(containerTest.BackBuffer, 50), "The test and control need to match.");
			Assert.IsTrue(containerControl.BackBuffer.Equals(containerTest.BackBuffer, 1), "The Anchored widget should be in the correct place.");
		}
        public ExportSettingsPage() :
            base("Cancel", "Export As")
        {
            var container = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.ParentLeftRight,
            };

            contentRow.AddChild(container);

            if (true)
            {
                // export as matter control
                matterControlButton         = new RadioButton("MatterControl".Localize(), textColor: ActiveTheme.Instance.PrimaryTextColor);
                matterControlButton.Checked = true;
                container.AddChild(matterControlButton);

                // export as slic3r
                slic3rButton = new RadioButton("Slic3r".Localize(), textColor: ActiveTheme.Instance.PrimaryTextColor);
                container.AddChild(slic3rButton);

                // export as cura
#if DEBUG
                curaButton = new RadioButton("Cura".Localize(), textColor: ActiveTheme.Instance.PrimaryTextColor);
                container.AddChild(curaButton);
#endif
            }
            else
            {
                // export as matter control
                matterControlButton         = new RadioButton("Export MatterControl settings (*.printer)".Localize(), textColor: ActiveTheme.Instance.PrimaryTextColor);
                matterControlButton.Checked = true;
                container.AddChild(matterControlButton);

                // export as slic3r
                slic3rButton = new RadioButton("Export Slic3r settings (*.ini)".Localize(), textColor: ActiveTheme.Instance.PrimaryTextColor);
                container.AddChild(slic3rButton);

                container.AddChild(
                    CreateDetailInfo("Export as a config.ini file that can be read by older versions of Matter Control and Slic3r.")
                    );

                // export as cura
#if DEBUG
                curaButton = new RadioButton("Export Cura settings (*.ini)".Localize(), textColor: ActiveTheme.Instance.PrimaryTextColor);
                container.AddChild(curaButton);

                container.AddChild(
                    CreateDetailInfo("Export as a file that can be read by Cura.\nNote: Not all settings are exportable in this format.")
                    );
#endif
            }

            var exportButton = textImageButtonFactory.Generate("Export Settings".Localize());
            exportButton.Click += (s, e) => UiThread.RunOnIdle(exportButton_Click);

            exportButton.Visible = true;
            cancelButton.Visible = true;

            //Add buttons to buttonContainer
            footerRow.AddChild(exportButton);
            footerRow.AddChild(new HorizontalSpacer());
            footerRow.AddChild(cancelButton);
        }
Example #44
0
        public override void OnLoad(EventArgs args)
        {
            base.OnLoad(args);

            bool smallScreen = Parent.Width <= 1180;

            Padding = smallScreen ? new BorderDouble(20, 5) : new BorderDouble(50, 30);

            var topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                VAnchor = VAnchor.ParentBottomTop,
                HAnchor = HAnchor.ParentLeftRight
            };

            AddChild(topToBottom);

            var bodyRow = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                VAnchor = VAnchor.ParentBottomTop,
                HAnchor = HAnchor.ParentLeftRight,
                Margin  = smallScreen ? new BorderDouble(30, 5, 30, 0) : new BorderDouble(30, 20, 30, 0),               // the -12 is to take out the top bar
            };

            topToBottom.AddChild(bodyRow);

            // Thumbnail section
            {
                int         imageSize   = smallScreen ? 300 : 500;
                ImageBuffer imageBuffer = PartThumbnailWidget.GetImageForItem(PrinterConnectionAndCommunication.Instance.ActivePrintItem, imageSize, imageSize);

                if (imageBuffer == null)
                {
                    imageBuffer = StaticData.Instance.LoadImage(Path.Combine("Images", "Screensaver", "part_thumbnail.png"));
                }

                WhiteToColor.DoWhiteToColor(imageBuffer, ActiveTheme.Instance.PrimaryAccentColor);

                var partThumbnail = new ImageWidget(imageBuffer)
                {
                    VAnchor = VAnchor.ParentCenter,
                    Margin  = smallScreen ? new BorderDouble(right: 20) : new BorderDouble(right: 50),
                };
                bodyRow.AddChild(partThumbnail);
            }

            bodyRow.AddChild(PrintingWindow.CreateVerticalLine());

            // Progress section
            {
                var expandingContainer = new HorizontalSpacer()
                {
                    VAnchor = VAnchor.FitToChildren | VAnchor.ParentCenter
                };
                bodyRow.AddChild(expandingContainer);

                var progressContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
                {
                    Margin  = new BorderDouble(50, 0),
                    VAnchor = VAnchor.ParentCenter | VAnchor.FitToChildren,
                    HAnchor = HAnchor.ParentCenter | HAnchor.FitToChildren,
                };
                expandingContainer.AddChild(progressContainer);

                progressDial = new ProgressDial()
                {
                    HAnchor = HAnchor.ParentCenter,
                    Height  = 200 * DeviceScale,
                    Width   = 200 * DeviceScale
                };
                progressContainer.AddChild(progressDial);

                var timeContainer = new FlowLayoutWidget()
                {
                    HAnchor = HAnchor.ParentCenter | HAnchor.FitToChildren,
                    Margin  = 3
                };
                progressContainer.AddChild(timeContainer);

                var timeImage = StaticData.Instance.LoadImage(Path.Combine("Images", "Screensaver", "time.png"));
                if (!ActiveTheme.Instance.IsDarkTheme)
                {
                    timeImage.InvertLightness();
                }

                timeContainer.AddChild(new ImageWidget(timeImage));

                timeWidget = new TextWidget("", pointSize: 22, textColor: ActiveTheme.Instance.PrimaryTextColor)
                {
                    AutoExpandBoundsToText = true,
                    Margin  = new BorderDouble(10, 0, 0, 0),
                    VAnchor = VAnchor.ParentCenter,
                };

                timeContainer.AddChild(timeWidget);

                int maxTextWidth = 350;
                printerName = new TextWidget(ActiveSliceSettings.Instance.GetValue(SettingsKey.printer_name), pointSize: 16, textColor: ActiveTheme.Instance.PrimaryTextColor)
                {
                    HAnchor     = HAnchor.ParentCenter,
                    MinimumSize = new Vector2(maxTextWidth, MinimumSize.y),
                    Width       = maxTextWidth,
                    Margin      = new BorderDouble(0, 3),
                };

                progressContainer.AddChild(printerName);

                partName = new TextWidget(PrinterConnectionAndCommunication.Instance.ActivePrintItem.GetFriendlyName(), pointSize: 16, textColor: ActiveTheme.Instance.PrimaryTextColor)
                {
                    HAnchor     = HAnchor.ParentCenter,
                    MinimumSize = new Vector2(maxTextWidth, MinimumSize.y),
                    Width       = maxTextWidth,
                    Margin      = new BorderDouble(0, 3)
                };
                progressContainer.AddChild(partName);
            }

            bodyRow.AddChild(PrintingWindow.CreateVerticalLine());

            // ZControls
            {
                var widget = new ZAxisControls(smallScreen)
                {
                    Margin  = new BorderDouble(left: 50),
                    VAnchor = VAnchor.ParentCenter,
                    Width   = 135
                };
                bodyRow.AddChild(widget);
            }

            var footerBar = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                VAnchor = VAnchor.ParentBottom | VAnchor.FitToChildren,
                HAnchor = HAnchor.ParentCenter | HAnchor.FitToChildren,
                Margin  = new BorderDouble(bottom: 0),
            };

            topToBottom.AddChild(footerBar);

            int extruderCount = ActiveSliceSettings.Instance.GetValue <int>(SettingsKey.extruder_count);

            extruderStatusWidgets = Enumerable.Range(0, extruderCount).Select((i) => new ExtruderStatusWidget(i)).ToList();

            bool hasHeatedBed = ActiveSliceSettings.Instance.GetValue <bool>("has_heated_bed");

            if (hasHeatedBed)
            {
                var extruderColumn = new FlowLayoutWidget(FlowDirection.TopToBottom);
                footerBar.AddChild(extruderColumn);

                // Add each status widget into the scene, placing into the appropriate column
                for (var i = 0; i < extruderCount; i++)
                {
                    var widget = extruderStatusWidgets[i];
                    widget.Margin = new BorderDouble(right: 20);
                    extruderColumn.AddChild(widget);
                }

                footerBar.AddChild(new BedStatusWidget(smallScreen)
                {
                    VAnchor = VAnchor.ParentCenter,
                });
            }
            else
            {
                if (extruderCount == 1)
                {
                    footerBar.AddChild(extruderStatusWidgets[0]);
                }
                else
                {
                    var columnA = new FlowLayoutWidget(FlowDirection.TopToBottom);
                    footerBar.AddChild(columnA);

                    var columnB = new FlowLayoutWidget(FlowDirection.TopToBottom);
                    footerBar.AddChild(columnB);

                    // Add each status widget into the scene, placing into the appropriate column
                    for (var i = 0; i < extruderCount; i++)
                    {
                        var widget = extruderStatusWidgets[i];
                        if (i % 2 == 0)
                        {
                            widget.Margin = new BorderDouble(right: 20);
                            columnA.AddChild(widget);
                        }
                        else
                        {
                            columnB.AddChild(widget);
                        }
                    }
                }
            }

            UiThread.RunOnIdle(() =>
            {
                CheckOnPrinter();
            });
        }
Example #45
0
		public void NestedFlowWidgetsTopToBottomTest(BorderDouble controlPadding, BorderDouble buttonMargin)
		{
			GuiWidget containerControl = new GuiWidget(300, 500);
			containerControl.Padding = controlPadding;
			containerControl.DoubleBuffer = true;

			{
				Button buttonTop = new Button("buttonTop");
				Button buttonBottom = new Button("buttonBottom");
				buttonTop.OriginRelativeParent = new VectorMath.Vector2(buttonTop.OriginRelativeParent.x, containerControl.LocalBounds.Top - buttonMargin.Top - controlPadding.Top - buttonTop.Height);
				buttonBottom.OriginRelativeParent = new VectorMath.Vector2(buttonBottom.OriginRelativeParent.x, buttonTop.BoundsRelativeToParent.Bottom - buttonBottom.Height - buttonMargin.Height);
				containerControl.AddChild(buttonTop);
				containerControl.AddChild(buttonBottom);
				containerControl.OnDraw(containerControl.NewGraphics2D());
			}

			GuiWidget containerTest = new GuiWidget(300, 500);
			containerTest.DoubleBuffer = true;
			{
				FlowLayoutWidget topToBottomFlowLayoutAll = new FlowLayoutWidget(FlowDirection.TopToBottom);
				topToBottomFlowLayoutAll.AnchorAll();
				topToBottomFlowLayoutAll.Padding = controlPadding;
				{
					FlowLayoutWidget topToBottomFlowLayoutTop = new FlowLayoutWidget(FlowDirection.TopToBottom);
					Button buttonTop = new Button("buttonTop");
					buttonTop.Margin = buttonMargin;
					topToBottomFlowLayoutTop.AddChild(buttonTop);
					topToBottomFlowLayoutTop.SetBoundsToEncloseChildren();
					topToBottomFlowLayoutAll.AddChild(topToBottomFlowLayoutTop);
				}

				{
					FlowLayoutWidget topToBottomFlowLayoutBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);
					Button buttonBottom = new Button("buttonBottom");
					buttonBottom.Margin = buttonMargin;
					topToBottomFlowLayoutBottom.AddChild(buttonBottom);
					topToBottomFlowLayoutBottom.SetBoundsToEncloseChildren();
					topToBottomFlowLayoutAll.AddChild(topToBottomFlowLayoutBottom);
				}

				containerTest.AddChild(topToBottomFlowLayoutAll);
			}

			containerTest.OnDraw(containerTest.NewGraphics2D());
			OutputImages(containerControl, containerTest);

			Assert.IsTrue(containerControl.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one.");
			Assert.IsTrue(containerControl.BackBuffer == containerTest.BackBuffer, "The Anchored widget should be in the correct place.");
		}
        public GCodeOptionsPanel(BedConfig sceneContext, PrinterConfig printer, ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            gcodeOptions = sceneContext.RendererOptions;

            var buttonPanel = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.Fit,
                VAnchor = VAnchor.Fit
            };

            var buttonGroup = new ObservableCollection <GuiWidget>();

            speedsButton = new RadioIconButton(AggContext.StaticData.LoadIcon("speeds.png", theme.InvertIcons), theme)
            {
                SiblingRadioButtonList = buttonGroup,
                Name        = "Speeds Button",
                Checked     = gcodeOptions.GCodeLineColorStyle == "Speeds",
                ToolTipText = "Show Speeds".Localize(),
                Margin      = theme.ButtonSpacing
            };
            speedsButton.Click += SwitchColorModes_Click;
            buttonGroup.Add(speedsButton);

            buttonPanel.AddChild(speedsButton);

            materialsButton = new RadioIconButton(AggContext.StaticData.LoadIcon("materials.png", theme.InvertIcons), theme)
            {
                SiblingRadioButtonList = buttonGroup,
                Name        = "Materials Button",
                Checked     = gcodeOptions.GCodeLineColorStyle == "Materials",
                ToolTipText = "Show Materials".Localize(),
                Margin      = theme.ButtonSpacing
            };
            materialsButton.Click += SwitchColorModes_Click;
            buttonGroup.Add(materialsButton);

            buttonPanel.AddChild(materialsButton);

            noColorButton = new RadioIconButton(AggContext.StaticData.LoadIcon("no-color.png", theme.InvertIcons), theme)
            {
                SiblingRadioButtonList = buttonGroup,
                Name        = "No Color Button",
                Checked     = gcodeOptions.GCodeLineColorStyle == "None",
                ToolTipText = "No Color".Localize(),
                Margin      = theme.ButtonSpacing
            };
            noColorButton.Click += SwitchColorModes_Click;
            buttonGroup.Add(noColorButton);

            buttonPanel.AddChild(noColorButton);

            this.AddChild(
                new SettingsItem(
                    "Color View".Localize(),
                    theme,
                    optionalControls: buttonPanel,
                    enforceGutter: false));

            gcodeOptions = sceneContext.RendererOptions;

            var viewOptions = sceneContext.GetBaseViewOptions();

            viewOptions.AddRange(new[]
            {
                new BoolOption(
                    "Model".Localize(),
                    () => gcodeOptions.GCodeModelView == "Semi-Transparent",
                    (value) => gcodeOptions.GCodeModelView = (value) ? "Semi-Transparent" : "None"),
                new BoolOption(
                    "Moves".Localize(),
                    () => gcodeOptions.RenderMoves,
                    (value) => gcodeOptions.RenderMoves = value),
                new BoolOption(
                    "Retractions".Localize(),
                    () => gcodeOptions.RenderRetractions,
                    (value) => gcodeOptions.RenderRetractions = value),
                new BoolOption(
                    "Extrusion".Localize(),
                    () => gcodeOptions.SimulateExtrusion,
                    (value) => gcodeOptions.SimulateExtrusion = value),
                new BoolOption(
                    "Transparent".Localize(),
                    () => gcodeOptions.TransparentExtrusion,
                    (value) => gcodeOptions.TransparentExtrusion = value),
                new BoolOption(
                    "Hide Offsets".Localize(),
                    () => gcodeOptions.HideExtruderOffsets,
                    (value) => gcodeOptions.HideExtruderOffsets = value,
                    () => printer.Settings.GetValue <int>(SettingsKey.extruder_count) > 1),
                new BoolOption(
                    "Sync To Print".Localize(),
                    () => gcodeOptions.SyncToPrint,
                    (value) =>
                {
                    gcodeOptions.SyncToPrint = value;
                    if (!gcodeOptions.SyncToPrint)
                    {
                        // If we are turning off sync to print, set the slider to full.
                        //layerRenderRatioSlider.SecondValue = 1;
                    }
                })
            });

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

            this.AddChild(optionsContainer);

            void BuildMenu()
            {
                foreach (var option in viewOptions.Where(option => option.IsVisible()))
                {
                    var settingsItem = new SettingsItem(
                        option.Title,
                        theme,
                        new SettingsItem.ToggleSwitchConfig()
                    {
                        Name         = option.Title + " Toggle",
                        Checked      = option.IsChecked(),
                        ToggleAction = option.SetValue
                    },
                        enforceGutter: false);

                    settingsItem.Padding = settingsItem.Padding.Clone(right: 8);

                    optionsContainer.AddChild(settingsItem);
                }
            }

            BuildMenu();

            PropertyChangedEventHandler syncProperties = (s, e) =>
            {
                if (e.PropertyName == nameof(gcodeOptions.RenderBed) ||
                    e.PropertyName == nameof(gcodeOptions.RenderBuildVolume))
                {
                    optionsContainer.CloseAllChildren();
                    BuildMenu();
                }
            };

            gcodeOptions.PropertyChanged += syncProperties;

            optionsContainer.Closed += (s, e) =>
            {
                gcodeOptions.PropertyChanged -= syncProperties;
            };
        }
Example #47
0
		public void NestedFlowWidgetsLeftToRightTest(BorderDouble controlPadding, BorderDouble buttonMargin)
		{
			GuiWidget containerControl = new GuiWidget(500, 300);
			containerControl.Padding = controlPadding;
			containerControl.DoubleBuffer = true;

			{
				Button buttonRight = new Button("buttonRight");
				Button buttonLeft = new Button("buttonLeft");
				buttonLeft.OriginRelativeParent = new VectorMath.Vector2(controlPadding.Left + buttonMargin.Left, buttonLeft.OriginRelativeParent.y);
				buttonRight.OriginRelativeParent = new VectorMath.Vector2(buttonLeft.BoundsRelativeToParent.Right + buttonMargin.Width, buttonRight.OriginRelativeParent.y);
				containerControl.AddChild(buttonRight);
				containerControl.AddChild(buttonLeft);
				containerControl.OnDraw(containerControl.NewGraphics2D());
			}

			GuiWidget containerTest = new GuiWidget(500, 300);
			containerTest.DoubleBuffer = true;
			{
				FlowLayoutWidget leftToRightFlowLayoutAll = new FlowLayoutWidget(FlowDirection.LeftToRight);
				leftToRightFlowLayoutAll.AnchorAll();
				leftToRightFlowLayoutAll.Padding = controlPadding;
				{
					FlowLayoutWidget leftToRightFlowLayoutLeft = new FlowLayoutWidget(FlowDirection.LeftToRight);
					Button buttonTop = new Button("buttonLeft");
					buttonTop.Margin = buttonMargin;
					leftToRightFlowLayoutLeft.AddChild(buttonTop);
					leftToRightFlowLayoutLeft.SetBoundsToEncloseChildren();
					leftToRightFlowLayoutAll.AddChild(leftToRightFlowLayoutLeft);
				}

				{
					FlowLayoutWidget leftToRightFlowLayoutRight = new FlowLayoutWidget(FlowDirection.LeftToRight);
					Button buttonBottom = new Button("buttonRight");
					buttonBottom.Margin = buttonMargin;
					leftToRightFlowLayoutRight.AddChild(buttonBottom);
					leftToRightFlowLayoutRight.SetBoundsToEncloseChildren();
					leftToRightFlowLayoutAll.AddChild(leftToRightFlowLayoutRight);
				}

				containerTest.AddChild(leftToRightFlowLayoutAll);
			}

			containerTest.OnDraw(containerTest.NewGraphics2D());
			OutputImages(containerControl, containerTest);

			Assert.IsTrue(containerControl.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one.");
			Assert.IsTrue(containerControl.BackBuffer == containerTest.BackBuffer, "The Anchored widget should be in the correct place.");
		}
Example #48
0
        protected void AddChildElements()
        {
            Button      editButton;
            AltGroupBox groupBox = new AltGroupBox(textImageButtonFactory.GenerateGroupBoxLabelWithEdit(label, out editButton));

            editButton.Click += (sender, e) =>
            {
                if (editSettingsWindow == null)
                {
                    editSettingsWindow         = new EditTemperaturePresetsWindow(editWindowLabel, GetTemperaturePresets(), SetTemperaturePresets);
                    editSettingsWindow.Closed += (popupWindowSender, popupWindowSenderE) => { editSettingsWindow = null; };
                }
                else
                {
                    editSettingsWindow.BringToFront();
                }
            };

            groupBox.TextColor   = ActiveTheme.Instance.PrimaryTextColor;
            groupBox.BorderColor = ActiveTheme.Instance.PrimaryTextColor;
            groupBox.HAnchor    |= Agg.UI.HAnchor.ParentLeftRight;
            // make sure the client area will get smaller when the contents get smaller
            groupBox.ClientArea.VAnchor = Agg.UI.VAnchor.FitToChildren;

            FlowLayoutWidget controlRow = new FlowLayoutWidget(Agg.UI.FlowDirection.TopToBottom);

            controlRow.Margin   = new BorderDouble(top: 2);
            controlRow.HAnchor |= HAnchor.ParentLeftRight;
            {
                // put in the temperature slider and preset buttons

                tempSliderContainer = new FlowLayoutWidget(Agg.UI.FlowDirection.TopToBottom);

                {
                    GuiWidget sliderLabels = GetSliderLabels();

                    tempSliderContainer.HAnchor = HAnchor.ParentLeftRight;
                    tempSliderContainer.AddChild(sliderLabels);
                    tempSliderContainer.Visible = false;
                }
                GuiWidget spacer = new GuiWidget(0, 10);
                spacer.HAnchor = Agg.UI.HAnchor.ParentLeftRight;

                // put in the temperature indicators
                {
                    FlowLayoutWidget temperatureIndicator = new FlowLayoutWidget();
                    temperatureIndicator.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
                    temperatureIndicator.Margin  = new BorderDouble(bottom: 0);
                    temperatureIndicator.Padding = new BorderDouble(0, 3);

                    // put in the actual temperature controls
                    {
                        FlowLayoutWidget extruderActualIndicator = new FlowLayoutWidget(Agg.UI.FlowDirection.LeftToRight);

                        extruderActualIndicator.Margin = new BorderDouble(3, 0);
                        string     extruderActualLabelTxt     = LocalizedString.Get("Actual");
                        string     extruderActualLabelTxtFull = string.Format("{0}: ", extruderActualLabelTxt);
                        TextWidget extruderActualLabel        = new TextWidget(extruderActualLabelTxtFull, pointSize: 10);
                        extruderActualLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                        extruderActualLabel.VAnchor   = VAnchor.ParentCenter;

                        actualTempIndicator = new TextWidget(string.Format("{0:0.0}°C", GetActualTemperature()), pointSize: 12);
                        actualTempIndicator.AutoExpandBoundsToText = true;
                        actualTempIndicator.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                        actualTempIndicator.VAnchor   = VAnchor.ParentCenter;

                        extruderActualIndicator.AddChild(extruderActualLabel);
                        extruderActualIndicator.AddChild(actualTempIndicator);

                        string extruderAboutLabelTxt     = LocalizedString.Get("Target");
                        string extruderAboutLabelTxtFull = string.Format("{0}: ", extruderAboutLabelTxt);

                        TextWidget extruderTargetLabel = new TextWidget(extruderAboutLabelTxtFull, pointSize: 10);
                        extruderTargetLabel.Margin    = new BorderDouble(left: 10);
                        extruderTargetLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                        extruderTargetLabel.VAnchor   = VAnchor.ParentCenter;

                        extruderActualIndicator.AddChild(extruderTargetLabel);
                        temperatureIndicator.AddChild(extruderActualIndicator);
                    }

                    // put in the target temperature controls
                    temperatureIndicator.AddChild(GetTargetTemperatureDisplay());

                    FlowLayoutWidget helperTextWidget = GetHelpTextWidget();

                    LinkButtonFactory linkFactory = new LinkButtonFactory();
                    linkFactory.textColor = ActiveTheme.Instance.PrimaryTextColor;
                    linkFactory.fontSize  = 10;

                    Button helpTextLink = linkFactory.Generate("?");

                    helpTextLink.Click += (sender, e) =>
                    {
                        helperTextWidget.Visible = !helperTextWidget.Visible;
                    };

                    this.presetButtonsContainer = GetPresetsContainer();
                    temperatureIndicator.AddChild(new HorizontalSpacer());
                    temperatureIndicator.AddChild(presetButtonsContainer);

                    controlRow.AddChild(temperatureIndicator);
                }
            }

            groupBox.AddChild(controlRow);

            this.AddChild(groupBox);
        }
        private void AddGeneralPannel(GuiWidget settingsColumn)
        {
            var generalPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit,
            };

            var configureIcon = AggContext.StaticData.LoadIcon("fa-cog_16.png", 16, 16, theme.InvertIcons);

            var generalSection = new SectionWidget("General".Localize(), generalPanel, theme, expandingContent: false)
            {
                Name    = "General Section",
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit,
            };

            settingsColumn.AddChild(generalSection);

            theme.ApplyBoxStyle(generalSection);

#if __ANDROID__
            // Camera Monitoring
            bool hasCamera = true || ApplicationSettings.Instance.get(ApplicationSettingsKey.HardwareHasCamera) == "true";

            var previewButton = new IconButton(configureIcon, theme)
            {
                ToolTipText = "Preview".Localize()
            };
            previewButton.Click += (s, e) =>
            {
                AppContext.Platform.OpenCameraPreview();
            };

            var printer = ApplicationController.Instance.ActivePrinters.FirstOrDefault();

            // TODO: Sort out how handle this better on Android and in a multi-printer setup
            if (printer != null)
            {
                this.AddSettingsRow(
                    new SettingsItem(
                        "Camera Monitoring".Localize(),
                        theme,
                        new SettingsItem.ToggleSwitchConfig()
                {
                    Checked      = printer.Settings.GetValue <bool>(SettingsKey.publish_bed_image),
                    ToggleAction = (itemChecked) =>
                    {
                        printer.Settings.SetValue(SettingsKey.publish_bed_image, itemChecked ? "1" : "0");
                    }
                },
                        previewButton,
                        AggContext.StaticData.LoadIcon("camera-24x24.png", 24, 24))
                {
                    Enabled = printer.Settings.PrinterSelected
                },
                    generalPanel
                    );
            }
#endif
            // Print Notifications
            var configureNotificationsButton = new IconButton(configureIcon, theme)
            {
                Name        = "Configure Notification Settings Button",
                ToolTipText = "Configure Notifications".Localize(),
                Margin      = new BorderDouble(left: 6),
                VAnchor     = VAnchor.Center
            };
            configureNotificationsButton.Click += (s, e) =>
            {
                if (ApplicationController.ChangeToPrintNotification != null)
                {
                    UiThread.RunOnIdle(() =>
                    {
                        ApplicationController.ChangeToPrintNotification(this.DialogWindow);
                    });
                }
            };

            this.AddSettingsRow(
                new SettingsItem(
                    "Notifications".Localize(),
                    theme,
                    new SettingsItem.ToggleSwitchConfig()
            {
                Checked      = UserSettings.Instance.get(UserSettingsKey.PrintNotificationsEnabled) == "true",
                ToggleAction = (itemChecked) =>
                {
                    UserSettings.Instance.set(UserSettingsKey.PrintNotificationsEnabled, itemChecked ? "true" : "false");
                }
            },
                    configureNotificationsButton,
                    AggContext.StaticData.LoadIcon("notify-24x24.png", 16, 16, theme.InvertIcons)),
                generalPanel);

            // LanguageControl
            var languageSelector = new LanguageSelector(theme);
            languageSelector.SelectionChanged += (s, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    string languageCode = languageSelector.SelectedValue;
                    if (languageCode != UserSettings.Instance.get(UserSettingsKey.Language))
                    {
                        UserSettings.Instance.set(UserSettingsKey.Language, languageCode);

                        if (languageCode == "L10N")
                        {
#if DEBUG
                            AppContext.Platform.GenerateLocalizationValidationFile();
#endif
                        }

                        ApplicationController.Instance.ResetTranslationMap();
                        ApplicationController.Instance.ReloadAll().ConfigureAwait(false);
                    }
                });
            };

            this.AddSettingsRow(new SettingsItem("Language".Localize(), languageSelector, theme), generalPanel);

#if !__ANDROID__
            // ThumbnailRendering
            var thumbnailsModeDropList = new MHDropDownList("", theme, maxHeight: 200 * GuiWidget.DeviceScale);
            thumbnailsModeDropList.AddItem("Flat".Localize(), "orthographic");
            thumbnailsModeDropList.AddItem("3D".Localize(), "raytraced");

            thumbnailsModeDropList.SelectedValue     = UserSettings.Instance.ThumbnailRenderingMode;
            thumbnailsModeDropList.SelectionChanged += (s, e) =>
            {
                string thumbnailRenderingMode = thumbnailsModeDropList.SelectedValue;
                if (thumbnailRenderingMode != UserSettings.Instance.ThumbnailRenderingMode)
                {
                    UserSettings.Instance.ThumbnailRenderingMode = thumbnailRenderingMode;

                    UiThread.RunOnIdle(() =>
                    {
                        // Ask if the user they would like to rebuild their thumbnails
                        StyledMessageBox.ShowMessageBox(
                            (bool rebuildThumbnails) =>
                        {
                            if (rebuildThumbnails)
                            {
                                string[] thumbnails = new string[]
                                {
                                    ApplicationController.CacheablePath(
                                        Path.Combine("Thumbnails", "Content"), ""),
                                    ApplicationController.CacheablePath(
                                        Path.Combine("Thumbnails", "Library"), "")
                                };
                                foreach (var directoryToRemove in thumbnails)
                                {
                                    try
                                    {
                                        if (Directory.Exists(directoryToRemove))
                                        {
                                            Directory.Delete(directoryToRemove, true);
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        GuiWidget.BreakInDebugger();
                                    }

                                    Directory.CreateDirectory(directoryToRemove);
                                }

                                ApplicationController.Instance.Library.NotifyContainerChanged();
                            }
                        },
                            "You are switching to a different thumbnail rendering mode. If you want, your current thumbnails can be removed and recreated in the new style. You can switch back and forth at any time. There will be some processing overhead while the new thumbnails are created.\n\nDo you want to rebuild your existing thumbnails now?".Localize(),
                            "Rebuild Thumbnails Now".Localize(),
                            StyledMessageBox.MessageType.YES_NO,
                            "Rebuild".Localize());
                    });
                }
            };

            this.AddSettingsRow(
                new SettingsItem(
                    "Thumbnails".Localize(),
                    thumbnailsModeDropList,
                    theme),
                generalPanel);
#endif

            // TextSize
            if (!double.TryParse(UserSettings.Instance.get(UserSettingsKey.ApplicationTextSize), out double currentTextSize))
            {
                currentTextSize = 1.0;
            }

            double sliderThumbWidth = 10 * GuiWidget.DeviceScale;
            double sliderWidth      = 100 * GuiWidget.DeviceScale;
            var    textSizeSlider   = new SolidSlider(default(Vector2), sliderThumbWidth, theme, .7, 2.5)
            {
                Name               = "Text Size Slider",
                Margin             = new BorderDouble(5, 0),
                Value              = currentTextSize,
                HAnchor            = HAnchor.Stretch,
                VAnchor            = VAnchor.Center,
                TotalWidthInPixels = sliderWidth,
            };
            theme.ApplySliderStyle(textSizeSlider);

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

            TextWidget sectionLabel = null;

            var textSizeApplyButton = new TextButton("Apply".Localize(), theme)
            {
                VAnchor         = VAnchor.Center,
                BackgroundColor = theme.SlightShade,
                Visible         = false,
                Margin          = new BorderDouble(right: 6)
            };
            textSizeApplyButton.Click += (s, e) => UiThread.RunOnIdle(() =>
            {
                GuiWidget.DeviceScale = textSizeSlider.Value;
                ApplicationController.Instance.ReloadAll().ConfigureAwait(false);
            });
            optionalContainer.AddChild(textSizeApplyButton);

            textSizeSlider.ValueChanged += (s, e) =>
            {
                double textSizeNew = textSizeSlider.Value;
                UserSettings.Instance.set(UserSettingsKey.ApplicationTextSize, textSizeNew.ToString("0.0"));
                sectionLabel.Text           = "Text Size".Localize() + $" : {textSizeNew:0.0}";
                textSizeApplyButton.Visible = textSizeNew != currentTextSize;
            };

            var textSizeRow = new SettingsItem(
                "Text Size".Localize() + $" : {currentTextSize:0.0}",
                textSizeSlider,
                theme,
                optionalContainer);

            sectionLabel = textSizeRow.Children <TextWidget>().FirstOrDefault();

            this.AddSettingsRow(textSizeRow, generalPanel);

            var themeSection = CreateThemePanel(theme);
            settingsColumn.AddChild(themeSection);
            theme.ApplyBoxStyle(themeSection);
        }
        public PrintHistoryWidget()
        {
            SetDisplayAttributes();

            textImageButtonFactory.borderWidth = 0;
            RGBA_Bytes historyPanelTextColor = ActiveTheme.Instance.PrimaryTextColor;

            FlowLayoutWidget allControls = new FlowLayoutWidget(FlowDirection.TopToBottom);

            {
                FlowLayoutWidget completedStatsContainer = new FlowLayoutWidget();
                completedStatsContainer.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
                completedStatsContainer.Padding = new BorderDouble(6, 2);

                showOnlyCompletedCheckbox        = new CheckBox(LocalizedString.Get("Only Show Completed"), historyPanelTextColor, textSize: 10);
                showOnlyCompletedCheckbox.Margin = new BorderDouble(top: 8);
                bool showOnlyCompleted = (UserSettings.Instance.get("PrintHistoryFilterShowCompleted") == "true");
                showOnlyCompletedCheckbox.Checked = showOnlyCompleted;
                showOnlyCompletedCheckbox.Width   = 200;

                completedStatsContainer.AddChild(new TextWidget("Completed Prints: ", pointSize: 10, textColor: historyPanelTextColor));
                completedStatsContainer.AddChild(new TextWidget(GetCompletedPrints().ToString(), pointSize: 14, textColor: historyPanelTextColor));
                completedStatsContainer.AddChild(new HorizontalSpacer());
                completedStatsContainer.AddChild(showOnlyCompletedCheckbox);

                FlowLayoutWidget historyStatsContainer = new FlowLayoutWidget();
                historyStatsContainer.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
                historyStatsContainer.Padding = new BorderDouble(6, 2);

                showTimestampCheckbox = new CheckBox(LocalizedString.Get("Show Timestamp"), historyPanelTextColor, textSize: 10);
                //showTimestampCheckbox.Margin = new BorderDouble(top: 8);
                bool showTimestamp = (UserSettings.Instance.get("PrintHistoryFilterShowTimestamp") == "true");
                showTimestampCheckbox.Checked = showTimestamp;
                showTimestampCheckbox.Width   = 200;

                historyStatsContainer.AddChild(new TextWidget("Total Print Time: ", pointSize: 10, textColor: historyPanelTextColor));
                historyStatsContainer.AddChild(new TextWidget(GetPrintTimeString(), pointSize: 14, textColor: historyPanelTextColor));
                historyStatsContainer.AddChild(new HorizontalSpacer());
                historyStatsContainer.AddChild(showTimestampCheckbox);

                FlowLayoutWidget searchPanel = new FlowLayoutWidget(FlowDirection.TopToBottom);
                searchPanel.BackgroundColor = ActiveTheme.Instance.TransparentDarkOverlay;
                searchPanel.HAnchor         = HAnchor.ParentLeftRight;
                searchPanel.Padding         = new BorderDouble(0, 6, 0, 2);

                searchPanel.AddChild(completedStatsContainer);
                searchPanel.AddChild(historyStatsContainer);

                FlowLayoutWidget buttonPanel = new FlowLayoutWidget();
                buttonPanel.HAnchor = HAnchor.ParentLeftRight;
                buttonPanel.Padding = new BorderDouble(0, 3);
                {
                    GuiWidget spacer = new GuiWidget();
                    spacer.HAnchor = HAnchor.ParentLeftRight;
                    buttonPanel.AddChild(spacer);
                }

                allControls.AddChild(searchPanel);
                historyView = new PrintHistoryDataView();
                allControls.AddChild(historyView);
                allControls.AddChild(buttonPanel);
            }
            allControls.AnchorAll();

            this.AddChild(allControls);

            AddHandlers();
        }