Initial use of colors for list items and buttons

This commit is contained in:
Peter Kirmeier 2023-04-29 22:42:28 +02:00
parent 14db7ef845
commit 55fccd17d5
3 changed files with 63 additions and 127 deletions

View file

@ -13,6 +13,7 @@ namespace SystemTrayMenu.Business
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using Microsoft.Win32;
using SystemTrayMenu.DataClasses;
@ -186,6 +187,8 @@ namespace SystemTrayMenu.Business
Closing,
}
public static SolidColorBrush BrushSelectedItemBorder => MenuDefines.ColorSelectedItemBorder.ToSolidColorBrush();
private Menu? MainMenu => menus[0];
private bool IsMainUsable => MainMenu?.IsUsable ?? false;
@ -571,9 +574,6 @@ namespace SystemTrayMenu.Business
dgv.MouseMove += waitToOpenMenu.MouseMove;
#endif
dgv.SelectionChanged += Dgv_SelectionChanged;
#if TODO // BorderColors and PaintEvent
dgv.RowPostPaint += Dgv_RowPostPaint;
#endif
}
if (menu.Level == 0)
@ -700,41 +700,28 @@ namespace SystemTrayMenu.Business
foreach (ListViewItemData itemData in dgv.Items)
{
RowData rowData = itemData.data;
if (rowData == null)
if (rowData.IsClicking)
{
// Case when filtering a previous menu
}
else if (!IsMainUsable)
{
#if TODO // Colors
itemData.DefaultCellStyle.SelectionBackColor = Color.White;
#endif
dgv.SelectedItems.Remove(itemData);
}
else if (rowData.IsClicking)
{
#if TODO // Colors
itemData.DefaultCellStyle.SelectionBackColor = MenuDefines.ColorIcons;
#endif
itemData.BorderBrush = MenuDefines.ColorIcons.ToSolidColorBrush();
itemData.BackgroundBrush = MenuDefines.ColorSelectedItem.ToSolidColorBrush();
dgv.SelectedItems.Add(itemData);
}
else if (rowData.IsMenuOpen)
{
itemData.BorderBrush = MenuDefines.ColorOpenFolderBorder.ToSolidColorBrush();
itemData.BackgroundBrush = MenuDefines.ColorOpenFolder.ToSolidColorBrush();
dgv.SelectedItems.Add(itemData);
}
else if (rowData.IsSelected)
{
#if TODO // Colors
itemData.DefaultCellStyle.SelectionBackColor = MenuDefines.ColorSelectedItem;
#endif
itemData.BorderBrush = MenuDefines.ColorSelectedItemBorder.ToSolidColorBrush();
itemData.BackgroundBrush = MenuDefines.ColorSelectedItem.ToSolidColorBrush();
dgv.SelectedItems.Add(itemData);
}
else
{
#if TODO // Colors
itemData.DefaultCellStyle.SelectionBackColor = Color.White;
#endif
itemData.BorderBrush = Brushes.White;
itemData.BackgroundBrush = Brushes.White;
dgv.SelectedItems.Remove(itemData);
}
}
@ -747,56 +734,6 @@ namespace SystemTrayMenu.Business
}
}
#if TODO // BorderColors and PaintEvent
private void Dgv_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
ListView dgv = (ListView)sender;
DataGridViewRow row = dgv.Items[e.RowIndex];
if (row.Selected)
{
RowData rowData = (RowData)row.Cells[2].Value;
int width = dgv.Columns[0].Width + dgv.Columns[1].Width;
Rectangle rowBounds = new(0, e.RowBounds.Top, width, e.RowBounds.Height);
if (rowData.IsClicking)
{
ControlPaint.DrawBorder(e.Graphics, rowBounds, MenuDefines.ColorIcons, ButtonBorderStyle.Solid);
row.DefaultCellStyle.SelectionBackColor = MenuDefines.ColorSelectedItem;
}
else if (rowData.IsContextMenuOpen || (rowData.IsMenuOpen && rowData.IsSelected))
{
ControlPaint.DrawBorder(e.Graphics, rowBounds, MenuDefines.ColorSelectedItemBorder, ButtonBorderStyle.Solid);
row.DefaultCellStyle.SelectionBackColor = MenuDefines.ColorSelectedItem;
}
else if (rowData.IsMenuOpen)
{
ControlPaint.DrawBorder(e.Graphics, rowBounds, MenuDefines.ColorOpenFolderBorder, ButtonBorderStyle.Solid);
row.DefaultCellStyle.SelectionBackColor = MenuDefines.ColorOpenFolder;
}
if (rowData.ProcessStarted)
{
rowData.ProcessStarted = false;
row.Cells[0].Value = Resources.StaticResources.LoadingIcon;
timerShowProcessStartedAsLoadingIcon.Stop();
timerShowProcessStartedAsLoadingIcon.Interval = TimeSpan.FromMilliseconds(Settings.Default.TimeUntilClosesAfterEnterPressed);
timerShowProcessStartedAsLoadingIcon.Tick += Tick;
void Tick(object sender, EventArgs e)
{
timerShowProcessStartedAsLoadingIcon.Tick -= Tick;
timerShowProcessStartedAsLoadingIcon.Stop();
row.Cells[0].Value = rowData.ReadIcon(false);
}
timerShowProcessStartedAsLoadingIcon.Start();
timerStillActiveCheck.Stop();
timerStillActiveCheck.Start();
}
}
}
#endif
private void SystemEvents_DisplaySettingsChanged(object? sender, EventArgs e)
{
dispatchter.Invoke(() =>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2022-2022 Peter Kirmeier -->
<!-- Copyright (c) 2022-2023 Peter Kirmeier -->
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
@ -7,6 +7,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:utils="clr-namespace:SystemTrayMenu.Utilities"
xmlns:business="clr-namespace:SystemTrayMenu.Business"
xmlns:local="clr-namespace:SystemTrayMenu.UserInterface"
x:Class="SystemTrayMenu.UserInterface.Menu"
mc:Ignorable="d" ResizeMode="NoResize" WindowStyle="None" Topmost="True" Background="Transparent" AllowsTransparency="True" SizeToContent="WidthAndHeight" ShowInTaskbar="False" SnapsToDevicePixels="True" UseLayoutRounding="True"
@ -111,6 +112,30 @@
</DockPanel>
<DockPanel x:Name="tableLayoutPanelBottom" DockPanel.Dock="Bottom" Margin="12,4">
<DockPanel.Resources>
<Style TargetType="{x:Type Button}">
<!-- TODO: Find better solution instead of re-implementing the control template of a button,
only to manage changing the mouse hover border color. -->
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border x:Name="Border" BorderThickness="1" BorderBrush="{TemplateBinding BorderBrush}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" Value="{x:Static business:Menus.BrushSelectedItemBorder}" TargetName="Border" />
<Setter Property="Background" Value="LightGray" TargetName="Border" />
<Setter Property="Opacity" Value="0.9" TargetName="Border" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</DockPanel.Resources>
<Label x:Name="labelStatus" Content="0 items" Padding="0" DockPanel.Dock="Left" FontWeight="Bold" VerticalAlignment="Center" Margin="0,0,10,0"/>
<Image x:Name="pictureBoxLoading" Width="18" Height="18" DockPanel.Dock="Right"
@ -148,7 +173,7 @@
<ListView x:Name="dgv" x:FieldModifier="internal" Margin="6,0" d:ItemsSource="{d:SampleData ItemCount=5}" ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Auto" BorderBrush="{x:Null}" Background="{x:Null}" ScrollViewer.ScrollChanged="HandleScrollChanged">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="{DynamicResource RowHeight}">
<StackPanel Orientation="Horizontal" Height="{DynamicResource RowHeight}" Background="{Binding BackgroundBrush}">
<Image Width="{DynamicResource ColumnIconWidth}" Margin="0,2,0,3" Source="{Binding ColumnIcon}" />
<Label Width="{DynamicResource ColumnTextWidth}" Margin="3,0" Padding="0" VerticalContentAlignment="Center">
<TextBlock TextTrimming="CharacterEllipsis" Text="{Binding ColumnText}"/>
@ -158,7 +183,8 @@
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}">
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="BorderBrush" Value="{Binding BorderBrush}"/>
<Setter Property="Margin" Value="0"/>
<Setter Property="Padding" Value="0"/>
<EventSetter Event="MouseEnter" Handler="ListViewItem_MouseEnter" />

View file

@ -1106,36 +1106,11 @@ namespace SystemTrayMenu.UserInterface
#endif
}
#if TODO // Misc MouseEvents and BorderColors
private void PictureBoxOpenFolder_Paint(object sender, PaintEventArgs e)
{
PictureBox pictureBox = (PictureBox)sender;
if (pictureBox.Tag != null && (bool)pictureBox.Tag)
{
Rectangle rowBounds = new(0, 0, pictureBox.Width, pictureBox.Height);
ControlPaint.DrawBorder(e.Graphics, rowBounds, MenuDefines.ColorSelectedItemBorder, ButtonBorderStyle.Solid);
}
}
#endif
private void PictureBoxOpenFolder_Click(object sender, RoutedEventArgs e)
{
Menus.OpenFolder(folderPath);
}
#if TODO // BorderColors
private void PictureBoxMenuAlwaysOpen_Paint(object sender, PaintEventArgs e)
{
PictureBox pictureBox = (PictureBox)sender;
if (pictureBox.Tag != null && (bool)pictureBox.Tag)
{
Rectangle rowBounds = new(0, 0, pictureBox.Width, pictureBox.Height);
ControlPaint.DrawBorder(e.Graphics, rowBounds, MenuDefines.ColorSelectedItemBorder, ButtonBorderStyle.Solid);
}
}
#endif
private void PictureBoxMenuAlwaysOpen_Click(object sender, RoutedEventArgs e)
{
if (Config.AlwaysOpenByPin = !Config.AlwaysOpenByPin)
@ -1148,35 +1123,11 @@ namespace SystemTrayMenu.UserInterface
}
}
#if TODO // BorderColors
private void PictureBoxSettings_Paint(object sender, PaintEventArgs e)
{
PictureBox pictureBox = (PictureBox)sender;
if (pictureBox.Tag != null && (bool)pictureBox.Tag)
{
Rectangle rowBounds = new(0, 0, pictureBox.Width, pictureBox.Height);
ControlPaint.DrawBorder(e.Graphics, rowBounds, MenuDefines.ColorSelectedItemBorder, ButtonBorderStyle.Solid);
}
}
#endif
private void PictureBoxSettings_MouseClick(object sender, RoutedEventArgs e)
{
SettingsWindow.ShowSingleInstance();
}
#if TODO // BorderColors
private void PictureBoxRestart_Paint(object sender, PaintEventArgs e)
{
PictureBox pictureBox = (PictureBox)sender;
if (pictureBox.Tag != null && (bool)pictureBox.Tag)
{
Rectangle rowBounds = new(0, 0, pictureBox.Width, pictureBox.Height);
ControlPaint.DrawBorder(e.Graphics, rowBounds, MenuDefines.ColorSelectedItemBorder, ButtonBorderStyle.Solid);
}
}
#endif
private void PictureBoxRestart_MouseClick(object sender, RoutedEventArgs e)
{
AppRestart.ByMenuButton();
@ -1302,6 +1253,8 @@ namespace SystemTrayMenu.UserInterface
/// </summary>
internal class ListViewItemData : INotifyPropertyChanged
{
private Brush? backgroundBrush;
private Brush? borderBrush;
private ImageSource? columnIcon;
internal ListViewItemData(ImageSource? columnIcon, string columnText, RowData rowData, int sortIndex)
@ -1314,6 +1267,26 @@ namespace SystemTrayMenu.UserInterface
public event PropertyChangedEventHandler? PropertyChanged;
public Brush? BackgroundBrush
{
get => backgroundBrush;
set
{
backgroundBrush = value;
CallPropertyChanged();
}
}
public Brush? BorderBrush
{
get => borderBrush;
set
{
borderBrush = value;
CallPropertyChanged();
}
}
public ImageSource? ColumnIcon
{
get => columnIcon;