Skip to content

Commit

Permalink
Edit mode work on
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz-kierepka-hl committed Jan 20, 2025
1 parent fe0d2c3 commit 83a4294
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 48 deletions.
8 changes: 6 additions & 2 deletions ChatAAC/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
RequestedThemeVariant="Default"
Name="Chat AAC"
x:DataType="local:App">




<Application.Styles>
<FluentTheme />
<StyleInclude Source="avares://Avalonia.Controls.ColorPicker/Themes/Fluent/Fluent.xaml" />
</Application.Styles>




<TrayIcon.Icons>
<TrayIcons>
<TrayIcon Icon="/Assets/avalonia-logo.ico"
Expand Down
15 changes: 8 additions & 7 deletions ChatAAC/ChatAAC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.2.3"/>
<PackageReference Include="Avalonia.Controls.ColorPicker" Version="11.2.3" />
<PackageReference Include="Avalonia.Controls.ItemsRepeater" Version="11.1.5"/>
<PackageReference Include="Avalonia.Desktop" Version="11.2.3"/>
<PackageReference Include="Avalonia.ReactiveUI" Version="11.2.3"/>
Expand All @@ -40,20 +41,20 @@
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.3"/>
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.4"/>
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.2.0.6"/>
<PackageReference Include="Avalonia.Xaml.Interactivity" Version="11.2.0.6"/>
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.2.0.7" />
<PackageReference Include="Avalonia.Xaml.Interactivity" Version="11.2.0.7" />
<PackageReference Include="BinToss.GroupBox.Avalonia" Version="1.0.0"/>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0"/>
<PackageReference Include="DotNet.Bundle" Version="0.9.13" />
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="9.0.0"/>
<PackageReference Include="Microsoft.SemanticKernel" Version="1.32.0"/>
<PackageReference Include="OllamaSharp" Version="4.0.17"/>
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="9.0.1" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.33.0" />
<PackageReference Include="OllamaSharp" Version="5.0.2" />
<PackageReference Include="ReactiveUI" Version="20.1.63"/>
<PackageReference Include="ReactiveUI.Fody" Version="19.5.41"/>
<PackageReference Include="RestSharp" Version="112.1.0"/>
<PackageReference Include="SkiaSharp" Version="3.116.1"/>
<PackageReference Include="System.Net.Http.Json" Version="9.0.0"/>
<PackageReference Include="System.Speech" Version="9.0.0"/>
<PackageReference Include="System.Net.Http.Json" Version="9.0.1" />
<PackageReference Include="System.Speech" Version="9.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
18 changes: 18 additions & 0 deletions ChatAAC/Converters/InvertBoolConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Globalization;
using Avalonia.Data.Converters;
using Avalonia.Media;

namespace ChatAAC.Converters;

public class InvertBoolConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is bool b)
return !b;
return false;
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
=> null;
}
50 changes: 44 additions & 6 deletions ChatAAC/ViewModels/EditButtonViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using ChatAAC.Models.Obf;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Media;
using ChatAAC.Views;

namespace ChatAAC.ViewModels;
Expand All @@ -19,6 +20,8 @@ public class EditButtonViewModel : ReactiveObject
private string _label;
private string _borderColor;
private string _backgroundColor;
private Color _borderColorAvalonia = Colors.Black;
private Color _backgroundColorAvalonia = Colors.White;
private string _vocalization;
private string _action;
private string? _loadBoardPath;
Expand All @@ -41,6 +44,14 @@ public EditButtonViewModel(Button button, IList<Image> obfImages)
_label = button.Label;
_borderColor = button.BorderColor;
_backgroundColor = button.BackgroundColor;

// Convert any existing string to an Avalonia color
if (Color.TryParse(button.BorderColor, out var bc))
_borderColorAvalonia = bc;
if (Color.TryParse(button.BackgroundColor, out var bg))
_backgroundColorAvalonia = bg;


_vocalization = button.Vocalization;
_action = button.Action;
_loadBoardPath = button.LoadBoard?.Path;
Expand Down Expand Up @@ -68,16 +79,43 @@ public string Label
set => this.RaiseAndSetIfChanged(ref _label, value);
}


public string BorderColor
{
get => _borderColor;
set => this.RaiseAndSetIfChanged(ref _borderColor, value);
get => _originalButton.BorderColor;
set
{
_originalButton.BorderColor = value;
// Optionally parse it to keep your color pickers in sync
if (Color.TryParse(value, out var c))
BorderColorAvalonia = c;
this.RaisePropertyChanged();
}
}

public string BackgroundColor
{
get => _backgroundColor;
set => this.RaiseAndSetIfChanged(ref _backgroundColor, value);
get => _originalButton.BackgroundColor;
set
{
_originalButton.BackgroundColor = value;
// Optionally parse it to keep your color pickers in sync
if (Color.TryParse(value, out var c))
BackgroundColorAvalonia = c;
this.RaisePropertyChanged();
}
}

public Color BorderColorAvalonia
{
get => _borderColorAvalonia;
set => this.RaiseAndSetIfChanged(ref _borderColorAvalonia, value);
}

public Color BackgroundColorAvalonia
{
get => _backgroundColorAvalonia;
set => this.RaiseAndSetIfChanged(ref _backgroundColorAvalonia, value);
}

public string Vocalization
Expand Down Expand Up @@ -121,8 +159,8 @@ private void Confirm()
// Save changes back to the original button
_originalButton.Id = _id;
_originalButton.Label = _label;
_originalButton.BorderColor = _borderColor;
_originalButton.BackgroundColor = _backgroundColor;
_originalButton.BorderColor = _borderColorAvalonia.ToString();
_originalButton.BackgroundColor = _backgroundColorAvalonia.ToString();
_originalButton.Vocalization = _vocalization;
_originalButton.Action = _action;

Expand Down
13 changes: 7 additions & 6 deletions ChatAAC/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ public MainViewModel()
// Initialize ToggleEditModeCommand
ToggleEditModeCommand = ReactiveCommand.Create(ToggleEditMode);


EditGridCommand = ReactiveCommand.CreateFromTask(EditGridAsync);
SaveBoardCommand = ReactiveCommand.CreateFromTask(SaveBoardAsync);

OpenSettingsCommand = ReactiveCommand.Create(() => OpenSettings());
SelectBoardAndLoadCommand = ReactiveCommand.CreateFromTask(SelectBoardAndLoadAsync);
ClearSelectedCommand = ReactiveCommand.Create(ClearSelected);
Expand Down Expand Up @@ -199,10 +201,9 @@ public int CurrentHistoryIndex
#endregion

#region Commands

public ReactiveCommand<Unit, Unit> ToggleEditModeCommand { get; }
public ReactiveCommand<Unit, Unit> EditGridCommand { get; }
public ReactiveCommand<Button, Unit> EditButtonCommand { get; }
public ReactiveCommand<Unit, Unit> SaveBoardCommand { get; }
public ReactiveCommand<Unit, Unit> ToggleEditModeCommand { get; }
public ReactiveCommand<Unit, Unit> OpenHistoryCommand { get; }
public ReactiveCommand<Unit, Unit> OpenSettingsCommand { get; }
public ReactiveCommand<Unit, Unit> SelectBoardAndLoadCommand { get; }
Expand Down Expand Up @@ -384,7 +385,7 @@ private async Task EditGridAsync()
DataContext = vm
};

await win.ShowDialog(desktop.MainWindow);
if (desktop.MainWindow != null) await win.ShowDialog(desktop.MainWindow);

if (!vm.IsConfirmed)
return;
Expand All @@ -410,7 +411,7 @@ private async Task EditButtonAsync(Button button)
DataContext = editVm
};

await editWindow.ShowDialog(desktop.MainWindow);
if (desktop.MainWindow != null) await editWindow.ShowDialog(desktop.MainWindow);

if (!editVm.IsConfirmed)
return;
Expand Down
58 changes: 32 additions & 26 deletions ChatAAC/Views/EditButtonWindow.axaml
Original file line number Diff line number Diff line change
@@ -1,40 +1,46 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:ChatAAC.ViewModels"
xmlns:converters="clr-namespace:ChatAAC.Converters"
x:Class="ChatAAC.Views.EditButtonWindow"
x:DataType="vm:EditButtonViewModel"
xmlns:local="clr-namespace:ChatAAC.Converters"
Title="Edit Button" Width="400" Height="600">

<!-- Local resources, e.g. your converter -->
<Window.Resources>
<local:StringToBitmapConverter x:Key="StringToBitmapConverter" />
<converters:StringToBitmapConverter x:Key="StringToBitmapConverter" />
</Window.Resources>

<!-- Put everything in a ScrollViewer -->
<ScrollViewer VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto">
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<StackPanel Margin="20" Spacing="10">
<TextBlock Text="ID:" FontWeight="Bold"/>
<TextBox Text="{Binding Id}"/>

<TextBlock Text="Label:" FontWeight="Bold"/>
<TextBox Text="{Binding Label}"/>
<!-- ID, Label, etc. omitted for brevity -->

<!-- Border Color Fields -->
<TextBlock Text="Border Color (hex string):" FontWeight="Bold" />
<TextBox Text="{Binding BorderColor, Mode=TwoWay}" />

<TextBlock Text="Pick a Border Color:" FontWeight="Bold" />
<!-- ColorPicker for border -->
<ColorPicker Color="{Binding BorderColorAvalonia, Mode=TwoWay}"
IsAlphaEnabled="True"
Width="250" />

<TextBlock Text="Border Color:" FontWeight="Bold"/>
<TextBox Text="{Binding BorderColor}"/>
<!-- Background Color Fields -->
<TextBlock Text="Background Color (hex string):" FontWeight="Bold" />
<TextBox Text="{Binding BackgroundColor, Mode=TwoWay}" />

<TextBlock Text="Background Color:" FontWeight="Bold"/>
<TextBox Text="{Binding BackgroundColor}"/>
<TextBlock Text="Pick a Background Color:" FontWeight="Bold" />
<!-- ColorPicker for background -->
<ColorPicker Color="{Binding BackgroundColorAvalonia, Mode=TwoWay}"
IsAlphaEnabled="True"
Width="250" />

<TextBlock Text="Vocalization:" FontWeight="Bold"/>
<TextBox Text="{Binding Vocalization}"/>
<TextBlock Text="Vocalization:" FontWeight="Bold" />
<TextBox Text="{Binding Vocalization}" />

<TextBlock Text="Action:" FontWeight="Bold"/>
<TextBox Text="{Binding Action}"/>
<TextBlock Text="Action:" FontWeight="Bold" />
<TextBox Text="{Binding Action}" />

<!-- Image ComboBox -->
<TextBlock Text="Select Image:" FontWeight="Bold"/>
<TextBlock Text="Select Image:" FontWeight="Bold" />
<ComboBox ItemsSource="{Binding AvailableImages}"
SelectedItem="{Binding SelectedImage, Mode=TwoWay}">
<ComboBox.ItemTemplate>
Expand All @@ -44,19 +50,19 @@
<Image MaxWidth="60" MaxHeight="60"
Source="{Binding ImagePath, Converter={StaticResource StringToBitmapConverter}}"
AutomationProperties.HelpText="{Binding Id}" />
<TextBlock Text="{Binding Id}" Margin="10,0,0,0"/>
<TextBlock Text="{Binding Id}" Margin="10,0,0,0" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>

<TextBlock Text="LoadBoard Path (optional):" FontWeight="Bold"/>
<TextBox Text="{Binding LoadBoardPath}"/>
<TextBlock Text="LoadBoard Path (optional):" FontWeight="Bold" />
<TextBox Text="{Binding LoadBoardPath}" />

<!-- Buttons on the right -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Spacing="10" Margin="0,20,0,0">
<Button Content="OK" Command="{Binding ConfirmCommand}" Width="80"/>
<Button Content="Cancel" Command="{Binding CancelCommand}" Width="80"/>
<Button Content="OK" Command="{Binding ConfirmCommand}" Width="80" />
<Button Content="Cancel" Command="{Binding CancelCommand}" Width="80" />
</StackPanel>
</StackPanel>
</ScrollViewer>
Expand Down
43 changes: 42 additions & 1 deletion ChatAAC/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<converters:EqualityToBrushConverter x:Key="EqualityToBrushConverter" />
<converters:NotNullToBoolConverter x:Key="NotNullToBoolConverter" />
<converters:ContrastForegroundBrushConverter x:Key="ContrastForegroundBrushConverter" />
<converters:InvertBoolConverter x:Key="InvertBoolConverter" />
</Window.Resources>

<Window.Styles>
Expand Down Expand Up @@ -110,7 +111,9 @@
</Grid>

<!-- Grammar Controls -->
<Border Grid.Row="1" BorderBrush="Gray" BorderThickness="1" CornerRadius="10" Padding="10">
<Border Grid.Row="1" BorderBrush="Gray" BorderThickness="1" CornerRadius="10" Padding="10"
IsVisible="{Binding IsEditMode, Converter={StaticResource InvertBoolConverter}}">

<Viewbox Stretch="Uniform" UseLayoutRounding="True">
<Grid ColumnDefinitions="*,Auto,Auto">
<!-- Tense Controls -->
Expand Down Expand Up @@ -252,10 +255,48 @@
</Grid>
</Viewbox>
</Border>
<!-- EDIT MODE panel: visible if IsEditMode == true -->
<StackPanel Grid.Row="1"
Orientation="Horizontal"
Spacing="10"
Margin="0,10,0,0"
IsVisible="{Binding IsEditMode}">
<TextBlock Text="EDIT MODE ACTIVE"
Foreground="Red"
FontWeight="Bold"
FontSize="16"
VerticalAlignment="Center"
Margin="0,0,10,0" />

<Button Classes="control"
Background="#AA33AA"
Command="{Binding EditGridCommand}"
Width="120" Height="40">
<TextBlock Text="Edit Grid" />
</Button>

<Button Classes="control"
Background="#4CAF50"
Command="{Binding SaveBoardCommand}"
Width="120" Height="40">
<TextBlock Text="Save Board" />
</Button>

<Button Classes="control"
Background="Orange"
Command="{Binding ToggleEditModeCommand}"
Width="120" Height="40">
<TextBlock Text="Exit Edit" />
</Button>
</StackPanel>
</Grid>

<!-- Main Symbols Grid -->
<Grid Grid.Row="2">
<Border BorderBrush="Red"
BorderThickness="2"
IsVisible="{Binding IsEditMode}" />

<Viewbox Stretch="Uniform" UseLayoutRounding="True">
<ItemsControl ItemsSource="{Binding Buttons}">
<ItemsControl.ItemsPanel>
Expand Down

0 comments on commit 83a4294

Please sign in to comment.