Files
QSafe/windows/QSafe.Desktop/Ui.cs
T

40 lines
3.1 KiB
C#

using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Automation;
namespace QSafe.Desktop;
public static class Ui
{
public static SolidColorBrush Brush(string color) => (SolidColorBrush)new BrushConverter().ConvertFromString(color)!;
public static TextBlock Text(string text, double size = 14, string color = "#F0F2F6", FontWeight? weight = null) => new() { Text = text, FontSize = size, Foreground = Brush(color), FontWeight = weight ?? FontWeights.Normal, TextWrapping = TextWrapping.Wrap };
public static TextBlock Glyph(string glyph, double size = 18, string color = "#969EAD") => new() { Text = glyph, FontFamily = new FontFamily("Segoe Fluent Icons, Segoe MDL2 Assets"), FontSize = size, Foreground = Brush(color), VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center };
public static Button Button(string text, Action action, string? style = null)
{
var b = new Button { Content = text, MinHeight = 38 };
AutomationProperties.SetName(b, text);
if (style != null) b.Style = (Style)Application.Current.FindResource(style);
b.Click += (_, _) => action(); return b;
}
public static Button IconButton(string glyph, string label, Action action)
{
var b = Button(label, action, "Quiet"); b.Content = Glyph(glyph, 17); b.ToolTip = label; b.Width = 38; b.Padding = new Thickness(8); return b;
}
public static Border Tile(string glyph, string color, double size = 42) => new() { Width = size, Height = size, CornerRadius = new CornerRadius(size / 3), Background = Brush("#252C32"), Child = Glyph(glyph, size * .46, color) };
public static Border Box(UIElement child, string background = "#171A20", double radius = 12, double padding = 20) => new() { Child = child, Background = Brush(background), CornerRadius = new CornerRadius(radius), Padding = new Thickness(padding), BorderBrush = Brush("#2C313B"), BorderThickness = new Thickness(1) };
public static void Label(Panel panel, string text) { var label = Text(text, 12, "#969EAD", FontWeights.SemiBold); label.Margin = new Thickness(0, 18, 0, 7); panel.Children.Add(label); }
public static TextBox Input(Panel panel, string label, string value = "", bool multiline = false)
{
Label(panel, label);
var input = new TextBox { Text = value, AcceptsReturn = multiline, TextWrapping = multiline ? TextWrapping.Wrap : TextWrapping.NoWrap, MinHeight = multiline ? 90 : 42, MaxHeight = multiline ? 180 : 48, VerticalScrollBarVisibility = multiline ? ScrollBarVisibility.Auto : ScrollBarVisibility.Hidden };
AutomationProperties.SetName(input, label); input.SpellCheck.IsEnabled = false; panel.Children.Add(input); return input;
}
public static StackPanel Row(params UIElement[] children)
{
var row = new StackPanel { Orientation = Orientation.Horizontal };
foreach (var c in children) row.Children.Add(c); return row;
}
public static Border Rule() => new() { Height = 1, Background = Brush("#2C313B"), Margin = new Thickness(0, 16, 0, 16) };
}