Skip to content

Commit a500615

Browse files
author
Luca
committed
Merge branch 'release/0.2.0' into main
2 parents fe79c19 + 7fe4092 commit a500615

7 files changed

Lines changed: 240 additions & 15 deletions

File tree

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<UserControl xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:controls="using:PiTouchDate.Controls"
4+
x:Class="PiTouchDate.Controls.Calendar"
5+
x:Name="CalRoot">
6+
7+
<UserControl.Styles>
8+
9+
<!-- Custom template for day buttons: full control over hover/today/selected states -->
10+
<Style Selector="Button.day">
11+
<Setter Property="HorizontalAlignment" Value="Stretch"/>
12+
<Setter Property="VerticalAlignment" Value="Stretch"/>
13+
<Setter Property="HorizontalContentAlignment" Value="Center"/>
14+
<Setter Property="VerticalContentAlignment" Value="Center"/>
15+
<Setter Property="Padding" Value="0"/>
16+
<Setter Property="Margin" Value="1"/>
17+
<Setter Property="FontSize" Value="12"/>
18+
<Setter Property="Foreground" Value="{DynamicResource SemiGrey5Color}"/>
19+
<Setter Property="Background" Value="Transparent"/>
20+
<Setter Property="BorderThickness" Value="0"/>
21+
<Setter Property="Template">
22+
<Setter.Value>
23+
<ControlTemplate TargetType="Button">
24+
<Border Name="DayBg"
25+
Background="{TemplateBinding Background}"
26+
CornerRadius="6"
27+
HorizontalAlignment="Stretch"
28+
VerticalAlignment="Stretch">
29+
<ContentPresenter HorizontalAlignment="Center"
30+
VerticalAlignment="Center"
31+
Content="{TemplateBinding Content}"
32+
Foreground="{TemplateBinding Foreground}"/>
33+
</Border>
34+
</ControlTemplate>
35+
</Setter.Value>
36+
</Setter>
37+
</Style>
38+
39+
<Style Selector="Button.day:pointerover /template/ Border#DayBg">
40+
<Setter Property="Background" Value="#20FFFFFF"/>
41+
</Style>
42+
43+
<!-- Today: blue background — overrides hover -->
44+
<Style Selector="Button.day.today /template/ Border#DayBg">
45+
<Setter Property="Background" Value="{DynamicResource SemiBlue4Color}"/>
46+
</Style>
47+
48+
<!-- Today: white text -->
49+
<Style Selector="Button.day.today">
50+
<Setter Property="Foreground" Value="White"/>
51+
</Style>
52+
53+
<!-- Days from adjacent months: dimmed -->
54+
<Style Selector="Button.day.otherMonth">
55+
<Setter Property="Opacity" Value="0.35"/>
56+
</Style>
57+
58+
</UserControl.Styles>
59+
60+
<Grid RowDefinitions="Auto, Auto, *, Auto">
61+
62+
<!-- Header: ‹ Maggio 2026 › -->
63+
<Grid Grid.Row="0" ColumnDefinitions="Auto, *, Auto" Margin="0,0,0,6">
64+
<Button Grid.Column="0" Classes="Link" Padding="8,4" Background="Transparent"
65+
Command="{Binding #CalRoot.PreviousMonthCommand}">
66+
<PathIcon Data="{DynamicResource SemiIconChevronLeft}" Width="14" Height="14"/>
67+
</Button>
68+
<TextBlock Grid.Column="1"
69+
Text="{Binding #CalRoot.HeaderText}"
70+
HorizontalAlignment="Center" VerticalAlignment="Center"
71+
FontWeight="SemiBold" FontSize="13"/>
72+
<Button Grid.Column="2" Classes="Link" Padding="8,4" Background="Transparent"
73+
Command="{Binding #CalRoot.NextMonthCommand}">
74+
<PathIcon Data="{DynamicResource SemiIconChevronRight}" Width="14" Height="14"/>
75+
</Button>
76+
</Grid>
77+
78+
<!-- Day-of-week labels, Monday-first (Italian) -->
79+
<Grid Grid.Row="1" ColumnDefinitions="*,*,*,*,*,*,*" Margin="0,0,0,2">
80+
<TextBlock Grid.Column="0" Text="L" HorizontalAlignment="Center" Opacity="0.45" FontSize="10"/>
81+
<TextBlock Grid.Column="1" Text="M" HorizontalAlignment="Center" Opacity="0.45" FontSize="10"/>
82+
<TextBlock Grid.Column="2" Text="M" HorizontalAlignment="Center" Opacity="0.45" FontSize="10"/>
83+
<TextBlock Grid.Column="3" Text="G" HorizontalAlignment="Center" Opacity="0.45" FontSize="10"/>
84+
<TextBlock Grid.Column="4" Text="V" HorizontalAlignment="Center" Opacity="0.45" FontSize="10"/>
85+
<TextBlock Grid.Column="5" Text="S" HorizontalAlignment="Center" Opacity="0.45" FontSize="10"/>
86+
<TextBlock Grid.Column="6" Text="D" HorizontalAlignment="Center" Opacity="0.45" FontSize="10"/>
87+
</Grid>
88+
89+
<!-- 6×7 day grid -->
90+
<ItemsControl Grid.Row="2" ItemsSource="{Binding #CalRoot.Days}">
91+
<ItemsControl.ItemsPanel>
92+
<ItemsPanelTemplate>
93+
<UniformGrid Columns="7" Rows="6"/>
94+
</ItemsPanelTemplate>
95+
</ItemsControl.ItemsPanel>
96+
<ItemsControl.ItemTemplate>
97+
<DataTemplate DataType="controls:CalendarDay">
98+
<Button Classes="day"
99+
Classes.today="{Binding IsToday}"
100+
Classes.otherMonth="{Binding IsOtherMonth}"
101+
Content="{Binding DayNumber}"/>
102+
</DataTemplate>
103+
</ItemsControl.ItemTemplate>
104+
</ItemsControl>
105+
106+
<!-- Return to today -->
107+
<Button Grid.Row="3" Classes="Link"
108+
Content="Oggi"
109+
Command="{Binding #CalRoot.GoToTodayCommand}"
110+
HorizontalAlignment="Center"
111+
Background="Transparent"
112+
Margin="0,4,0,0"/>
113+
114+
</Grid>
115+
</UserControl>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System;
2+
using System.Collections.ObjectModel;
3+
using System.Globalization;
4+
using System.Windows.Input;
5+
using Avalonia;
6+
using Avalonia.Controls;
7+
using ReactiveUI;
8+
9+
namespace PiTouchDate.Controls;
10+
11+
public partial class Calendar : UserControl
12+
{
13+
public static readonly StyledProperty<DateTime> DisplayDateProperty =
14+
AvaloniaProperty.Register<Calendar, DateTime>(nameof(DisplayDate), DateTime.Today);
15+
16+
public DateTime DisplayDate
17+
{
18+
get => GetValue(DisplayDateProperty);
19+
set => SetValue(DisplayDateProperty, value);
20+
}
21+
22+
private string _headerText = "";
23+
public static readonly DirectProperty<Calendar, string> HeaderTextProperty =
24+
AvaloniaProperty.RegisterDirect<Calendar, string>(nameof(HeaderText), o => o._headerText);
25+
public string HeaderText => _headerText;
26+
27+
public ObservableCollection<CalendarDay> Days { get; } = new();
28+
29+
public ICommand PreviousMonthCommand { get; }
30+
public ICommand NextMonthCommand { get; }
31+
public ICommand GoToTodayCommand { get; }
32+
33+
public Calendar()
34+
{
35+
PreviousMonthCommand = ReactiveCommand.Create(() => DisplayDate = DisplayDate.AddMonths(-1));
36+
NextMonthCommand = ReactiveCommand.Create(() => DisplayDate = DisplayDate.AddMonths(1));
37+
GoToTodayCommand = ReactiveCommand.Create(() => DisplayDate = DateTime.Today);
38+
39+
InitializeComponent();
40+
_UpdateCalendar();
41+
}
42+
43+
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs e)
44+
{
45+
base.OnPropertyChanged(e);
46+
47+
if (e.Property == DisplayDateProperty)
48+
_UpdateCalendar();
49+
}
50+
51+
private void _UpdateCalendar()
52+
{
53+
var display = DisplayDate;
54+
55+
var raw = display.ToString("MMMM yyyy", CultureInfo.CurrentCulture);
56+
var newHeader = char.ToUpperInvariant(raw[0]) + raw[1..];
57+
SetAndRaise(HeaderTextProperty, ref _headerText, newHeader);
58+
59+
var firstDay = new DateTime(display.Year, display.Month, 1);
60+
var daysBack = ((int)firstDay.DayOfWeek + 6) % 7; // Monday = 0
61+
var startDay = firstDay.AddDays(-daysBack);
62+
63+
Days.Clear();
64+
for (var i = 0; i < 42; i++)
65+
{
66+
var date = startDay.AddDays(i);
67+
Days.Add(new CalendarDay(
68+
date,
69+
date.Month == display.Month,
70+
date.Date == DateTime.Today
71+
));
72+
}
73+
}
74+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
3+
namespace PiTouchDate.Controls;
4+
5+
public record CalendarDay(DateTime Date, bool IsCurrentMonth, bool IsToday)
6+
{
7+
public int DayNumber => Date.Day;
8+
public bool IsOtherMonth => !IsCurrentMonth;
9+
}

