Merge pull request #3147 from jlewin/design_tools

Consolidate row style helpers
This commit is contained in:
johnlewin 2018-04-06 16:00:46 -07:00 committed by GitHub
commit dd9de6c564
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 152 additions and 185 deletions

View file

@ -1717,7 +1717,7 @@ namespace MatterHackers.MatterControl
container.AddChild(printAreaButton); container.AddChild(printAreaButton);
} }
this. BindBedOptions(container, bedButton, printAreaButton, sceneContext.RendererOptions); this.BindBedOptions(container, bedButton, printAreaButton, sceneContext.RendererOptions);
return container; return container;
} }

View file

@ -59,7 +59,6 @@ namespace MatterHackers.MatterControl.ConfigurationPage
this.buttonFactory = buttonFactory; this.buttonFactory = buttonFactory;
this.HAnchor = HAnchor.Stretch; this.HAnchor = HAnchor.Stretch;
this.VAnchor = VAnchor.Fit; this.VAnchor = VAnchor.Fit;
this.Padding = new BorderDouble(right: 4);
// Camera Monitoring // Camera Monitoring
bool hasCamera = true || ApplicationSettings.Instance.get(ApplicationSettingsKey.HardwareHasCamera) == "true"; bool hasCamera = true || ApplicationSettings.Instance.get(ApplicationSettingsKey.HardwareHasCamera) == "true";
@ -358,10 +357,9 @@ namespace MatterHackers.MatterControl.ConfigurationPage
private void AddSettingsRow(GuiWidget widget) private void AddSettingsRow(GuiWidget widget)
{ {
this.AddChild(widget); this.AddChild(widget);
this.AddChild(new HorizontalLine(70)
{ widget.BorderColor = ApplicationController.Instance.Theme.GetBorderColor(25);
Margin = new BorderDouble(left: 30), widget.Padding = widget.Padding.Clone(right: 10);
});
} }
private FlowLayoutWidget GetThemeControl(ThemeConfig theme) private FlowLayoutWidget GetThemeControl(ThemeConfig theme)

View file

