Initial work on new SettingsItem type for ApplicationSettings
This commit is contained in:
parent
8afc92ae33
commit
9a4d119590
3 changed files with 118 additions and 46 deletions
|
|
@ -156,57 +156,25 @@ namespace MatterHackers.MatterControl.ConfigurationPage
|
|||
{
|
||||
bool hasCamera = true || ApplicationSettings.Instance.get(ApplicationSettingsKey.HardwareHasCamera) == "true";
|
||||
|
||||
var settingsRow = new FlowLayoutWidget()
|
||||
{
|
||||
HAnchor = HAnchor.ParentLeftRight,
|
||||
Margin = new BorderDouble(bottom: 4),
|
||||
};
|
||||
|
||||
ImageBuffer cameraIconImage = StaticData.Instance.LoadIcon("camera-24x24.png", 24, 24);
|
||||
cameraIconImage.SetRecieveBlender(new BlenderPreMultBGRA());
|
||||
|
||||
var openCameraButton = buttonFactory.Generate("Preview".Localize().ToUpper());
|
||||
openCameraButton.Click += (s, e) =>
|
||||
var previewButton = buttonFactory.Generate("Preview".Localize().ToUpper());
|
||||
previewButton.Click += (s, e) =>
|
||||
{
|
||||
MatterControlApplication.Instance.OpenCameraPreview();
|
||||
};
|
||||
openCameraButton.Margin = new BorderDouble(left: 6);
|
||||
|
||||
settingsRow.AddChild(new ImageWidget(cameraIconImage)
|
||||
{
|
||||
Margin = new BorderDouble(right: 6)
|
||||
});
|
||||
settingsRow.AddChild(new TextWidget("Camera Monitoring".Localize())
|
||||
{
|
||||
AutoExpandBoundsToText = true,
|
||||
TextColor = menuTextColor,
|
||||
VAnchor = VAnchor.ParentCenter
|
||||
});
|
||||
settingsRow.AddChild(new HorizontalSpacer());
|
||||
settingsRow.AddChild(openCameraButton);
|
||||
|
||||
if (hasCamera)
|
||||
{
|
||||
var publishImageSwitchContainer = new FlowLayoutWidget()
|
||||
return new SettingsItem(
|
||||
"Camera Monitoring".Localize(),
|
||||
buttonFactory,
|
||||
new SettingsItem.ToggleSwitchConfig()
|
||||
{
|
||||
VAnchor = VAnchor.ParentCenter,
|
||||
Margin = new BorderDouble(left: 16)
|
||||
};
|
||||
|
||||
CheckBox toggleSwitch = ImageButtonFactory.CreateToggleSwitch(ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.publish_bed_image), menuTextColor);
|
||||
|
||||
toggleSwitch.CheckedStateChanged += (sender, e) =>
|
||||
{
|
||||
ActiveSliceSettings.Instance.SetValue(SettingsKey.publish_bed_image, toggleSwitch.Checked ? "1" : "0");
|
||||
};
|
||||
publishImageSwitchContainer.AddChild(toggleSwitch);
|
||||
|
||||
publishImageSwitchContainer.SetBoundsToEncloseChildren();
|
||||
|
||||
settingsRow.AddChild(publishImageSwitchContainer);
|
||||
}
|
||||
|
||||
return settingsRow;
|
||||
Checked = ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.publish_bed_image),
|
||||
ToggleAction = (itemChecked) =>
|
||||
{
|
||||
ActiveSliceSettings.Instance.SetValue(SettingsKey.publish_bed_image, itemChecked ? "1" : "0");
|
||||
}
|
||||
},
|
||||
previewButton,
|
||||
StaticData.Instance.LoadIcon("camera-24x24.png", 24, 24));
|
||||
}
|
||||
|
||||
private FlowLayoutWidget GetThemeControl()
|
||||
|
|
|
|||
103
ConfigurationPage/ApplicationSettings/SettingsItem.cs
Normal file
103
ConfigurationPage/ApplicationSettings/SettingsItem.cs
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
using System;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.Image;
|
||||
using MatterHackers.Agg.ImageProcessing;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.MatterControl.CustomWidgets;
|
||||
|
||||
namespace MatterHackers.MatterControl.ConfigurationPage
|
||||
{
|
||||
public class SettingsItem : FlowLayoutWidget
|
||||
{
|
||||
public class ToggleSwitchConfig
|
||||
{
|
||||
public bool Checked { get; set; }
|
||||
public Action<bool> ToggleAction { get; set; }
|
||||
}
|
||||
|
||||
public SettingsItem(string text, TextImageButtonFactory buttonFactory, ToggleSwitchConfig toggleSwitchConfig = null, GuiWidget optionalControls = null, ImageBuffer iconImage = null)
|
||||
: base(FlowDirection.LeftToRight)
|
||||
{
|
||||
var switchContainer = new FlowLayoutWidget()
|
||||
{
|
||||
VAnchor = VAnchor.ParentCenter,
|
||||
Margin = new BorderDouble(left: 16),
|
||||
Width = 45
|
||||
};
|
||||
|
||||
CheckBox toggleSwitch = null;
|
||||
if (toggleSwitchConfig != null)
|
||||
{
|
||||
toggleSwitch = GenerateToggleSwitch(toggleSwitchConfig.Checked);
|
||||
toggleSwitch.CheckedStateChanged += (sender, e) =>
|
||||
{
|
||||
toggleSwitchConfig.ToggleAction?.Invoke(toggleSwitch.Checked);
|
||||
};
|
||||
switchContainer.AddChild(toggleSwitch);
|
||||
switchContainer.SetBoundsToEncloseChildren();
|
||||
}
|
||||
|
||||
CreateChildControls(text, switchContainer, optionalControls, iconImage);
|
||||
}
|
||||
|
||||
public SettingsItem (string text, TextImageButtonFactory buttonFactory, GuiWidget settingsControls, GuiWidget optionalControls = null, ImageBuffer iconImage = null)
|
||||
: base (FlowDirection.LeftToRight)
|
||||
{
|
||||
CreateChildControls(text, settingsControls, optionalControls, iconImage);
|
||||
}
|
||||
|
||||
private void CreateChildControls(string text, GuiWidget settingsControls, GuiWidget optionalControls, ImageBuffer imageBuffer = null)
|
||||
{
|
||||
this.HAnchor = HAnchor.ParentLeftRight;
|
||||
this.Height = 40;
|
||||
|
||||
var sectionLabel = new TextWidget(text)
|
||||
{
|
||||
AutoExpandBoundsToText = true,
|
||||
TextColor = ActiveTheme.Instance.PrimaryTextColor,
|
||||
VAnchor = VAnchor.ParentCenter
|
||||
};
|
||||
|
||||
if (imageBuffer != null)
|
||||
{
|
||||
if (!ActiveTheme.Instance.IsDarkTheme)
|
||||
{
|
||||
InvertLightness.DoInvertLightness(imageBuffer);
|
||||
}
|
||||
|
||||
this.AddChild(new ImageWidget(imageBuffer)
|
||||
{
|
||||
Margin = new BorderDouble(right: 6, left: 6),
|
||||
VAnchor = VAnchor.ParentCenter
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add an icon place holder to get consistent label indenting on items lacking icons
|
||||
this.AddChild(new GuiWidget()
|
||||
{
|
||||
Width = 24 + 12,
|
||||
Height = 24,
|
||||
Margin = new BorderDouble(0)
|
||||
});
|
||||
}
|
||||
|
||||
// Add flag to align all labels - fill empty space if sectionIconPath is empty
|
||||
this.AddChild(sectionLabel, -1);
|
||||
this.AddChild(new HorizontalSpacer());
|
||||
if (optionalControls != null)
|
||||
{
|
||||
this.AddChild(optionalControls);
|
||||
}
|
||||
this.AddChild(settingsControls);
|
||||
}
|
||||
|
||||
private CheckBox GenerateToggleSwitch(bool initiallyChecked)
|
||||
{
|
||||
CheckBox toggleSwitch = ImageButtonFactory.CreateToggleSwitch(initiallyChecked);
|
||||
toggleSwitch.VAnchor = Agg.UI.VAnchor.ParentCenter;
|
||||
|
||||
return toggleSwitch;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue