Beispiel #1
0
		private void OutputImage(GuiWidget widgetToOutput, string fileName)
		{
			if (saveImagesForDebug)
			{
				OutputImage(widgetToOutput.BackBuffer, fileName);
			}
		}
Beispiel #2
0
    public GuiDisplayObject(SortedList args)
    {
        //Pflichtfelde
        if(args.ContainsKey("rect") == false){
            throw new Exception("No Rect defined");
        }

        //Text
        _text = "";
        if(args.ContainsKey("text")){
            _text = (string) args["text"];
        }

        _args = args;
        _id = _idCounter++;
        _go2D = new GameObject("2D GameObject - " + _id);

        //Position
        _rect = (Rect) args["rect"];
        _widget = _go2D.AddComponent<GuiWidget>();
        _widget.LocalPosition = new Vector2(_rect.x, _rect.y);
        _widget.Dimension = new Vector2(_rect.width, _rect.height);

        //make active
        Visible = true;
    }
Beispiel #3
0
		public void BottomAndTopTextControl(double controlPadding, double buttonMargin)
		{
			GuiWidget containerControl = new GuiWidget(200, 300);
			containerControl.DoubleBuffer = true;
			containerControl.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
			TextWidget controlButton1 = new TextWidget("text1");
			controlButton1.Margin = new BorderDouble(buttonMargin);
			controlButton1.OriginRelativeParent = new VectorMath.Vector2(-controlButton1.LocalBounds.Left, -controlButton1.LocalBounds.Bottom + controlPadding + buttonMargin);
			controlButton1.LocalBounds = new RectangleDouble(controlButton1.LocalBounds.Left, controlButton1.LocalBounds.Bottom, controlButton1.LocalBounds.Right, controlButton1.LocalBounds.Bottom + containerControl.Height - (controlPadding + buttonMargin) * 2);
			containerControl.AddChild(controlButton1);
			containerControl.OnDraw(containerControl.NewGraphics2D());

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

			TextWidget testButton1 = new TextWidget("text1");
			testButton1.Margin = new BorderDouble(buttonMargin);
			testButton1.VAnchor = VAnchor.ParentBottom | VAnchor.ParentTop;
			containerTest.AddChild(testButton1);
			containerTest.OnDraw(containerTest.NewGraphics2D());
			OutputImages(containerControl, containerTest);

			// now change it's size
			containerTest.LocalBounds = containerControl.LocalBounds;
			containerTest.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);

			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.");
		}
Beispiel #4
0
 public ContainerWidget(Game game, GuiWidget[] widgets = null)
     : base(game)
 {
     if (widgets != null) {
         Widgets.AddRange(widgets);
     }
     UpdateBounds = GetType() != typeof(ContainerWidget);
 }
Beispiel #5
0
		private void OutputImages(GuiWidget control, GuiWidget test)
		{
			if (saveImagesForDebug)
			{
				ImageTgaIO.Save(control.BackBuffer, "image-control.tga");
				ImageTgaIO.Save(test.BackBuffer, "image-test.tga");
			}
		}
 protected override void OnInit()
 {
     if (Target == null) {
         Target = GetComponent<GuiWidget> ();
     }
     if (Target == null) {
         enabled = false;
     }
 }
Beispiel #7
0
		public void SendKey(Keys keyDown, char keyPressed, GuiWidget reciever)
		{
			KeyEventArgs keyDownEvent = new KeyEventArgs(keyDown);
			reciever.OnKeyDown(keyDownEvent);
			if (!keyDownEvent.SuppressKeyPress)
			{
				KeyPressEventArgs keyPressEvent = new KeyPressEventArgs(keyPressed);
				reciever.OnKeyPress(keyPressEvent);
			}
		}
		public void TextWidgetVisibleTest()
		{
			{
				GuiWidget rectangleWidget = new GuiWidget(100, 50);
				TextWidget itemToAdd = new TextWidget("test Item", 10, 10);
				rectangleWidget.AddChild(itemToAdd);
				rectangleWidget.DoubleBuffer = true;
				rectangleWidget.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
				rectangleWidget.OnDraw(rectangleWidget.BackBuffer.NewGraphics2D());

				ImageBuffer textOnly = new ImageBuffer(75, 20, 32, new BlenderBGRA());
				textOnly.NewGraphics2D().Clear(RGBA_Bytes.White);

				textOnly.NewGraphics2D().DrawString("test Item", 1, 1);

				if (saveImagesForDebug)
				{
					ImageTgaIO.Save(rectangleWidget.BackBuffer, "-rectangleWidget.tga");
					//ImageTgaIO.Save(itemToAdd.Children[0].BackBuffer, "-internalTextWidget.tga");
					ImageTgaIO.Save(textOnly, "-textOnly.tga");
				}

				Assert.IsTrue(rectangleWidget.BackBuffer.FindLeastSquaresMatch(textOnly, 1), "TextWidgets need to be drawing.");
				rectangleWidget.Close();
			}

			{
				GuiWidget rectangleWidget = new GuiWidget(100, 50);
				TextEditWidget itemToAdd = new TextEditWidget("test Item", 10, 10);
				rectangleWidget.AddChild(itemToAdd);
				rectangleWidget.DoubleBuffer = true;
				rectangleWidget.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
				rectangleWidget.OnDraw(rectangleWidget.BackBuffer.NewGraphics2D());

				ImageBuffer textOnly = new ImageBuffer(75, 20, 32, new BlenderBGRA());
				textOnly.NewGraphics2D().Clear(RGBA_Bytes.White);

				TypeFacePrinter stringPrinter = new TypeFacePrinter("test Item", 12);
				IVertexSource offsetText = new VertexSourceApplyTransform(stringPrinter, Affine.NewTranslation(1, -stringPrinter.LocalBounds.Bottom));
				textOnly.NewGraphics2D().Render(offsetText, RGBA_Bytes.Black);

				if (saveImagesForDebug)
				{
					ImageTgaIO.Save(rectangleWidget.BackBuffer, "-rectangleWidget.tga");
					//ImageTgaIO.Save(itemToAdd.Children[0].BackBuffer, "-internalTextWidget.tga");
					ImageTgaIO.Save(textOnly, "-textOnly.tga");
				}

				Assert.IsTrue(rectangleWidget.BackBuffer.FindLeastSquaresMatch(textOnly, 1), "TextWidgets need to be drawing.");
				rectangleWidget.Close();
			}
		}
Beispiel #9
0
		public GroupBox(GuiWidget groupBoxLabel)
			: base(HAnchor.FitToChildren, VAnchor.FitToChildren)
		{
			this.Padding = new BorderDouble(14, 14, 14, 16);
			groupBoxLabel.Margin = new BorderDouble(20, 0, 0, -this.Padding.Top);
			groupBoxLabel.VAnchor = UI.VAnchor.ParentTop;
			groupBoxLabel.HAnchor = UI.HAnchor.ParentLeft;
			base.AddChild(groupBoxLabel);

			this.groupBoxLabel = groupBoxLabel;

			clientArea = new GuiWidget(HAnchor.Max_FitToChildren_ParentWidth, VAnchor.Max_FitToChildren_ParentHeight);
			base.AddChild(clientArea);
		}
		public void LimitScrolToContetsTests()
		{
			GuiWidget containerControl = new GuiWidget(200, 200);
			containerControl.DoubleBuffer = true;
			containerControl.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
			containerControl.OnDraw(containerControl.NewGraphics2D());

			ScrollableWidget containerTest = new ScrollableWidget(200, 200);
			containerTest.DoubleBuffer = true;
			containerTest.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
			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.");
		}
Beispiel #11
0
		public void TextEditTextSelectionTests()
		{
			GuiWidget container = new GuiWidget();
			container.LocalBounds = new RectangleDouble(0, 0, 200, 200);
			TextEditWidget editField1 = new TextEditWidget("", 0, 0, pixelWidth: 51);
			container.AddChild(editField1);

			// select the conrol and type something in it
			container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0));
			container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 0, 0, 0, 0));
			SendKey(Keys.A, 'a', container);
			Assert.IsTrue(editField1.Text == "a", "It should have a in it.");

			// select the begining again and type something else in it
			container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0));
			container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 0, 0, 0, 0));
			SendKey(Keys.B, 'b', container);
			Assert.IsTrue(editField1.Text == "ba", "It should have ba in it.");

			// select the ba and delete them
			container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0));
			container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 0, 15, 0, 0));
			container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 0, 15, 0, 0));
			SendKey(Keys.Back, ' ', container);
			Assert.IsTrue(editField1.Text == "", "It should have nothing in it.");

			// select the other way
			editField1.Text = "ab";
			Assert.IsTrue(editField1.Text == "ab", "It should have ab in it.");
			container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 15, 0, 0));
			container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 0, 0, 0, 0));
			container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 0, 0, 0, 0));
			SendKey(Keys.Back, ' ', container);
			Assert.IsTrue(editField1.Text == "", "It should have nothing in it.");

			// select the other way but start far to the right
			editField1.Text = "abc";
			Assert.IsTrue(editField1.Text == "abc", "It should have abc in it.");
			container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 30, 0, 0));
			container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 0, 0, 0, 0));
			container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 0, 0, 0, 0));
			SendKey(Keys.Back, ' ', container);
			Assert.IsTrue(editField1.Text == "", "It should have nothing in it.");

			container.Close();
		}
		public void ValidateOnlyTopWidgetGetsLeftClick()
		{
			bool gotClick = false;
			GuiWidget container = new GuiWidget();
			container.Name = "container";
			container.LocalBounds = new RectangleDouble(0, 0, 200, 200);
			Button button = new Button("Test", 100, 100);
			button.Name = "button";
			button.Click += (sender, e) => { gotClick = true; };
			container.AddChild(button);

			GuiWidget blockingWidegt = new GuiWidget();
			blockingWidegt.Name = "blockingWidegt";
			blockingWidegt.LocalBounds = new RectangleDouble(105, 105, 125, 125);
			container.AddChild(blockingWidegt);

			// the widget is not in the way
			Assert.IsTrue(gotClick == false);
			container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 101, 101, 0));
			Assert.IsTrue(container.MouseCaptured == false);
			Assert.IsTrue(blockingWidegt.MouseCaptured == false);
			Assert.IsTrue(container.ChildHasMouseCaptured == true);
			Assert.IsTrue(blockingWidegt.ChildHasMouseCaptured == false);
			Assert.IsTrue(button.MouseCaptured == true);
			container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 101, 101, 0));
			Assert.IsTrue(container.MouseCaptured == false);
			Assert.IsTrue(blockingWidegt.MouseCaptured == false);
			Assert.IsTrue(button.MouseCaptured == false);
			Assert.IsTrue(gotClick == true);

			gotClick = false;

			// the widget is in the way
			Assert.IsTrue(gotClick == false);
			container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 110, 110, 0));
			Assert.IsTrue(container.MouseCaptured == false);
			Assert.IsTrue(blockingWidegt.MouseCaptured == true);
			Assert.IsTrue(button.MouseCaptured == false);
			container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 110, 110, 0));
			Assert.IsTrue(container.MouseCaptured == false);
			Assert.IsTrue(blockingWidegt.MouseCaptured == false);
			Assert.IsTrue(button.MouseCaptured == false);
			Assert.IsTrue(gotClick == false);
		}
