Simplify, expose previously wrapped SectionWidget, sync styling

This commit is contained in:
John Lewin 2018-01-10 18:22:13 -08:00
parent 2ff53914ea
commit 0825a9132b
9 changed files with 207 additions and 229 deletions

View file

@ -19,59 +19,12 @@ namespace MatterHackers.MatterControl.PrinterControls
private TextImageButtonFactory buttonFactory;
private PrinterConfig printer;
public CalibrationControls(PrinterConfig printer, ThemeConfig theme)
private CalibrationControls(PrinterConfig printer, ThemeConfig theme)
: base(FlowDirection.TopToBottom)
{
this.printer = printer;
this.buttonFactory = theme.ButtonFactory;
var container = new FlowLayoutWidget(FlowDirection.TopToBottom)
{
HAnchor = HAnchor.Stretch,
VAnchor = VAnchor.Fit,
Padding = new BorderDouble(3, 0)
};
Button editButton = buttonFactory.GenerateIconButton(AggContext.StaticData.LoadIcon("icon_edit.png", 16, 16, IconColor.Theme));
editButton.Click += (sender, e) =>
{
UiThread.RunOnIdle(() =>
{
if (editLevelingSettingsWindow == null)
{
editLevelingSettingsWindow = new EditLevelingSettingsWindow(printer.Settings);
editLevelingSettingsWindow.Closed += (sender2, e2) =>
{
editLevelingSettingsWindow = null;
};
}
else
{
editLevelingSettingsWindow.BringToFront();
}
});
};
this.AddChild(
new SectionWidget(
"Calibration".Localize(),
container,
theme,
editButton));
if (!printer.Settings.GetValue<bool>(SettingsKey.has_hardware_leveling))
{
container.AddChild(GetAutoLevelControl());
}
printer.Connection.CommunicationStateChanged.RegisterEvent(PrinterStatusChanged, ref unregisterEvents);
printer.Connection.EnableChanged.RegisterEvent(PrinterStatusChanged, ref unregisterEvents);
SetVisibleControls();
}
private FlowLayoutWidget GetAutoLevelControl()
{
var buttonRow = new FlowLayoutWidget()
{
Name = "AutoLevelRowItem",
@ -127,7 +80,29 @@ namespace MatterHackers.MatterControl.PrinterControls
buttonRow.AddChild(printLevelingSwitch);
}
return buttonRow;
this.AddChild(buttonRow);
printer.Connection.CommunicationStateChanged.RegisterEvent(PrinterStatusChanged, ref unregisterEvents);
printer.Connection.EnableChanged.RegisterEvent(PrinterStatusChanged, ref unregisterEvents);
SetVisibleControls();
}
public static SectionWidget CreateSection(PrinterConfig printer, ThemeConfig theme)
{
var widget = new CalibrationControls(printer, theme);
var editButton = new IconButton(AggContext.StaticData.LoadIcon("icon_edit.png", 16, 16, IconColor.Theme), theme);
editButton.Click += (s, e) =>
{
widget.EditOptions();
};
return new SectionWidget(
"Calibration".Localize(),
widget,
theme,
editButton);
}
public override void OnClosed(ClosedEventArgs e)
@ -136,6 +111,25 @@ namespace MatterHackers.MatterControl.PrinterControls
base.OnClosed(e);
}
private void EditOptions()
{
UiThread.RunOnIdle(() =>
{
if (editLevelingSettingsWindow == null)
{
editLevelingSettingsWindow = new EditLevelingSettingsWindow(printer.Settings);
editLevelingSettingsWindow.Closed += (s, e) =>
{
editLevelingSettingsWindow = null;
};
}
else
{
editLevelingSettingsWindow.BringToFront();
}
});
}
private void PrinterStatusChanged(object sender, EventArgs e)
{
SetVisibleControls();

View file

@ -47,7 +47,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
{
heading = new TextWidget(sectionTitle, pointSize: pointSize, textColor: theme.Colors.PrimaryTextColor);
}
heading.Padding = new BorderDouble(0, 3, 0, 6);
heading.Padding = new BorderDouble(0, 5, 0, 6);
if (rightAlignedContent == null)
{

View file

@ -205,7 +205,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
foreach(var sectionWidget in scrollableContent.Children<SectionWidget>())
{
var contentPanel = sectionWidget.ContentPanel;
contentPanel.Padding = new BorderDouble(16, 8, 8, 4);
contentPanel.Padding = new BorderDouble(16, 8, 8, 2);
}
HashSet<IObject3DEditor> mappedEditors;

View file

@ -53,16 +53,9 @@ namespace MatterHackers.MatterControl.PrinterControls
private EventHandler unregisterEvents;
public AdjustmentControls(PrinterConfig printer, ThemeConfig theme)
private AdjustmentControls(PrinterConfig printer, ThemeConfig theme)
: base (FlowDirection.TopToBottom)
{
var topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom)
{
Margin = new BorderDouble(0, 0, 0, 0),
HAnchor = HAnchor.Stretch,
Padding = new BorderDouble(3, 0, 3, 0)
};
double sliderWidth = 300 * GuiWidget.DeviceScale;
double sliderThumbWidth = 10 * GuiWidget.DeviceScale;
@ -128,7 +121,7 @@ namespace MatterHackers.MatterControl.PrinterControls
};
row.AddChild(feedRateValue);
topToBottom.AddChild(row);
this.AddChild(row);
}
{
@ -194,15 +187,9 @@ namespace MatterHackers.MatterControl.PrinterControls
row.AddChild(extrusionRatioSlider);
row.AddChild(extrusionValue);
topToBottom.AddChild(row);
this.AddChild(row);
}
this.AddChild(
new SectionWidget(
"Tuning Adjustment".Localize(),
topToBottom,
theme));
ActiveSliceSettings.SettingChanged.RegisterEvent((s, e) =>
{
var eventArgs = e as StringEventArgs;
@ -221,6 +208,14 @@ namespace MatterHackers.MatterControl.PrinterControls
}, ref unregisterEvents);
}
public static SectionWidget CreateSection(PrinterConfig printer, ThemeConfig theme)
{
return new SectionWidget(
"Tuning Adjustment".Localize(),
new AdjustmentControls(printer, theme),
theme);
}
public override void OnLoad(EventArgs args)
{
// This is a hack to fix the layout issue this control is having.

View file

@ -45,7 +45,7 @@ namespace MatterHackers.MatterControl.PrinterControls
private CheckBox toggleSwitch;
public FanControls(PrinterConnection printerConnection, ThemeConfig theme)
private FanControls(PrinterConnection printerConnection, ThemeConfig theme)
: base(FlowDirection.TopToBottom)
{
this.HAnchor = HAnchor.Stretch;
@ -103,11 +103,7 @@ namespace MatterHackers.MatterControl.PrinterControls
VAnchor = VAnchor.Center
});
this.AddChild(
new SectionWidget(
"Fan".Localize(),
leftToRight,
theme));
this.AddChild(leftToRight);
// CreateFanControls
printerConnection.FanSpeedSet.RegisterEvent((s, e) =>
@ -126,6 +122,14 @@ namespace MatterHackers.MatterControl.PrinterControls
, ref unregisterEvents);
}
public static SectionWidget CreateSection(PrinterConfig printer, ThemeConfig theme)
{
return new SectionWidget(
"Fan".Localize(),
new FanControls(printer.Connection, theme),
theme);
}
public override void OnClosed(ClosedEventArgs e)
{
unregisterEvents?.Invoke(this, null);

View file

@ -37,65 +37,56 @@ using MatterHackers.MatterControl.SlicerConfiguration;
namespace MatterHackers.MatterControl.PrinterControls
{
public class MacroControls : FlowLayoutWidget
public class MacroControls : FlowLeftRightWithWrapping
{
//private PrinterConfig printer;
public MacroControls(PrinterConfig printer, ThemeConfig theme)
: base(FlowDirection.TopToBottom)
private MacroControls(PrinterConfig printer, ThemeConfig theme)
{
this.HAnchor = HAnchor.Stretch;
var noMacrosFound = new TextWidget("No macros are currently set up for this printer.".Localize(), pointSize: 10)
{
TextColor = ActiveTheme.Instance.PrimaryTextColor,
};
this.AddChild(noMacrosFound);
var buttonFactory = ApplicationController.Instance.Theme.HomingButtons;
if (printer.Settings?.GetMacros(MacroUiLocation.Controls).Any() != true)
{
noMacrosFound.Visible = true;
return;
}
// add the widgets to this window
Button editButton = buttonFactory.GenerateIconButton(AggContext.StaticData.LoadIcon("icon_edit.png", 16, 16, IconColor.Theme));
foreach (GCodeMacro macro in printer.Settings.GetMacros(MacroUiLocation.Controls))
{
Button macroButton = theme.HomingButtons.Generate(GCodeMacro.FixMacroName(macro.Name));
macroButton.Margin = new BorderDouble(right: 5);
macroButton.Click += (s, e) => macro.Run(printer.Connection);
this.AddChild(macroButton);
}
this.Children.CollectionChanged += (s, e) =>
{
if (!this.HasBeenClosed)
{
noMacrosFound.Visible = this.Children.Count == 0;
}
};
}
public static SectionWidget CreateSection(PrinterConfig printer, ThemeConfig theme)
{
var widget = new MacroControls(printer, theme);
var editButton = new IconButton(AggContext.StaticData.LoadIcon("icon_edit.png", 16, 16, IconColor.Theme), theme);
editButton.Click += (s, e) =>
{
DialogWindow.Show(new MacroListPage(printer.Settings));
};
this.AddChild(
new SectionWidget(
"Macros".Localize(),
GetMacroButtonContainer(buttonFactory, printer),
theme,
editButton));
}
private FlowLayoutWidget GetMacroButtonContainer(TextImageButtonFactory buttonFactory, PrinterConfig printer)
{
var macroContainer = new FlowLeftRightWithWrapping();
var noMacrosFound = new TextWidget("No macros are currently set up for this printer.".Localize(), pointSize: 10)
{
TextColor = ActiveTheme.Instance.PrimaryTextColor,
};
macroContainer.AddChild(noMacrosFound);
if (printer.Settings?.GetMacros(MacroUiLocation.Controls).Any() != true)
{
noMacrosFound.Visible = true;
return macroContainer;
}
foreach (GCodeMacro macro in printer.Settings.GetMacros(MacroUiLocation.Controls))
{
Button macroButton = buttonFactory.Generate(GCodeMacro.FixMacroName(macro.Name));
macroButton.Margin = new BorderDouble(right: 5);
macroButton.Click += (s, e) => macro.Run(printer.Connection);
macroContainer.AddChild(macroButton);
}
macroContainer.Children.CollectionChanged += (s, e) =>
{
if (!this.HasBeenClosed)
{
noMacrosFound.Visible = macroContainer.Children.Count == 0;
}
};
return macroContainer;
return new SectionWidget(
"Macros".Localize(),
widget,
theme,
editButton);
}
}
}

View file

@ -64,12 +64,67 @@ namespace MatterHackers.MatterControl.PrinterControls
private EventHandler unregisterEvents;
private MovementControls(PrinterConfig printer, ThemeConfig theme)
: base (FlowDirection.TopToBottom)
{
this.printer = printer;
this.theme = theme;
jogControls = new JogControls(printer, new XYZColors())
{
HAnchor = HAnchor.Left | HAnchor.Stretch,
Margin = 0
};
this.AddChild(CreateDisableableContainer(GetHomeButtonBar()));
// Separator line
this.AddChild(new HorizontalLine(alpha: 50)
{
Margin = new BorderDouble(0, 5)
});
this.AddChild(jogControls);
this.AddChild(CreateDisableableContainer(GetHWDestinationBar()));
}
public static SectionWidget CreateSection(PrinterConfig printer, ThemeConfig theme)
{
var widget = new MovementControls(printer, theme);
var editButton = new IconButton(AggContext.StaticData.LoadIcon("icon_edit.png", 16, 16, IconColor.Theme), theme);
editButton.Click += (s, e) => widget.EditOptions();
return new SectionWidget(
"Movement".Localize(),
widget,
theme,
editButton);
}
public override void OnClosed(ClosedEventArgs e)
{
unregisterEvents?.Invoke(this, null);
base.OnClosed(e);
}
private void EditOptions()
{
if (editManualMovementSettingsWindow == null)
{
editManualMovementSettingsWindow = new EditManualMovementSpeedsWindow("Movement Speeds".Localize(), printer.Settings.Helpers.GetMovementSpeedsString(), SetMovementSpeeds);
editManualMovementSettingsWindow.Closed += (s, e) =>
{
editManualMovementSettingsWindow = null;
};
}
else
{
editManualMovementSettingsWindow.BringToFront();
}
}
/// <summary>
/// Helper method to create DisableableWidget containers and populate the DisableableWidgets local property.
/// </summary>
@ -87,63 +142,6 @@ namespace MatterHackers.MatterControl.PrinterControls
return container;
}
public MovementControls(PrinterConfig printer, ThemeConfig theme)
: base (FlowDirection.TopToBottom)
{
this.printer = printer;
this.theme = theme;
var buttonFactory = theme.DisableableControlBase;
Button editButton = buttonFactory.GenerateIconButton(AggContext.StaticData.LoadIcon("icon_edit.png", 16, 16, IconColor.Theme));
editButton.Click += (sender, e) =>
{
if (editManualMovementSettingsWindow == null)
{
editManualMovementSettingsWindow = new EditManualMovementSpeedsWindow("Movement Speeds".Localize(), printer.Settings.Helpers.GetMovementSpeedsString(), SetMovementSpeeds);
editManualMovementSettingsWindow.Closed += (s, e2) =>
{
editManualMovementSettingsWindow = null;
};
}
else
{
editManualMovementSettingsWindow.BringToFront();
}
};
jogControls = new JogControls(printer, new XYZColors())
{
HAnchor = HAnchor.Left | HAnchor.Stretch,
Margin = 0
};
manualControlsLayout = new FlowLayoutWidget(FlowDirection.TopToBottom)
{
HAnchor = HAnchor.Stretch,
VAnchor = VAnchor.Fit,
};
manualControlsLayout.AddChild(CreateDisableableContainer(GetHomeButtonBar()));
// Separator line
manualControlsLayout.AddChild(new HorizontalLine(alpha: 50)
{
Margin = new BorderDouble(0, 5)
});
manualControlsLayout.AddChild(jogControls);
manualControlsLayout.AddChild(CreateDisableableContainer(GetHWDestinationBar()));
this.AddChild(
new SectionWidget(
"Movement".Localize(),
manualControlsLayout,
theme,
editButton));
}
private void SetMovementSpeeds(string speedString)
{
if (!string.IsNullOrEmpty(speedString))
@ -369,5 +367,4 @@ namespace MatterHackers.MatterControl.PrinterControls
base.OnClosed(e);
}
}
}

