mattercontrol/ControlElements/ToggleSwitchFactory.cs

61 lines
2.5 KiB
C#
Raw Normal View History

2015-04-08 15:20:10 -07:00
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
namespace MatterHackers.MatterControl
{
public class ToggleSwitchFactory
{
public RGBA_Bytes defaultBackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
2015-04-08 15:20:10 -07:00
public RGBA_Bytes defaultInteriorColor = new RGBA_Bytes(220, 220, 220);
public RGBA_Bytes defaultThumbColor = ActiveTheme.Instance.PrimaryAccentColor;
public RGBA_Bytes defaultExteriorColor = ActiveTheme.Instance.PrimaryTextColor;
public double defaultSwitchHeight = 24;
2015-04-08 15:20:10 -07:00
public double defaultSwitchWidth = 60;
2015-04-08 15:20:10 -07:00
public const string defaultTrueText = "On";
public const string defaultFalseText = "Off";
2015-04-08 15:20:10 -07:00
public ToggleSwitchFactory()
{
}
public ToggleSwitch Generate(bool value = false)
{
2015-04-08 15:20:10 -07:00
ToggleSwitch toggleSwitch = new ToggleSwitch(defaultSwitchWidth, defaultSwitchHeight, value, defaultBackgroundColor, defaultInteriorColor, defaultThumbColor, defaultExteriorColor);
return toggleSwitch;
}
2015-04-08 15:20:10 -07:00
public ToggleSwitch GenerateGivenTextWidget(TextWidget assocTextWidget, string trueText = defaultTrueText, string falseText = defaultFalseText, bool value = false)
{
2015-04-08 15:20:10 -07:00
ToggleSwitch toggleSwitch = new ToggleSwitch(assocTextWidget, trueText, falseText, defaultSwitchWidth, defaultSwitchHeight, value, defaultBackgroundColor, defaultInteriorColor, defaultThumbColor, defaultExteriorColor);
return toggleSwitch;
}
2015-04-08 15:20:10 -07:00
public FlowLayoutWidget GenerateToggleSwitchAndTextWidget(string trueText = defaultTrueText, string falseText = defaultFalseText, bool value = false)
{
FlowLayoutWidget leftToRight = new FlowLayoutWidget();
2015-04-08 15:20:10 -07:00
// leftToRight.Padding = new BorderDouble(3, 0, 0, 5) * TextWidget.GlobalPointSizeScaleRatio;
2015-04-08 15:20:10 -07:00
TextWidget textWidget = new TextWidget(defaultFalseText, pointSize: 10, textColor: ActiveTheme.Instance.PrimaryTextColor);
textWidget.VAnchor = VAnchor.ParentCenter;
2015-04-08 15:20:10 -07:00
ToggleSwitch toggleSwitch = new ToggleSwitch(textWidget, trueText, falseText, defaultSwitchWidth, defaultSwitchHeight, value, defaultBackgroundColor, defaultInteriorColor, defaultThumbColor, defaultExteriorColor);
toggleSwitch.VAnchor = VAnchor.ParentCenter;
2015-04-08 15:20:10 -07:00
setToggleSwitchColors(toggleSwitch);
2015-04-08 15:20:10 -07:00
leftToRight.AddChild(toggleSwitch);
leftToRight.AddChild(textWidget);
return leftToRight;
}
private void setToggleSwitchColors(ToggleSwitch toggleSwitch)
{
toggleSwitch.BackgroundColor = defaultBackgroundColor;
toggleSwitch.InteriorColor = defaultInteriorColor;
toggleSwitch.ThumbColor = defaultThumbColor;
toggleSwitch.ExteriorColor = defaultExteriorColor;
}
}
2015-04-08 15:20:10 -07:00
}