Beispiel #13
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");
		}
        public void ValidateSimpleLeftClick()
        {
            GuiWidget container = new GuiWidget();
            container.Name = "Container";
            container.LocalBounds = new RectangleDouble(0, 0, 200, 200);
            Button button = new Button("Test", 100, 100);
            button.Name = "button";
            bool gotClick = false;
            button.Click += (sender, e) => { gotClick = true; };
            container.AddChild(button);

            Assert.IsTrue(gotClick == false);
            Assert.IsTrue(button.Focused == false);

            container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 10, 10, 0));
            container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 10, 10, 0));
            Assert.IsTrue(gotClick == false);
            Assert.IsTrue(button.Focused == false);
            
            container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 110, 110, 0));
            container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 10, 10, 0));
            Assert.IsTrue(gotClick == false);
            Assert.IsTrue(button.Focused == true, "Down click triggers focused."); 

            Assert.IsTrue(gotClick == false);
            container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 110, 110, 0));
            container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 110, 110, 0));
            Assert.IsTrue(gotClick == true);
            Assert.IsTrue(button.Focused == true);

            gotClick = false;
            container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 10, 10, 0));
            container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 10, 10, 0));
            Assert.IsTrue(gotClick == false);
            Assert.IsTrue(button.Focused == false);

        }
Beispiel #15
0
 public DropDownMenu(GuiWidget topMenuWidget, Direction direction = Direction.Down)
     : base(direction)
 {
 }
        public TemperatureWidgetBase(string textValue)
            : base(52 * TextWidget.GlobalPointSizeScaleRatio, 52 * TextWidget.GlobalPointSizeScaleRatio)
        {
            whiteButtonFactory.FixedHeight     = 18 * TextWidget.GlobalPointSizeScaleRatio;
            whiteButtonFactory.fontSize        = 7;
            whiteButtonFactory.normalFillColor = RGBA_Bytes.White;
            whiteButtonFactory.normalTextColor = RGBA_Bytes.DarkGray;

            FlowLayoutWidget container = new FlowLayoutWidget(FlowDirection.TopToBottom);

            container.AnchorAll();

            this.BackgroundColor = new RGBA_Bytes(255, 255, 255, 200);
            this.Margin          = new BorderDouble(0, 2) * TextWidget.GlobalPointSizeScaleRatio;

            GuiWidget labelContainer = new GuiWidget();

            labelContainer.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
            labelContainer.Height  = 18 * TextWidget.GlobalPointSizeScaleRatio;

            labelTextWidget = new TextWidget("", pointSize: 8);
            labelTextWidget.AutoExpandBoundsToText = true;
            labelTextWidget.HAnchor   = HAnchor.ParentCenter;
            labelTextWidget.VAnchor   = VAnchor.ParentCenter;
            labelTextWidget.TextColor = ActiveTheme.Instance.SecondaryAccentColor;
            labelTextWidget.Visible   = false;

            labelContainer.AddChild(labelTextWidget);

            GuiWidget indicatorContainer = new GuiWidget();

            indicatorContainer.AnchorAll();

            indicatorTextWidget           = new TextWidget(textValue, pointSize: 11);
            indicatorTextWidget.TextColor = ActiveTheme.Instance.PrimaryAccentColor;
            indicatorTextWidget.HAnchor   = HAnchor.ParentCenter;
            indicatorTextWidget.VAnchor   = VAnchor.ParentCenter;
            indicatorTextWidget.AutoExpandBoundsToText = true;

            indicatorContainer.AddChild(indicatorTextWidget);

            GuiWidget buttonContainer = new GuiWidget();

            buttonContainer.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
            buttonContainer.Height  = 18 * TextWidget.GlobalPointSizeScaleRatio;

            preheatButton         = whiteButtonFactory.Generate("Preheat".Localize().ToUpper());
            preheatButton.Cursor  = Cursors.Hand;
            preheatButton.Visible = false;

            buttonContainer.AddChild(preheatButton);

            container.AddChild(labelContainer);
            container.AddChild(indicatorContainer);
            container.AddChild(buttonContainer);


            this.AddChild(container);
            ActiveTheme.Instance.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents);

            this.MouseEnterBounds    += onEnterBounds;
            this.MouseLeaveBounds    += onLeaveBounds;
            this.preheatButton.Click += onPreheatButtonClick;
        }
        private void AddDisplay(PrinterSettings printerSettings,
                                ThemeConfig theme,
                                bool showClearButton,
                                string setting,
                                int toolIndex,
                                TextWidget widget)
        {
            GuiWidget clearZOffsetButton = null;

            void Printer_SettingChanged(object s, StringEventArgs e)
            {
                if (e?.Data == setting)
                {
                    double zOffset = printerSettings.GetValue <double>(setting);
                    bool   hasOverriddenZOffset = zOffset != 0;

                    if (clearZOffsetButton != null)
                    {
                        clearZOffsetButton.Visible = hasOverriddenZOffset;
                    }

                    widget.Text = zOffset.ToString("0.##");
                    DescribeExtruder(widget, toolIndex);
                }
            }

            var zOffsetStreamContainer = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                Margin  = new BorderDouble(3, 0),
                Padding = new BorderDouble(3),
                HAnchor = HAnchor.Fit | HAnchor.Right,
                VAnchor = VAnchor.Absolute,
                Height  = 20 * GuiWidget.DeviceScale
            };

            this.AddChild(zOffsetStreamContainer);

            var zoffset = printerSettings.GetValue <double>(setting);

            zOffsetStreamContainer.AddChild(widget);

            if (showClearButton)
            {
                clearZOffsetButton             = theme.CreateSmallResetButton();
                clearZOffsetButton.Name        = "Clear ZOffset button";
                clearZOffsetButton.ToolTipText = "Clear ZOffset".Localize();
                clearZOffsetButton.Visible     = zoffset != 0;
                clearZOffsetButton.Click      += (sender, e) =>
                {
                    printerSettings.SetValue(setting, "0");
                };
                zOffsetStreamContainer.AddChild(clearZOffsetButton);
            }

            printerSettings.SettingChanged += Printer_SettingChanged;

            this.Closed += (s, e) =>
            {
                printerSettings.SettingChanged -= Printer_SettingChanged;
            };
        }
 public TooltipButton(double x, double y, GuiWidget buttonView)
     : base(x, y, buttonView)
 {
 }
Beispiel #19
0
        private FlowLayoutWidget CreateEButtons(double buttonSeparationDistance)
        {
            int extruderCount = ActiveSliceSettings.Instance.GetValue <int>(SettingsKey.extruder_count);

            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;
            mmLabel.Margin  = new BorderDouble(left: 10);
            setMoveDistanceControl.AddChild(mmLabel);
            setMoveDistanceControl.HAnchor = Agg.UI.HAnchor.ParentLeft;
            eButtons.AddChild(setMoveDistanceControl);

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

            return(eButtons);
        }
Beispiel #20
0
        public RepetierEEPromPage(PrinterConfig printer)
            : base(printer)
        {
            AlwaysOnTopOfMain = true;

            this.WindowTitle = "Firmware EEPROM Settings".Localize();

            currentEePromSettings = new EePromRepetierStorage();

            var topToBottom = contentRow;

            var row = new FlowLayoutWidget
            {
                HAnchor = HAnchor.Stretch,
            };

            GuiWidget descriptionWidget = AddDescription("Description".Localize());

            descriptionWidget.Margin = new BorderDouble(left: 3);
            row.AddChild(descriptionWidget);

            CreateSpacer(row);

            row.AddChild(new TextWidget("Value".Localize(), pointSize: theme.FontSize10, textColor: ActiveTheme.Instance.PrimaryTextColor)
            {
                VAnchor = VAnchor.Center,
                Margin  = new BorderDouble(left: 5, right: 60)
            });
            topToBottom.AddChild(row);

            {
                var settingsAreaScrollBox = new ScrollableWidget(true);
                settingsAreaScrollBox.ScrollArea.HAnchor |= HAnchor.Stretch;
                settingsAreaScrollBox.AnchorAll();
                settingsAreaScrollBox.BackgroundColor = theme.MinimalShade;
                topToBottom.AddChild(settingsAreaScrollBox);

                settingsColumn = new FlowLayoutWidget(FlowDirection.TopToBottom)
                {
                    HAnchor = HAnchor.MaxFitOrStretch
                };

                settingsAreaScrollBox.AddChild(settingsColumn);
            }


            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);
                                    RebuildUi();
                                }
                            });
                        }, .1);
                    };

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

            // put in the save button
            var buttonSave = theme.CreateDialogButton("Save To EEPROM".Localize());

            buttonSave.Click += (s, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    currentEePromSettings.Save(printer.Connection);
                    currentEePromSettings.Clear();
                    this.DialogWindow.Close();
                });
            };
            this.AddPageAction(buttonSave);

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

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

            currentEePromSettings.Clear();
            printer.Connection.CommunicationUnconditionalFromPrinter.RegisterEvent(currentEePromSettings.Add, ref unregisterEvents);
            currentEePromSettings.SettingAdded += NewSettingReadFromPrinter;
            currentEePromSettings.AskPrinterForSettings(printer.Connection);

#if SIMULATE_CONNECTION
            UiThread.RunOnIdle(AddSimulatedItems);
#endif
        }