View file

@ -31,6 +31,7 @@ using System;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.SlicerConfiguration;
namespace MatterHackers.MatterControl.PrinterControls
@ -41,33 +42,26 @@ namespace MatterHackers.MatterControl.PrinterControls
private CheckBox atxPowertoggleSwitch;
private PrinterConfig printer;
public PowerControls(PrinterConfig printer, int headingPointSize)
private PowerControls(PrinterConfig printer)
: base(FlowDirection.TopToBottom)
{
this.printer = printer;
var fanControlsGroupBox = new AltGroupBox(new TextWidget("ATX Power Control".Localize(), pointSize: headingPointSize, textColor: ActiveTheme.Instance.SecondaryAccentColor, bold: true));
fanControlsGroupBox.Margin = new BorderDouble(0);
fanControlsGroupBox.BorderColor = ActiveTheme.Instance.PrimaryTextColor;
fanControlsGroupBox.HAnchor |= HAnchor.Stretch;
this.AddChild(fanControlsGroupBox);
this.HAnchor = HAnchor.Stretch;
this.VAnchor = VAnchor.Stretch;
this.Visible = printer.Settings.GetValue<bool>(SettingsKey.has_power_control);
this.Enabled = printer.Connection.PrinterIsConnected;
atxPowertoggleSwitch = ImageButtonFactory.CreateToggleSwitch(false);
atxPowertoggleSwitch.HAnchor = HAnchor.Left;
atxPowertoggleSwitch.Margin = new BorderDouble(6, 0, 6, 6);
atxPowertoggleSwitch.CheckedStateChanged += (sender, e) =>
{
printer.Connection.AtxPowerEnabled = atxPowertoggleSwitch.Checked;
};
FlowLayoutWidget paddingContainer = new FlowLayoutWidget();
paddingContainer.Padding = new BorderDouble(3, 5, 3, 0);
{
paddingContainer.AddChild(atxPowertoggleSwitch);
}
fanControlsGroupBox.AddChild(paddingContainer);
this.AddChild(atxPowertoggleSwitch);
printer.Connection.CommunicationStateChanged.RegisterEvent((s, e) =>
{
{
this.Visible = printer.Settings.GetValue<bool>(SettingsKey.has_power_control);
this.Enabled = printer.Connection.PrinterIsConnected;
}, ref unregisterEvents);
@ -76,12 +70,14 @@ namespace MatterHackers.MatterControl.PrinterControls
{
this.atxPowertoggleSwitch.Checked = printer.Connection.AtxPowerEnabled;
}, ref unregisterEvents);
}
this.Visible = printer.Settings.GetValue<bool>(SettingsKey.has_power_control);
this.Enabled = printer.Connection.PrinterIsConnected;
this.HAnchor = HAnchor.Stretch;
this.VAnchor = VAnchor.Stretch;
public static SectionWidget CreateSection(PrinterConfig printer, ThemeConfig theme)
{
return new SectionWidget(
"ATX Power Control".Localize(),
new PowerControls(printer),
theme);
}
public override void OnClosed(ClosedEventArgs e)

