Move theme accent buttons to SectionWidget heading

This commit is contained in:
John Lewin 2018-10-20 23:05:19 -07:00
parent 1fda1e231d
commit fc9099139a
2 changed files with 110 additions and 52 deletions

View file

@ -34,7 +34,11 @@ using MatterHackers.Agg;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.Library;
using MatterHackers.MatterControl.PartPreviewWindow;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.ConfigurationPage
{
@ -60,17 +64,15 @@ namespace MatterHackers.MatterControl.ConfigurationPage
_themeProvider = AppContext.ThemeProviders.Values.First();
}
this.SelectionColor = activeTheme.MinimalShade;
accentPanelColor = activeTheme.ResolveColor(activeTheme.SectionBackgroundColor, activeTheme.SlightShade);
// Add color selector
this.AddChild(colorSelector = new AccentColorsWidget(this));
this.SelectionColor = activeTheme.MinimalShade;
this.AddChild(previewButtonPanel = new FlowLayoutWidget()
{
HAnchor = HAnchor.Stretch,
VAnchor = VAnchor.Fit,
BackgroundColor = this.SelectionColor,
Padding = new BorderDouble(left: colorSelector.ColorButtons.First().Border.Left)
//BackgroundColor = activeTheme.MinimalShade
});
this.CreateThemeModeButtons();
@ -78,6 +80,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage
public ImageBuffer CheckMark { get; } = AggContext.StaticData.LoadIcon("426.png", 16, 16, invertImage: true);
private Color accentPanelColor;
public Color SelectionColor { get; private set; }
public IColorTheme ThemeProvider
@ -109,36 +113,91 @@ namespace MatterHackers.MatterControl.ConfigurationPage
accentColor = _themeProvider.DefaultColor;
}
var activeMode = UserSettings.Instance.get(UserSettingsKey.ThemeMode);
int providerIndex = 0;
foreach (var mode in _themeProvider.Modes)
foreach (var provider in AppContext.ThemeProviders.Values)
{
var themeset = _themeProvider.GetTheme(mode, accentColor);
previewButtonPanel.AddChild(new ThemePreviewButton(themeset.Theme, this)
if (providerIndex > 0)
{
HAnchor = HAnchor.Absolute,
VAnchor = VAnchor.Absolute,
Width = 80,
Height = 65,
Mode = mode,
Margin = new BorderDouble(theme.DefaultContainerPadding, theme.DefaultContainerPadding, 0, theme.DefaultContainerPadding),
Border = 1,
IsActive = mode == activeMode,
BorderColor = theme.BorderColor20,
});
previewButtonPanel.AddChild(new VerticalLine()
{
BackgroundColor = theme.MinimalShade,
Margin = new BorderDouble(0, theme.DefaultContainerPadding),
});
}
foreach (var mode in provider.Modes)
{
var themeset = provider.GetTheme(mode, accentColor);
var previewContainer = new GuiWidget()
{
HAnchor = HAnchor.Fit | HAnchor.Left,
VAnchor = VAnchor.Fit | VAnchor.Center,
};
previewButtonPanel.AddChild(previewContainer);
if (themeset.ThemeName == AppContext.ThemeSet.ThemeName)
{
previewContainer.BackgroundColor = theme.MinimalShade;
}
previewContainer.AddChild(new ThemePreviewButton(themeset, this)
{
HAnchor = HAnchor.Absolute,
VAnchor = VAnchor.Absolute,
Width = 80,
Height = 65,
Mode = mode,
Border = 1,
IsActive = AppContext.ThemeSet.ThemeName == themeset.ThemeName,
BorderColor = theme.BorderColor20,
Margin = theme.DefaultContainerPadding
});
if (AppContext.ThemeSet.ThemeName == themeset.ThemeName)
{
var imageBuffer = new ImageBuffer(20, 20);
var graphics = imageBuffer.NewGraphics2D();
var arrowHeight = 8;
var upArrow = new VertexStorage();
upArrow.MoveTo(-arrowHeight, -arrowHeight);
upArrow.LineTo(arrowHeight, -arrowHeight);
upArrow.LineTo(0, 0);
var dropArrowBounds = new RectangleDouble(0, 0, 20, arrowHeight +2);
var center = dropArrowBounds.Center;
center.Y += 3;
graphics.Render(upArrow, center, accentPanelColor);
imageBuffer.SetPreMultiply();
previewContainer.AddChild(new ImageWidget(imageBuffer, false)
{
HAnchor = HAnchor.Center,
VAnchor = VAnchor.Bottom,
});
}
}
providerIndex++;
}
}
public void PreviewTheme(Color sourceAccentColor)
{
foreach (var previewButton in previewButtonPanel.Children<ThemePreviewButton>())
var previewButton = previewButtonPanel.Descendants<ThemePreviewButton>().FirstOrDefault(t => t.ThemeSet.ThemeName == AppContext.ThemeSet.ThemeName);
if (previewButton != null)
{
previewButton.PreviewThemeColor(sourceAccentColor);
}
}
public void SetThemeColor(Color accentColor, string mode = null)
public void SetThemeColor(ThemeSet themeSet, Color accentColor, string mode = null)
{
lastColor = accentColor;
@ -147,38 +206,36 @@ namespace MatterHackers.MatterControl.ConfigurationPage
colorButton.BorderColor = (colorButton.SourceColor == accentColor) ? Color.White : Color.Transparent;
}
if (mode == null)
{
mode = this.ThemeProvider.DefaultMode;
themeSet.Theme.PrimaryAccentColor = accentColor;
themeSet.Theme.AccentMimimalOverlay = accentColor.WithAlpha(90);
var lastMode = UserSettings.Instance.get(UserSettingsKey.ThemeMode);
if (this.ThemeProvider.Modes.Contains(lastMode))
{
mode = lastMode;
}
}
AppContext.SetTheme(themeSet);
Console.WriteLine("Getting/setting theme for " + accentColor.Html);
AppContext.SetTheme(this.ThemeProvider.GetTheme(mode, accentColor));
previewButtonPanel.BackgroundColor = this.SelectionColor;
}
public class AccentColorsWidget : FlowLayoutWidget
{
private int containerHeight = (int)(20 * GuiWidget.DeviceScale);
private ThemeColorPanel themeColorPanel;
private int containerHeight;
private int buttonSpacing;
private List<ColorButton> colorButtons = new List<ColorButton>();
private ThemeSet themeSet;
public AccentColorsWidget(ThemeColorPanel themeColorPanel)
public AccentColorsWidget(ThemeSet themeSet, int buttonHeight = 18, int buttonSpacing = 3)
{
this.themeColorPanel = themeColorPanel;
this.themeSet = themeSet;
this.Margin = new BorderDouble(left: buttonSpacing);
this.buttonSpacing = buttonSpacing;
containerHeight = (int)(buttonHeight * GuiWidget.DeviceScale);
this.RebuildColorButtons();
}
private List<ColorButton> colorButtons = new List<ColorButton>();
public IEnumerable<ColorButton> ColorButtons => colorButtons;
public ThemeColorPanel ThemeColorPanel { get; set; }
public void RebuildColorButtons()
{
this.CloseAllChildren();
@ -187,11 +244,10 @@ namespace MatterHackers.MatterControl.ConfigurationPage
bool firstItem = true;
foreach (var color in themeColorPanel.ThemeProvider.Colors)
foreach (var color in themeSet.AccentColors)
{
var colorButton = CreateThemeButton(color);
var colorButton = this.CreateThemeButton(color);
colorButton.Width = containerHeight;
colorButton.BorderColor = (color == AppContext.Theme.Colors.SourceColor) ? themeColorPanel.SelectionColor : Color.Transparent;
colorButtons.Add(colorButton);
@ -212,21 +268,16 @@ namespace MatterHackers.MatterControl.ConfigurationPage
Cursor = Cursors.Hand,
Width = containerHeight,
Height = containerHeight,
Border = 6,
Margin = buttonSpacing
};
colorButton.Click += (s, e) =>
{
themeColorPanel.SetThemeColor(colorButton.BackgroundColor);
AppContext.SetThemeAccentColor(colorButton.BackgroundColor);
};
colorButton.MouseEnterBounds += (s, e) =>
{
foreach(var button in this.ColorButtons)
{
button.BorderColor = (button == colorButton) ? themeColorPanel.SelectionColor : Color.Transparent;
}
themeColorPanel.PreviewTheme(colorButton.BackgroundColor);
this.ThemeColorPanel?.PreviewTheme(colorButton.BackgroundColor);
};
return colorButton;