Making tool bar able to hind elements

This commit is contained in:
Lars Brubaker 2021-09-15 17:44:24 -07:00
parent 4a509e6ae8
commit c61afe9fee
10 changed files with 241 additions and 69 deletions

View file

@ -808,6 +808,7 @@ namespace MatterHackers.MatterControl
new OperationGroup("Path")
{
TitleResolver = () => "Path".Localize(),
Visible = OperationGroup.GetVisible("Path", false),
Operations = new List<SceneOperation>()
{
LinearExtrudeOperation(),
@ -815,6 +816,7 @@ namespace MatterHackers.MatterControl
SmoothPathOperation(),
InflatePathOperation(),
OutlinePathOperation(),
AddBaseOperation(),
}
},
new OperationGroup("Merge")
@ -847,12 +849,12 @@ namespace MatterHackers.MatterControl
{
ReduceOperation(),
RepairOperation(),
AddBaseOperation(),
}
},
new OperationGroup("Printing")
{
TitleResolver = () => "Printing".Localize(),
Visible = OperationGroup.GetVisible("Path", false),
Operations = new List<SceneOperation>()
{
ToggleSupportOperation(),
@ -862,6 +864,7 @@ namespace MatterHackers.MatterControl
new OperationGroup("Design Apps")
{
TitleResolver = () => "Design Apps".Localize(),
Visible = OperationGroup.GetVisible("Path", false),
Operations = new List<SceneOperation>()
{
FitToBoundsOperation(),

View file

@ -121,16 +121,28 @@ namespace MatterHackers.Agg.UI
public EventHandler VisibleChanged;
private bool _visible;
private static string VisibleKey(string opperationGroupName)
{
return $"scene_operation_visible_{opperationGroupName}";
}
public static bool GetVisible(string id, bool defaultIfNotSet)
{
return UserSettings.Instance.Fields.GetBool(VisibleKey(id), defaultIfNotSet);
}
public bool Visible
{
get => _visible;
get
{
return GetVisible(this.Id, true);
}
set
{
if (_visible != value)
if (Visible != value)
{
_visible = value;
UserSettings.Instance.Fields.SetBool(VisibleKey(Id), value);
VisibleChanged?.Invoke(this, null);
}
}

View file

@ -406,7 +406,7 @@ namespace MatterHackers.MatterControl.DesignTools
}
rowContainer = CreateSettingsRow(property,
PublicPropertySliderFunctions.GetFieldContentWithSlider(property, context, field, undoBuffer, (valueString) => { return double.Parse(valueString); }),
PublicPropertySliderFunctions.GetFieldContentWithSlider(property, context, field, undoBuffer, (valueString) => { return double.Parse(valueString); }, theme),
theme);
}
}
@ -836,7 +836,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
doubleExpresion.Expression = valueString;
return doubleExpresion;
}),
}, theme),
theme,
rows);
@ -911,7 +911,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
intExpresion.Expression = valueString;
return intExpresion;
}),
}, theme),
theme,
rows);

View file

@ -40,7 +40,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
public static class PublicPropertySliderFunctions
{
public static GuiWidget GetFieldContentWithSlider(EditableProperty property, PPEContext context, UIField field, UndoBuffer undoBuffer, Func<string, object> valueFromString)
public static GuiWidget GetFieldContentWithSlider(EditableProperty property, PPEContext context, UIField field, UndoBuffer undoBuffer, Func<string, object> valueFromString, ThemeConfig theme)
{
var sliderAttribute = property.PropertyInfo.GetCustomAttributes(true).OfType<SliderAttribute>().FirstOrDefault();
if (sliderAttribute != null)
@ -55,6 +55,10 @@ namespace MatterHackers.MatterControl.DesignTools
VAnchor = VAnchor.Center,
};
slider.View.TrackColor = theme.TextColor;
slider.View.ThumbColor = theme.PrimaryAccentColor;
slider.View.TrackHeight = 1 * GuiWidget.DeviceScale;
Func<double> getFieldValue = null;
double GetSlider0To1FromField()

View file

@ -37,6 +37,7 @@ using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.ImageProcessing;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.PartPreviewWindow
@ -410,6 +411,73 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
return menuItem;
}
/// <summary>
/// Create and add a new menu item
/// </summary>
/// <param name="text">The text of the item</param>
/// <param name="items"></param>
/// <param name="getter"></param>
/// <param name="setter"></param>
/// <returns></returns>
public MenuItem CreateButtonSelectMenuItem(string text, IEnumerable<(string key, string text)> buttonKvps, string startingValue, Action<string> setter)
{
var textWidget = new TextWidget(text, pointSize: theme.DefaultFontSize, textColor: theme.TextColor)
{
Padding = MenuPadding,
VAnchor = VAnchor.Center,
};
return this.CreateButtonSelectMenuItem(textWidget, text, buttonKvps, startingValue, setter);
}
public MenuItem CreateButtonSelectMenuItem(string text, ImageBuffer icon, IEnumerable<(string key, string text)> buttonKvps, string startingValue, Action<string> setter)
{
var row = new FlowLayoutWidget()
{
Selectable = false
};
row.AddChild(new IconButton(icon, theme));
var textWidget = new TextWidget(text, pointSize: theme.DefaultFontSize, textColor: theme.TextColor)
{
Padding = MenuPadding,
VAnchor = VAnchor.Center
};
row.AddChild(textWidget);
return this.CreateButtonSelectMenuItem(row, text, buttonKvps, startingValue, setter);
}
public MenuItem CreateButtonSelectMenuItem(GuiWidget guiWidget, string name, IEnumerable<(string key, string text)> buttonKvps, string startingValue, Action<string> setter)
{
var row = new FlowLayoutWidget()
{
HAnchor = HAnchor.MaxFitOrStretch,
Name = name + " Menu Item",
};
row.AddChild(guiWidget);
row.AddChild(new HorizontalSpacer());
foreach(var buttonKvp in buttonKvps)
{
var localKey = buttonKvp.key;
var button = EnumDisplayField.CreateThemedRadioButton(buttonKvp.text, buttonKvp.key, "", startingValue == buttonKvp.key, () =>
{
setter?.Invoke(localKey);
}, theme);
row.AddChild(button);
}
var menuItem = new MenuItemHoldOpen(row, theme)
{
};
this.AddChild(menuItem);
return menuItem;
}
public MenuItem CreateMenuItem(GuiWidget guiWidget, string name, ImageBuffer icon = null)
{
var menuItem = new MenuItem(guiWidget, theme)
@ -483,6 +551,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
}
public bool KeepMenuOpen => false;
public override void OnDraw(Graphics2D graphics2D)
{
if (this.Image != null)
@ -496,6 +566,16 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
base.OnDraw(graphics2D);
}
}
public class MenuItemHoldOpen : MenuItem, IIgnoredPopupChild
{
public MenuItemHoldOpen(GuiWidget content, ThemeConfig theme)
: base(content, theme)
{
}
public bool KeepMenuOpen => false;
}
}
public static class PopupMenuExtensions

View file

