2017-06-16 18:06:07 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using MatterHackers.Agg;
|
|
|
|
|
|
using MatterHackers.Agg.Image;
|
|
|
|
|
|
using MatterHackers.Agg.ImageProcessing;
|
|
|
|
|
|
using MatterHackers.Agg.UI;
|
|
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
2017-06-16 21:31:07 -07:00
|
|
|
|
using MatterHackers.VectorMath;
|
2017-06-16 18:06:07 -07:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.ConfigurationPage
|
|
|
|
|
|
{
|
|
|
|
|
|
public class SettingsItem : FlowLayoutWidget
|
|
|
|
|
|
{
|
|
|
|
|
|
public class ToggleSwitchConfig
|
|
|
|
|
|
{
|
|
|
|
|
|
public bool Checked { get; set; }
|
2018-03-13 08:39:57 -07:00
|
|
|
|
public string Name { get; set; }
|
2017-06-16 18:06:07 -07:00
|
|
|
|
public Action<bool> ToggleAction { get; set; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-31 11:43:25 -07:00
|
|
|
|
private static Color menuTextColor = Color.Black;
|
2017-06-16 20:05:52 -07:00
|
|
|
|
|
2018-01-11 16:12:08 -08:00
|
|
|
|
public SettingsItem(string text, Color textColor, ToggleSwitchConfig toggleSwitchConfig = null, GuiWidget optionalControls = null, ImageBuffer iconImage = null, bool enforceGutter = true)
|
|
|
|
|
|
: this(text, textColor, CreateToggleSwitch(toggleSwitchConfig, textColor), optionalControls, iconImage, enforceGutter)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-06-27 18:41:34 -07:00
|
|
|
|
public SettingsItem(string text, ToggleSwitchConfig toggleSwitchConfig = null, GuiWidget optionalControls = null, ImageBuffer iconImage = null, bool enforceGutter = true)
|
2018-01-11 16:12:08 -08:00
|
|
|
|
: this(text, CreateToggleSwitch(toggleSwitchConfig, menuTextColor), optionalControls, iconImage, enforceGutter)
|
2017-06-16 18:06:07 -07:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-11 16:12:08 -08:00
|
|
|
|
public SettingsItem(string text, GuiWidget settingsControls, GuiWidget optionalControls = null, ImageBuffer imageBuffer = null, bool enforceGutter = true)
|
|
|
|
|
|
: this(text, menuTextColor, settingsControls, optionalControls, imageBuffer, enforceGutter)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public SettingsItem (string text, Color textColor, GuiWidget settingsControls, GuiWidget optionalControls = null, ImageBuffer imageBuffer = null, bool enforceGutter = true)
|
2017-06-16 18:06:07 -07:00
|
|
|
|
: base (FlowDirection.LeftToRight)
|
|
|
|
|
|
{
|
2018-01-12 09:51:42 -08:00
|
|
|
|
var theme = ApplicationController.Instance.Theme;
|
2018-01-11 16:12:08 -08:00
|
|
|
|
this.SettingsControl = settingsControls;
|
2017-08-07 15:47:27 -07:00
|
|
|
|
this.HAnchor = HAnchor.Stretch;
|
2018-01-14 10:13:42 -08:00
|
|
|
|
this.MinimumSize = new Vector2(0, theme.ButtonHeight);
|
2017-06-16 21:31:07 -07:00
|
|
|
|
|
2017-06-16 18:06:07 -07:00
|
|
|
|
if (imageBuffer != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.AddChild(new ImageWidget(imageBuffer)
|
|
|
|
|
|
{
|
|
|
|
|
|
Margin = new BorderDouble(right: 6, left: 6),
|
2017-08-07 15:47:27 -07:00
|
|
|
|
VAnchor = VAnchor.Center
|
2017-06-16 18:06:07 -07:00
|
|
|
|
});
|
|
|
|
|
|
}
|
2017-06-27 18:41:34 -07:00
|
|
|
|
else if (enforceGutter)
|
2017-06-16 18:06:07 -07:00
|
|
|
|
{
|
2018-04-04 10:11:57 -07:00
|
|
|
|
// Add an icon placeholder to get consistent label indenting on items lacking icons
|
2017-06-16 18:06:07 -07:00
|
|
|
|
this.AddChild(new GuiWidget()
|
|
|
|
|
|
{
|
|
|
|
|
|
Width = 24 + 12,
|
|
|
|
|
|
Height = 24,
|
|
|
|
|
|
Margin = new BorderDouble(0)
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-12 09:51:42 -08:00
|
|
|
|
this.AddChild(new TextWidget(text, textColor: textColor, pointSize: theme.DefaultFontSize)
|
2017-06-27 18:41:34 -07:00
|
|
|
|
{
|
|
|
|
|
|
AutoExpandBoundsToText = true,
|
2017-08-07 15:47:27 -07:00
|
|
|
|
VAnchor = VAnchor.Center,
|
2017-06-27 18:41:34 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
2017-06-16 18:06:07 -07:00
|
|
|
|
this.AddChild(new HorizontalSpacer());
|
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-04 10:11:57 -07:00
|
|
|
|
private static GuiWidget CreateToggleSwitch(ToggleSwitchConfig toggleSwitchConfig, Color textColor)
|
2017-08-12 11:22:41 -07:00
|
|
|
|
{
|
|
|
|
|
|
if (toggleSwitchConfig == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-04 10:11:57 -07:00
|
|
|
|
var toggleSwitch = new RoundedToggleSwitch(ApplicationController.Instance.Theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|