public MaterialControls(PrinterConfig printer, ThemeConfig theme, int initialMaterialIndex) : base(FlowDirection.TopToBottom) { this.theme = theme; this.HAnchor = HAnchor.Fit; this.VAnchor = VAnchor.Fit; materialButtons.Clear(); int extruderCount = 4; for (int extruderIndex = -1; extruderIndex < extruderCount; extruderIndex++) { var name = $"{"Material".Localize()} {extruderIndex + 1}"; if (extruderIndex == -1) { name = "Default".Localize(); } var buttonView = new FlowLayoutWidget() { HAnchor = HAnchor.Fit, VAnchor = VAnchor.Fit }; var scaledButtonSize = 24 * GuiWidget.DeviceScale; GuiWidget colorButton; buttonView.AddChild(colorButton = new ItemColorButton(theme, MaterialRendering.Color(printer, extruderIndex, theme.BorderColor)) { Width = scaledButtonSize, Height = scaledButtonSize, BackgroundRadius = scaledButtonSize / 2, BackgroundOutlineWidth = 1, BorderColor = theme.TextColor, VAnchor = VAnchor.Center, Margin = new BorderDouble(3, 0, 5, 0), }); buttonView.AddChild(new TextWidget(name, pointSize: theme.DefaultFontSize, textColor: theme.TextColor) { VAnchor = VAnchor.Center }); var radioButtonView = new RadioButtonView(buttonView) { TextColor = theme.TextColor, Selectable = false }; radioButtonView.RadioCircle.Margin = radioButtonView.RadioCircle.Margin.Clone(right: 5); var radioButton = new RadioButton(radioButtonView) { HAnchor = HAnchor.Fit, VAnchor = VAnchor.Fit, TextColor = theme.TextColor, Checked = extruderIndex == initialMaterialIndex, Name = name + " Button" }; materialButtons.Add(radioButton); this.AddChild(radioButton); int localExtruderIndex = extruderIndex; radioButton.Click += (sender, e) => { IndexChanged?.Invoke(this, localExtruderIndex); }; } }
public MaterialControls(PrinterConfig printer, ThemeConfig theme, int initialMaterialIndex) : base(FlowDirection.TopToBottom) { this.theme = theme; this.HAnchor = HAnchor.Fit; this.VAnchor = VAnchor.Fit; materialButtons.Clear(); int extruderCount = 4; for (int extruderIndex = -1; extruderIndex < extruderCount; extruderIndex++) { var name = $"{"Material".Localize()} {extruderIndex + 1}"; if (extruderIndex == -1) { name = "Default".Localize(); } var buttonView = new FlowLayoutWidget() { HAnchor = HAnchor.Fit, VAnchor = VAnchor.Fit }; var scaledButtonSize = 16 * GuiWidget.DeviceScale; GuiWidget colorButton; buttonView.AddChild(colorButton = new ItemColorButton(theme, MaterialRendering.Color(printer, extruderIndex, theme.BorderColor)) { Width = scaledButtonSize, Height = scaledButtonSize, VAnchor = VAnchor.Center, Margin = new BorderDouble(3, 0, 5, 0), }); buttonView.AddChild(new TextWidget(name, pointSize: theme.DefaultFontSize, textColor: theme.TextColor) { VAnchor = VAnchor.Center }); var radioButtonView = new RadioButtonView(buttonView) { TextColor = theme.TextColor }; radioButtonView.RadioCircle.Margin = radioButtonView.RadioCircle.Margin.Clone(right: 5); var radioButton = new RadioButton(radioButtonView) { HAnchor = HAnchor.Fit, VAnchor = VAnchor.Fit, TextColor = theme.TextColor, Checked = extruderIndex == initialMaterialIndex, Name = name + " Button" }; materialButtons.Add(radioButton); this.AddChild(radioButton); radioButton.MouseMove += (s, e) => { var screenSpace = radioButton.TransformToScreenSpace(e.Position); var colorButtonSpace = colorButton.TransformFromScreenSpace(screenSpace); if (colorButton.LocalBounds.Contains(colorButtonSpace)) { var parent = colorButton.Parent; while (parent != radioButton) { parent.Selectable = true; parent = parent.Parent; } } else { var parent = colorButton.Parent; while (parent != radioButton) { parent.Selectable = false; parent = parent.Parent; } } }; radioButton.MouseLeaveBounds += (s, e) => { }; int localExtruderIndex = extruderIndex; radioButton.Click += (sender, e) => { IndexChanged?.Invoke(this, localExtruderIndex); }; } }