PiTouchDate/Controls/ScreenKeyboard/ScreenKeyboard.axaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ private record struct KeyDef(string Label, string Action, double Width = 1.0);
5959
[K("1"), K("2"), K("3"), K("4"), K("5"), K("6"), K("7"), K("8"), K("9"), K("0")],
6060
[K("!"), K("@"), K("#"), K("$"), K("%"), K("&"), K("*"), K("("), K(")"), K("-"), K("?")],
6161
[K("_"), K("="), K("+"), K("["), K("]"), K("{"), K("}"), K(";"), K(":"), K("'")],
62-
[Sp("abc", "ModeLower", 1.5), Sp("", "ModeSymbols2", 1.5), Sp("spazio", "Space", 5.0), Sp(".", ".", 0.75), Sp("⌫", "Backspace", 1.25)],
62+
[Sp("abc", "ModeLower", 1.5), Sp("", "ModeSymbols2", 1.5), Sp("spazio", "Space", 5.0), Sp(".", ".", 0.75), Sp("⌫", "Backspace", 1.25)],
6363
];
6464

6565
private static readonly KeyDef[][] SymbolRows2 =
6666
[
6767
[K("^"), K("~"), K("`"), K("\""), K("<"), K(">"), K("/"), K("\\"), K("|"), K(",")],
6868
[K("."), K("€"), K("£"), K("¥"), K("°"), K("•"), K("–"), K("—"), K("×"), K("÷")],
6969
[K("±"), K("™"), K("©"), K("®"), K("←"), K("→"), K("↑"), K("↓"), K("§"), K("¶")],
70-
[Sp("", "ModeSymbols", 1.5), Sp("abc", "ModeLower", 1.5), Sp("spazio", "Space", 5.0), Sp("⌫", "Backspace", 2.0)],
70+
[Sp("abc", "ModeLower", 1.5), Sp("", "ModeSymbols", 1.5), Sp("spazio", "Space", 5.0), Sp("⌫", "Backspace", 2.0)],
7171
];
7272

