Add overflow menu to header, move non-primary actions to overflow menu

This commit is contained in:
John Lewin 2018-06-18 09:42:13 -07:00
parent cf0dbb7326
commit cf094c4fb8
3 changed files with 65 additions and 108 deletions

View file

@ -33,6 +33,7 @@ using MatterHackers.Agg;
using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.PartPreviewWindow;
using MatterHackers.MatterControl.PrinterCommunication;
namespace MatterHackers.MatterControl.EeProm
@ -97,50 +98,14 @@ namespace MatterHackers.MatterControl.EeProm
currentEePromSettings = new EePromMarlinSettings(printerConnection);
currentEePromSettings.eventAdded += SetUiToPrinterSettings;
GuiWidget mainContainer = new GuiWidget();
mainContainer.AnchorAll();
mainContainer.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
mainContainer.Padding = new BorderDouble(3, 0);
// space filling color
GuiWidget spaceFiller = new GuiWidget(0, 500);
spaceFiller.VAnchor = VAnchor.Bottom;
spaceFiller.HAnchor = HAnchor.Stretch;
spaceFiller.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
spaceFiller.Padding = new BorderDouble(top: 3);
mainContainer.AddChild(spaceFiller);
double topBarHeight = 0;
// the top button bar
{
FlowLayoutWidget topButtonBar = new FlowLayoutWidget();
topButtonBar.HAnchor = HAnchor.Stretch;
topButtonBar.VAnchor = VAnchor.Fit | VAnchor.Top;
topButtonBar.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
topButtonBar.Margin = new BorderDouble(0, 3);
Button buttonSetToFactorySettings = textImageButtonFactory.Generate("Reset to Factory Defaults".Localize());
topButtonBar.AddChild(buttonSetToFactorySettings);
buttonSetToFactorySettings.Click += (sender, e) =>
{
currentEePromSettings.SetPrinterToFactorySettings();
currentEePromSettings.Update();
};
mainContainer.AddChild(topButtonBar);
topBarHeight = topButtonBar.Height;
}
var mainContainer = contentRow;
// the center content
FlowLayoutWidget conterContent = new FlowLayoutWidget(FlowDirection.TopToBottom);
conterContent.VAnchor = VAnchor.Fit | VAnchor.Top;
conterContent.HAnchor = HAnchor.Stretch;
conterContent.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
conterContent.Padding = new BorderDouble(top: 3);
conterContent.Margin = new BorderDouble(top: topBarHeight);
var conterContent = new FlowLayoutWidget(FlowDirection.TopToBottom)
{
VAnchor = VAnchor.Fit | VAnchor.Top,
HAnchor = HAnchor.Stretch
};
conterContent.AddChild(Create4FieldSet("Steps per mm".Localize() + ":",
"X:", ref stepsPerMmX,
@ -186,22 +151,12 @@ namespace MatterHackers.MatterControl.EeProm
conterContent.AddChild(CreateField("Maximum Z jerk [mm/s]".Localize() + ":", ref maxZJerk));
conterContent.AddChild(CreateField("Maximum E jerk [mm/s]".Localize() + ":", ref maxEJerk));
GuiWidget topBottomSpacer = new GuiWidget(1, 1);
topBottomSpacer.VAnchor = VAnchor.Stretch;
conterContent.AddChild(topBottomSpacer);
mainContainer.AddChild(conterContent);
// the bottom button bar
{
FlowLayoutWidget bottomButtonBar = new FlowLayoutWidget();
bottomButtonBar.HAnchor = Agg.UI.HAnchor.MaxFitOrStretch;
bottomButtonBar.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
bottomButtonBar.Margin = new BorderDouble(0, 3);
Button buttonSave = textImageButtonFactory.Generate("Save to EEProm".Localize());
bottomButtonBar.AddChild(buttonSave);
buttonSave.Click += (sender, e) =>
var buttonSave = theme.CreateDialogButton("Save to EEProm".Localize());
buttonSave.Click += (s, e) =>
{
UiThread.RunOnIdle(() =>
{
@ -210,15 +165,21 @@ namespace MatterHackers.MatterControl.EeProm
Close();
});
};
this.AddPageAction(buttonSave);
}
CreateSpacer(bottomButtonBar);
printerConnection.CommunicationUnconditionalFromPrinter.RegisterEvent(currentEePromSettings.Add, ref unregisterEvents);
// put in the import button
#if true
// and ask the printer to send the settings
currentEePromSettings.Update();
if (headerRow is OverflowBar overflowBar)
{
overflowBar.ExtendOverflowMenu = (popupMenu) =>
{
Button buttonImport = textImageButtonFactory.Generate("Import".Localize() + "...");
buttonImport.Margin = new BorderDouble(0, 3);
buttonImport.Click += (sender, e) =>
var menuItem = popupMenu.CreateMenuItem("Import".Localize());
menuItem.Name = "Import Menu Item";
menuItem.Click += (s, e) =>
{
UiThread.RunOnIdle(() =>
{
@ -234,18 +195,15 @@ namespace MatterHackers.MatterControl.EeProm
{
currentEePromSettings.Import(openParams.FileName);
SetUiToPrinterSettings(null, null);
}
}
});
});
};
bottomButtonBar.AddChild(buttonImport);
}
// put in the export button
{
Button buttonExport = textImageButtonFactory.Generate("Export".Localize() + "...");
buttonExport.Margin = new BorderDouble(0, 3);
buttonExport.Click += (sender, e) =>
// put in the export button
menuItem = popupMenu.CreateMenuItem("Export".Localize());
menuItem.Name = "Export Menu Item";
menuItem.Click += (s, e) =>
{
UiThread.RunOnIdle(() =>
{
@ -267,24 +225,18 @@ namespace MatterHackers.MatterControl.EeProm
});
});
};
bottomButtonBar.AddChild(buttonExport);
}
#endif
Button buttonAbort = textImageButtonFactory.Generate("Close".Localize());
bottomButtonBar.AddChild(buttonAbort);
buttonAbort.Click += buttonAbort_Click;
popupMenu.CreateHorizontalLine();
mainContainer.AddChild(bottomButtonBar);
menuItem = popupMenu.CreateMenuItem("Reset to Factory Defaults".Localize());
menuItem.Click += (s, e) =>
{
currentEePromSettings.SetPrinterToFactorySettings();
currentEePromSettings.Update();
};
};
}
printerConnection.CommunicationUnconditionalFromPrinter.RegisterEvent(currentEePromSettings.Add, ref unregisterEvents);
AddChild(mainContainer);
// and ask the printer to send the settings
currentEePromSettings.Update();
foreach (GuiWidget widget in leftStuffToSize)
{
widget.Width = maxWidthOfLeftStuff;
@ -393,18 +345,6 @@ namespace MatterHackers.MatterControl.EeProm
return currentTabIndex++;
}
private static void CreateSpacer(FlowLayoutWidget buttonBar)
{
GuiWidget spacer = new GuiWidget(1, 1);
spacer.HAnchor = Agg.UI.HAnchor.Stretch;
buttonBar.AddChild(spacer);
}
private void buttonAbort_Click(object sender, EventArgs e)
{
UiThread.RunOnIdle(Close);
}
public override void OnClosed(ClosedEventArgs e)
{
unregisterEvents?.Invoke(this, null);

View file

@ -43,10 +43,11 @@ namespace MatterHackers.MatterControl.EeProm
private EventHandler unregisterEvents;
public EEPromPage(PrinterConnection printerConnection)
: base(useOverflowBar: true)
{
this.HeaderText = "EEProm Settings".Localize();
this.WindowSize = new VectorMath.Vector2(650, 480);
headerRow.Visible = false;
headerRow.Margin = this.headerRow.Margin.Clone(bottom: 0);
// Close window if printer is disconnected
printerConnection.CommunicationStateChanged.RegisterEvent((s, e) =>

View file

@ -33,17 +33,18 @@ using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.PartPreviewWindow;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl
{
public class DialogPage : FlowLayoutWidget
{
protected FlowLayoutWidget headerRow;
protected GuiWidget headerRow;
protected FlowLayoutWidget contentRow;
protected FlowLayoutWidget footerRow;
private WrappedTextWidget headerLabel;
private TextWidget headerLabel;
private GuiWidget cancelButton;
public Vector2 WindowSize { get; set; }
@ -55,7 +56,7 @@ namespace MatterHackers.MatterControl
protected ThemeConfig theme;
public DialogPage(string cancelButtonText = null)
public DialogPage(string cancelButtonText = null, bool useOverflowBar = false)
: base (FlowDirection.TopToBottom)
{
theme = ApplicationController.Instance.Theme;
@ -75,17 +76,32 @@ namespace MatterHackers.MatterControl
cancelButton.Name = "Cancel Wizard Button";
// Create the header row for the widget
headerRow = new FlowLayoutWidget(FlowDirection.LeftToRight)
if (useOverflowBar)
{
Name = "HeaderRow",
Margin = new BorderDouble(0, 3, 0, 0),
Padding = new BorderDouble(0, 12),
HAnchor = HAnchor.Stretch,
VAnchor = VAnchor.Fit
};
headerRow = new OverflowBar(theme)
{
Name = "HeaderRow",
Margin = new BorderDouble(0, 3, 0, 0),
Padding = new BorderDouble(0, 12),
HAnchor = HAnchor.Stretch,
VAnchor = VAnchor.Fit
};
}
else
{
headerRow = new FlowLayoutWidget(FlowDirection.LeftToRight)
{
Name = "HeaderRow",
Margin = new BorderDouble(0, 3, 0, 0),
Padding = new BorderDouble(0, 12),
HAnchor = HAnchor.Stretch,
VAnchor = VAnchor.Fit
};
}
this.AddChild(headerRow);
headerLabel = new WrappedTextWidget("Setup Wizard".Localize(), pointSize: 24, textColor: theme.Colors.PrimaryAccentColor)
headerLabel = new TextWidget("Setup Wizard".Localize(), pointSize: 24, textColor: theme.Colors.PrimaryAccentColor)
{
HAnchor = HAnchor.Stretch
};
@ -114,7 +130,7 @@ namespace MatterHackers.MatterControl
#if !__ANDROID__
headerRow.Padding = new BorderDouble(0, 3, 0, 3);
headerLabel.TextWidget.PointSize = 14;
headerLabel.PointSize = 14;
headerLabel.TextColor = theme.Colors.PrimaryTextColor;
contentRow.Padding = new BorderDouble(5);