Extract reusable aspects to common base
This commit is contained in:
parent
3264dffa16
commit
a027951be5
5 changed files with 174 additions and 70 deletions
162
SlicerConfiguration/SettingsRow.cs
Normal file
162
SlicerConfiguration/SettingsRow.cs
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
/*
|
||||
Copyright (c) 2018, Lars Brubaker, John Lewin
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
The views and conclusions contained in the software and documentation are those
|
||||
of the authors and should not be interpreted as representing official policies,
|
||||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.Image;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.VectorMath;
|
||||
|
||||
namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||
{
|
||||
public class SettingsRow : FlowLayoutWidget
|
||||
{
|
||||
protected GuiWidget overrideIndicator;
|
||||
public GuiWidget NameArea { get; }
|
||||
protected const bool debugLayout = false;
|
||||
protected ThemeConfig theme;
|
||||
|
||||
private bool mouseInBounds = false;
|
||||
private Color hoverColor;
|
||||
private bool fullRowSelect;
|
||||
|
||||
public GuiWidget ActionWidget { get; set; }
|
||||
|
||||
public SettingsRow(ThemeConfig theme, ImageBuffer icon = null, bool enforceGutter = false, bool fullRowSelect = false)
|
||||
{
|
||||
this.theme = theme;
|
||||
this.MinimumSize = new Vector2(0, 28);
|
||||
this.fullRowSelect = fullRowSelect;
|
||||
|
||||
hoverColor = theme.MinimalShade;
|
||||
|
||||
if (icon != null)
|
||||
{
|
||||
this.AddChild(new ImageWidget(icon)
|
||||
{
|
||||
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(overrideIndicator = new GuiWidget()
|
||||
{
|
||||
VAnchor = VAnchor.Stretch,
|
||||
HAnchor = HAnchor.Absolute,
|
||||
Width = 3,
|
||||
Margin = new BorderDouble(right: 6)
|
||||
});
|
||||
|
||||
this.AddChild(this.NameArea = new GuiWidget()
|
||||
{
|
||||
MinimumSize = new Vector2(50, 0),
|
||||
HAnchor = HAnchor.Stretch,
|
||||
VAnchor = VAnchor.Fit | VAnchor.Center,
|
||||
DebugShowBounds = debugLayout
|
||||
});
|
||||
|
||||
if (fullRowSelect)
|
||||
{
|
||||
this.Cursor = Cursors.Hand;
|
||||
}
|
||||
}
|
||||
|
||||
public static GuiWidget CreateSettingsLabel(string label, string helpText, Color textColor)
|
||||
{
|
||||
return new WrappedTextWidget(label, pointSize: 10, textColor: textColor)
|
||||
{
|
||||
VAnchor = VAnchor.Center | VAnchor.Fit,
|
||||
ToolTipText = helpText.Localize(),
|
||||
Margin = new BorderDouble(0, 5, 5, 5),
|
||||
};
|
||||
}
|
||||
|
||||
// HACK: ******** Remove dynamic lookup in favor of a known label/title widget *************************************************
|
||||
public override string ToolTipText
|
||||
{
|
||||
get => NameArea.Children.FirstOrDefault()?.ToolTipText;
|
||||
set
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public override void AddChild(GuiWidget childToAdd, int indexInChildrenList = -1)
|
||||
{
|
||||
if (fullRowSelect)
|
||||
{
|
||||
childToAdd.Selectable = false;
|
||||
}
|
||||
|
||||
base.AddChild(childToAdd, indexInChildrenList);
|
||||
}
|
||||
|
||||
public override Color BackgroundColor
|
||||
{
|
||||
get => (mouseInBounds) ? hoverColor : base.BackgroundColor;
|
||||
set => base.BackgroundColor = value;
|
||||
}
|
||||
|
||||
public override void OnMouseEnterBounds(MouseEventArgs mouseEvent)
|
||||
{
|
||||
mouseInBounds = true;
|
||||
this.Invalidate();
|
||||
base.OnMouseEnter(mouseEvent);
|
||||
}
|
||||
|
||||
public override void OnMouseLeaveBounds(MouseEventArgs mouseEvent)
|
||||
{
|
||||
mouseInBounds = false;
|
||||
|
||||
this.Invalidate();
|
||||
base.OnMouseLeaveBounds(mouseEvent);
|
||||
}
|
||||
|
||||
public override void OnClick(MouseEventArgs mouseEvent)
|
||||
{
|
||||
if (ActionWidget != null)
|
||||
{
|
||||
ActionWidget.OnClick(new MouseEventArgs(mouseEvent, 5, 5));
|
||||
}
|
||||
|
||||
base.OnClick(mouseEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (c) 2017, Lars Brubaker, John Lewin
|
||||
Copyright (c) 2018, Lars Brubaker, John Lewin
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -27,16 +27,14 @@ of the authors and should not be interpreted as representing official policies,
|
|||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.VectorMath;
|
||||
|
||||
namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||
{
|
||||
public class SliceSettingsRow : FlowLayoutWidget
|
||||
public class SliceSettingsRow : SettingsRow
|
||||
{
|
||||
private static readonly Color materialSettingBackgroundColor = Color.Orange;
|
||||
private static readonly Color qualitySettingBackgroundColor = Color.YellowGreen;
|
||||
|
|
@ -49,33 +47,14 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
private GuiWidget dataArea;
|
||||
private GuiWidget unitsArea;
|
||||
private GuiWidget restoreArea;
|
||||
private GuiWidget overrideIndicator;
|
||||
private Button restoreButton = null;
|
||||
|
||||
private const bool debugLayout = false;
|
||||
|
||||
public SliceSettingsRow(PrinterConfig printer, SettingsContext settingsContext, SliceSettingData settingData, Color textColor, bool fullRow = false)
|
||||
public SliceSettingsRow(PrinterConfig printer, SettingsContext settingsContext, SliceSettingData settingData, Color textColor, ThemeConfig theme, bool fullRowSelect = false)
|
||||
: base (theme, fullRowSelect: fullRowSelect)
|
||||
{
|
||||
this.printer = printer;
|
||||
this.settingData = settingData;
|
||||
this.settingsContext = settingsContext;
|
||||
this.MinimumSize = new Vector2(0, 28);
|
||||
|
||||
this.AddChild(overrideIndicator = new GuiWidget()
|
||||
{
|
||||
VAnchor = VAnchor.Stretch,
|
||||
HAnchor = HAnchor.Absolute,
|
||||
Width = 3,
|
||||
Margin = new BorderDouble(right: 6)
|
||||
});
|
||||
|
||||
this.AddChild(this.NameArea = new GuiWidget()
|
||||
{
|
||||
MinimumSize = new Vector2(50, 0),
|
||||
HAnchor = HAnchor.Stretch,
|
||||
VAnchor = VAnchor.Fit | VAnchor.Center,
|
||||
DebugShowBounds = debugLayout
|
||||
});
|
||||
|
||||
this.AddChild(dataArea = new FlowLayoutWidget
|
||||
{
|
||||
|
|
@ -131,8 +110,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
}
|
||||
}
|
||||
|
||||
public GuiWidget NameArea { get; }
|
||||
|
||||
public Color HighlightColor
|
||||
{
|
||||
get => overrideIndicator.BackgroundColor;
|
||||
|
|
@ -145,31 +122,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
}
|
||||
}
|
||||
|
||||
private Color hoverColor => ApplicationController.Instance.Theme.MinimalShade;
|
||||
|
||||
public override Color BackgroundColor
|
||||
{
|
||||
get => (mouseInBounds) ? hoverColor : base.BackgroundColor;
|
||||
set => base.BackgroundColor = value;
|
||||
}
|
||||
|
||||
private bool mouseInBounds = false;
|
||||
|
||||
public override void OnMouseEnterBounds(MouseEventArgs mouseEvent)
|
||||
{
|
||||
mouseInBounds = true;
|
||||
this.Invalidate();
|
||||
base.OnMouseEnter(mouseEvent);
|
||||
}
|
||||
|
||||
public override void OnMouseLeaveBounds(MouseEventArgs mouseEvent)
|
||||
{
|
||||
mouseInBounds = false;
|
||||
|
||||
this.Invalidate();
|
||||
base.OnMouseLeaveBounds(mouseEvent);
|
||||
}
|
||||
|
||||
public void UpdateStyle()
|
||||
{
|
||||
if (settingsContext.ContainsKey(settingData.SlicerConfigName))
|
||||
|
|
|
|||
|
|
@ -534,11 +534,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
|
||||
topToBottomSettings.AddChild(settingsRow);
|
||||
|
||||
topToBottomSettings.AddChild(lastLine = new HorizontalLine(20)
|
||||
{
|
||||
Margin = 0
|
||||
});
|
||||
|
||||
if (ApplicationController.Instance.ShowHelpControls)
|
||||
{
|
||||
topToBottomSettings.AddChild(AddInHelpText(topToBottomSettings, settingData));
|
||||
|
|
@ -667,11 +662,14 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
bool useDefaultSavePattern = true;
|
||||
bool placeFieldInDedicatedRow = false;
|
||||
|
||||
var settingsRow = new SliceSettingsRow(printer, settingsContext, settingData, textColor)
|
||||
bool fullRowSelect = settingData.DataEditType == SliceSettingData.DataEditTypes.CHECK_BOX;
|
||||
var settingsRow = new SliceSettingsRow(printer, settingsContext, settingData, textColor, theme, fullRowSelect: fullRowSelect)
|
||||
{
|
||||
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)
|
||||
};
|
||||
|
||||
if (!PrinterSettings.KnownSettings.Contains(settingData.SlicerConfigName))
|
||||
|
|
@ -685,7 +683,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
else
|
||||
{
|
||||
settingsRow.NameArea.AddChild(
|
||||
CreateSettingsLabel(settingData.PresentationName.Localize(), settingData.HelpText, textColor));
|
||||
SettingsRow.CreateSettingsLabel(settingData.PresentationName.Localize(), settingData.HelpText, textColor));
|
||||
|
||||
switch (settingData.DataEditType)
|
||||
{
|
||||
|
|
@ -860,6 +858,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
if (!placeFieldInDedicatedRow)
|
||||
{
|
||||
settingsRow.AddContent(uiField.Content);
|
||||
settingsRow.ActionWidget = uiField.Content;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -920,16 +919,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
}
|
||||
}
|
||||
|
||||
public static GuiWidget CreateSettingsLabel(string label, string helpText, Color textColor)
|
||||
{
|
||||
return new WrappedTextWidget(label, pointSize: 10, textColor: textColor)
|
||||
{
|
||||
VAnchor = VAnchor.Center | VAnchor.Fit,
|
||||
ToolTipText = helpText.Localize(),
|
||||
Margin = new BorderDouble(0, 5, 5, 5),
|
||||
};
|
||||
}
|
||||
|
||||
public void FilterToOverrides()
|
||||
{
|
||||
var defaultCascade = printer.Settings.defaultLayerCascade;
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
};
|
||||
column.AddChild(row);
|
||||
|
||||
var labelWidget = SliceSettingsTabView.CreateSettingsLabel($"Nozzle {i + 1}", "", textColor);
|
||||
var labelWidget = SettingsRow.CreateSettingsLabel($"Nozzle {i + 1}", "", textColor);
|
||||
labelWidget.Name = $"Nozzle {i}";
|
||||
labelWidget.Margin = new BorderDouble(right: 60);
|
||||
row.AddChild(labelWidget);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue