Fix button position/size - use consistent type for icon actions

This commit is contained in:
John Lewin 2017-09-25 13:45:42 -07:00
parent 4b5137fdb6
commit 5a856f6d8f
10 changed files with 213 additions and 125 deletions

View file

@ -70,102 +70,6 @@ namespace MatterHackers.MatterControl.ActionBar
} }
} }
public class SimpleButton : FlowLayoutWidget
{
public ImageBuffer Image { get; set; }
public BorderDouble ImageMargin { get; set; }
public BorderDouble ImagePadding { get; set; }
public double FontSize { get; set; } = 12;
public int BorderWidth { get; set; }
public RGBA_Bytes BorderColor { get; set; } = RGBA_Bytes.Transparent;
private int borderRadius = 0;
public SimpleButton(string text, ImageBuffer image = null)
{
this.HAnchor = HAnchor.Left | HAnchor.Fit;
this.VAnchor = VAnchor.Top | VAnchor.Fit;
this.Text = text;
this.Image = image;
this.AddChild(new GuiWidget() { BackgroundColor = RGBA_Bytes.Green, Height = 10, Width = 20 });
UiThread.RunOnIdle(() =>
{
if (this.Image != null)
{
this.AddChild(
new ImageWidget(this.Image)
{
Margin = ImageMargin,
Padding = ImagePadding,
VAnchor = VAnchor.Stretch,
});
}
if (!string.IsNullOrEmpty(this.Text))
{
this.AddChild(new TextWidget(this.Text, pointSize: this.FontSize));
}
this.AddChild(new GuiWidget() { BackgroundColor = RGBA_Bytes.Red, Height = 10, Width = 20 });
});
}
public override void OnLayout(LayoutEventArgs layoutEventArgs)
{
base.OnLayout(layoutEventArgs);
}
/*
public override void OnLoad(EventArgs args)
{
if (this.Image != null)
{
this.AddChild(new ImageWidget(this.Image)
{
Margin = ImageMargin
});
}
if (!string.IsNullOrEmpty(this.Text))
{
this.AddChild(new TextWidget(this.Text, pointSize: this.FontSize));
}
base.OnLoad(args);
}*/
public override void OnDraw(Graphics2D graphics2D)
{
if (this.BorderColor.Alpha0To255 > 0)
{
RectangleDouble borderRectangle = LocalBounds;
if (BorderWidth > 0)
{
if (BorderWidth == 1)
{
graphics2D.Rectangle(borderRectangle, this.BorderColor);
}
else
{
graphics2D.Render(
new Stroke(
new RoundedRect(borderRectangle, this.borderRadius),
BorderWidth),
this.BorderColor);
}
}
}
base.OnDraw(graphics2D);
}
}
public class PrinterConnectButton : GuiWidget public class PrinterConnectButton : GuiWidget
{ {
private readonly string disconnectAndCancelTitle = "Disconnect and stop the current print?".Localize(); private readonly string disconnectAndCancelTitle = "Disconnect and stop the current print?".Localize();

View file

@ -112,6 +112,7 @@ namespace MatterHackers.MatterControl
public TextImageButtonFactory NoMarginWhite { get; private set; } public TextImageButtonFactory NoMarginWhite { get; private set; }
public BorderDouble ToolbarPadding { get; set; } = 3; public BorderDouble ToolbarPadding { get; set; } = 3;
public RGBA_Bytes PrimaryTabFillColor { get; internal set; } public RGBA_Bytes PrimaryTabFillColor { get; internal set; }
public double ButtonHeight { get; internal set; } = 28;
private EventHandler unregisterEvents; private EventHandler unregisterEvents;

View file

@ -70,7 +70,7 @@ namespace MatterHackers.MatterControl
leftNav.AddChild(new BrandMenuButton() leftNav.AddChild(new BrandMenuButton()
{ {
MinimumSize = new VectorMath.Vector2(0, 40), MinimumSize = new VectorMath.Vector2(0, 32),
HAnchor = HAnchor.Stretch, HAnchor = HAnchor.Stretch,
VAnchor = VAnchor.Fit VAnchor = VAnchor.Fit
}); });
@ -98,7 +98,7 @@ namespace MatterHackers.MatterControl
{ {
HAnchor = HAnchor.Stretch, HAnchor = HAnchor.Stretch,
VAnchor = VAnchor.Fit, VAnchor = VAnchor.Fit,
Margin = 6 Margin = new BorderDouble(6, 0)
}; };
var icon = AggContext.StaticData.LoadImage(Path.Combine("Images", "mh-app-logo.png")); var icon = AggContext.StaticData.LoadImage(Path.Combine("Images", "mh-app-logo.png"));

View file

@ -34,6 +34,7 @@ using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI; using MatterHackers.Agg.UI;
using MatterHackers.ImageProcessing; using MatterHackers.ImageProcessing;
using System; using System;
using MatterHackers.MatterControl.CustomWidgets;
namespace MatterHackers.MatterControl namespace MatterHackers.MatterControl
{ {
@ -104,12 +105,7 @@ namespace MatterHackers.MatterControl
icon.InvertLightness(); icon.InvertLightness();
} }
return new Button(0, 0, return new IconButton(icon);
new ButtonViewThreeImage(
icon.AjustAlpha(.7),
icon.AjustAlpha(.9),
icon.AjustAlpha(1),
icon.AjustAlpha(.2)));
} }
public CheckBox GenerateCheckBoxButton(string label, ImageBuffer normalImage, ImageBuffer normalToPressedImage = null, ImageBuffer pressedImage = null, ImageBuffer pressedToNormalImage = null, string pressedLabel = null) public CheckBox GenerateCheckBoxButton(string label, ImageBuffer normalImage, ImageBuffer normalToPressedImage = null, ImageBuffer pressedImage = null, ImageBuffer pressedToNormalImage = null, string pressedLabel = null)

