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);
}
this. BindBedOptions(container, bedButton, printAreaButton, sceneContext.RendererOptions);
this.BindBedOptions(container, bedButton, printAreaButton, sceneContext.RendererOptions);
return container;
}

View file

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

View file

@ -1,14 +1,13 @@
using System;
using MatterHackers.Agg;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.ImageProcessing;
using MatterHackers.Agg.UI;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.VectorMath;
using MatterHackers.MatterControl.SlicerConfiguration;
namespace MatterHackers.MatterControl.ConfigurationPage
{
public class SettingsItem : FlowLayoutWidget
public class SettingsItem : SettingsRow
{
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)
: base (FlowDirection.LeftToRight)
: base (text, "", textColor, ApplicationController.Instance.Theme)
{
var theme = ApplicationController.Instance.Theme;
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)
{

View file

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

View file

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

View file

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

View file

@ -42,7 +42,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
public class OverflowBar : Toolbar
{
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)
{

View file

@ -33,6 +33,7 @@ using MatterHackers.Agg;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.VectorMath;
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)
{
this.theme = theme;
this.MinimumSize = new Vector2(0, 28);
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;
if (icon != null)
@ -85,15 +91,9 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
Margin = new BorderDouble(right: 6)
});
GuiWidget nameArea;
this.AddChild(nameArea = new GuiWidget()
{
MinimumSize = new Vector2(50, 0),
HAnchor = HAnchor.Stretch,
VAnchor = VAnchor.Fit | VAnchor.Center,
DebugShowBounds = debugLayout
});
nameArea.AddChild(settingsLabel = SettingsRow.CreateSettingsLabel(title, helpText, textColor));
this.AddChild(settingsLabel = SettingsRow.CreateSettingsLabel(title, helpText, textColor));
this.AddChild(new HorizontalSpacer());
if (fullRowSelect)
{
@ -103,11 +103,11 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
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,
ToolTipText = helpText.Localize(),
Margin = new BorderDouble(0, 5, 5, 5),
AutoExpandBoundsToText = true,
VAnchor = VAnchor.Center,
ToolTipText = string.IsNullOrWhiteSpace(helpText) ? null : helpText,
};
}

View file

@ -50,7 +50,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
private Button restoreButton = null;
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.settingData = settingData;

View file

@ -512,6 +512,8 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
HorizontalLine lastLine = null;
GuiWidget settingsRow = null;
foreach (SliceSettingData settingData in subGroup.Settings)
{
// 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)
&& settingShouldBeShown)
{
var settingsRow = CreateItemRow(settingData);
settingsRow = CreateItemRow(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();
return (topToBottomSettings.Children.Count == 1) ? null : topToBottomSettings;
@ -628,142 +636,133 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
bool placeFieldInDedicatedRow = false;
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,
VAnchor = VAnchor.Fit,
MinimumSize = new Vector2(0, theme.ButtonHeight),
Border = new BorderDouble(bottom: 1),
BorderColor = theme.GetBorderColor((theme.Colors.IsDarkTheme) ? 3 : 5)
};
case SliceSettingData.DataEditTypes.INT:
{
switch (settingData.DataEditType)
{
case SliceSettingData.DataEditTypes.INT:
var intField = new IntField();
uiField = intField;
var intField = new IntField();
uiField = intField;
if (settingData.SlicerConfigName == "extruder_count")
{
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;
intField.MinValue = 0;
}
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)
foreach (var setSettingsData in settingData.SetSettingsOnChange)
{
// Linked settings should be updated in all cases (user clicked checkbox, user clicked clear)
foreach (var setSettingsData in settingData.SetSettingsOnChange)
{
string targetValue;
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:
case SliceSettingData.DataEditTypes.WIDE_STRING:
uiField = new TextField();
break;
// Store actual field value
settingsContext.SetValue(settingData.SlicerConfigName, uiField.Value);
}
};
break;
case SliceSettingData.DataEditTypes.MULTI_LINE_TEXT:
uiField = new MultilineStringField();
placeFieldInDedicatedRow = true;
break;
case SliceSettingData.DataEditTypes.STRING:
case SliceSettingData.DataEditTypes.WIDE_STRING:
uiField = new TextField();
break;
case SliceSettingData.DataEditTypes.COM_PORT:
useDefaultSavePattern = false;
case SliceSettingData.DataEditTypes.MULTI_LINE_TEXT:
uiField = new MultilineStringField();
placeFieldInDedicatedRow = true;
break;
sliceSettingValue = printer.Settings.Helpers.ComPort();
case SliceSettingData.DataEditTypes.COM_PORT:
useDefaultSavePattern = false;
uiField = new ComPortField(printer, theme);
uiField.ValueChanged += (s, e) =>
sliceSettingValue = printer.Settings.Helpers.ComPort();
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:
uiField = new ListField()
{
ListItems = settingData.ListValues.Split(',').ToList()
};
break;
case SliceSettingData.DataEditTypes.LIST:
uiField = new ListField()
{
ListItems = settingData.ListValues.Split(',').ToList()
};
break;
case SliceSettingData.DataEditTypes.HARDWARE_PRESENT:
uiField = new ToggleboxField(textColor);
break;
case SliceSettingData.DataEditTypes.HARDWARE_PRESENT:
uiField = new ToggleboxField(textColor);
break;
case SliceSettingData.DataEditTypes.VECTOR2:
uiField = new Vector2Field();
break;
case SliceSettingData.DataEditTypes.VECTOR2:
uiField = new Vector2Field();
break;
case SliceSettingData.DataEditTypes.OFFSET2:
placeFieldInDedicatedRow = true;
uiField = new ExtruderOffsetField(settingsContext, settingData.SlicerConfigName, textColor);
break;
case SliceSettingData.DataEditTypes.OFFSET2:
placeFieldInDedicatedRow = true;
uiField = new ExtruderOffsetField(settingsContext, settingData.SlicerConfigName, textColor);
break;
#if !__ANDROID__
case SliceSettingData.DataEditTypes.IP_LIST:
uiField = new IpAddessField(printer);
break;
case SliceSettingData.DataEditTypes.IP_LIST:
uiField = new IpAddessField(printer);
break;
#endif
default:
// Missing Setting
settingsRow.AddContent(new TextWidget($"Missing the setting for '{settingData.DataEditType}'.")
{
TextColor = textColor,
BackgroundColor = Color.Red
});
break;
}
default:
// Missing Setting
settingsRow.AddContent(new TextWidget($"Missing the setting for '{settingData.DataEditType}'.")
{
TextColor = textColor,
BackgroundColor = Color.Red
});
break;
}
if (uiField != null)