Beispiel #21
0
        public PartTabPage(PartWorkspace workspace, ThemeConfig theme, string tabTitle)
            : base(tabTitle)
        {
            this.sceneContext    = workspace.SceneContext;
            this.theme           = theme;
            this.BackgroundColor = theme.BackgroundColor;
            this.Padding         = 0;
            this.Workspace       = workspace;

            bool isPrinterType = this is PrinterTabPage;

            var favoritesBarAndView3DWidget = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            };

            viewToolBarControls = new ViewToolBarControls(workspace, theme, sceneContext.Scene.UndoBuffer, isPrinterType, !(this is PrinterTabPage))
            {
                VAnchor = VAnchor.Top | VAnchor.Fit,
                HAnchor = HAnchor.Left | HAnchor.Stretch,
                Visible = true,
            };

            // Shade border if toolbar is secondary rather than primary
            theme.ApplyBottomBorder(viewToolBarControls, shadedBorder: this is PrinterTabPage);

            viewToolBarControls.ResetView += (sender, e) =>
            {
                if (view3DWidget.Visible)
                {
                    this.view3DWidget.ResetView();
                }
            };

            // The 3D model view
            view3DWidget = new View3DWidget(
                Printer,
                sceneContext,
                viewToolBarControls,
                theme,
                this,
                editorType: isPrinterType ? Object3DControlsLayer.EditorType.Printer : Object3DControlsLayer.EditorType.Part);

            // add in the task display
            view3DWidget.AddChild(new RunningTasksWidget(theme, Printer)
            {
                MinimumSize = new Vector2(100, 0),
                Margin      = new BorderDouble(9, 0, 0, 9),
                VAnchor     = VAnchor.Top | VAnchor.Fit,
                HAnchor     = HAnchor.Left | HAnchor.Fit,
            });

            viewToolBarControls.SetView3DWidget(view3DWidget);

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

            topToBottom.AddChild(leftToRight = new FlowLayoutWidget()
            {
                Name    = "View3DContainerParent",
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            });

            view3DContainer = new GuiWidget()
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            };

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

            toolbarAndView3DWidget.AddChild(viewToolBarControls);

            var favoritesBarContext = new LibraryConfig()
            {
                ActiveContainer = ApplicationController.Instance.Library.RootLibaryContainer
            };

            var leftBar = new GuiWidget()
            {
                VAnchor     = VAnchor.Stretch,
                HAnchor     = HAnchor.Fit,
                Border      = new BorderDouble(top: 1, right: 1),
                BorderColor = theme.BorderColor20,
            };

            favoritesBarAndView3DWidget.AddChild(leftBar);

            bool expanded = UserSettings.Instance.get(UserSettingsKey.FavoritesBarExpansion) != "0";

            favoritesBar = new LibraryListView(favoritesBarContext, theme)
            {
                Name = "LibraryView",
                // Drop containers
                ContainerFilter = (container) => false,
                // HAnchor = HAnchor.Fit,
                HAnchor          = HAnchor.Absolute,
                VAnchor          = VAnchor.Stretch,
                AllowContextMenu = false,
                ActiveSort       = SortKey.ModifiedDate,
                Ascending        = true,
                // restore to state for favorites bar size
                Width           = expanded ? 55 * GuiWidget.DeviceScale : 33 * GuiWidget.DeviceScale,
                ListContentView = new IconView(theme, expanded ? 48 * GuiWidget.DeviceScale : 24 * GuiWidget.DeviceScale)
                {
                    VAnchor = VAnchor.Fit | VAnchor.Top
                },
            };

            // favoritesBar.ScrollArea.HAnchor = HAnchor.Fit;
            favoritesBar.ListContentView.HAnchor = HAnchor.Fit;
            leftBar.AddChild(favoritesBar);

            void UpdateWidth(object s, EventArgs e)
            {
                if (s is GuiWidget widget)
                {
                    favoritesBar.Width = widget.Width;
                }
            }

            favoritesBar.ListContentView.BoundsChanged += UpdateWidth;

            favoritesBar.ScrollArea.VAnchor = VAnchor.Fit;

            favoritesBar.VerticalScrollBar.Show = ScrollBar.ShowState.Never;

            var expandedImage  = StaticData.Instance.LoadIcon("expand.png", 16, 16).SetToColor(theme.TextColor);
            var collapsedImage = StaticData.Instance.LoadIcon("collapse.png", 16, 16).SetToColor(theme.TextColor);

            var expandBarButton = new IconButton(expanded ? collapsedImage : expandedImage, theme)
            {
                HAnchor     = HAnchor.Center,
                VAnchor     = VAnchor.Absolute | VAnchor.Bottom,
                Margin      = new BorderDouble(bottom: 3, top: 3),
                Height      = theme.ButtonHeight - 6 * GuiWidget.DeviceScale,
                Width       = theme.ButtonHeight - 6 * GuiWidget.DeviceScale,
                ToolTipText = expanded ? "Reduced Width".Localize() : "Expand Width".Localize(),
            };

            expandBarButton.Click += (s, e) => UiThread.RunOnIdle(async() =>
            {
                expanded = !expanded;

                // remove from the one we are deleting
                favoritesBar.ListContentView.BoundsChanged -= UpdateWidth;
                UserSettings.Instance.set(UserSettingsKey.FavoritesBarExpansion, expanded ? "1" : "0");
                favoritesBar.ListContentView         = new IconView(theme, expanded ? 48 * GuiWidget.DeviceScale : 24 * GuiWidget.DeviceScale);
                favoritesBar.ListContentView.HAnchor = HAnchor.Fit;
                // add to the one we created
                favoritesBar.ListContentView.BoundsChanged += UpdateWidth;
                expandBarButton.SetIcon(expanded ? collapsedImage : expandedImage);
                expandBarButton.Invalidate();
                expandBarButton.ToolTipText = expanded ? "Reduced Width".Localize() : "Expand Width".Localize();

                await favoritesBar.Reload();
                UpdateWidth(favoritesBar.ListContentView, null);
            });
            leftBar.AddChild(expandBarButton);

            favoritesBar.Margin = new BorderDouble(bottom: expandBarButton.Height + expandBarButton.Margin.Height);

            favoritesBarAndView3DWidget.AddChild(view3DWidget);
            toolbarAndView3DWidget.AddChild(favoritesBarAndView3DWidget);

            view3DContainer.AddChild(toolbarAndView3DWidget);

            leftToRight.AddChild(view3DContainer);

            if (sceneContext.World.RotationMatrix == Matrix4X4.Identity)
            {
                this.view3DWidget.ResetView();
            }

            this.AnchorAll();
        }
 private void AddSettingsRow(GuiWidget widget, GuiWidget container)
 {
     container.AddChild(widget);
     widget.Padding = widget.Padding.Clone(right: 10);
 }
        private void AddGeneralPannel(GuiWidget settingsColumn)
        {
            var generalPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit,
            };

            var configureIcon = StaticData.Instance.LoadIcon("fa-cog_16.png", 16, 16).SetToColor(theme.TextColor);

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

            // 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,
                    StaticData.Instance.LoadIcon("notify-24x24.png", 16, 16).SetToColor(theme.TextColor)),
                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);

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

            // 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);
        }
        private void AddAdvancedPannel(GuiWidget settingsColumn)
        {
            var advancedPanel = new FlowLayoutWidget(FlowDirection.TopToBottom);

            var advancedSection = new SectionWidget("Advanced".Localize(), advancedPanel, theme, serializationKey: "ApplicationSettings-Advanced", expanded: false)
            {
                Name    = "Advanced Section",
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit,
                Margin  = 0
            };

            settingsColumn.AddChild(advancedSection);

            theme.ApplyBoxStyle(advancedSection);

            // Touch Screen Mode
            this.AddSettingsRow(
                new SettingsItem(
                    "Touch Screen Mode".Localize(),
                    theme,
                    new SettingsItem.ToggleSwitchConfig()
            {
                Checked      = UserSettings.Instance.get(UserSettingsKey.ApplicationDisplayMode) == "touchscreen",
                ToggleAction = (itemChecked) =>
                {
                    string displayMode = itemChecked ? "touchscreen" : "responsive";
                    if (displayMode != UserSettings.Instance.get(UserSettingsKey.ApplicationDisplayMode))
                    {
                        UserSettings.Instance.set(UserSettingsKey.ApplicationDisplayMode, displayMode);
                        UiThread.RunOnIdle(() => ApplicationController.Instance.ReloadAll().ConfigureAwait(false));
                    }
                }
            }),
                advancedPanel);

            AddUserBoolToggle(advancedPanel,
                              "Enable Socketeer Client".Localize(),
                              UserSettingsKey.ApplicationUseSocketeer,
                              true,
                              false);

            AddUserBoolToggle(advancedPanel,
                              "Utilize High Res Monitors".Localize(),
                              UserSettingsKey.ApplicationUseHeigResDisplays,
                              true,
                              false);

            var openCacheButton = new IconButton(StaticData.Instance.LoadIcon("fa-link_16.png", 16, 16).SetToColor(theme.TextColor), theme)
            {
                ToolTipText = "Open Folder".Localize(),
            };

            openCacheButton.Click += (s, e) => UiThread.RunOnIdle(() =>
            {
                Process.Start(ApplicationDataStorage.ApplicationUserDataPath);
            });

            this.AddSettingsRow(
                new SettingsItem(
                    "Application Storage".Localize(),
                    openCacheButton,
                    theme),
                advancedPanel);

            var clearCacheButton = new HoverIconButton(StaticData.Instance.LoadIcon("remove.png", 16, 16).SetToColor(theme.TextColor), theme)
            {
                ToolTipText = "Clear Cache".Localize(),
            };

            clearCacheButton.Click += (s, e) => UiThread.RunOnIdle(() =>
            {
                CacheDirectory.DeleteCacheData();
            });

            this.AddSettingsRow(
                new SettingsItem(
                    "Application Cache".Localize(),
                    clearCacheButton,
                    theme),
                advancedPanel);

#if DEBUG
            var configureIcon = StaticData.Instance.LoadIcon("fa-cog_16.png", 16, 16).SetToColor(theme.TextColor);

            var configurePluginsButton = new IconButton(configureIcon, theme)
            {
                ToolTipText = "Configure Plugins".Localize(),
                Margin      = 0
            };
            configurePluginsButton.Click += (s, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    DialogWindow.Show <PluginsPage>();
                });
            };

            this.AddSettingsRow(
                new SettingsItem(
                    "Plugins".Localize(),
                    configurePluginsButton,
                    theme),
                advancedPanel);
