feat: Phase 0 shells, design system, server skeleton, Docker and CI

- Titano.Ui: DESIGN.md tokens (dark/light), generated 16-px icon set,
  styles for all standard controls, custom chrome window with snap
  layouts, rail, job bar, Auto/manual slider, chips, toasts.
- Titano desktop shell with sections, Settings (language, theme),
  About and a --capture screenshot mode.
- Titano Server skeleton: env/server.json configuration, self-signed
  TLS with fingerprint, /health, /server/info, i18n endpoint and the
  embedded admin panel; in-process server tests.
- Docker image (multi-arch, PUID/PGID, health check), compose file,
  Unraid template; CI, release and nightly workflows; changelog tool.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-02 09:35:03 +00:00
1 parent 800843d2ae
commit c40b6a7cd3
122 files changed
+6838 -22

No files matched your search

+142
View File
@@ -0,0 +1,142 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
namespace Titano.Ui.Controls;
/// <summary>
/// Advisor-aware slider (BRIEF §10.4, DESIGN §4): in Auto the track is accent with an "Auto · value" pill whose
/// tooltip carries the advisor's reason; touching the slider switches to manual (sun track, value shown, reset
/// button returns to Auto). When not applicable the value reads "n/a" with the reason in the tooltip.
/// </summary>
[TemplatePart(Name = PartSlider, Type = typeof(Slider))]
public class AutoSlider : Control
{
public const string PartSlider = "PART_Slider";
public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register(nameof(Header), typeof(string), typeof(AutoSlider));
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(nameof(Value), typeof(double), typeof(AutoSlider),
new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnValueChanged));
public static readonly DependencyProperty MinimumProperty = DependencyProperty.Register(nameof(Minimum), typeof(double), typeof(AutoSlider), new PropertyMetadata(0.0));
public static readonly DependencyProperty MaximumProperty = DependencyProperty.Register(nameof(Maximum), typeof(double), typeof(AutoSlider), new PropertyMetadata(1.0));
public static readonly DependencyProperty SmallChangeProperty = DependencyProperty.Register(nameof(SmallChange), typeof(double), typeof(AutoSlider), new PropertyMetadata(0.01));
public static readonly DependencyProperty IsSnapToTickEnabledProperty = DependencyProperty.Register(nameof(IsSnapToTickEnabled), typeof(bool), typeof(AutoSlider), new PropertyMetadata(false));
public static readonly DependencyProperty TickFrequencyProperty = DependencyProperty.Register(nameof(TickFrequency), typeof(double), typeof(AutoSlider), new PropertyMetadata(1.0));
public static readonly DependencyProperty IsAutoProperty = DependencyProperty.Register(nameof(IsAuto), typeof(bool), typeof(AutoSlider),
new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
public static readonly DependencyProperty AutoValueProperty = DependencyProperty.Register(nameof(AutoValue), typeof(double), typeof(AutoSlider), new PropertyMetadata(0.0, OnAutoValueChanged));
public static readonly DependencyProperty AutoReasonProperty = DependencyProperty.Register(nameof(AutoReason), typeof(string), typeof(AutoSlider));
public static readonly DependencyProperty IsApplicableProperty = DependencyProperty.Register(nameof(IsApplicable), typeof(bool), typeof(AutoSlider), new PropertyMetadata(true));
public static readonly DependencyProperty NotApplicableReasonProperty = DependencyProperty.Register(nameof(NotApplicableReason), typeof(string), typeof(AutoSlider));
public static readonly DependencyProperty ValueFormatProperty = DependencyProperty.Register(nameof(ValueFormat), typeof(string), typeof(AutoSlider), new PropertyMetadata("0.##", OnFormatChanged));
public static readonly DependencyProperty DisplayValueProperty = DependencyProperty.Register(nameof(DisplayValue), typeof(string), typeof(AutoSlider), new PropertyMetadata(string.Empty));
public static readonly DependencyProperty AutoTextProperty = DependencyProperty.Register(nameof(AutoText), typeof(string), typeof(AutoSlider), new PropertyMetadata(string.Empty));
public static readonly DependencyProperty SliderToolTipProperty = DependencyProperty.Register(nameof(SliderToolTip), typeof(object), typeof(AutoSlider));
public static readonly RoutedCommand ResetCommand = new(nameof(ResetCommand), typeof(AutoSlider));
private Slider? _slider;
private bool _syncing;
static AutoSlider()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(AutoSlider), new FrameworkPropertyMetadata(typeof(AutoSlider)));
}
public AutoSlider()
{
CommandBindings.Add(new CommandBinding(ResetCommand, (_, _) => ResetToAuto()));
UpdateTexts();
}
public string? Header { get => (string?)GetValue(HeaderProperty); set => SetValue(HeaderProperty, value); }
public double Value { get => (double)GetValue(ValueProperty); set => SetValue(ValueProperty, value); }
public double Minimum { get => (double)GetValue(MinimumProperty); set => SetValue(MinimumProperty, value); }
public double Maximum { get => (double)GetValue(MaximumProperty); set => SetValue(MaximumProperty, value); }
public double SmallChange { get => (double)GetValue(SmallChangeProperty); set => SetValue(SmallChangeProperty, value); }
public bool IsSnapToTickEnabled { get => (bool)GetValue(IsSnapToTickEnabledProperty); set => SetValue(IsSnapToTickEnabledProperty, value); }
public double TickFrequency { get => (double)GetValue(TickFrequencyProperty); set => SetValue(TickFrequencyProperty, value); }
public bool IsAuto { get => (bool)GetValue(IsAutoProperty); set => SetValue(IsAutoProperty, value); }
public double AutoValue { get => (double)GetValue(AutoValueProperty); set => SetValue(AutoValueProperty, value); }
public string? AutoReason { get => (string?)GetValue(AutoReasonProperty); set => SetValue(AutoReasonProperty, value); }
public bool IsApplicable { get => (bool)GetValue(IsApplicableProperty); set => SetValue(IsApplicableProperty, value); }
public string? NotApplicableReason { get => (string?)GetValue(NotApplicableReasonProperty); set => SetValue(NotApplicableReasonProperty, value); }
public string ValueFormat { get => (string)GetValue(ValueFormatProperty); set => SetValue(ValueFormatProperty, value); }
/// <summary>Formatted current value (read by the template).</summary>
public string DisplayValue { get => (string)GetValue(DisplayValueProperty); private set => SetValue(DisplayValueProperty, value); }
/// <summary>"Auto · 41" pill text; the "Auto" word comes from the catalog (Common.Auto).</summary>
public string AutoText { get => (string)GetValue(AutoTextProperty); private set => SetValue(AutoTextProperty, value); }
/// <summary>Tooltip of the slider track: what moving it does.</summary>
public object? SliderToolTip { get => GetValue(SliderToolTipProperty); set => SetValue(SliderToolTipProperty, value); }
public override void OnApplyTemplate()
{
if (_slider is not null)
{
_slider.ValueChanged -= OnSliderValueChanged;
_slider.PreviewMouseDown -= OnSliderTouched;
_slider.PreviewKeyDown -= OnSliderTouched;
}
base.OnApplyTemplate();
_slider = GetTemplateChild(PartSlider) as Slider;
if (_slider is not null)
{
_slider.Value = IsAuto ? AutoValue : Value;
_slider.ValueChanged += OnSliderValueChanged;
_slider.PreviewMouseDown += OnSliderTouched;
_slider.PreviewKeyDown += OnSliderTouched;
}
}
/// <summary>Returns the control to the advisor's value.</summary>
public void ResetToAuto()
{
IsAuto = true;
Value = AutoValue;
UpdateTexts();
}
private void OnSliderTouched(object sender, RoutedEventArgs e)
{
if (e is KeyEventArgs k && k.Key is not (Key.Left or Key.Right or Key.Up or Key.Down or Key.PageUp or Key.PageDown or Key.Home or Key.End)) return;
IsAuto = false;
}
private void OnSliderValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (_syncing) return;
Value = e.NewValue;
}
private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var s = (AutoSlider)d;
if (s._slider is not null && !s._syncing)
{
s._syncing = true;
s._slider.Value = (double)e.NewValue;
s._syncing = false;
}
s.UpdateTexts();
}
private static void OnAutoValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var s = (AutoSlider)d;
if (s.IsAuto) s.Value = (double)e.NewValue;
s.UpdateTexts();
}
private static void OnFormatChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => ((AutoSlider)d).UpdateTexts();
private void UpdateTexts()
{
var culture = Core.Localization.Loc.Culture;
DisplayValue = Value.ToString(ValueFormat, culture);
AutoText = Core.Localization.Loc.L("Common.Auto") + " · " + AutoValue.ToString(ValueFormat, culture);
}
}
+61
View File
@@ -0,0 +1,61 @@
using System.Windows;
using System.Windows.Media;
using Titano.Core.Branding;
namespace Titano.Ui.Controls;
/// <summary>The Titano mark drawn as vectors from <see cref="BrandMark"/> geometry (plate optional).</summary>
public sealed class BrandMarkIcon : FrameworkElement
{
public static readonly DependencyProperty ShowPlateProperty = DependencyProperty.Register(
nameof(ShowPlate), typeof(bool), typeof(BrandMarkIcon), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
private static readonly Brush Accent = Frozen(new SolidColorBrush(Color.FromRgb(BrandMark.Accent.R, BrandMark.Accent.G, BrandMark.Accent.B)));
private static readonly Brush Sun = Frozen(new SolidColorBrush(Color.FromRgb(BrandMark.Sun.R, BrandMark.Sun.G, BrandMark.Sun.B)));
private static readonly Brush Plate = Frozen(new SolidColorBrush(Color.FromRgb(BrandMark.Plate.R, BrandMark.Plate.G, BrandMark.Plate.B)));
public bool ShowPlate
{
get => (bool)GetValue(ShowPlateProperty);
set => SetValue(ShowPlateProperty, value);
}
protected override Size MeasureOverride(Size availableSize)
{
var s = double.IsInfinity(availableSize.Width) ? 16 : Math.Min(availableSize.Width, double.IsInfinity(availableSize.Height) ? availableSize.Width : availableSize.Height);
return new Size(s, s);
}
protected override void OnRender(DrawingContext dc)
{
var size = Math.Min(ActualWidth, ActualHeight);
if (size <= 0) return;
var scale = size / BrandMark.Canvas;
dc.PushTransform(new ScaleTransform(scale, scale));
if (ShowPlate)
dc.DrawRoundedRectangle(Plate, null, new Rect(0, 0, BrandMark.Canvas, BrandMark.Canvas), BrandMark.PlateRadius, BrandMark.PlateRadius);
// Below ~24 px keep the stroke at least ~1.3 device pixels.
var stroke = Math.Max(BrandMark.StrokeWidth, 1.3 / scale);
for (var i = 0; i < BrandMark.TickCount; i++)
{
var (a0, a1) = BrandMark.TickAngles(i);
var (x0, y0) = BrandMark.Polar(a0);
var (x1, y1) = BrandMark.Polar(a1);
var figure = new PathFigure { StartPoint = new Point(x0, y0) };
figure.Segments.Add(new ArcSegment(new Point(x1, y1), new Size(BrandMark.RingRadius, BrandMark.RingRadius), 0, false, SweepDirection.Clockwise, true));
var geometry = new PathGeometry([figure]);
var pen = new Pen(Accent, stroke) { StartLineCap = PenLineCap.Round, EndLineCap = PenLineCap.Round };
dc.PushOpacity(BrandMark.TickOpacity(i));
dc.DrawGeometry(null, pen, geometry);
dc.Pop();
}
dc.DrawEllipse(Sun, null, new Point(BrandMark.SunX, BrandMark.SunY), BrandMark.SunRadius, BrandMark.SunRadius);
dc.Pop();
}
private static Brush Frozen(SolidColorBrush b)
{
b.Freeze();
return b;
}
}
+29
View File
@@ -0,0 +1,29 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace Titano.Ui.Controls;
/// <summary>24-px pill (DESIGN §4). Selected or recommended chips use the accent border and text.</summary>
public class Chip : ContentControl
{
public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register(nameof(IsSelected), typeof(bool), typeof(Chip));
public static readonly DependencyProperty IsRecommendedProperty = DependencyProperty.Register(nameof(IsRecommended), typeof(bool), typeof(Chip));
public static readonly DependencyProperty RemoveCommandProperty = DependencyProperty.Register(nameof(RemoveCommand), typeof(ICommand), typeof(Chip));
public static readonly DependencyProperty RemoveCommandParameterProperty = DependencyProperty.Register(nameof(RemoveCommandParameter), typeof(object), typeof(Chip));
public static readonly DependencyProperty RemoveToolTipProperty = DependencyProperty.Register(nameof(RemoveToolTip), typeof(object), typeof(Chip));
static Chip()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(Chip), new FrameworkPropertyMetadata(typeof(Chip)));
}
public bool IsSelected { get => (bool)GetValue(IsSelectedProperty); set => SetValue(IsSelectedProperty, value); }
public bool IsRecommended { get => (bool)GetValue(IsRecommendedProperty); set => SetValue(IsRecommendedProperty, value); }
/// <summary>When set, a small ✕ button removes the chip (filters, tags).</summary>
public ICommand? RemoveCommand { get => (ICommand?)GetValue(RemoveCommandProperty); set => SetValue(RemoveCommandProperty, value); }
public object? RemoveCommandParameter { get => GetValue(RemoveCommandParameterProperty); set => SetValue(RemoveCommandParameterProperty, value); }
public object? RemoveToolTip { get => GetValue(RemoveToolTipProperty); set => SetValue(RemoveToolTipProperty, value); }
}
+28
View File
@@ -0,0 +1,28 @@
using System.Windows;
using System.Windows.Media;
namespace Titano.Ui.Controls;
/// <summary>Attached brushes that let one control template serve every button variant (DESIGN §4 states).</summary>
public static class ControlState
{
public static readonly DependencyProperty HoverBackgroundProperty = DependencyProperty.RegisterAttached("HoverBackground", typeof(Brush), typeof(ControlState));
public static readonly DependencyProperty PressedBackgroundProperty = DependencyProperty.RegisterAttached("PressedBackground", typeof(Brush), typeof(ControlState));
public static readonly DependencyProperty HoverBorderBrushProperty = DependencyProperty.RegisterAttached("HoverBorderBrush", typeof(Brush), typeof(ControlState));
public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.RegisterAttached("CornerRadius", typeof(CornerRadius), typeof(ControlState), new FrameworkPropertyMetadata(new CornerRadius(6)));
public static readonly DependencyProperty AccentProperty = DependencyProperty.RegisterAttached("Accent", typeof(Brush), typeof(ControlState), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits));
public static Brush? GetHoverBackground(DependencyObject d) => (Brush?)d.GetValue(HoverBackgroundProperty);
public static void SetHoverBackground(DependencyObject d, Brush? v) => d.SetValue(HoverBackgroundProperty, v);
public static Brush? GetPressedBackground(DependencyObject d) => (Brush?)d.GetValue(PressedBackgroundProperty);
public static void SetPressedBackground(DependencyObject d, Brush? v) => d.SetValue(PressedBackgroundProperty, v);
public static Brush? GetHoverBorderBrush(DependencyObject d) => (Brush?)d.GetValue(HoverBorderBrushProperty);
public static void SetHoverBorderBrush(DependencyObject d, Brush? v) => d.SetValue(HoverBorderBrushProperty, v);
public static CornerRadius GetCornerRadius(DependencyObject d) => (CornerRadius)d.GetValue(CornerRadiusProperty);
public static void SetCornerRadius(DependencyObject d, CornerRadius v) => d.SetValue(CornerRadiusProperty, v);
/// <summary>Fill colour of slider tracks and progress (accent = Auto, sun = manual).</summary>
public static Brush? GetAccent(DependencyObject d) => (Brush?)d.GetValue(AccentProperty);
public static void SetAccent(DependencyObject d, Brush? v) => d.SetValue(AccentProperty, v);
}
+44
View File
@@ -0,0 +1,44 @@
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace Titano.Ui.Controls;
/// <summary>null → Collapsed, otherwise Visible.</summary>
public sealed class NullToCollapsedConverter : IValueConverter
{
public static NullToCollapsedConverter Instance { get; } = new();
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) =>
value is null || value is string { Length: 0 } ? Visibility.Collapsed : Visibility.Visible;
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotSupportedException();
}
/// <summary>true → Collapsed (inverse of BooleanToVisibilityConverter).</summary>
public sealed class InverseBoolToVisibilityConverter : IValueConverter
{
public static InverseBoolToVisibilityConverter Instance { get; } = new();
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) =>
value is true ? Visibility.Collapsed : Visibility.Visible;
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotSupportedException();
}
/// <summary>0 → Collapsed, any other number → Visible.</summary>
public sealed class ZeroToCollapsedConverter : IValueConverter
{
public static ZeroToCollapsedConverter Instance { get; } = new();
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) =>
value switch
{
int i => i == 0 ? Visibility.Collapsed : Visibility.Visible,
long l => l == 0 ? Visibility.Collapsed : Visibility.Visible,
double d => d == 0 ? Visibility.Collapsed : Visibility.Visible,
_ => Visibility.Collapsed,
};
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotSupportedException();
}
+17
View File
@@ -0,0 +1,17 @@
using System.Windows;
using System.Windows.Controls;
namespace Titano.Ui.Controls;
/// <summary>Empty state: the mark, one sentence and the action buttons supplied as content (BRIEF §0.2 rule 6).</summary>
public class EmptyState : ContentControl
{
public static readonly DependencyProperty MessageProperty = DependencyProperty.Register(nameof(Message), typeof(string), typeof(EmptyState));
static EmptyState()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(EmptyState), new FrameworkPropertyMetadata(typeof(EmptyState)));
}
public string? Message { get => (string?)GetValue(MessageProperty); set => SetValue(MessageProperty, value); }
}
+32
View File
@@ -0,0 +1,32 @@
using System.Windows;
namespace Titano.Ui.Controls;
/// <summary>Attached field helpers: placeholder text and an inline leading icon for text inputs.</summary>
public static class Field
{
public static readonly DependencyProperty PlaceholderProperty = DependencyProperty.RegisterAttached(
"Placeholder", typeof(string), typeof(Field), new FrameworkPropertyMetadata(null));
public static readonly DependencyProperty GlyphProperty = DependencyProperty.RegisterAttached(
"Glyph", typeof(IconData), typeof(Field), new FrameworkPropertyMetadata(null));
public static string? GetPlaceholder(DependencyObject d) => (string?)d.GetValue(PlaceholderProperty);
public static void SetPlaceholder(DependencyObject d, string? value) => d.SetValue(PlaceholderProperty, value);
public static IconData? GetGlyph(DependencyObject d) => (IconData?)d.GetValue(GlyphProperty);
public static void SetGlyph(DependencyObject d, IconData? value) => d.SetValue(GlyphProperty, value);
}
/// <summary>Attached glyph for buttons: renders an <see cref="IconData"/> before (or instead of) the content.</summary>
public static class ButtonIcon
{
public static readonly DependencyProperty GlyphProperty = DependencyProperty.RegisterAttached(
"Glyph", typeof(IconData), typeof(ButtonIcon), new FrameworkPropertyMetadata(null));
public static IconData? GetGlyph(DependencyObject d) => (IconData?)d.GetValue(GlyphProperty);
public static void SetGlyph(DependencyObject d, IconData? value) => d.SetValue(GlyphProperty, value);
}
+79
View File
@@ -0,0 +1,79 @@
using System.Windows;
using System.Windows.Documents;
using System.Windows.Media;
namespace Titano.Ui.Controls;
/// <summary>Renders an <see cref="IconData"/> on the 16-unit grid, scaled to the element size, in the inherited foreground.</summary>
public sealed class Icon : FrameworkElement
{
public static readonly DependencyProperty GlyphProperty = DependencyProperty.Register(
nameof(Glyph), typeof(IconData), typeof(Icon),
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
public static readonly DependencyProperty ForegroundProperty = TextElement.ForegroundProperty.AddOwner(
typeof(Icon), new FrameworkPropertyMetadata(Brushes.Gray, FrameworkPropertyMetadataOptions.Inherits | FrameworkPropertyMetadataOptions.AffectsRender));
public static readonly DependencyProperty SizeProperty = DependencyProperty.Register(
nameof(Size), typeof(double), typeof(Icon),
new FrameworkPropertyMetadata(16.0, FrameworkPropertyMetadataOptions.AffectsMeasure));
public static readonly DependencyProperty StrokeWidthProperty = DependencyProperty.Register(
nameof(StrokeWidth), typeof(double), typeof(Icon),
new FrameworkPropertyMetadata(1.5, FrameworkPropertyMetadataOptions.AffectsRender));
static Icon()
{
SnapsToDevicePixelsProperty.OverrideMetadata(typeof(Icon), new FrameworkPropertyMetadata(true));
FocusableProperty.OverrideMetadata(typeof(Icon), new FrameworkPropertyMetadata(false));
}
public IconData? Glyph
{
get => (IconData?)GetValue(GlyphProperty);
set => SetValue(GlyphProperty, value);
}
public Brush Foreground
{
get => (Brush)GetValue(ForegroundProperty);
set => SetValue(ForegroundProperty, value);
}
/// <summary>Edge length in device-independent pixels (default 16).</summary>
public double Size
{
get => (double)GetValue(SizeProperty);
set => SetValue(SizeProperty, value);
}
/// <summary>Stroke width on the 16-unit grid (default 1.5).</summary>
public double StrokeWidth
{
get => (double)GetValue(StrokeWidthProperty);
set => SetValue(StrokeWidthProperty, value);
}
protected override Size MeasureOverride(Size availableSize) => new(Size, Size);
protected override void OnRender(DrawingContext dc)
{
var glyph = Glyph;
if (glyph is null) return;
var scale = Size / 16.0;
dc.PushTransform(new ScaleTransform(scale, scale));
if (glyph.Fill is not null) dc.DrawGeometry(Foreground, null, glyph.Fill);
if (glyph.Stroke is not null)
{
var pen = new Pen(Foreground, StrokeWidth)
{
StartLineCap = PenLineCap.Round,
EndLineCap = PenLineCap.Round,
LineJoin = PenLineJoin.Round,
};
pen.Freeze();
dc.DrawGeometry(null, pen, glyph.Stroke);
}
dc.Pop();
}
}
+30
View File
@@ -0,0 +1,30 @@
using System.Windows.Media;
namespace Titano.Ui.Controls;
/// <summary>A 16×16 icon: a stroked outline and an optional filled part (DESIGN.md §5).</summary>
public sealed class IconData
{
private Geometry? _stroke;
private Geometry? _fill;
/// <summary>Outline drawn with a 1.5-px round pen in the foreground colour.</summary>
public Geometry? Stroke
{
get => _stroke;
set => _stroke = Freeze(value);
}
/// <summary>Solid part filled with the foreground colour.</summary>
public Geometry? Fill
{
get => _fill;
set => _fill = Freeze(value);
}
private static Geometry? Freeze(Geometry? g)
{
if (g is { CanFreeze: true, IsFrozen: false }) g.Freeze();
return g;
}
}
+34
View File
@@ -0,0 +1,34 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace Titano.Ui.Controls;
/// <summary>40-px strip under the title bar: current job, progress, time left and a stop button (DESIGN §4).</summary>
public class JobBar : Control
{
public static readonly DependencyProperty TextProperty = DependencyProperty.Register(nameof(Text), typeof(string), typeof(JobBar));
public static readonly DependencyProperty ProgressProperty = DependencyProperty.Register(nameof(Progress), typeof(double), typeof(JobBar), new PropertyMetadata(0.0));
public static readonly DependencyProperty IsIndeterminateProperty = DependencyProperty.Register(nameof(IsIndeterminate), typeof(bool), typeof(JobBar));
public static readonly DependencyProperty IsActiveProperty = DependencyProperty.Register(nameof(IsActive), typeof(bool), typeof(JobBar));
public static readonly DependencyProperty StopCommandProperty = DependencyProperty.Register(nameof(StopCommand), typeof(ICommand), typeof(JobBar));
public static readonly DependencyProperty StopToolTipProperty = DependencyProperty.Register(nameof(StopToolTip), typeof(object), typeof(JobBar));
static JobBar()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(JobBar), new FrameworkPropertyMetadata(typeof(JobBar)));
}
public string? Text { get => (string?)GetValue(TextProperty); set => SetValue(TextProperty, value); }
/// <summary>0..1.</summary>
public double Progress { get => (double)GetValue(ProgressProperty); set => SetValue(ProgressProperty, value); }
public bool IsIndeterminate { get => (bool)GetValue(IsIndeterminateProperty); set => SetValue(IsIndeterminateProperty, value); }
/// <summary>A job is running: shows the progress fill and the stop button.</summary>
public bool IsActive { get => (bool)GetValue(IsActiveProperty); set => SetValue(IsActiveProperty, value); }
public ICommand? StopCommand { get => (ICommand?)GetValue(StopCommandProperty); set => SetValue(StopCommandProperty, value); }
public object? StopToolTip { get => GetValue(StopToolTipProperty); set => SetValue(StopToolTipProperty, value); }
}
+43
View File
@@ -0,0 +1,43 @@
using System.Windows;
using System.Windows.Controls;
namespace Titano.Ui.Controls;
/// <summary>Attached state of the navigation rail (DESIGN §3: 128 px, collapses to 48 px icons).</summary>
public static class NavRail
{
public static readonly DependencyProperty IsCollapsedProperty = DependencyProperty.RegisterAttached(
"IsCollapsed", typeof(bool), typeof(NavRail), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.Inherits));
public static bool GetIsCollapsed(DependencyObject d) => (bool)d.GetValue(IsCollapsedProperty);
public static void SetIsCollapsed(DependencyObject d, bool value) => d.SetValue(IsCollapsedProperty, value);
}
/// <summary>One rail entry: icon, label, optional attention badge; active = card fill + 3-px accent edge.</summary>
public class NavRailButton : RadioButton
{
public static readonly DependencyProperty GlyphProperty = DependencyProperty.Register(
nameof(Glyph), typeof(IconData), typeof(NavRailButton));
public static readonly DependencyProperty BadgeProperty = DependencyProperty.Register(
nameof(Badge), typeof(int), typeof(NavRailButton), new PropertyMetadata(0));
static NavRailButton()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(NavRailButton), new FrameworkPropertyMetadata(typeof(NavRailButton)));
}
public IconData? Glyph
{
get => (IconData?)GetValue(GlyphProperty);
set => SetValue(GlyphProperty, value);
}
/// <summary>Count of things needing attention; hidden when 0.</summary>
public int Badge
{
get => (int)GetValue(BadgeProperty);
set => SetValue(BadgeProperty, value);
}
}
+42
View File
@@ -0,0 +1,42 @@
using System.Windows;
using System.Windows.Controls;
namespace Titano.Ui.Controls;
/// <summary>Status vocabulary of DESIGN §4: colour is always paired with a glyph and a word.</summary>
public enum StatusKind
{
Analysed,
NotAnalysed,
Proxies,
NoProxies,
Rendered,
Synced,
Remote,
Analysing,
Warning,
Error,
Running,
Queued,
Done,
Failed,
Paused,
Online,
Offline,
}
/// <summary>Glyph + text in the colour of the status kind.</summary>
public class StatusGlyph : Control
{
public static readonly DependencyProperty KindProperty = DependencyProperty.Register(nameof(Kind), typeof(StatusKind), typeof(StatusGlyph), new PropertyMetadata(StatusKind.Analysed));
public static readonly DependencyProperty TextProperty = DependencyProperty.Register(nameof(Text), typeof(string), typeof(StatusGlyph));
static StatusGlyph()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(StatusGlyph), new FrameworkPropertyMetadata(typeof(StatusGlyph)));
FocusableProperty.OverrideMetadata(typeof(StatusGlyph), new FrameworkPropertyMetadata(false));
}
public StatusKind Kind { get => (StatusKind)GetValue(KindProperty); set => SetValue(KindProperty, value); }
public string? Text { get => (string?)GetValue(TextProperty); set => SetValue(TextProperty, value); }
}
+138
View File
@@ -0,0 +1,138 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Shell;
using Titano.Ui.Interop;
using Titano.Ui.Theming;
namespace Titano.Ui.Controls;
/// <summary>
/// Window with Titano's custom chrome: 34-px title bar in the Chrome colour, brand mark, title, optional
/// title-bar content and drawn caption buttons. The maximise button answers HTMAXBUTTON so Windows 11
/// snap layouts appear on hover.
/// </summary>
[TemplatePart(Name = PartMaximize, Type = typeof(Button))]
public class TitanoWindow : Window
{
public const string PartMaximize = "PART_Maximize";
public static readonly DependencyProperty TitleBarContentProperty = DependencyProperty.Register(
nameof(TitleBarContent), typeof(object), typeof(TitanoWindow));
public static readonly DependencyProperty IsDialogProperty = DependencyProperty.Register(
nameof(IsDialog), typeof(bool), typeof(TitanoWindow), new PropertyMetadata(false));
public static readonly DependencyProperty IsMaximizeHoveredProperty = DependencyProperty.Register(
nameof(IsMaximizeHovered), typeof(bool), typeof(TitanoWindow), new PropertyMetadata(false));
private Button? _maximize;
static TitanoWindow()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(TitanoWindow), new FrameworkPropertyMetadata(typeof(TitanoWindow)));
}
public TitanoWindow()
{
WindowChrome.SetWindowChrome(this, new WindowChrome
{
CaptionHeight = 34,
ResizeBorderThickness = new Thickness(6),
GlassFrameThickness = new Thickness(0),
CornerRadius = new CornerRadius(0),
UseAeroCaptionButtons = false,
});
CommandBindings.Add(new CommandBinding(SystemCommands.CloseWindowCommand, (_, _) => SystemCommands.CloseWindow(this)));
CommandBindings.Add(new CommandBinding(SystemCommands.MinimizeWindowCommand, (_, _) => SystemCommands.MinimizeWindow(this)));
CommandBindings.Add(new CommandBinding(SystemCommands.MaximizeWindowCommand, (_, _) => ToggleMaximize()));
CommandBindings.Add(new CommandBinding(SystemCommands.RestoreWindowCommand, (_, _) => ToggleMaximize()));
UseLayoutRounding = true;
TextOptions.SetTextFormattingMode(this, TextFormattingMode.Display);
}
/// <summary>Extra content placed in the title bar between the title and the caption buttons.</summary>
public object? TitleBarContent
{
get => GetValue(TitleBarContentProperty);
set => SetValue(TitleBarContentProperty, value);
}
/// <summary>Dialog windows show only the close button.</summary>
public bool IsDialog
{
get => (bool)GetValue(IsDialogProperty);
set => SetValue(IsDialogProperty, value);
}
/// <summary>True while the pointer is over the maximise button (non-client, so tracked from WndProc).</summary>
public bool IsMaximizeHovered
{
get => (bool)GetValue(IsMaximizeHoveredProperty);
set => SetValue(IsMaximizeHoveredProperty, value);
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_maximize = GetTemplateChild(PartMaximize) as Button;
}
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
ThemeManager.ApplyChrome(this);
if (PresentationSource.FromVisual(this) is HwndSource source) source.AddHook(WndProc);
}
private void ToggleMaximize()
{
if (WindowState == WindowState.Maximized) SystemCommands.RestoreWindow(this);
else SystemCommands.MaximizeWindow(this);
}
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
switch (msg)
{
case NativeMethods.WM_NCHITTEST when _maximize is { IsVisible: true } && ResizeMode is ResizeMode.CanResize or ResizeMode.CanResizeWithGrip:
if (IsOverMaximize(lParam))
{
IsMaximizeHovered = true;
handled = true;
return NativeMethods.HTMAXBUTTON;
}
IsMaximizeHovered = false;
break;
case NativeMethods.WM_NCLBUTTONDOWN when wParam == NativeMethods.HTMAXBUTTON:
handled = true;
break;
case NativeMethods.WM_NCLBUTTONUP when wParam == NativeMethods.HTMAXBUTTON:
handled = true;
ToggleMaximize();
break;
case NativeMethods.WM_NCMOUSELEAVE:
IsMaximizeHovered = false;
break;
}
return IntPtr.Zero;
}
private bool IsOverMaximize(IntPtr lParam)
{
if (_maximize is null) return false;
var x = unchecked((short)(long)lParam);
var y = unchecked((short)((long)lParam >> 16));
try
{
var point = _maximize.PointFromScreen(new Point(x, y));
return point.X >= 0 && point.Y >= 0 && point.X < _maximize.ActualWidth && point.Y < _maximize.ActualHeight;
}
catch (InvalidOperationException)
{
return false;
}
}
}
+79
View File
@@ -0,0 +1,79 @@
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Threading;
using Titano.Ui.Mvvm;
namespace Titano.Ui.Controls;
/// <summary>One in-window notification (DESIGN §4: 420 px, accent left edge, one action, 8 s, hover pauses).</summary>
public sealed class Toast : ObservableObject
{
public required string Title { get; init; }
public string? Message { get; init; }
public string? ActionText { get; init; }
public ICommand? ActionCommand { get; init; }
public string? ActionToolTip { get; init; }
public TimeSpan Lifetime { get; init; } = TimeSpan.FromSeconds(8);
}
/// <summary>Bottom-right stack of <see cref="Toast"/>s with auto-dismiss.</summary>
public class ToastHost : ItemsControl
{
private readonly Dictionary<Toast, DispatcherTimer> _timers = [];
static ToastHost()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ToastHost), new FrameworkPropertyMetadata(typeof(ToastHost)));
}
public ToastHost()
{
ItemsSource = Toasts;
CommandBindings.Add(new CommandBinding(DismissCommand, (_, e) =>
{
if (e.Parameter is Toast t) Dismiss(t);
}));
}
public static RoutedCommand DismissCommand { get; } = new(nameof(DismissCommand), typeof(ToastHost));
public ObservableCollection<Toast> Toasts { get; } = [];
public void Show(Toast toast)
{
Toasts.Add(toast);
while (Toasts.Count > 3) Dismiss(Toasts[0]);
var timer = new DispatcherTimer { Interval = toast.Lifetime };
timer.Tick += (_, _) => Dismiss(toast);
_timers[toast] = timer;
timer.Start();
}
/// <summary>Pauses or resumes the dismissal timer (hover pauses).</summary>
public void SetPaused(Toast toast, bool paused)
{
if (!_timers.TryGetValue(toast, out var timer)) return;
if (paused) timer.Stop();
else timer.Start();
}
public void Dismiss(Toast toast)
{
if (_timers.Remove(toast, out var timer)) timer.Stop();
Toasts.Remove(toast);
}
protected override void OnPreviewMouseMove(MouseEventArgs e)
{
base.OnPreviewMouseMove(e);
foreach (var t in Toasts.ToList()) SetPaused(t, true);
}
protected override void OnMouseLeave(MouseEventArgs e)
{
base.OnMouseLeave(e);
foreach (var t in Toasts.ToList()) SetPaused(t, false);
}
}