2017-06-16 18:06:07 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using MatterHackers.Agg;
|
|
|
|
|
|
using MatterHackers.Agg.Image;
|
|
|
|
|
|
using MatterHackers.Agg.UI;
|
|
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.ConfigurationPage
|
|
|
|
|
|
{
|
2018-04-06 14:40:41 -07:00
|
|
|
|
public class SettingsItem : SettingsRow
|
2017-06-16 18:06:07 -07:00
|
|
|
|
{
|
|
|
|
|
|
public class ToggleSwitchConfig
|
|
|
|
|
|
{
|
|
|
|
|
|
public bool Checked { get; set; }
|
2019-04-01 16:35:44 -07:00
|
|
|
|
|
2018-03-13 08:39:57 -07:00
|
|
|
|
public string Name { get; set; }
|
2019-04-01 16:35:44 -07:00
|
|
|
|
|
2017-06-16 18:06:07 -07:00
|
|
|
|
public Action<bool> ToggleAction { get; set; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-12 08:42:10 -07:00
|
|
|
|
public SettingsItem(string text, ThemeConfig theme, ToggleSwitchConfig toggleSwitchConfig = null, GuiWidget optionalControls = null, ImageBuffer iconImage = null, bool enforceGutter = true)
|
|
|
|
|
|
: this(text, CreateToggleSwitch(toggleSwitchConfig, theme), theme, optionalControls, iconImage, enforceGutter)
|
2018-01-11 16:12:08 -08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-12 08:42:10 -07:00
|
|
|
|
public SettingsItem (string text, GuiWidget settingsControls, ThemeConfig theme, GuiWidget optionalControls = null, ImageBuffer imageBuffer = null, bool enforceGutter = true)
|
2018-10-12 12:12:15 -07:00
|
|
|
|
: base (text, "", theme, imageBuffer)
|
2017-06-16 18:06:07 -07:00
|
|
|
|
{
|
2018-01-11 16:12:08 -08:00
|
|
|
|
this.SettingsControl = settingsControls;
|
2017-06-27 18:41:34 -07:00
|
|
|
|
|
2017-06-16 18:06:07 -07:00
|
|
|
|
if (optionalControls != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.AddChild(optionalControls);
|
|
|
|
|
|
}
|
2017-06-27 18:41:34 -07:00
|
|
|
|
|
2017-08-12 10:35:37 -07:00
|
|
|
|
if (settingsControls != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.AddChild(settingsControls);
|
|
|
|
|
|
}
|
2017-06-16 18:06:07 -07:00
|
|
|
|
}
|
2017-08-12 11:22:41 -07:00
|
|
|
|
|
2018-01-11 16:12:08 -08:00
|
|
|
|
public GuiWidget SettingsControl { get; }
|
|
|
|
|
|
|
2018-04-12 08:42:10 -07:00
|
|
|
|
private static GuiWidget CreateToggleSwitch(ToggleSwitchConfig toggleSwitchConfig, ThemeConfig theme)
|
2017-08-12 11:22:41 -07:00
|
|
|
|
{
|
|
|
|
|
|
if (toggleSwitchConfig == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-12 08:42:10 -07:00
|
|
|
|
var toggleSwitch = new RoundedToggleSwitch(theme)
|
2018-04-04 10:11:57 -07:00
|
|
|
|
{
|
|
|
|
|
|
VAnchor = VAnchor.Center,
|
|
|
|
|
|
Checked = toggleSwitchConfig.Checked,
|
|
|
|
|
|
Name = toggleSwitchConfig.Name,
|
|
|
|
|
|
Margin = new BorderDouble(left: 16),
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2017-08-12 11:22:41 -07:00
|
|
|
|
toggleSwitch.CheckedStateChanged += (sender, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
toggleSwitchConfig.ToggleAction?.Invoke(toggleSwitch.Checked);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return toggleSwitch;
|
|
|
|
|
|
}
|
2017-06-16 18:06:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|