Use new toggle control for CheckboxField

This commit is contained in:
John Lewin 2018-04-05 18:23:21 -07:00
parent abe3f50799
commit 8431f7a5ef

View file

@ -30,6 +30,7 @@ either expressed or implied, of the FreeBSD Project.
using System; using System;
using MatterHackers.Agg; using MatterHackers.Agg;
using MatterHackers.Agg.UI; using MatterHackers.Agg.UI;
using MatterHackers.MatterControl.CustomWidgets;
namespace MatterHackers.MatterControl.SlicerConfiguration namespace MatterHackers.MatterControl.SlicerConfiguration
{ {
@ -68,19 +69,13 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
public class ToggleboxField : UIField public class ToggleboxField : UIField
{ {
private CheckBox checkBoxWidget; private ICheckbox checkBoxWidget;
private Color textColor; private Color textColor;
public bool Checked public bool Checked
{ {
get get => checkBoxWidget.Checked;
{ set => checkBoxWidget.Checked = value;
return checkBoxWidget.Checked;
}
set
{
checkBoxWidget.Checked = value;
}
} }
public ToggleboxField(Color textColor) public ToggleboxField(Color textColor)
@ -92,20 +87,19 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
{ {
var pixelWidth = this.ControlWidth + 6; // HACK: work around agg-bug where text fields are padding*2 bigger than ControlWidth var pixelWidth = this.ControlWidth + 6; // HACK: work around agg-bug where text fields are padding*2 bigger than ControlWidth
checkBoxWidget = ImageButtonFactory.CreateToggleSwitch(false, textColor, pixelWidth, pixelHeight: 24 * GuiWidget.DeviceScale, useStandardLabels: false); var toggleSwitch = new RoundedToggleSwitch(ApplicationController.Instance.Theme); // ImageButtonFactory.CreateToggleSwitch(false, textColor, pixelWidth, pixelHeight: 24 * GuiWidget.DeviceScale, useStandardLabels: false);
checkBoxWidget.VAnchor = VAnchor.Center; toggleSwitch.VAnchor = VAnchor.Center;
checkBoxWidget.Name = this.Name; toggleSwitch.Name = this.Name;
checkBoxWidget.Margin = 0; toggleSwitch.Margin = 0;
checkBoxWidget.Click += (s, e) => toggleSwitch.CheckedStateChanged += (s, e) =>
{ {
Console.WriteLine("Checkbox Click Event: " + this.checkBoxWidget.Checked);
this.SetValue( this.SetValue(
this.checkBoxWidget.Checked ? "1" : "0", this.checkBoxWidget.Checked ? "1" : "0",
userInitiated: true); userInitiated: true);
}; };
this.Content = this.checkBoxWidget; this.Content = toggleSwitch;
checkBoxWidget = toggleSwitch;
} }
protected override void OnValueChanged(FieldChangedEventArgs fieldChangedEventArgs) protected override void OnValueChanged(FieldChangedEventArgs fieldChangedEventArgs)