@ -130,6 +130,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
}
public OverflowMenuButton(string text, ThemeConfig theme)
: base(text, CreateOverflowIcon(theme), theme)
{
}
public OverflowMenuButton(OverflowBar overflowBar, ThemeConfig theme)
: this(overflowBar, CreateOverflowIcon(theme), theme)
{

View file

@ -199,25 +199,41 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
var operationButtonGroup = CreateOperationButtonGroup(theme, operationGroup);
void UpdateVisability(object s, EventArgs e)
{
if (operationGroup.Visible)
{
if (operationGroup.Collapse)
{
actionDropDown.Visible = true;
operationButtonGroup.Visible = false;
DoWrappingLayout();
}
else
{
actionDropDown.Visible = false;
operationButtonGroup.Visible = true;
DoWrappingLayout();
}
}
else
{
actionDropDown.Visible = false;
operationButtonGroup.Visible = false;
DoWrappingLayout();
}
}
UserSettings.Instance.SettingChanged += UpdateVisability;
operationGroup.CollapseChanged += UpdateVisability;
operationGroup.VisibleChanged += UpdateVisability;
this.Closed += (s, e) =>
{
operationGroup.CollapseChanged -= UpdateVisability;
UserSettings.Instance.SettingChanged -= UpdateVisability;
operationGroup.CollapseChanged -= UpdateVisability;
operationGroup.VisibleChanged -= UpdateVisability;
};
UpdateVisability(operationGroup, null);
@ -270,11 +286,17 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
// add the options menu
var optionsButton = new OverflowBar.OverflowMenuButton(theme);
this.AddChild(new HorizontalSpacer());
var overflowIcon = StaticData.Instance.LoadIcon(Path.Combine("ViewTransformControls", "overflow.png"), 32, 32).SetToColor(theme.TextColor);
var optionsButton = new PopupMenuButton(overflowIcon, theme)
{
AlignToRightEdge = true
};
this.AddChild(optionsButton);
optionsButton.Name = "Printer Overflow Menu";
optionsButton.ToolTipText = "Printer Options".Localize();
GeneratePrinterOverflowMenu(optionsButton, theme);
optionsButton.Name = "ToolBar Overflow Menu";
optionsButton.ToolTipText = "Tool Bar Options".Localize();
optionsButton.DynamicPopupContent = () => GenerateToolBarOptionsMenu(theme);
// Register listeners
undoBuffer.Changed += UndoBuffer_Changed;
@ -285,12 +307,53 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
UpdateToolbarButtons(null, null);
}
private void GeneratePrinterOverflowMenu(PopupMenuButton optionsButton, ThemeConfig theme)
private GuiWidget GenerateToolBarOptionsMenu(ThemeConfig theme)
{
optionsButton.DynamicPopupContent = () =>
var popupMenu = new PopupMenu(theme)
{
return new GuiWidget(50, 100);
Padding = new BorderDouble(0, 7),
};
var buttonData = new (string, string)[]
{
("Collapsed".Localize(), "Collapsed"),
("Expanded".Localize(), "Expanded"),
("Hidden".Localize(), "Hidden"),
};
foreach (var namedAction in SceneOperations.All)
{
if (namedAction is OperationGroup operationGroup)
{
var startingValue = operationGroup.Collapse ? "Collapsed" : "Expanded";
if(!operationGroup.Visible)
{
startingValue = "Hidden";
}
popupMenu.CreateButtonSelectMenuItem(operationGroup.Title, buttonData, startingValue, (value) =>
{
switch (value)
{
case "Expanded":
operationGroup.Collapse = false;
operationGroup.Visible = true;
break;
case "Collapsed":
operationGroup.Collapse = true;
operationGroup.Visible = true;
break;
case "Hidden":
operationGroup.Visible = false;
break;
}
});
}
};
return popupMenu;
}
private FlowLayoutWidget CreateOperationButtonGroup(ThemeConfig theme, OperationGroup operationGroup)

View file

@ -1910,7 +1910,6 @@ Make sure that your printer is turned on. Some printers will appear to be connec
resetSerialPort.Close();
// let the process know we canceled not ended normally.
CommunicationState = CommunicationStates.Disconnected;
}
}
@ -2114,8 +2113,6 @@ Make sure that your printer is turned on. Some printers will appear to be connec
public PrintingModes PrintingMode { get; private set; }
private CancellationTokenSource printingCancellation;
public enum PrintingModes
{
Normal,
@ -2138,8 +2135,6 @@ Make sure that your printer is turned on. Some printers will appear to be connec
this.PrintingMode = printingMode;
printingCancellation = new CancellationTokenSource();
haveReportedError = false;
PrintWasCanceled = false;
cancelPrintNextWriteLine = false;
@ -2149,6 +2144,7 @@ Make sure that your printer is turned on. Some printers will appear to be connec
ClearQueuedGCode();
ActivePrintTask = printTaskToUse;
CanceledPrintTask = null;
await Task.Run(() =>
{
@ -2203,7 +2199,7 @@ Make sure that your printer is turned on. Some printers will appear to be connec
ActivePrintTask.CommitAndPushToServer();
Task.Run(() => this.SyncProgressToDB(printingCancellation.Token));
Task.Run(() => this.SyncProgressToDB());
PrintStarted?.Invoke(this, null);
}
@ -2297,9 +2293,10 @@ Make sure that your printer is turned on. Some printers will appear to be connec
{
lock (locker)
{
// Flag as canceled, wait briefly for listening threads to catch up
printingCancellation.Cancel();
Thread.Sleep(15);
TerminalLog.WriteLine("Print Canceled");
// Flag as canceled
this.cancelPrintNextWriteLine = true;
CancelInProgressStreamProcessors();
// get rid of all the gcode we have left to print
@ -2312,7 +2309,6 @@ Make sure that your printer is turned on. Some printers will appear to be connec
}
// let the process know we canceled not ended normally.
this.cancelPrintNextWriteLine = true;
CanceleRequested?.Invoke(this, null);
if (markPrintCanceled
&& ActivePrintTask != null)
@ -2509,13 +2505,17 @@ Make sure that your printer is turned on. Some printers will appear to be connec
public GCodeStream TotalGCodeStream => totalGCodeStream;
private void SyncProgressToDB(CancellationToken cancellationToken)
private void SyncProgressToDB()
{
// var timer = Stopwatch.StartNew();
bool WatingForPrintToFinish()
{
var canceled = cancelPrintNextWriteLine || PrintWasCanceled;
var stillPrinting = this.CommunicationState != CommunicationStates.FinishedPrint && this.CommunicationState != CommunicationStates.Connected;
while (!cancellationToken.IsCancellationRequested
&& this.CommunicationState != CommunicationStates.FinishedPrint
&& this.CommunicationState != CommunicationStates.Connected)
return !canceled && stillPrinting;
}
while (WatingForPrintToFinish())
{
double secondsSinceStartedPrint = timePrinting.Elapsed.TotalSeconds;

View file

@ -236,7 +236,21 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
{
var localIndex = index;
var radioButton = new RadioTextButton(enumItem.Value, theme)
var radioButton = CreateThemedRadioButton(enumItem.Value, enumItem.Key, descriptions[index], this.InitialValue == enumItem.Key, () => this.SetValue(enumItem.Key, true), theme);
menuRow.AddChild(radioButton);
var localItem = enumItem;
index++;
}
this.Content = menuRow;
}
public static RadioTextButton CreateThemedRadioButton(string text, string key, string toolTipText, bool startChecked, Action setChecked, ThemeConfig theme)
{
var radioButton = new RadioTextButton(text, theme)
{
VAnchor = VAnchor.Center | VAnchor.Fit,
DrawUnderline = false,
@ -247,7 +261,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
SelectedBackgroundColor = theme.PrimaryAccentColor,
UnselectedBackgroundColor = theme.MinimalShade,
BackgroundColor = theme.MinimalShade,
ToolTipText = descriptions[index]
ToolTipText = toolTipText
};
radioButton.CheckedStateChanged += (s, e) =>
@ -257,26 +271,17 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
};
// set it if checked
if (enumItem.Key == this.InitialValue)
{
radioButton.Checked = true;
}
radioButton.Checked = startChecked;
menuRow.AddChild(radioButton);
var localItem = enumItem;
radioButton.CheckedStateChanged += (s, e) =>
{
if (radioButton.Checked)
{
this.SetValue(localItem.Key, true);
setChecked?.Invoke();
}
};
index++;
}
this.Content = menuRow;
return radioButton;
}
private void AddIconRow(IEnumerable<(string Key, string Value)> enumItems, List<string> descriptions)

@ -1 +1 @@
Subproject commit 7e55f2c529b1504924b65ec3a296d1e82876d20d
Subproject commit 53d5cec07af14d5395d750024e3b69f1056faa22