#endif

            var gitHubPat = UserSettings.Instance.get("GitHubPat");
            if (gitHubPat == null)
            {
                gitHubPat = "";
            }
            var accessToken = new MHTextEditWidget(gitHubPat, theme, pixelWidth: 350, messageWhenEmptyAndNotSelected: "Enter Person Access Token".Localize())
            {
                HAnchor = HAnchor.Absolute,
                Margin  = new BorderDouble(5),
                Name    = "GitHubPat Edit Field"
            };
            accessToken.ActualTextEditWidget.EnterPressed += (s, e) =>
            {
                UserSettings.Instance.set("GitHubPat", accessToken.ActualTextEditWidget.Text);
            };
            accessToken.Closed += (s, e) =>
            {
                UserSettings.Instance.set("GitHubPat", accessToken.ActualTextEditWidget.Text);
            };
            this.AddSettingsRow(
                new SettingsItem(
                    "GitHub Personal Access Token".Localize(),
                    accessToken,
                    theme)
            {
                ToolTipText = "This is used to increase the number of downloads allowed when browsing GitHub repositories".Localize(),
            },
                advancedPanel);

            advancedPanel.Children <SettingsItem>().First().Border = new BorderDouble(0, 1);
        }
        public FlowLayoutWidget createPrinterConnectionMessageContainer()
        {
            FlowLayoutWidget container = new FlowLayoutWidget(FlowDirection.TopToBottom);

            container.VAnchor = VAnchor.Stretch;
            container.Margin  = new BorderDouble(5);
            BorderDouble elementMargin = new BorderDouble(top: 5);

            string     printerMessageOneText = "MatterControl will now attempt to auto-detect printer.".Localize();
            TextWidget printerMessageOne     = new TextWidget(printerMessageOneText, 0, 0, 10);

            printerMessageOne.Margin    = new BorderDouble(0, 10, 0, 5);
            printerMessageOne.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            printerMessageOne.HAnchor   = HAnchor.Stretch;
            printerMessageOne.Margin    = elementMargin;

            string     printerMessageFourBeg  = "Connect printer and power on".Localize();
            string     printerMessageFourFull = string.Format("1.) {0}.", printerMessageFourBeg);
            TextWidget printerMessageFour     = new TextWidget(printerMessageFourFull, 0, 0, 12);

            printerMessageFour.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            printerMessageFour.HAnchor   = HAnchor.Stretch;
            printerMessageFour.Margin    = elementMargin;

            string     printerMessageFiveTxtBeg  = "Press".Localize();
            string     printerMessageFiveTxtEnd  = "Connect".Localize();
            string     printerMessageFiveTxtFull = string.Format("2.) {0} '{1}'.", printerMessageFiveTxtBeg, printerMessageFiveTxtEnd);
            TextWidget printerMessageFive        = new TextWidget(printerMessageFiveTxtFull, 0, 0, 12);

            printerMessageFive.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            printerMessageFive.HAnchor   = HAnchor.Stretch;
            printerMessageFive.Margin    = elementMargin;

            GuiWidget vSpacer = new GuiWidget();

            vSpacer.VAnchor = VAnchor.Stretch;

            var manualLink = new LinkLabel("Manual Configuration".Localize(), theme)
            {
                Margin    = new BorderDouble(0, 5),
                TextColor = theme.Colors.PrimaryTextColor
            };

            manualLink.Click += (s, e) => UiThread.RunOnIdle(() =>
            {
                DialogWindow.ChangeToPage(new SetupStepComPortManual(printer));
            });

            printerErrorMessage = new TextWidget("", 0, 0, 10)
            {
                AutoExpandBoundsToText = true,
                TextColor = Color.Red,
                HAnchor   = HAnchor.Stretch,
                Margin    = elementMargin
            };

            container.AddChild(printerMessageOne);
            container.AddChild(printerMessageFour);
            container.AddChild(printerErrorMessage);
            container.AddChild(vSpacer);
            container.AddChild(manualLink);

            container.HAnchor = HAnchor.Stretch;
            return(container);
        }
 public static void SetEnabled(this GuiWidget guiWidget, bool enabled)
 {
     guiWidget.Enabled = enabled;
 }
Beispiel #27
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.");
		}
Beispiel #28
0
 public RadioButton(GuiWidget view)
     : this(0, 0, view)
 {
 }
Beispiel #29
0
		private GuiWidget CreateLeftToRightMiddleWidget(BorderDouble buttonMargin, double buttonSize, VAnchor vAnchor, RGBA_Bytes color)
		{
			GuiWidget middle = new GuiWidget(buttonSize / 2, buttonSize);
			middle.Margin = buttonMargin;
			middle.HAnchor = HAnchor.ParentLeftRight;
			middle.VAnchor = vAnchor;
			middle.BackgroundColor = color;
			return middle;
		}
Beispiel #30
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);
			}
		}
        public ViewControls3D(MeshViewerWidget meshViewerWidget)
        {
            if (ActiveTheme.Instance.DisplayMode == ActiveTheme.ApplicationDisplayType.Touchscreen)
            {
                buttonHeight = 40;
            }
            else
            {
                buttonHeight = 20;
            }

            this.meshViewerWidget = meshViewerWidget;
            TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory();

            textImageButtonFactory.normalTextColor   = ActiveTheme.Instance.PrimaryTextColor;
            textImageButtonFactory.hoverTextColor    = ActiveTheme.Instance.PrimaryTextColor;
            textImageButtonFactory.disabledTextColor = ActiveTheme.Instance.PrimaryTextColor;
            textImageButtonFactory.pressedTextColor  = ActiveTheme.Instance.PrimaryTextColor;

            BackgroundColor = new RGBA_Bytes(0, 0, 0, 120);
            textImageButtonFactory.FixedHeight             = buttonHeight;
            textImageButtonFactory.FixedWidth              = buttonHeight;
            textImageButtonFactory.AllowThemeToAdjustImage = false;
            textImageButtonFactory.checkedBorderColor      = RGBA_Bytes.White;

            string rotateIconPath = Path.Combine("ViewTransformControls", "rotate.png");

            rotateButton             = textImageButtonFactory.GenerateRadioButton("", rotateIconPath);
            rotateButton.ToolTipText = "Rotate (Alt + L. Mouse)".Localize();
            rotateButton.Margin      = new BorderDouble(3);
            AddChild(rotateButton);
            rotateButton.Click += (sender, e) =>
            {
                this.ActiveButton = ViewControls3DButtons.Rotate;
            };

            string translateIconPath = Path.Combine("ViewTransformControls", "translate.png");

            translateButton             = textImageButtonFactory.GenerateRadioButton("", translateIconPath);
            translateButton.ToolTipText = "Move (Shift + L. Mouse)".Localize();
            translateButton.Margin      = new BorderDouble(3);
            AddChild(translateButton);
            translateButton.Click += (sender, e) =>
            {
                this.ActiveButton = ViewControls3DButtons.Translate;
            };

            string scaleIconPath = Path.Combine("ViewTransformControls", "scale.png");

            scaleButton             = textImageButtonFactory.GenerateRadioButton("", scaleIconPath);
            scaleButton.ToolTipText = "Zoom (Ctrl + L. Mouse)".Localize();
            scaleButton.Margin      = new BorderDouble(3);
            AddChild(scaleButton);
            scaleButton.Click += (sender, e) =>
            {
                this.ActiveButton = ViewControls3DButtons.Scale;
            };

            partSelectSeparator = new GuiWidget(2, 32);
            partSelectSeparator.BackgroundColor = RGBA_Bytes.White;
            partSelectSeparator.Margin          = new BorderDouble(3);
            AddChild(partSelectSeparator);

            string partSelectIconPath = Path.Combine("ViewTransformControls", "partSelect.png");

            partSelectButton             = textImageButtonFactory.GenerateRadioButton("", partSelectIconPath);
            partSelectButton.ToolTipText = "Select Part".Localize();
            partSelectButton.Margin      = new BorderDouble(3);
            AddChild(partSelectButton);
            partSelectButton.Click += (sender, e) =>
            {
                this.ActiveButton = ViewControls3DButtons.PartSelect;
            };

            Margin   = new BorderDouble(5);
            HAnchor |= Agg.UI.HAnchor.ParentLeft;
            VAnchor  = Agg.UI.VAnchor.ParentTop;
            rotateButton.Checked = true;

            SetMeshViewerDisplayTheme();
            partSelectButton.CheckedStateChanged += SetMeshViewerDisplayTheme;

            ActiveTheme.Instance.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents);
        }
Beispiel #32
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);
			}
		}
Beispiel #33
0
        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>();

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

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

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

                        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.Margin  = new BorderDouble(left: 10);
                        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;
        }
Beispiel #34
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.");
		}
Beispiel #35
0
        private void AddStandardUi(ThemeConfig theme)
        {
            var extensionArea = new LeftClipFlowLayoutWidget()
            {
                BackgroundColor = theme.TabBarBackground,
                VAnchor         = VAnchor.Stretch,
                Padding         = new BorderDouble(left: 8)
            };

            SearchPanel searchPanel = null;

            bool searchPanelOpenOnMouseDown = false;

            var searchButton = theme.CreateSearchButton();

            searchButton.Name       = "App Search Button";
            searchButton.MouseDown += (s, e) =>
            {
                searchPanelOpenOnMouseDown = searchPanel != null;
            };

            searchButton.Click += SearchButton_Click;
            extensionArea.AddChild(searchButton);

            async void SearchButton_Click(object sender, EventArgs e)
            {
                if (searchPanel == null && !searchPanelOpenOnMouseDown)
                {
                    void ShowSearchPanel()
                    {
                        searchPanel         = new SearchPanel(this.TabControl, searchButton, theme);
                        searchPanel.Closed += SearchPanel_Closed;

                        var systemWindow = this.Parents <SystemWindow>().FirstOrDefault();

                        systemWindow.ShowRightSplitPopup(
                            new MatePoint(searchButton),
                            new MatePoint(searchPanel),
                            borderWidth: 0);
                    }

                    if (HelpIndex.IndexExists)
                    {
                        ShowSearchPanel();
                    }
                    else
                    {
                        searchButton.Enabled = false;

                        try
                        {
                            // Show popover
                            var popover = new Popover(ArrowDirection.Up, 7, 5, 0)
                            {
                                TagColor = theme.AccentMimimalOverlay
                            };

                            popover.AddChild(new TextWidget("Preparing help".Localize() + "...", pointSize: theme.DefaultFontSize - 1, textColor: theme.TextColor));

                            popover.ArrowOffset = (int)(popover.Width - (searchButton.Width / 2));

                            this.Parents <SystemWindow>().FirstOrDefault().ShowPopover(
                                new MatePoint(searchButton)
                            {
                                Mate    = new MateOptions(MateEdge.Right, MateEdge.Bottom),
                                AltMate = new MateOptions(MateEdge.Right, MateEdge.Bottom),
                                Offset  = new RectangleDouble(12, 0, 12, 0)
                            },
                                new MatePoint(popover)
                            {
                                Mate    = new MateOptions(MateEdge.Right, MateEdge.Top),
                                AltMate = new MateOptions(MateEdge.Left, MateEdge.Bottom)
                            });

                            await Task.Run(async() =>
                            {
                                // Start index generation
                                await HelpIndex.RebuildIndex();

                                UiThread.RunOnIdle(() =>
                                {
                                    // Close popover
                                    popover.Close();

                                    // Continue to original task
                                    ShowSearchPanel();
                                });
                            });
                        }
                        catch
                        {
                        }

                        searchButton.Enabled = true;
                    }
                }
                else
                {
                    searchPanel?.CloseOnIdle();
                    searchPanelOpenOnMouseDown = false;
                }
            }

            void SearchPanel_Closed(object sender, EventArgs e)
            {
                // Unregister
                searchPanel.Closed -= SearchPanel_Closed;

                // Release
                searchPanel = null;
            }

            tabControl = new ChromeTabs(extensionArea, theme)
            {
                VAnchor         = VAnchor.Stretch,
                HAnchor         = HAnchor.Stretch,
                BackgroundColor = theme.BackgroundColor,
                BorderColor     = theme.MinimalShade,
                Border          = new BorderDouble(left: 1),
            };

            tabControl.PlusClicked += (s, e) => UiThread.RunOnIdle(() =>
            {
                this.CreatePartTab().ConfigureAwait(false);
            });

            // Force the ActionArea to be as high as ButtonHeight
            tabControl.TabBar.ActionArea.MinimumSize = new Vector2(0, theme.ButtonHeight);
            tabControl.TabBar.BackgroundColor        = theme.TabBarBackground;
            tabControl.TabBar.BorderColor            = theme.BackgroundColor;

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

            if (Application.EnableNetworkTraffic)
            {
                // add in the update available button
                updateAvailableButton = new LinkLabel("Update Available".Localize(), theme)
                {
                    Visible     = false,
                    Name        = "Update Available Link",
                    ToolTipText = "There is a new update available for download".Localize(),
                    VAnchor     = VAnchor.Center,
                    Margin      = new BorderDouble(10, 0),
                    TextColor   = theme.PrimaryAccentColor
                };

                // Register listeners
                UserSettings.Instance.SettingChanged += SetLinkButtonsVisibility;

                SetLinkButtonsVisibility(this, null);

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

                tabControl.TabBar.ActionArea.AddChild(updateAvailableButton);

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

            this.AddChild(tabControl);

            ApplicationController.Instance.NotifyPrintersTabRightElement(extensionArea);

            ChromeTab tab = null;

            // Upgrade tab
            if (!ApplicationController.Instance.IsMatterControlPro())
            {
                tabControl.AddTab(
                    tab = new ChromeTab("Upgrade", "Upgrade".Localize(), tabControl, new UpgradeToProTabPage(theme), theme, hasClose: false)
                {
                    MinimumSize = new Vector2(0, theme.TabButtonHeight),
                    Name        = "Upgrade",
                    Padding     = new BorderDouble(15, 0),
                });

                tab.AfterDraw += (s, e) =>
                {
                    e.Graphics2D.Circle(tab.LocalBounds.Right - 25 * DeviceScale,
                                        tab.LocalBounds.Bottom + tab.Height / 2 - 1 * DeviceScale,
                                        5 * DeviceScale,
                                        theme.PrimaryAccentColor);
                };
            }
            else
            {
                // Store tab
                tabControl.AddTab(
                    tab = new ChromeTab("Store", "Store".Localize(), tabControl, new StoreTabPage(theme), theme, hasClose: false)
                {
                    MinimumSize = new Vector2(0, theme.TabButtonHeight),
                    Name        = "Store Tab",
                    Padding     = new BorderDouble(15, 0),
                });
            }

            EnableReduceWidth(tab, theme);

            // Library tab
            var libraryWidget = new LibraryWidget(this, theme)
            {
                BackgroundColor = theme.BackgroundColor
            };

            tabControl.AddTab(
                tab = new ChromeTab("Library", "Library".Localize(), tabControl, libraryWidget, theme, hasClose: false)
            {
                MinimumSize = new Vector2(0, theme.TabButtonHeight),
                Name        = "Library Tab",
                Padding     = new BorderDouble(15, 0),
            });
            EnableReduceWidth(tab, theme);

            // Hardware tab
            tabControl.AddTab(
                tab = new ChromeTab(
                    "Hardware",
                    "Hardware".Localize(),
                    tabControl,
                    new HardwareTabPage(theme)
            {
                BackgroundColor = theme.BackgroundColor
            },
                    theme,
                    hasClose: false)
            {
                MinimumSize = new Vector2(0, theme.TabButtonHeight),
                Name        = "Hardware Tab",
                Padding     = new BorderDouble(15, 0),
            });
            EnableReduceWidth(tab, theme);

            SetInitialTab();

            var brandMenu = new BrandMenuButton(theme)
            {
                HAnchor         = HAnchor.Fit,
                VAnchor         = VAnchor.Fit,
                BackgroundColor = theme.TabBarBackground,
                Padding         = theme.TabbarPadding.Clone(right: theme.DefaultContainerPadding)
            };

            tabControl.TabBar.ActionArea.AddChild(brandMenu, 0);

            tabControl.TabBar.ActionArea.VAnchor = VAnchor.Absolute;
            tabControl.TabBar.ActionArea.Height  = brandMenu.Height;

            // Restore active workspace tabs
            foreach (var workspace in ApplicationController.Instance.Workspaces)
            {
                ChromeTab newTab;

                // Create and switch to new printer tab
                if (workspace.Printer?.Settings.PrinterSelected == true)
                {
                    newTab = this.CreatePrinterTab(workspace, theme);
                }
                else
                {
                    newTab = this.CreatePartTab(workspace);
                }

                if (newTab.Key == ApplicationController.Instance.MainTabKey)
                {
                    tabControl.ActiveTab = newTab;
                }

                tabControl.RefreshTabPointers();
            }

            statusBar = new Toolbar(theme.TabbarPadding)
            {
                HAnchor         = HAnchor.Stretch,
                VAnchor         = VAnchor.Absolute,
                Padding         = 1,
                Height          = 22 * GuiWidget.DeviceScale,
                BackgroundColor = theme.BackgroundColor,
                Border          = new BorderDouble(top: 1),
                BorderColor     = theme.BorderColor20,
            };
            this.AddChild(statusBar);

            statusBar.ActionArea.VAnchor = VAnchor.Stretch;

            tasksContainer = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                HAnchor         = HAnchor.Fit,
                VAnchor         = VAnchor.Stretch,
                BackgroundColor = theme.MinimalShade,
                Name            = "runningTasksPanel"
            };
            statusBar.AddChild(tasksContainer);

            stretchStatusPanel = new GuiWidget()
            {
                HAnchor         = HAnchor.Stretch,
                VAnchor         = VAnchor.Stretch,
                Padding         = new BorderDouble(right: 3),
                Margin          = new BorderDouble(right: 2, top: 1, bottom: 1),
                Border          = new BorderDouble(1),
                BackgroundColor = theme.MinimalShade.WithAlpha(10),
                BorderColor     = theme.SlightShade,
                Width           = 200 * GuiWidget.DeviceScale
            };
            statusBar.AddChild(stretchStatusPanel);

            var panelBackgroundColor = theme.MinimalShade.WithAlpha(10);

            statusBar.AddChild(this.CreateThemeStatusPanel(theme, panelBackgroundColor));

            statusBar.AddChild(this.CreateNetworkStatusPanel(theme));

            this.RenderRunningTasks(theme, ApplicationController.Instance.Tasks);
        }
Beispiel #36
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);
			}
		}
Beispiel #37
0
        public RunningTaskRow(string title, RunningTaskDetails taskDetails, ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            this.taskDetails = taskDetails;
            this.theme       = theme;

            this.MinimumSize = new Vector2(100, 20);

            var detailsPanel = new GuiWidget()
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit,
            };

            var rowContainer = new GuiWidget()
            {
                VAnchor = VAnchor.Fit,
                HAnchor = HAnchor.Stretch,
            };

            this.AddChild(rowContainer);

            var topRow = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit,
                Padding = 0,
            };

            rowContainer.AddChild(topRow);

            progressBar = new ProgressBar()
            {
                HAnchor     = HAnchor.Stretch,
                Height      = 2 * GuiWidget.DeviceScale,
                VAnchor     = VAnchor.Absolute | VAnchor.Bottom,
                FillColor   = theme.PrimaryAccentColor,
                BorderColor = Color.Transparent,
                Margin      = new BorderDouble(32, 7, theme.ButtonHeight * 2 + 14, 0),
                Visible     = !taskDetails.IsExpanded
            };
            rowContainer.AddChild(progressBar);

            expandButton = new ExpandCheckboxButton(!string.IsNullOrWhiteSpace(title) ? title : taskDetails.Title, theme, 10)
            {
                VAnchor         = VAnchor.Center | VAnchor.Fit,
                HAnchor         = HAnchor.Stretch,
                Checked         = false,
                Padding         = 0,
                AlwaysShowArrow = true
            };
            expandButton.CheckedStateChanged += (s, e) =>
            {
                taskDetails.IsExpanded = expandButton.Checked;
                SetExpansionMode(theme, detailsPanel, expandButton.Checked);
            };
            topRow.AddChild(expandButton);

            IconButton resumeButton = null;

            var pauseButton = new IconButton(AggContext.StaticData.LoadIcon("fa-pause_12.png", 12, 12, theme.InvertIcons), theme)
            {
                Margin      = theme.ButtonSpacing,
                Enabled     = taskDetails.Options?.PauseAction != null,
                ToolTipText = taskDetails.Options?.PauseToolTip ?? "Pause".Localize()
            };

            if (taskDetails.Options?.IsPaused != null)
            {
                RunningInterval runningInterval = null;
                runningInterval = UiThread.SetInterval(() =>
                {
                    if (taskDetails.Options.IsPaused())
                    {
                        pauseButton.Visible  = false;
                        resumeButton.Visible = true;
                    }
                    else
                    {
                        pauseButton.Visible  = true;
                        resumeButton.Visible = false;
                    }
                    if (this.HasBeenClosed)
                    {
                        UiThread.ClearInterval(runningInterval);
                    }
                }, .2);
            }
            pauseButton.Click += (s, e) =>
            {
                taskDetails.Options?.PauseAction();
                pauseButton.Visible  = false;
                resumeButton.Visible = true;
            };
            topRow.AddChild(pauseButton);

            resumeButton = new IconButton(AggContext.StaticData.LoadIcon("fa-play_12.png", 12, 12, theme.InvertIcons), theme)
            {
                Visible     = false,
                Margin      = theme.ButtonSpacing,
                ToolTipText = taskDetails.Options?.ResumeToolTip ?? "Resume".Localize(),
                Name        = "Resume Task Button"
            };
            resumeButton.Click += (s, e) =>
            {
                taskDetails.Options?.ResumeAction();
                pauseButton.Visible  = true;
                resumeButton.Visible = false;
            };
            topRow.AddChild(resumeButton);

            var stopButton = new IconButton(AggContext.StaticData.LoadIcon("fa-stop_12.png", 12, 12, theme.InvertIcons), theme)
            {
                Margin      = theme.ButtonSpacing,
                Name        = "Stop Task Button",
                ToolTipText = taskDetails.Options?.StopToolTip ?? "Cancel".Localize()
            };

            stopButton.Click += (s, e) =>
            {
                var stopAction = taskDetails.Options?.StopAction;
                if (stopAction == null)
                {
                    taskDetails.CancelTask();
                }
                else
                {
                    stopAction.Invoke(() =>
                    {
                        stopButton.Enabled = true;
                    });
                }

                stopButton.Enabled = false;
            };
            topRow.AddChild(stopButton);

            this.AddChild(detailsPanel);

            // Add rich progress controls
            if (taskDetails.Options?.RichProgressWidget?.Invoke() is GuiWidget guiWidget)
            {
                detailsPanel.AddChild(guiWidget);
            }
            else
            {
                expandButton.Expandable = false;
            }

            if (taskDetails.Options?.ReadOnlyReporting == true)
            {
                stopButton.Visible   = false;
                pauseButton.Visible  = false;
                resumeButton.Visible = false;

                // Ensure the top row is as big as it would be with buttons
                topRow.MinimumSize = new Vector2(0, resumeButton.Height);
            }

            SetExpansionMode(theme, detailsPanel, taskDetails.IsExpanded);

            taskDetails.ProgressChanged += TaskDetails_ProgressChanged;
        }
        public MainViewWidget(ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            this.AnchorAll();
            this.theme           = theme;
            this.Name            = "PartPreviewContent";
            this.BackgroundColor = theme.BackgroundColor;

            // Push TouchScreenMode into GuiWidget
            GuiWidget.TouchScreenMode = UserSettings.Instance.IsTouchScreen;

            var extensionArea = new LeftClipFlowLayoutWidget()
            {
                BackgroundColor = theme.TabBarBackground,
                VAnchor         = VAnchor.Stretch,
                Padding         = new BorderDouble(left: 8)
            };

            tabControl = new ChromeTabs(extensionArea, theme)
            {
                VAnchor         = VAnchor.Stretch,
                HAnchor         = HAnchor.Stretch,
                BackgroundColor = theme.BackgroundColor,
                BorderColor     = theme.MinimalShade,
                Border          = new BorderDouble(left: 1),
            };

            tabControl.PlusClicked += (s, e) => UiThread.RunOnIdle(() =>
            {
                this.CreatePartTab().ConfigureAwait(false);
            });

            // Force the ActionArea to be as high as ButtonHeight
            tabControl.TabBar.ActionArea.MinimumSize = new Vector2(0, theme.ButtonHeight);
            tabControl.TabBar.BackgroundColor        = theme.TabBarBackground;
            tabControl.TabBar.BorderColor            = theme.BackgroundColor;

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

            if (Application.EnableNetworkTraffic)
            {
                // add in the update available button
                updateAvailableButton = new LinkLabel("Update Available".Localize(), theme)
                {
                    Visible     = false,
                    Name        = "Update Available Link",
                    ToolTipText = "There is a new update available for download".Localize(),
                    VAnchor     = VAnchor.Center,
                    Margin      = new BorderDouble(10, 0)
                };

                // Register listeners
                UserSettings.Instance.SettingChanged += SetLinkButtonsVisibility;

                SetLinkButtonsVisibility(this, null);

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

                tabControl.TabBar.ActionArea.AddChild(updateAvailableButton);

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

            this.AddChild(tabControl);

            ApplicationController.Instance.NotifyPrintersTabRightElement(extensionArea);

            // Store tab
            tabControl.AddTab(
                new ChromeTab("Store", "Store".Localize(), tabControl, new StoreTabPage(theme), theme, hasClose: false)
            {
                MinimumSize = new Vector2(0, theme.TabButtonHeight),
                Name        = "Store Tab",
                Padding     = new BorderDouble(15, 0),
            });

            // Library tab
            var libraryWidget = new LibraryWidget(this, theme)
            {
                BackgroundColor = theme.BackgroundColor
            };

            tabControl.AddTab(
                new ChromeTab("Library", "Library".Localize(), tabControl, libraryWidget, theme, hasClose: false)
            {
                MinimumSize = new Vector2(0, theme.TabButtonHeight),
                Name        = "Library Tab",
                Padding     = new BorderDouble(15, 0),
            });

            // Hardware tab
            tabControl.AddTab(
                new ChromeTab(
                    "Hardware",
                    "Hardware".Localize(),
                    tabControl,
                    new HardwareTabPage(theme)
            {
                BackgroundColor = theme.BackgroundColor
            },
                    theme,
                    hasClose: false)
            {
                MinimumSize = new Vector2(0, theme.TabButtonHeight),
                Name        = "Hardware Tab",
                Padding     = new BorderDouble(15, 0),
            });

            string tabKey = ApplicationController.Instance.MainTabKey;

            if (string.IsNullOrEmpty(tabKey))
            {
                tabKey = "Hardware";
            }

            // HACK: Restore to the first printer tab if PrinterTabSelected and tabKey not found. This allows sign in/out to remain on the printer tab across different users
            if (!tabControl.AllTabs.Any(t => t.Key == tabKey) &&
                ApplicationController.Instance.PrinterTabSelected)
            {
                var key = tabControl.AllTabs.Where(t => t.TabContent is PrinterTabPage).FirstOrDefault()?.Key;
                if (key != null)
                {
                    tabKey = key;
                }
            }

            var brandMenu = new BrandMenuButton(theme)
            {
                HAnchor         = HAnchor.Fit,
                VAnchor         = VAnchor.Fit,
                BackgroundColor = theme.TabBarBackground,
                Padding         = theme.TabbarPadding.Clone(right: theme.DefaultContainerPadding)
            };

            tabControl.TabBar.ActionArea.AddChild(brandMenu, 0);

            // Restore active workspace tabs
            foreach (var workspace in ApplicationController.Instance.Workspaces)
            {
                // Create and switch to new printer tab
                if (workspace.Printer?.Settings.PrinterSelected == true)
                {
                    tabControl.ActiveTab = this.CreatePrinterTab(workspace, theme);
                }
                else
                {
                    tabControl.ActiveTab = this.CreatePartTab(workspace);
                }

                tabControl.RefreshTabPointers();
            }

            tabControl.SelectedTabKey = tabKey;

            statusBar = new Toolbar(theme)
            {
                HAnchor         = HAnchor.Stretch,
                VAnchor         = VAnchor.Absolute,
                Padding         = 1,
                Height          = 22,
                BackgroundColor = theme.BackgroundColor,
                Border          = new BorderDouble(top: 1),
                BorderColor     = theme.BorderColor20,
            };
            this.AddChild(statusBar);

            statusBar.ActionArea.VAnchor = VAnchor.Stretch;

            tasksContainer = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                HAnchor         = HAnchor.Fit,
                VAnchor         = VAnchor.Stretch,
                BackgroundColor = theme.MinimalShade,
                Name            = "runningTasksPanel"
            };
            statusBar.AddChild(tasksContainer);

            stretchStatusPanel = new GuiWidget()
            {
                HAnchor         = HAnchor.Stretch,
                VAnchor         = VAnchor.Stretch,
                Padding         = new BorderDouble(right: 3),
                Margin          = new BorderDouble(right: 2, top: 1, bottom: 1),
                Border          = new BorderDouble(1),
                BackgroundColor = theme.MinimalShade.WithAlpha(10),
                BorderColor     = theme.SlightShade,
                Width           = 200
            };
            statusBar.AddChild(stretchStatusPanel);

            var panelBackgroundColor = theme.MinimalShade.WithAlpha(10);

            statusBar.AddChild(
                this.CreateThemeStatusPanel(theme, panelBackgroundColor));

            statusBar.AddChild(
                this.CreateNetworkStatusPanel(theme));

            this.RenderRunningTasks(theme, ApplicationController.Instance.Tasks);

            // Register listeners
            PrinterSettings.AnyPrinterSettingChanged          += Printer_SettingChanged;
            ApplicationController.Instance.WorkspacesChanged  += Workspaces_Changed;
            ApplicationController.Instance.Tasks.TasksChanged += Tasks_TasksChanged;
            tabControl.ActiveTabChanged += TabControl_ActiveTabChanged;

            ApplicationController.Instance.ShellFileOpened += this.Instance_OpenNewFile;

            ApplicationController.Instance.MainView = this;
        }
 /// <summary>
 /// Helper method to populate the DisableableWidgets local property.
 /// </summary>
 /// <param name="widget">The widget to add and return.</param>
 private GuiWidget AddToDisableableList(GuiWidget widget)
 {
     this.DisableableWidgets.Add(widget);
     return(widget);
 }
Beispiel #40
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 EditLevelingSettingsWindow()
            : base(400, 200)
        {
            Title = LocalizedString.Get("Leveling Settings".Localize());

            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("Sampled Positions".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);

            BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;

            double oldHeight = textImageButtonFactory.FixedHeight;

            textImageButtonFactory.FixedHeight = 30;

            // put in the movement edit controls
            PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(ActivePrinterProfile.Instance.ActivePrinter);

            positions[0] = levelingData.sampledPosition0;
            positions[1] = levelingData.sampledPosition1;
            positions[2] = levelingData.sampledPosition2;

            int tab_index = 0;

            for (int row = 0; row < 3; row++)
            {
                FlowLayoutWidget leftRightEdit = new FlowLayoutWidget();
                leftRightEdit.Padding  = new BorderDouble(3);
                leftRightEdit.HAnchor |= Agg.UI.HAnchor.ParentLeftRight;
                TextWidget positionLabel;

                string whichPositionText = LocalizedString.Get("Position");
                positionLabel = new TextWidget("{0} {1,-5}".FormatWith(whichPositionText, row + 1), textColor: ActiveTheme.Instance.PrimaryTextColor);

                positionLabel.VAnchor = VAnchor.ParentCenter;
                leftRightEdit.AddChild(positionLabel);

                for (int axis = 0; axis < 3; axis++)
                {
                    GuiWidget hSpacer = new GuiWidget();
                    hSpacer.HAnchor = HAnchor.ParentLeftRight;

                    leftRightEdit.AddChild(hSpacer);

                    string axisName = "x";
                    if (axis == 1)
                    {
                        axisName = "y";
                    }
                    else if (axis == 2)
                    {
                        axisName = "z";
                    }

                    TextWidget typeEdit = new TextWidget("  {0}: ".FormatWith(axisName), textColor: ActiveTheme.Instance.PrimaryTextColor);
                    typeEdit.VAnchor = VAnchor.ParentCenter;
                    leftRightEdit.AddChild(typeEdit);

                    int    linkCompatibleRow  = row;
                    int    linkCompatibleAxis = axis;
                    double minValue           = double.MinValue;
                    if (axis == 2 && ActiveSliceSettings.Instance.GetActiveValue("z_can_be_negative") == "0")
                    {
                        minValue = 0;
                    }
                    MHNumberEdit valueEdit = new MHNumberEdit(positions[linkCompatibleRow][linkCompatibleAxis], allowNegatives: true, allowDecimals: true, minValue: minValue, pixelWidth: 60, tabIndex: tab_index++);
                    valueEdit.ActuallNumberEdit.InternalTextEditWidget.EditComplete += (sender, e) =>
                    {
                        positions[linkCompatibleRow][linkCompatibleAxis] = valueEdit.ActuallNumberEdit.Value;
                    };

                    valueEdit.Margin = new BorderDouble(3);
                    leftRightEdit.AddChild(valueEdit);
                }

                presetsFormContainer.AddChild(leftRightEdit);

                presetsFormContainer.AddChild(new CustomWidgets.HorizontalLine());
            }

            textImageButtonFactory.FixedHeight = oldHeight;


            ShowAsSystemWindow();
            MinimumSize = new Vector2(Width, Height);

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

            savePresetsButton.Click += new EventHandler(save_Click);

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

            cancelPresetsButton.Click += (sender, e) =>
            {
                UiThread.RunOnIdle((state) =>
                {
                    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);
        }
Beispiel #42
0
        public TreeNode(ThemeConfig theme, bool useIcon = true, TreeNode nodeParent = null)
            : base(FlowDirection.TopToBottom)
        {
            this.HAnchor = HAnchor.Fit | HAnchor.Left;
            this.VAnchor = VAnchor.Fit;

            this.NodeParent = nodeParent;

            this.TitleBar        = new FlowLayoutWidget();
            this.TitleBar.Click += (s, e) =>
            {
                if (TreeView != null)
                {
                    TreeView.SelectedNode = this;
                }

                this.TreeView.NotifyItemClicked(this.TitleBar, e);
            };

            this.TitleBar.MouseDown += (s, e) =>
            {
                if (TreeView != null &&
                    e.Button == MouseButtons.Left &&
                    e.Clicks == 2)
                {
                    TreeView.SelectedNode = this;
                    this.TreeView.NotifyItemDoubleClicked(this.TitleBar, e);
                }
            };

            this.AddChild(this.TitleBar);

            // add a check box
            expandWidget = new TreeExpandWidget(theme)
            {
                Expandable = GetNodeCount(false) != 0,
                VAnchor    = VAnchor.Fit | VAnchor.Center,
                Height     = 16,
                Width      = 16
            };

            expandWidget.Click += (s, e) =>
            {
                this.Expanded         = !this.Expanded;
                expandWidget.Expanded = this.Expanded;
            };

            this.TitleBar.AddChild(expandWidget);

            this.HighlightRegion = new FlowLayoutWidget()
            {
                VAnchor    = VAnchor.Fit,
                HAnchor    = HAnchor.Fit,
                Padding    = useIcon ? new BorderDouble(2) : new BorderDouble(4, 2),
                Selectable = false
            };
            this.TitleBar.AddChild(this.HighlightRegion);

            // add a check box
            if (useIcon)
            {
                _image = new ImageBuffer(16, 16);

                this.HighlightRegion.AddChild(imageWidget = new ImageWidget(this.Image, listenForImageChanged: false)
                {
                    VAnchor    = VAnchor.Center,
                    Margin     = new BorderDouble(right: 4),
                    Selectable = false
                });
            }
            ;

            this.HighlightRegion.AddChild(textWidget = new TextWidget(this.Text, pointSize: theme.DefaultFontSize, textColor: theme.TextColor)
            {
                Selectable             = false,
                AutoExpandBoundsToText = true,
                VAnchor = VAnchor.Center
            });

            content = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Fit | HAnchor.Left,
                Visible = false,                 // content starts out not visible
                Name    = "content",
                Margin  = new BorderDouble(12, 3),
            };
            this.AddChild(content);

            // Register listeners
            this.Nodes.CollectionChanged += this.Nodes_CollectionChanged;
        }
Beispiel #43
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;
			}
		}
Beispiel #44
0
 public override void AddChild(GuiWidget childToAdd, int indexInChildrenList = -1)
 {
     ActionArea.AddChild(childToAdd, indexInChildrenList);
 }
Beispiel #45
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);
		}
Beispiel #46
0
 // If max height is > 0 it will limit the height of the menu
 public Menu(GuiWidget view, Direction direction = Direction.Down, double maxHeight = 0)
     : this(direction, maxHeight)
 {
     AddChild(view);
 }
Beispiel #47
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.");
		}
Beispiel #48
0
		private void OutputImages(GuiWidget control, GuiWidget test)
		{
			OutputImage(control, "image-control.tga");
			OutputImage(test, "image-test.tga");
		}
Beispiel #49
0
 public override void AddChild(GuiWidget childToAdd, int indexInChildrenList = -1)
 {
     childToAdd.VAnchor = VAnchor.Center;
     base.AddChild(childToAdd, indexInChildrenList);
 }
 internal void SetRenderTarget(GuiWidget renderSource)
 {
     this.renderSource       = renderSource;
     renderSource.AfterDraw += RenderSource_DrawExtra;
 }
Beispiel #51
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.");
		}
Beispiel #52
0
 public void SetHoveredWidget(GuiWidget widgetToShowToolTipFor)
 {
     ToolTipManager.SetHoveredWidget(widgetToShowToolTipFor);
 }
Beispiel #53
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.");
		}
Beispiel #54
0
        public SimpleTab(string tabLabel, SimpleTabs parentTabControl, GuiWidget tabContent, ThemeConfig theme, string tabImageUrl = null, bool hasClose = true, double pointSize = 12, ImageBuffer iconImage = null)
        {
            this.HAnchor = HAnchor.Fit;
            this.VAnchor = VAnchor.Fit | VAnchor.Bottom;
            this.Padding = 0;
            this.Margin  = 0;
            this.theme   = theme;

            this.TabContent       = tabContent;
            this.parentTabControl = parentTabControl;

            if (iconImage != null)
            {
                tabPill = new TabPill(tabLabel, ActiveTheme.Instance.PrimaryTextColor, iconImage, pointSize);
            }
            else
            {
                tabPill = new TabPill(tabLabel, ActiveTheme.Instance.PrimaryTextColor, tabImageUrl, pointSize);
            }
            tabPill.Margin = (hasClose) ? new BorderDouble(right: 16) : 0;

            this.AddChild(tabPill);

            if (hasClose)
            {
                var closeButton = theme.CreateSmallResetButton();
                closeButton.HAnchor     = HAnchor.Right;
                closeButton.Margin      = new BorderDouble(right: 7, top: 1);
                closeButton.Name        = "Close Tab Button";
                closeButton.ToolTipText = "Close".Localize();
                closeButton.Click      += (sender, e) =>
                {
                    UiThread.RunOnIdle(() =>
                    {
                        if (TabContent is PrinterTabPage printerTab &&
                            printerTab.printer.Connection.PrinterIsPrinting)
                        {
                            StyledMessageBox.ShowMessageBox(
                                (bool response) =>
                            {
                                if (response)
                                {
                                    UiThread.RunOnIdle(() =>
                                    {
                                        this.parentTabControl.RemoveTab(this);
                                        this.CloseClicked?.Invoke(this, null);
                                    });
                                }
                            },
                                "Cancel the current print?".Localize(),
                                "Cancel Print?".Localize(),
                                StyledMessageBox.MessageType.YES_NO,
                                "Cancel Print".Localize(),
                                "Continue Printing".Localize());
                        }
                        else                         // need to handle asking about saving a
                        {
                            UiThread.RunOnIdle(() =>
                            {
                                this.parentTabControl.RemoveTab(this);
                                this.CloseClicked?.Invoke(this, null);
                            });
                        }
                    });
Beispiel #55
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 static GuiWidget GetQualityWidget(ThemeConfig theme, PrintTask printTask, Action clicked, double buttonFontSize)
        {
            var content = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.Fit | HAnchor.Stretch
            };
            var siblings = new List <GuiWidget>();

            var textWidget = new TextWidget("Print Quality".Localize() + ":", pointSize: theme.DefaultFontSize, textColor: theme.TextColor)
            {
                VAnchor = VAnchor.Center
            };

            content.AddChild(textWidget);

            var size = (int)(buttonFontSize * GuiWidget.DeviceScale);

            var star     = StaticData.Instance.LoadIcon("star.png", size, size, theme.InvertIcons);
            var openStar = StaticData.Instance.LoadIcon("open_star.png", size, size, theme.InvertIcons);
            var failure  = StaticData.Instance.LoadIcon("failure.png", size, size, theme.InvertIcons);

            content.AddChild(new GuiWidget(size, 1));

            content.MouseLeaveBounds += (s, e) =>
            {
                SetStarState(theme, siblings, printTask);
            };

            for (int i = 0; i < QualityNames.Length; i++)
            {
                var       buttonIndex = i;
                GuiWidget buttonContent;
                if (i == 0)
                {
                    buttonContent = new ImageWidget(failure);
                }
                else
                {
                    buttonContent = new GuiWidget()
                    {
                        HAnchor = HAnchor.Fit,
                        VAnchor = VAnchor.Fit
                    };
                    buttonContent.AddChild(new ImageWidget(openStar)
                    {
                        Name = "open"
                    });
                    buttonContent.AddChild(new ImageWidget(star)
                    {
                        Name    = "closed",
                        Visible = false
                    });
                }

                var button = new RadioButton(buttonContent)
                {
                    Enabled     = printTask.PrintComplete,
                    Checked     = printTask.QualityWasSet && printTask.PrintQuality == i,
                    ToolTipText = QualityNames[i],
                    Margin      = 0,
                    Padding     = 5,
                    HAnchor     = HAnchor.Fit,
                    VAnchor     = VAnchor.Fit,
                };

                button.MouseEnterBounds += (s, e) =>
                {
                    // set the correct filled stars for the hover
                    for (int j = 0; j < siblings.Count; j++)
                    {
                        var open   = siblings[j].Descendants().Where(d => d.Name == "open").FirstOrDefault();
                        var closed = siblings[j].Descendants().Where(d => d.Name == "closed").FirstOrDefault();

                        if (j == 0)
                        {
                            if (buttonIndex == 0)
                            {
                                siblings[j].BackgroundColor = theme.AccentMimimalOverlay;
                            }
                            else
                            {
                                siblings[j].BackgroundColor = Color.Transparent;
                            }
                        }
                        else if (j <= buttonIndex)
                        {
                            siblings[j].BackgroundColor = theme.AccentMimimalOverlay;
                        }
                        else
                        {
                            siblings[j].BackgroundColor = Color.Transparent;
                        }

                        if (j <= buttonIndex)
                        {
                            if (open != null)
                            {
                                open.Visible   = false;
                                closed.Visible = true;
                            }
                        }
                        else
                        {
                            if (open != null)
                            {
                                open.Visible   = true;
                                closed.Visible = false;
                            }
                        }
                    }
                };

                siblings.Add(button);

                button.SiblingRadioButtonList = siblings;

                content.AddChild(button);

                button.Click += (s, e) =>
                {
                    printTask.PrintQuality  = siblings.IndexOf((GuiWidget)s);
                    printTask.QualityWasSet = true;
                    printTask.CommitAndPushToServer();
                    clicked();
                };
            }

            SetStarState(theme, siblings, printTask);

            return(content);
        }
Beispiel #57
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.");
		}
        public static GuiWidget CreateDefaultOptions(GuiWidget textField, ThemeConfig theme, Action selectionChanged)
        {
            var selectString   = "- " + "What went wrong?".Localize() + " -";
            var menuButton     = new PopupMenuButton(selectString, theme);
            var menuButtonText = menuButton.Descendants <TextWidget>().First();

            menuButtonText.AutoExpandBoundsToText = true;

            void AddSelection(PopupMenu menu, string text, bool other = false)
            {
                var menuItem = menu.CreateMenuItem(text);

                menuItem.Click += (s, e) =>
                {
                    if (other)
                    {
                        textField.Text    = "";
                        textField.Visible = true;
                        UiThread.RunOnIdle(textField.Focus);
                        menuButtonText.Text = "Other".Localize() + "...";
                    }
                    else
                    {
                        textField.Text      = text;
                        textField.Visible   = false;
                        menuButtonText.Text = textField.Text;
                    }

                    selectionChanged?.Invoke();
                };
            }

            menuButton.DynamicPopupContent = () =>
            {
                var popupMenu = new PopupMenu(ApplicationController.Instance.MenuTheme);

                popupMenu.CreateSubMenu("First Layer".Localize(),
                                        theme,
                                        (menu) =>
                {
                    AddSelection(menu, "First Layer Bad Quality".Localize());
                    AddSelection(menu, "Initial Z Height Incorrect".Localize());
                });
                popupMenu.CreateSubMenu("Quality".Localize(),
                                        theme,
                                        (menu) =>
                {
                    AddSelection(menu, "General Quality".Localize());
                    AddSelection(menu, "Rough Overhangs".Localize());
                    AddSelection(menu, "Skipped Layers".Localize());
                    AddSelection(menu, "Some Parts Lifted".Localize());
                    AddSelection(menu, "Stringing / Poor retractions".Localize());
                    AddSelection(menu, "Warping".Localize());
                    AddSelection(menu, "Dislodged From Bed".Localize());
                    AddSelection(menu, "Layer Shift".Localize());
                });
                popupMenu.CreateSubMenu("Mechanical".Localize(),
                                        theme,
                                        (menu) =>
                {
                    AddSelection(menu, "Bed Dislodged".Localize());
                    AddSelection(menu, "Bowden Tube Popped Out".Localize());
                    AddSelection(menu, "Extruder Slipping".Localize());
                    AddSelection(menu, "Flooded Hot End".Localize());
                    AddSelection(menu, "Power Outage".Localize());
                });
                popupMenu.CreateSubMenu("Computer / MatterControl    ".Localize(),
                                        theme,
                                        (menu) =>
                {
                    AddSelection(menu, "Computer Crashed".Localize());
                    AddSelection(menu, "Computer Slow / Lagging".Localize());
                    AddSelection(menu, "Couldn't Resume".Localize());
                    AddSelection(menu, "Wouldn’t Slice Correctly".Localize());
                });
                popupMenu.CreateSubMenu("Filament".Localize(),
                                        theme,
                                        (menu) =>
                {
                    AddSelection(menu, "Filament Jam".Localize());
                    AddSelection(menu, "Filament Runout".Localize());
                    AddSelection(menu, "Filament Snapped".Localize());
                });
                popupMenu.CreateSubMenu("Heating".Localize(),
                                        theme,
                                        (menu) =>
                {
                    AddSelection(menu, "Thermal Runaway - Bed".Localize());
                    AddSelection(menu, "Thermal Runaway - Hot End".Localize());
                    AddSelection(menu, "Heating".Localize());
                    AddSelection(menu, "Took Too Long To Heat".Localize());
                    AddSelection(menu, "Bad Thermistor".Localize());
                    AddSelection(menu, "Bad Thermistor".Localize());
                });
                AddSelection(popupMenu, "Test Print".Localize());
                AddSelection(popupMenu, "User Error".Localize());
                AddSelection(popupMenu, "Other".Localize(), true);

                return(popupMenu);
            };

            textField.Visible  = false;
            menuButton.VAnchor = VAnchor.Fit;

            return(menuButton);
        }
Beispiel #59
0
 public ButtonWidget(Game game, string label, GuiWidget[] widgets, Action action = null)
     : this(game, label, action)
 {
     Widgets.AddRange(widgets);
 }
        private async void GetFilesAndCollectionsInCurrentDirectory(bool recursive = false)
        {
            List <string> newReadDirectoryDirectories = new List <string>();
            List <string> newReadDirectoryFiles       = new List <string>();

            await Task.Run(() =>
            {
                try
                {
                    string[] directories = null;
                    if (recursive)
                    {
                        directories = Directory.GetDirectories(Path.Combine(rootPath, currentDirectory), "*.*", SearchOption.AllDirectories);
                    }
                    else
                    {
                        directories = Directory.GetDirectories(Path.Combine(rootPath, currentDirectory));
                    }
                    foreach (string directoryName in directories)
                    {
                        string subPath = directoryName.Substring(rootPath.Length + 1);
                        newReadDirectoryDirectories.Add(subPath);
                    }
                }
                catch (Exception)
                {
                    GuiWidget.BreakInDebugger();
                }

                try
                {
                    string upperFilter = keywordFilter.ToUpper();
                    string[] files     = Directory.GetFiles(Path.Combine(rootPath, currentDirectory));
                    foreach (string filename in files)
                    {
                        string fileExtensionLower = Path.GetExtension(filename).ToLower();
                        if (!string.IsNullOrEmpty(fileExtensionLower) &&
                            ApplicationSettings.LibraryFilterFileExtensions.Contains(fileExtensionLower))
                        {
                            if (upperFilter.Trim() == string.Empty ||
                                FileNameContainsFilter(filename, upperFilter))
                            {
                                newReadDirectoryFiles.Add(filename);
                            }
                        }
                    }
                    if (recursive)
                    {
                        foreach (string directory in newReadDirectoryDirectories)
                        {
                            string subDirectory        = Path.Combine(rootPath, directory);
                            string[] subDirectoryFiles = Directory.GetFiles(subDirectory);
                            foreach (string filename in subDirectoryFiles)
                            {
                                if (ApplicationSettings.LibraryFilterFileExtensions.Contains(Path.GetExtension(filename).ToLower()))
                                {
                                    if (keywordFilter.Trim() == string.Empty ||
                                        FileNameContainsFilter(filename, upperFilter))
                                    {
                                        newReadDirectoryFiles.Add(filename);
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    GuiWidget.BreakInDebugger();
                }
            });

            if (recursive)
            {
                currentDirectoryDirectories.Clear();
            }
            else
            {
                currentDirectoryDirectories = newReadDirectoryDirectories;
            }
            currentDirectoryFiles = newReadDirectoryFiles;

            OnDataReloaded(null);
        }