@ -1,14 +1,13 @@
using System; using System;
using MatterHackers.Agg; using MatterHackers.Agg;
using MatterHackers.Agg.Image; using MatterHackers.Agg.Image;
using MatterHackers.Agg.ImageProcessing;
using MatterHackers.Agg.UI; using MatterHackers.Agg.UI;
using MatterHackers.MatterControl.CustomWidgets; using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.VectorMath; using MatterHackers.MatterControl.SlicerConfiguration;
namespace MatterHackers.MatterControl.ConfigurationPage namespace MatterHackers.MatterControl.ConfigurationPage
{ {
public class SettingsItem : FlowLayoutWidget public class SettingsItem : SettingsRow
{ {
public class ToggleSwitchConfig public class ToggleSwitchConfig
{ {
@ -35,39 +34,10 @@ namespace MatterHackers.MatterControl.ConfigurationPage
} }
public SettingsItem (string text, Color textColor, GuiWidget settingsControls, GuiWidget optionalControls = null, ImageBuffer imageBuffer = null, bool enforceGutter = true) public SettingsItem (string text, Color textColor, GuiWidget settingsControls, GuiWidget optionalControls = null, ImageBuffer imageBuffer = null, bool enforceGutter = true)
: base (FlowDirection.LeftToRight) : base (text, "", textColor, ApplicationController.Instance.Theme)
{ {
var theme = ApplicationController.Instance.Theme; var theme = ApplicationController.Instance.Theme;
this.SettingsControl = settingsControls; this.SettingsControl = settingsControls;
this.HAnchor = HAnchor.Stretch;
this.MinimumSize = new Vector2(0, theme.ButtonHeight);
if (imageBuffer != null)
{
this.AddChild(new ImageWidget(imageBuffer)
{
Margin = new BorderDouble(right: 6, left: 6),
VAnchor = VAnchor.Center
});
}
else if (enforceGutter)
{
// Add an icon placeholder to get consistent label indenting on items lacking icons
this.AddChild(new GuiWidget()
{
Width = 24 + 12,
Height = 24,
Margin = new BorderDouble(0)
});
}
this.AddChild(new TextWidget(text, textColor: textColor, pointSize: theme.DefaultFontSize)
{
AutoExpandBoundsToText = true,
VAnchor = VAnchor.Center,
});
this.AddChild(new HorizontalSpacer());
if (optionalControls != null) if (optionalControls != null)
{ {

View file

@ -62,7 +62,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{ {
HAnchor = HAnchor.Stretch, HAnchor = HAnchor.Stretch,
VAnchor = VAnchor.Fit, VAnchor = VAnchor.Fit,
Margin = new BorderDouble(right: 10)
}); });
this.AddChild( this.AddChild(

View file

@ -31,6 +31,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using System.Linq;
using MatterHackers.Agg; using MatterHackers.Agg;
using MatterHackers.Agg.Platform; using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI; using MatterHackers.Agg.UI;
@ -249,23 +250,22 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
void BuildMenu() void BuildMenu()
{ {
foreach (var option in viewOptions) foreach (var option in viewOptions.Where(option => option.IsVisible()))
{ {
if (option.IsVisible()) var settingsItem = new SettingsItem(
{ option.Title,
optionsContainer.AddChild( theme.Colors.PrimaryTextColor,
new SettingsItem( new SettingsItem.ToggleSwitchConfig()
option.Title, {
theme.Colors.PrimaryTextColor, Name = option.Title + " Toggle",
new SettingsItem.ToggleSwitchConfig() Checked = option.IsChecked(),
{ ToggleAction = option.SetValue
Name = option.Title + " Toggle", },
Checked = option.IsChecked(), enforceGutter: false);
ToggleAction = option.SetValue
}, settingsItem.Padding = settingsItem.Padding.Clone(right: 8);
enforceGutter: false)
); optionsContainer.AddChild(settingsItem);
}
} }
} }

View file

@ -136,7 +136,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
buttonPanel, buttonPanel,
enforceGutter: false) enforceGutter: false)
{ {
Margin = new BorderDouble(bottom: 2) Margin = new BorderDouble(bottom: 2),
Border = 0
}); });
foreach (var option in sceneContext.GetBaseViewOptions()) foreach (var option in sceneContext.GetBaseViewOptions())

View file

@ -42,7 +42,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
public class OverflowBar : Toolbar public class OverflowBar : Toolbar
{ {
private static HashSet<Type> ignoredTypes = new HashSet<Type> { typeof(HorizontalLine), typeof(SearchInputBox) }; private static HashSet<Type> ignoredTypes = new HashSet<Type> { typeof(HorizontalLine), typeof(SearchInputBox) };
private static HashSet<Type> ignoredInMenuTypes = new HashSet<Type> { typeof(VerticalLine), typeof(HorizontalLine), typeof(SearchInputBox) }; private static HashSet<Type> ignoredInMenuTypes = new HashSet<Type> { typeof(VerticalLine), typeof(HorizontalLine), typeof(SearchInputBox), typeof(HorizontalSpacer) };
public OverflowBar(ThemeConfig theme) public OverflowBar(ThemeConfig theme)
{ {

View file

@ -33,6 +33,7 @@ using MatterHackers.Agg;
using MatterHackers.Agg.Image; using MatterHackers.Agg.Image;
using MatterHackers.Agg.UI; using MatterHackers.Agg.UI;
using MatterHackers.Localizations; using MatterHackers.Localizations;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.VectorMath; using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.SlicerConfiguration namespace MatterHackers.MatterControl.SlicerConfiguration
@ -53,9 +54,14 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
public SettingsRow(string title, string helpText, Color textColor, ThemeConfig theme, ImageBuffer icon = null, bool enforceGutter = false, bool fullRowSelect = false) public SettingsRow(string title, string helpText, Color textColor, ThemeConfig theme, ImageBuffer icon = null, bool enforceGutter = false, bool fullRowSelect = false)
{ {
this.theme = theme; this.theme = theme;
this.MinimumSize = new Vector2(0, 28);
this.fullRowSelect = fullRowSelect; this.fullRowSelect = fullRowSelect;
this.HAnchor = HAnchor.Stretch;
this.VAnchor = VAnchor.Fit;
this.MinimumSize = new Vector2(0, theme.ButtonHeight);
this.Border = new BorderDouble(bottom: 1);
this.BorderColor = theme.GetBorderColor((theme.Colors.IsDarkTheme) ? 3 : 5);
hoverColor = theme.MinimalShade; hoverColor = theme.MinimalShade;
if (icon != null) if (icon != null)
@ -85,15 +91,9 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
Margin = new BorderDouble(right: 6) Margin = new BorderDouble(right: 6)
}); });
GuiWidget nameArea; this.AddChild(settingsLabel = SettingsRow.CreateSettingsLabel(title, helpText, textColor));
this.AddChild(nameArea = new GuiWidget()
{ this.AddChild(new HorizontalSpacer());
MinimumSize = new Vector2(50, 0),
HAnchor = HAnchor.Stretch,
VAnchor = VAnchor.Fit | VAnchor.Center,
DebugShowBounds = debugLayout
});
nameArea.AddChild(settingsLabel = SettingsRow.CreateSettingsLabel(title, helpText, textColor));
if (fullRowSelect) if (fullRowSelect)
{ {
@ -103,11 +103,11 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
public static GuiWidget CreateSettingsLabel(string label, string helpText, Color textColor) public static GuiWidget CreateSettingsLabel(string label, string helpText, Color textColor)
{ {
return new WrappedTextWidget(label, pointSize: 10, textColor: textColor) return new TextWidget(label, textColor: textColor, pointSize: 10)
{ {
VAnchor = VAnchor.Center | VAnchor.Fit, AutoExpandBoundsToText = true,
ToolTipText = helpText.Localize(), VAnchor = VAnchor.Center,
Margin = new BorderDouble(0, 5, 5, 5), ToolTipText = string.IsNullOrWhiteSpace(helpText) ? null : helpText,
}; };
} }

View file

@ -50,7 +50,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
private Button restoreButton = null; private Button restoreButton = null;
public SliceSettingsRow(PrinterConfig printer, SettingsContext settingsContext, SliceSettingData settingData, Color textColor, ThemeConfig theme, bool fullRowSelect = false) public SliceSettingsRow(PrinterConfig printer, SettingsContext settingsContext, SliceSettingData settingData, Color textColor, ThemeConfig theme, bool fullRowSelect = false)
: base (settingData.PresentationName.Localize(), settingData.HelpText, textColor, theme, fullRowSelect: fullRowSelect) : base (settingData.PresentationName.Localize(), settingData.HelpText.Localize(), textColor, theme, fullRowSelect: fullRowSelect)
{ {
this.printer = printer; this.printer = printer;
this.settingData = settingData; this.settingData = settingData;

View file

@ -512,6 +512,8 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
HorizontalLine lastLine = null; HorizontalLine lastLine = null;
GuiWidget settingsRow = null;
foreach (SliceSettingData settingData in subGroup.Settings) foreach (SliceSettingData settingData in subGroup.Settings)
{ {
// Note: tab sections may disappear if / when they are empty, as controlled by: // Note: tab sections may disappear if / when they are empty, as controlled by:
@ -521,7 +523,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
if (EngineMappingsMatterSlice.Instance.MapContains(settingData.SlicerConfigName) if (EngineMappingsMatterSlice.Instance.MapContains(settingData.SlicerConfigName)
&& settingShouldBeShown) && settingShouldBeShown)
{ {
var settingsRow = CreateItemRow(settingData); settingsRow = CreateItemRow(settingData);
this.settingsRows.Add((settingsRow, settingData)); this.settingsRows.Add((settingsRow, settingData));
@ -529,6 +531,12 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
} }
} }
// Hide border on last item in group
if (settingsRow != null)
{
settingsRow.BorderColor = Color.Transparent;
}
lastLine?.Close(); lastLine?.Close();
return (topToBottomSettings.Children.Count == 1) ? null : topToBottomSettings; return (topToBottomSettings.Children.Count == 1) ? null : topToBottomSettings;
@ -628,142 +636,133 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
bool placeFieldInDedicatedRow = false; bool placeFieldInDedicatedRow = false;
bool fullRowSelect = settingData.DataEditType == SliceSettingData.DataEditTypes.CHECK_BOX; bool fullRowSelect = settingData.DataEditType == SliceSettingData.DataEditTypes.CHECK_BOX;
var settingsRow = new SliceSettingsRow(printer, settingsContext, settingData, textColor, theme, fullRowSelect: fullRowSelect) var settingsRow = new SliceSettingsRow(printer, settingsContext, settingData, textColor, theme, fullRowSelect: fullRowSelect);
switch (settingData.DataEditType)
{ {
HAnchor = HAnchor.Stretch, case SliceSettingData.DataEditTypes.INT:
VAnchor = VAnchor.Fit,
MinimumSize = new Vector2(0, theme.ButtonHeight),
Border = new BorderDouble(bottom: 1),
BorderColor = theme.GetBorderColor((theme.Colors.IsDarkTheme) ? 3 : 5)
};
{ var intField = new IntField();
switch (settingData.DataEditType) uiField = intField;
{
case SliceSettingData.DataEditTypes.INT:
var intField = new IntField(); if (settingData.SlicerConfigName == "extruder_count")
uiField = intField; {
intField.MaxValue = 4;
intField.MinValue = 0;
}
if (settingData.SlicerConfigName == "extruder_count") break;
case SliceSettingData.DataEditTypes.DOUBLE:
case SliceSettingData.DataEditTypes.OFFSET:
uiField = new DoubleField();
break;
case SliceSettingData.DataEditTypes.POSITIVE_DOUBLE:
if (settingData.SetSettingsOnChange.Count > 0)
{
uiField = new BoundDoubleField(settingsContext, settingData);
}
else
{
uiField = new PositiveDoubleField();
};
break;
case SliceSettingData.DataEditTypes.DOUBLE_OR_PERCENT:
uiField = new DoubleOrPercentField();
break;
case SliceSettingData.DataEditTypes.INT_OR_MM:
uiField = new IntOrMmField();
break;
case SliceSettingData.DataEditTypes.CHECK_BOX:
uiField = new ToggleboxField(textColor);
useDefaultSavePattern = false;
uiField.ValueChanged += (s, e) =>
{
if (e.UserInitiated)
{ {
intField.MaxValue = 4; // Linked settings should be updated in all cases (user clicked checkbox, user clicked clear)
intField.MinValue = 0; foreach (var setSettingsData in settingData.SetSettingsOnChange)
}
break;
case SliceSettingData.DataEditTypes.DOUBLE:
case SliceSettingData.DataEditTypes.OFFSET:
uiField = new DoubleField();
break;
case SliceSettingData.DataEditTypes.POSITIVE_DOUBLE:
if (settingData.SetSettingsOnChange.Count > 0)
{
uiField = new BoundDoubleField(settingsContext, settingData);
}
else
{
uiField = new PositiveDoubleField();
};
break;
case SliceSettingData.DataEditTypes.DOUBLE_OR_PERCENT:
uiField = new DoubleOrPercentField();
break;
case SliceSettingData.DataEditTypes.INT_OR_MM:
uiField = new IntOrMmField();
break;
case SliceSettingData.DataEditTypes.CHECK_BOX:
uiField = new ToggleboxField(textColor);
useDefaultSavePattern = false;
uiField.ValueChanged += (s, e) =>
{
if (e.UserInitiated)
{ {
// Linked settings should be updated in all cases (user clicked checkbox, user clicked clear) string targetValue;
foreach (var setSettingsData in settingData.SetSettingsOnChange)
{
string targetValue;
if (uiField.Content is CheckBox checkbox) if (uiField.Content is CheckBox checkbox)
{
if (setSettingsData.TryGetValue(checkbox.Checked ? "OnValue" : "OffValue", out targetValue))
{ {
if (setSettingsData.TryGetValue(checkbox.Checked ? "OnValue" : "OffValue", out targetValue)) settingsContext.SetValue(setSettingsData["TargetSetting"], targetValue);
{
settingsContext.SetValue(setSettingsData["TargetSetting"], targetValue);
}
} }
} }
// Store actual field value
settingsContext.SetValue(settingData.SlicerConfigName, uiField.Value);
} }
};
break;
case SliceSettingData.DataEditTypes.STRING: // Store actual field value
case SliceSettingData.DataEditTypes.WIDE_STRING: settingsContext.SetValue(settingData.SlicerConfigName, uiField.Value);
uiField = new TextField(); }
break; };
break;
case SliceSettingData.DataEditTypes.MULTI_LINE_TEXT: case SliceSettingData.DataEditTypes.STRING:
uiField = new MultilineStringField(); case SliceSettingData.DataEditTypes.WIDE_STRING:
placeFieldInDedicatedRow = true; uiField = new TextField();
break; break;
case SliceSettingData.DataEditTypes.COM_PORT: case SliceSettingData.DataEditTypes.MULTI_LINE_TEXT:
useDefaultSavePattern = false; uiField = new MultilineStringField();
placeFieldInDedicatedRow = true;
break;
sliceSettingValue = printer.Settings.Helpers.ComPort(); case SliceSettingData.DataEditTypes.COM_PORT:
useDefaultSavePattern = false;
uiField = new ComPortField(printer, theme); sliceSettingValue = printer.Settings.Helpers.ComPort();
uiField.ValueChanged += (s, e) =>
uiField = new ComPortField(printer, theme);
uiField.ValueChanged += (s, e) =>
{
if (e.UserInitiated)
{ {
if (e.UserInitiated) printer.Settings.Helpers.SetComPort(uiField.Value);
{ }
printer.Settings.Helpers.SetComPort(uiField.Value); };
}
};
break; break;
case SliceSettingData.DataEditTypes.LIST: case SliceSettingData.DataEditTypes.LIST:
uiField = new ListField() uiField = new ListField()
{ {
ListItems = settingData.ListValues.Split(',').ToList() ListItems = settingData.ListValues.Split(',').ToList()
}; };
break; break;
case SliceSettingData.DataEditTypes.HARDWARE_PRESENT: case SliceSettingData.DataEditTypes.HARDWARE_PRESENT:
uiField = new ToggleboxField(textColor); uiField = new ToggleboxField(textColor);
break; break;
case SliceSettingData.DataEditTypes.VECTOR2: case SliceSettingData.DataEditTypes.VECTOR2:
uiField = new Vector2Field(); uiField = new Vector2Field();
break; break;
case SliceSettingData.DataEditTypes.OFFSET2: case SliceSettingData.DataEditTypes.OFFSET2:
placeFieldInDedicatedRow = true; placeFieldInDedicatedRow = true;
uiField = new ExtruderOffsetField(settingsContext, settingData.SlicerConfigName, textColor); uiField = new ExtruderOffsetField(settingsContext, settingData.SlicerConfigName, textColor);
break; break;
#if !__ANDROID__ #if !__ANDROID__
case SliceSettingData.DataEditTypes.IP_LIST: case SliceSettingData.DataEditTypes.IP_LIST:
uiField = new IpAddessField(printer); uiField = new IpAddessField(printer);
break; break;
#endif #endif
default: default:
// Missing Setting // Missing Setting
settingsRow.AddContent(new TextWidget($"Missing the setting for '{settingData.DataEditType}'.") settingsRow.AddContent(new TextWidget($"Missing the setting for '{settingData.DataEditType}'.")
{ {
TextColor = textColor, TextColor = textColor,
BackgroundColor = Color.Red BackgroundColor = Color.Red
}); });
break; break;
}
} }
if (uiField != null) if (uiField != null)