View file

@ -100,14 +100,14 @@ namespace MatterHackers.MatterControl.CustomWidgets
AddChild(topToBottom); AddChild(topToBottom);
} }
private ImageWidget CreatePinButton() private GuiWidget CreatePinButton()
{ {
var icon = AggContext.StaticData.LoadIcon(this.ControlIsPinned ? "Pushpin_16x.png" : "PushpinUnpin_16x.png", 16, 16).InvertLightness(); var icon = AggContext.StaticData.LoadIcon(this.ControlIsPinned ? "Pushpin_16x.png" : "PushpinUnpin_16x.png", 16, 16).InvertLightness();
var imageWidget = new ImageWidget(icon)
var imageWidget = new IconButton(icon)
{ {
Name = "Pin Settings Button", Name = "Pin Settings Button",
Margin = new BorderDouble(right: 25, top: 6), Margin = new BorderDouble(right: 2),
MinimumSize = new Vector2(16, 16)
}; };
imageWidget.Click += (s, e) => imageWidget.Click += (s, e) =>
{ {
@ -272,7 +272,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
tabControl.TabBar.AddChild(new HorizontalSpacer()); tabControl.TabBar.AddChild(new HorizontalSpacer());
var pinButton = this.CreatePinButton(); var pinButton = this.CreatePinButton();
pinButton.Margin = new BorderDouble(right: 18, bottom: 7); //pinButton.Margin = new BorderDouble(right: 18, bottom: 7);
tabControl.TabBar.AddChild(pinButton); tabControl.TabBar.AddChild(pinButton);
if (printer.ViewState.SliceSettingsTabIndex < tabControl.TabCount) if (printer.ViewState.SliceSettingsTabIndex < tabControl.TabCount)

View file

@ -28,9 +28,13 @@ either expressed or implied, of the FreeBSD Project.
*/ */
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using MatterHackers.Agg; using MatterHackers.Agg;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI; using MatterHackers.Agg.UI;
using MatterHackers.ImageProcessing;
using MatterHackers.Localizations; using MatterHackers.Localizations;
using MatterHackers.MatterControl.Library; using MatterHackers.MatterControl.Library;
@ -45,7 +49,10 @@ namespace MatterHackers.MatterControl.CustomWidgets
this.listView = listView; this.listView = listView;
this.Name = "FolderBreadCrumbWidget"; this.Name = "FolderBreadCrumbWidget";
UiThread.RunOnIdle(() => SetBreadCrumbs(listView.ActiveContainer)); UiThread.RunOnIdle(() => SetBreadCrumbs(listView.ActiveContainer));
HAnchor = HAnchor.Stretch;
this.HAnchor = HAnchor.Stretch;
this.VAnchor = VAnchor.Fit | VAnchor.Center;
this.Padding = new BorderDouble(left: 2);
} }
public static IEnumerable<ILibraryContainer> ItemAndParents(ILibraryContainer item) public static IEnumerable<ILibraryContainer> ItemAndParents(ILibraryContainer item)
@ -68,12 +75,13 @@ namespace MatterHackers.MatterControl.CustomWidgets
bool haveFilterRunning = !string.IsNullOrEmpty(currentContainer.KeywordFilter); bool haveFilterRunning = !string.IsNullOrEmpty(currentContainer.KeywordFilter);
var icon = LibraryProviderHelpers.LoadInvertIcon("FileDialog", "up_folder_20.png"); var theme = ApplicationController.Instance.Theme;
//icon = LibraryProviderHelpers.ResizeImage(icon, 20, 20);
Button upbutton = buttonFactory.Generate("", icon); var upbutton = new IconButton(AggContext.StaticData.LoadIcon(Path.Combine("FileDialog", "up_folder_20.png")))
upbutton.Name = "Library Up Button"; {
upbutton.Margin = 0; Name = "Library Up Button",
Margin = new BorderDouble(right: 2)
};
upbutton.Click += (s, e) => upbutton.Click += (s, e) =>
{ {
if (listView.ActiveContainer.Parent != null) if (listView.ActiveContainer.Parent != null)

View file

@ -0,0 +1,179 @@
/*
Copyright (c) 2017, 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 MatterHackers.Agg;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.UI;
using MatterHackers.ImageProcessing;
namespace MatterHackers.MatterControl.CustomWidgets
{
public class SimpleButton : Button
{
private bool mouseInBounds = false;
public RGBA_Bytes HoverColor { get; set; } = RGBA_Bytes.Transparent;
public RGBA_Bytes MouseDownColor { get; set; } = RGBA_Bytes.Transparent;
public override void OnMouseEnterBounds(MouseEventArgs mouseEvent)
{
mouseInBounds = true;
base.OnMouseEnterBounds(mouseEvent);
this.Invalidate();
}
public override void OnMouseLeaveBounds(MouseEventArgs mouseEvent)
{
mouseInBounds = false;
base.OnMouseLeaveBounds(mouseEvent);
this.Invalidate();
}
public override void OnMouseDown(MouseEventArgs mouseEvent)
{
base.OnMouseDown(mouseEvent);
this.Invalidate();
}
public override void OnMouseUp(MouseEventArgs mouseEvent)
{
base.OnMouseUp(mouseEvent);
this.Invalidate();
}
public override RGBA_Bytes BackgroundColor
{
get
{
if (this.MouseCaptured
&& mouseInBounds
&& this.Enabled)
{
return this.MouseDownColor;
}
else if (this.mouseInBounds
&& this.Enabled)
{
return this.HoverColor;
}
else
{
return base.BackgroundColor;
}
}
set => base.BackgroundColor = value;
}
}
public class IconButton : SimpleButton
{
private ImageWidget imageWidget;
private ImageBuffer image;
public IconButton(ImageBuffer icon)
{
var theme = ApplicationController.Instance.Theme;
this.image = icon;
this.HoverColor = theme.SlightShade;
this.MouseDownColor = theme.MinimalShade;
this.HAnchor = HAnchor.Absolute;
this.VAnchor = VAnchor.Absolute | VAnchor.Center;
this.Height = theme.ButtonHeight;
this.Width = theme.ButtonHeight;
this.Margin = 0;
imageWidget = new ImageWidget(icon)
{
HAnchor = HAnchor.Center,
VAnchor = VAnchor.Center,
Selectable = false
};
this.AddChild(imageWidget);
}
public override bool Enabled
{
get => base.Enabled;
set
{
base.Enabled = value;
imageWidget.Image = (value) ? image : this.DisabledImage;
}
}
private ImageBuffer _disabledImage;
public ImageBuffer DisabledImage
{
get
{
// Lazy construct on first access
if (_disabledImage == null)
{
_disabledImage = image.AjustAlpha(0.2);
}
return _disabledImage;
}
}
}
public class TextButton : SimpleButton
{
private TextWidget textWidget;
public TextButton(ThemeConfig theme)
{
this.textWidget = new TextWidget("", pointSize: theme.ButtonFactory.fontSize);
}
public override string Text
{
get => base.Text;
set
{
this.textWidget.Text = value;
base.Text = value;
}
}
public override bool Enabled
{
get => base.Enabled;
set
{
base.Enabled = value;
}
}
}
}

View file

@ -105,9 +105,8 @@ namespace MatterHackers.MatterControl.PrintLibrary
breadCrumbWidget = new FolderBreadCrumbWidget(libraryView); breadCrumbWidget = new FolderBreadCrumbWidget(libraryView);
navBar.AddChild(breadCrumbWidget); navBar.AddChild(breadCrumbWidget);
var icon = AggContext.StaticData.LoadIcon("icon_search_24x24.png", 16, 16); var theme = ApplicationController.Instance.Theme;
var buttonFactory = theme.SmallMarginButtonFactory;
var buttonFactory = ApplicationController.Instance.Theme.SmallMarginButtonFactory;
var searchPanel = new SearchInputBox() var searchPanel = new SearchInputBox()
{ {
@ -133,10 +132,11 @@ namespace MatterHackers.MatterControl.PrintLibrary
navBar.AddChild(searchPanel); navBar.AddChild(searchPanel);
Button searchButton = buttonFactory.Generate("", icon); var searchButton = new IconButton(AggContext.StaticData.LoadIcon("icon_search_24x24.png", 16, 16))
searchButton.ToolTipText = "Search".Localize(); {
searchButton.Name = "Search Library Button"; Name = "Search Library Button",
searchButton.Margin = 0; ToolTipText = "Search".Localize()
};
searchButton.Click += (s, e) => searchButton.Click += (s, e) =>
{ {
if (searchPanel.Visible) if (searchPanel.Visible)

View file

@ -139,6 +139,7 @@
<Compile Include="ConfigurationPage\ApplicationSettings\ThemePreviewButton.cs" /> <Compile Include="ConfigurationPage\ApplicationSettings\ThemePreviewButton.cs" />
<Compile Include="ControlElements\TextImageWidget.cs" /> <Compile Include="ControlElements\TextImageWidget.cs" />
<Compile Include="CustomWidgets\DockingTabControl.cs" /> <Compile Include="CustomWidgets\DockingTabControl.cs" />
<Compile Include="CustomWidgets\SimpleButton.cs" />
<Compile Include="CustomWidgets\NamedAction.cs" /> <Compile Include="CustomWidgets\NamedAction.cs" />
<Compile Include="CustomWidgets\RadioImageWidget.cs" /> <Compile Include="CustomWidgets\RadioImageWidget.cs" />
<Compile Include="CustomWidgets\RadioPanelWidget.cs" /> <Compile Include="CustomWidgets\RadioPanelWidget.cs" />

View file

@ -34,7 +34,6 @@ using MatterHackers.Agg.ImageProcessing;
using MatterHackers.Agg.Platform; using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI; using MatterHackers.Agg.UI;
using MatterHackers.Localizations; using MatterHackers.Localizations;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.PartPreviewWindow namespace MatterHackers.MatterControl.PartPreviewWindow
{ {
@ -112,7 +111,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
public PopupButton() public PopupButton()
{ {
} }
public PopupButton(GuiWidget buttonView) public PopupButton(GuiWidget buttonView)
{ {
this.Margin = 3; this.Margin = 3;
@ -144,7 +143,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{ {
// HACK: Child controls seem to be interfering with this.MouseCaptured - this short term workaround ensure we get clicks but likely mean mouse down outside of the control will fire the popup // HACK: Child controls seem to be interfering with this.MouseCaptured - this short term workaround ensure we get clicks but likely mean mouse down outside of the control will fire the popup
bool mouseUpInBounds = this.PositionWithinLocalBounds(mouseEvent.X, mouseEvent.Y); bool mouseUpInBounds = this.PositionWithinLocalBounds(mouseEvent.X, mouseEvent.Y);
// Only show the popup if the menu was hidden as the mouse events started // Only show the popup if the menu was hidden as the mouse events started
if ((mouseUpInBounds || buttonView?.MouseCaptured == true) if ((mouseUpInBounds || buttonView?.MouseCaptured == true)
&& !menuVisibileAtMouseDown) && !menuVisibileAtMouseDown)