View file

@ -29,7 +29,10 @@ either expressed or implied, of the FreeBSD Project.
using System;
using MatterHackers.Agg;
using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.PrinterControls;
using MatterHackers.MatterControl.SlicerConfiguration;
@ -109,48 +112,46 @@ namespace MatterHackers.MatterControl
};
this.AddChild(controlsTopToBottomLayout);
movementControlsContainer = new MovementControls(printer, theme)
{
Margin = new BorderDouble(top: 6),
HAnchor = HAnchor.Stretch,
VAnchor = VAnchor.Fit
};
controlsTopToBottomLayout.AddChild(movementControlsContainer);
SectionWidget sectionWidget;
sectionWidget = MovementControls.CreateSection(printer, theme);
controlsTopToBottomLayout.AddChild(sectionWidget);
movementControlsContainer = sectionWidget.ContentPanel as MovementControls;
if (!printer.Settings.GetValue<bool>(SettingsKey.has_hardware_leveling))
{
calibrationControlsContainer = new CalibrationControls(printer, theme);
controlsTopToBottomLayout.AddChild(calibrationControlsContainer);
sectionWidget = CalibrationControls.CreateSection(printer, theme);
controlsTopToBottomLayout.AddChild(sectionWidget);
calibrationControlsContainer = sectionWidget.ContentPanel;
}
macroControlsContainer = new MacroControls(printer, theme);
controlsTopToBottomLayout.AddChild(macroControlsContainer);
sectionWidget = MacroControls.CreateSection(printer, theme);
controlsTopToBottomLayout.AddChild(sectionWidget);
macroControlsContainer = sectionWidget.ContentPanel;
var linearPanel = new FlowLayoutWidget()
{
HAnchor = HAnchor.Stretch
};
controlsTopToBottomLayout.AddChild(linearPanel);
fanControlsContainer = new FanControls(printer.Connection, theme);
if (printer.Settings.GetValue<bool>(SettingsKey.has_fan))
{
controlsTopToBottomLayout.AddChild(fanControlsContainer);
sectionWidget = FanControls.CreateSection(printer, theme);
controlsTopToBottomLayout.AddChild(sectionWidget);
fanControlsContainer = sectionWidget.ContentPanel;
}
#if !__ANDROID__
controlsTopToBottomLayout.AddChild(new PowerControls(printer, headingPointSize)
{
HAnchor = HAnchor.Stretch,
VAnchor = VAnchor.Fit
});
sectionWidget = PowerControls.CreateSection(printer, theme);
controlsTopToBottomLayout.AddChild(sectionWidget);
#endif
tuningAdjustmentControlsContainer = new AdjustmentControls(printer, theme)
sectionWidget = AdjustmentControls.CreateSection(printer, theme);
controlsTopToBottomLayout.AddChild(sectionWidget);
tuningAdjustmentControlsContainer = sectionWidget.ContentPanel;
// Enforce panel padding in sidebar
foreach (var widget in controlsTopToBottomLayout.Children<SectionWidget>())
{
HAnchor = HAnchor.Stretch,
VAnchor = VAnchor.Fit
};
controlsTopToBottomLayout.AddChild(tuningAdjustmentControlsContainer);
var contentPanel = widget.ContentPanel;
contentPanel.Padding = new BorderDouble(16, 16, 8, 2);
}
// HACK: this is a hack to make the layout engine fire again for this control
UiThread.RunOnIdle(() => tuningAdjustmentControlsContainer.Width = tuningAdjustmentControlsContainer.Width + 1);