7373
private static KeyDef K(string key) => new(key, key);

PiTouchDate/ViewModels/MainWindowViewModel.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ public string CurrentTime
3636
set => this.RaiseAndSetIfChanged(ref _currentTime, value);
3737
}
3838

39+
private DateTime _calendarSelectedDate = DateTime.Today;
40+
public DateTime CalendarSelectedDate
41+
{
42+
get => _calendarSelectedDate;
43+
set => this.RaiseAndSetIfChanged(ref _calendarSelectedDate, value);
44+
}
45+
3946
private int _screenBrightness = 255;
4047
public int ScreenBrightness
4148
{
@@ -89,7 +96,7 @@ public MainWindowViewModel()
8996
private void _ReloadShownInfo(bool forceUpdate = false)
9097
{
9198
var now = DateTime.Now;
92-
Console.WriteLine($"Fired at: {DateTime.Now:HH:mm:ss}");
99+
Console.WriteLine($"Fired at {DateTime.Now:HH:mm:ss}");
93100

94101
if (forceUpdate || _previousDT.Date != now.Date)
95102
{
@@ -102,7 +109,7 @@ private void _ReloadShownInfo(bool forceUpdate = false)
102109

103110
CurrentDate = now.ToString("d MMMM yyyy").ToUpper();
104111

105-
// TODO: Update calendar day
112+
CalendarSelectedDate = now.Date;
106113
}
107114

108115

PiTouchDate/ViewModels/Overlays/WifiSettingsOverlayViewModel.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,14 @@ private async Task StartScanningLoop(CancellationToken ct)
100100
{
101101
Scanning = true;
102102
try {
103-
await RefreshNetworks();
103+
await RefreshNetworks(ct);
104104
IsRefreshError = false;
105105
}
106+
catch (OperationCanceledException)
107+
{
108+
Scanning = false;
109+
return;
110+
}
106111
catch (Exception ex)
107112
{
108113
Console.WriteLine($"Got exception: {ex.GetType()}");
@@ -114,7 +119,14 @@ private async Task StartScanningLoop(CancellationToken ct)
114119
}
115120
}
116121

117-
await Task.Delay(TimeSpan.FromSeconds(5), ct).ConfigureAwait(false);
122+
try
123+
{
124+
await Task.Delay(TimeSpan.FromSeconds(10), ct).ConfigureAwait(false);
125+
}
126+
catch (OperationCanceledException)
127+
{
128+
return;
129+
}
118130
}
119131
}
120132

@@ -127,9 +139,9 @@ public void Dispose()
127139
}
128140

129141

130-
private async Task RefreshNetworks ()
142+
private async Task RefreshNetworks(CancellationToken ct = default)
131143
{
132-
IReadOnlyList<WifiNetwork> currentNetworks = await _wifiManager.GetNetworksAsync();
144+
IReadOnlyList<WifiNetwork> currentNetworks = await _wifiManager.GetNetworksAsync(cancellationToken: ct);
133145

134146
await Dispatcher.UIThread.InvokeAsync(() =>
135147
{

PiTouchDate/Views/MainWindow.axaml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,18 @@
2424
<Grid ColumnDefinitions="55*, 45*">
2525
<Grid Grid.Column="0" RowDefinitions="*, Auto">
2626
<controls:Card Grid.Row="0">
27-
<Grid RowDefinitions="*,Auto,Auto,*">
28-
<TextBlock Grid.Row="1" Text="{Binding WeekDay}" HorizontalAlignment="Center" Classes="H1"/>
29-
<TextBlock Grid.Row="2" Text="{Binding CurrentDate}" HorizontalAlignment="Center" />
27+
<Grid RowDefinitions="*,Auto">
28+
<Viewbox Grid.Row="0" Margin="16,0,16,8">
29+
<TextBlock Text="{Binding WeekDay}" Classes="H1" FontWeight="Bold"/>
30+
</Viewbox>
31+
<TextBlock Grid.Row="1" Text="{Binding CurrentDate}" HorizontalAlignment="Center"
32+
Margin="8,0,8,8" Foreground="{DynamicResource SemiLightBlue6}" FontSize="18"/>
3033
</Grid>
3134
</controls:Card>
3235

3336
<controls:Card Grid.Row="1" Command="{Binding OnWeatherCardClicked}" Height="100"
3437
HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
38+
3539
<Grid ColumnDefinitions="Auto,*,Auto" Margin="16,0">
3640
<PathIcon Grid.Column="0"
3741
Data="{DynamicResource SemiIconCloud}"
@@ -54,12 +58,16 @@
5458
</Grid>
5559

5660
<Grid Grid.Column="1" RowDefinitions="Auto, *, Auto">
57-
<controls:Card Grid.Row="0">
58-
<TextBlock Text="{Binding CurrentTime}"/>
61+
<controls:Card Grid.Row="0" Height="100">
62+
<Viewbox Margin="8,8">
63+
<TextBlock Text="{Binding CurrentTime}" FontWeight="Bold"/>
64+
</Viewbox>
5965
</controls:Card>
6066

61-
<controls:Card Grid.Row="1">
62-
Calendar
67+
<controls:Card Grid.Row="1" Padding="6"
68+
HorizontalContentAlignment="Stretch"
69+
VerticalContentAlignment="Stretch">
70+
<controls:Calendar DisplayDate="{Binding CalendarSelectedDate, Mode=TwoWay}"/>
6371
</controls:Card>
6472

6573
<Grid Grid.Row="2" ColumnDefinitions="*,*,*">

0 commit comments

Comments
 (0)