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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue