Exemple #1
0
        public RadioTextButton CreateMicroRadioButton(string text, IList <GuiWidget> siblingRadioButtonList = null)
        {
            var radioButton = new RadioTextButton(text, this, this.FontSize8)
            {
                SiblingRadioButtonList = siblingRadioButtonList,
                Padding = new BorderDouble(5, 0),
                SelectedBackgroundColor   = this.SlightShade,
                UnselectedBackgroundColor = this.SlightShade,
                HoverColor = this.AccentMimimalOverlay,
                Margin     = new BorderDouble(right: 1),
                HAnchor    = HAnchor.Absolute,
                Height     = this.MicroButtonHeight,
                Width      = this.MicroButtonWidth
            };

            // Add to sibling list if supplied
            siblingRadioButtonList?.Add(radioButton);

            return(radioButton);
        }
Exemple #2
0
        public JogControls(PrinterConfig printer, XYZColors colors, ThemeConfig theme)
        {
            this.theme   = theme;
            this.printer = printer;

            double distanceBetweenControls  = 12;
            double buttonSeparationDistance = 10;

            var allControlsTopToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Stretch
            };

            var allControlsLeftToRight = new FlowLayoutWidget();

            using (allControlsLeftToRight.LayoutLock())
            {
                var xYZWithDistance = new FlowLayoutWidget(FlowDirection.TopToBottom);
                {
                    var xYZControls = new FlowLayoutWidget();
                    xYZControls.AddChild(this.CreateXYGridControl(colors, distanceBetweenControls, buttonSeparationDistance));

                    FlowLayoutWidget zButtons = JogControls.CreateZButtons(printer, buttonSeparationDistance, out zPlusControl, out zMinusControl, colors, theme);
                    zButtons.VAnchor = VAnchor.Bottom;
                    xYZControls.AddChild(zButtons);
                    xYZWithDistance.AddChild(xYZControls);

                    // add in some movement radio buttons
                    var setMoveDistanceControl = new FlowLayoutWidget
                    {
                        HAnchor = HAnchor.Left | HAnchor.Fit,
                        VAnchor = VAnchor.Fit
                    };

                    {
                        var moveRadioButtons = new FlowLayoutWidget();
                        var radioList        = new List <GuiWidget>();

                        movePointZeroTwoMmButton = theme.CreateMicroRadioButton("0.02", radioList);
                        movePointZeroTwoMmButton.CheckedStateChanged += (s, e) =>
                        {
                            if (movePointZeroTwoMmButton.Checked)
                            {
                                SetXYZMoveAmount(.02);
                            }
                        };
                        moveRadioButtons.AddChild(movePointZeroTwoMmButton);

                        var pointOneButton = theme.CreateMicroRadioButton("0.1", radioList);
                        pointOneButton.CheckedStateChanged += (s, e) =>
                        {
                            if (pointOneButton.Checked)
                            {
                                SetXYZMoveAmount(.1);
                            }
                        };
                        moveRadioButtons.AddChild(pointOneButton);

                        moveOneMmButton = theme.CreateMicroRadioButton("1", radioList);
                        moveOneMmButton.CheckedStateChanged += (s, e) =>
                        {
                            if (moveOneMmButton.Checked)
                            {
                                SetXYZMoveAmount(1);
                            }
                        };
                        moveRadioButtons.AddChild(moveOneMmButton);

                        tenButton = theme.CreateMicroRadioButton("10", radioList);
                        tenButton.CheckedStateChanged += (s, e) =>
                        {
                            if (tenButton.Checked)
                            {
                                SetXYZMoveAmount(10);
                            }
                        };
                        moveRadioButtons.AddChild(tenButton);

                        oneHundredButton = theme.CreateMicroRadioButton("100", radioList);
                        oneHundredButton.CheckedStateChanged += (s, e) =>
                        {
                            if (oneHundredButton.Checked)
                            {
                                SetXYZMoveAmount(100);
                            }
                        };
                        moveRadioButtons.AddChild(oneHundredButton);

                        tenButton.Checked = true;
                        SetXYZMoveAmount(10);
                        moveRadioButtons.Margin = new BorderDouble(0, 3);
                        setMoveDistanceControl.AddChild(moveRadioButtons);

                        moveRadioButtons.AddChild(new TextWidget("mm", textColor: theme.TextColor, pointSize: 8)
                        {
                            Margin  = new BorderDouble(left: 10),
                            VAnchor = VAnchor.Center
                        });
                    }

                    xYZWithDistance.AddChild(setMoveDistanceControl);
                }

                allControlsLeftToRight.AddChild(xYZWithDistance);

#if !__ANDROID__
                allControlsLeftToRight.AddChild(GetHotkeyControlContainer());
#endif
                // Bar between Z And E
                allControlsLeftToRight.AddChild(new GuiWidget(1, 1)
                {
                    VAnchor         = VAnchor.Stretch,
                    BackgroundColor = colors.ZColor,
                    Margin          = new BorderDouble(distanceBetweenControls, 5)
                });

                // EButtons
                disableableEButtons         = CreateEButtons(buttonSeparationDistance, colors);
                disableableEButtons.Name    = "disableableEButtons";
                disableableEButtons.HAnchor = HAnchor.Fit;
                disableableEButtons.VAnchor = VAnchor.Fit | VAnchor.Top;

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

            using (this.LayoutLock())
            {
                this.AddChild(allControlsTopToBottom);
                this.HAnchor = HAnchor.Fit;
                this.VAnchor = VAnchor.Fit;
                Margin       = new BorderDouble(3);
            }

            this.PerformLayout();

            // Register listeners
            printer.Settings.SettingChanged += Printer_SettingChanged;
        }
        private void EnableReduceWidth(RadioTextButton enumTab)
        {
            var deviceScale = GuiWidget.DeviceScale;
            var padingSize  = enumTab.Padding.Left * deviceScale;

            enumTab.MinimumSize = new Vector2(padingSize * 3, enumTab.Height);
            enumTab.HAnchor     = HAnchor.Stretch;

            // delay this for an update so that the layout of the text widget has happened and its size has been updated.
            var textWidget = enumTab.Descendants <TextWidget>().First();

            textWidget.Margin  = new BorderDouble(enumTab.Padding.Left, 0, 0, 0);
            textWidget.HAnchor = HAnchor.Left;

            enumTab.AfterDraw += (s, e) =>
            {
                if (enumTab.Width < enumTab.MaximumSize.X)
                {
                    var bounds = enumTab.LocalBounds;
                    var g      = e.Graphics2D;
                    var color  = enumTab.SelectedBackgroundColor;
                    if (!enumTab.Checked)
                    {
                        foreach (var parent in enumTab.Parents <GuiWidget>())
                        {
                            if (parent.BackgroundColor.alpha > 200)
                            {
                                color = parent.BackgroundColor;
                                break;
                            }
                        }
                    }
                    // cover the text with an alpha mask
                    for (int i = 0; i < padingSize + 1; i++)
                    {
                        var x = bounds.Right - padingSize + i;
                        g.Line(x, bounds.Bottom, x, bounds.Top, color.WithAlpha(Math.Min(255, i / 10.0 * deviceScale)));
                    }
                }
            };

            // the text
            var maxWidth = textWidget.Width + enumTab.Padding.Width * deviceScale;

            enumTab.MaximumSize = new Vector2(maxWidth, enumTab.MaximumSize.Y);
            enumTab.Padding     = new BorderDouble(0, enumTab.Padding.Bottom, 0, enumTab.Padding.Top);

            if (string.IsNullOrEmpty(enumTab.ToolTipText))
            {
                // wait for this size change to take effect and update the tool tip
                enumTab.BoundsChanged += (s, e) =>
                {
                    if (enumTab.Width < enumTab.MaximumSize.X)
                    {
                        enumTab.ToolTipText = textWidget.Text;
                    }
                    else
                    {
                        enumTab.ToolTipText = "";
                    }
                };
            }

            enumTab.HAnchor = HAnchor.Stretch;
        }