Merge pull request #3893 from jlewin/master

Add resizable favorites bar
This commit is contained in:
johnlewin 2018-10-25 17:49:20 -07:00 committed by GitHub
commit 436fca63f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 85 additions and 30 deletions

View file

@ -183,7 +183,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
{
Width = this.ConstrainedWidth,
VAnchor = VAnchor.Stretch,
SpliterBarColor = theme.SplitterBackground,
SplitterBarColor = theme.SplitterBackground,
SplitterWidth = theme.SplitterWidth,
MinimumSize = new Vector2(this.MinDockingWidth, 0)
};
@ -255,7 +255,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
VAnchor = VAnchor.Stretch,
HAnchor = HAnchor.Right,
BackgroundColor = theme.ActiveTabColor,
SpliterBarColor = theme.SplitterBackground,
SplitterBarColor = theme.SplitterBackground,
SplitterWidth = theme.SplitterWidth,
};
resizeContainer.AddChild(new DockingWindowContent(this, item.widget, item.text, theme)

View file

@ -53,7 +53,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
this.grabSide = grabSide;
this.HAnchor = HAnchor.Absolute;
this.SplitterWidth = theme.SplitterWidth;
this.SpliterBarColor = theme.SplitterBackground;
this.SplitterBarColor = theme.SplitterBackground;
}
public override Cursors Cursor
@ -71,7 +71,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
set => base.Cursor = value;
}
public Color SpliterBarColor { get; set; }
public Color SplitterBarColor { get; set; }
public int SplitterWidth
{
@ -81,6 +81,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
if (_splitterWidth != value)
{
_splitterWidth = value;
if (grabSide == GrabBarSide.Left)
{
this.Padding = new BorderDouble(_splitterWidth, 0, 0, 0);
@ -89,6 +90,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
{
this.Padding = new BorderDouble(0, 0, _splitterWidth, 0);
}
this.MinimumSize = new VectorMath.Vector2(_splitterWidth, 0);
}
}
@ -103,11 +105,11 @@ namespace MatterHackers.MatterControl.CustomWidgets
{
if (grabSide == GrabBarSide.Left)
{
graphics2D.FillRectangle(LocalBounds.Left, LocalBounds.Bottom, LocalBounds.Left + this.SplitterWidth, LocalBounds.Top, this.SpliterBarColor);
graphics2D.FillRectangle(LocalBounds.Left, LocalBounds.Bottom, LocalBounds.Left + this.SplitterWidth, LocalBounds.Top, this.SplitterBarColor);
}
else
{
graphics2D.FillRectangle(LocalBounds.Right - this.SplitterWidth, LocalBounds.Bottom, LocalBounds.Right, LocalBounds.Top, this.SpliterBarColor);
graphics2D.FillRectangle(LocalBounds.Right - this.SplitterWidth, LocalBounds.Bottom, LocalBounds.Right, LocalBounds.Top, this.SplitterBarColor);
}
base.OnDraw(graphics2D);

View file

@ -67,6 +67,16 @@ namespace MatterHackers.MatterControl.CustomWidgets
}
public override void OnBoundsChanged(EventArgs e)
{
if (!reloading)
{
this.LayoutIcons();
}
base.OnBoundsChanged(e);
}
private void LayoutIcons()
{
int currentWidth = (int)this.Size.X;
if (reflownWidth != currentWidth)
@ -101,8 +111,6 @@ namespace MatterHackers.MatterControl.CustomWidgets
}
}
}
base.OnBoundsChanged(e);
}
private int RecomputeFlowValues(int leftRightItemMargin)
@ -185,13 +193,18 @@ namespace MatterHackers.MatterControl.CustomWidgets
this.CloseAllChildren();
}
private bool reloading = false;
public void BeginReload()
{
reloading = true;
columnCount = RecomputeFlowValues(1);
}
public void EndReload()
{
reloading = false;
this.LayoutIcons();
}
}

View file

@ -30,6 +30,7 @@ either expressed or implied, of the FreeBSD Project.
using System;
using System.Linq;
using MatterHackers.Agg;
using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.CustomWidgets;
@ -131,21 +132,59 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
ActiveContainer = ApplicationController.Instance.Library.RootLibaryContainer
};
var leftBar = new FlowLayoutWidget(FlowDirection.TopToBottom)
{
VAnchor = VAnchor.Stretch
};
favoritesBarAndView3DWidget.AddChild(leftBar);
bool expanded = UserSettings.Instance.get(UserSettingsKey.FavoritesBarExpansion) != "0";
favoritesBar = new LibraryListView(favoritesBarContext, theme)
{
Name = "LibraryView",
// Drop containers
ContainerFilter = (container) => false,
BackgroundColor = theme.ActiveTabColor,
ListContentView = new IconListView(theme, 22),
Border = new BorderDouble(top: 1, right: 1),
BorderColor = theme.BorderColor20,
HAnchor = HAnchor.Absolute,
Width = 33,
AllowContextMenu = false
};
VAnchor = VAnchor.Fit | VAnchor.Top,
AllowContextMenu = false,
favoritesBarAndView3DWidget.AddChild(favoritesBar);
// restore to state for favorites bar size
Width = expanded ? 55 : 33,
ListContentView = new IconListView(theme, expanded ? 48 : 24),
};
leftBar.AddChild(favoritesBar);
leftBar.AddChild(new VerticalSpacer());
var expandedImage = AggContext.StaticData.LoadIcon("expand.png", 18, 18, theme.InvertIcons);
var collapsedImage = AggContext.StaticData.LoadIcon("collapse.png", 18, 18, theme.InvertIcons);
var expandBarButton = new IconButton(expanded ? collapsedImage : expandedImage, theme)
{
HAnchor = HAnchor.Center,
VAnchor = VAnchor.Absolute,
Margin = new BorderDouble(bottom: 4)
};
expandBarButton.Click += (s, e) => UiThread.RunOnIdle(() =>
{
expanded = !expanded;
UserSettings.Instance.set(UserSettingsKey.FavoritesBarExpansion, expanded ? "1" : "0");
favoritesBar.ListContentView = new IconListView(theme, expanded ? 48 : 24);
favoritesBar.Width = expanded ? 55 : 33;
expandBarButton.SetIcon(expanded ? collapsedImage : expandedImage);
expandBarButton.Invalidate();
favoritesBar.Reload().ConfigureAwait(false);
});
leftBar.AddChild(expandBarButton);
favoritesBarAndView3DWidget.AddChild(view3DWidget);
toolbarAndView3DWidget.AddChild(favoritesBarAndView3DWidget);

View file

@ -1,5 +1,5 @@
/*
Copyright (c) 2017, Lars Brubaker, John Lewin
Copyright (c) 20178 Lars Brubaker, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -37,6 +37,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
public Color HoverColor { get; set; } = new Color(0, 0, 0, 40);
public Color OpenColor { get; set; } = new Color(0, 0, 0, 40);
public event EventHandler PopupWindowClosed;
public event EventHandler BeforePopup;
public event EventHandler<GuiWidget> ConfigurePopup;
@ -44,7 +46,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
protected GuiWidget buttonView;
private bool menuVisibileAtMouseDown = false;
private bool menuVisible = false;
protected bool menuVisible = false;
private PopupWidget popupWidget;
public PopupButton()
@ -70,6 +72,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
public Color PopupBorderColor { get; set; } = Color.Transparent;
public override Color BackgroundColor
{
get => menuVisible ? this.OpenColor : base.BackgroundColor;
set => base.BackgroundColor = value;
}
public override void OnMouseDown(MouseEventArgs mouseEvent)
{
// Store the menu state at the time of mousedown
@ -87,16 +95,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
base.OnClick(mouseEvent);
}
public override void OnDraw(Graphics2D graphics2D)
{
if (menuVisible)
{
graphics2D.FillRectangle(this.LocalBounds, HoverColor);
}
base.OnDraw(graphics2D);
}
public void ShowPopup()
{
if (PopupLayoutEngine == null)

View file

@ -166,7 +166,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
Width = printer?.ViewState.SelectedObjectPanelWidth ?? 200,
VAnchor = VAnchor.Stretch,
HAnchor = HAnchor.Absolute,
SpliterBarColor = theme.SplitterBackground,
SplitterBarColor = theme.SplitterBackground,
SplitterWidth = theme.SplitterWidth,
Visible = false,
};

View file

@ -163,7 +163,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
VAnchor = VAnchor.Stretch,
HAnchor = HAnchor.Absolute,
BackgroundColor = theme.InteractionLayerOverlayColor,
SpliterBarColor = theme.SplitterBackground,
SplitterBarColor = theme.SplitterBackground,
SplitterWidth = theme.SplitterWidth,
MinimumSize = new Vector2(theme.SplitterWidth, 0)
};

View file

@ -527,8 +527,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
VAnchor = VAnchor.Fit,
};
PopupMenuButton libraryPopup = null;
var openColor = theme.ResolveColor(theme.ActiveTabColor, theme.SlightShade);
PopupMenuButton libraryPopup = null;
libraryPopup = new PopupMenuButton(buttonView, theme)
{
MakeScrollable = false,
@ -544,10 +545,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
var verticalResizeContainer = new VerticalResizeContainer(theme, GrabBarSide.Right)
{
BackgroundColor = theme.TabBarBackground,
Padding = new BorderDouble(0, 0, theme.DefaultContainerPadding / 2, 0),
BackgroundColor = openColor,
MinimumSize = new Vector2(120, 50),
Height = libraryPopup.TransformToScreenSpace(libraryPopup.Position).Y,
SplitterBarColor = theme.SlightShade,
};
double.TryParse(UserSettings.Instance.get(UserSettingsKey.PopupLibraryWidth), out double controlWidth);
@ -607,6 +608,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
BackgroundColor = theme.ToolbarButtonBackground,
HoverColor = theme.ToolbarButtonHover,
MouseDownColor = theme.ToolbarButtonDown,
OpenColor = openColor,
DrawArrow = true,
Margin = theme.ButtonSpacing,
};

View file

@ -68,6 +68,7 @@ namespace MatterHackers.MatterControl
public const string SelectedObjectEditorHeight = nameof(SelectedObjectEditorHeight);
public const string SelectionTreeViewPanelExpanded = nameof(SelectionTreeViewPanelExpanded);
public const string ThemeName = nameof(ThemeName);
public const string FavoritesBarExpansion= nameof(FavoritesBarExpansion);
}
public class UserSettings

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

BIN
StaticData/Icons/expand.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB