Skip to content

Commit

Permalink
hook up global consoloniaAccessText usage
Browse files Browse the repository at this point in the history
Fix bug on keyup where Alt modifier not being passed for Alt keys.
Added Labels page.
  • Loading branch information
tomlm committed Dec 14, 2024
1 parent 5dbd6a8 commit 732b8c7
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 4 deletions.
23 changes: 23 additions & 0 deletions src/Consolonia.Core/Infrastructure/ConsoloniaApplication.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using System;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
using Avalonia.Input;
using Consolonia.Core.Controls;
using Consolonia.Core.Helpers;
using Consolonia.Core.Infrastructure;

Expand All @@ -21,6 +25,25 @@ public override void RegisterServices()

public override void OnFrameworkInitializationCompleted()
{
// override AccessText to use ConsoloniaAccessText as default contentpresenter for unknown data types (aka string)
this.DataTemplates.Add(new FuncDataTemplate<object>(
(data, s) =>
{
if (data != null && data is string str)
{
var result = new ConsoloniaAccessText();
result.Bind(TextBlock.TextProperty,
result.GetObservable(Control.DataContextProperty));
return result;
}
else
{
return null;
}
},
true)
);

base.OnFrameworkInitializationCompleted();

this.AddConsoloniaDesignMode();
Expand Down
19 changes: 19 additions & 0 deletions src/Consolonia.Gallery/Gallery/GalleryViews/GalleryLabel.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=System.Runtime"
xmlns:drawing="clr-namespace:Consolonia.Core.Drawing;assembly=Consolonia.Core"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="Consolonia.Gallery.Gallery.GalleryViews.GalleryLabel">
<!--Copied from https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Themes.Default/TextBox.xaml-->
<Grid HorizontalAlignment="Left" VerticalAlignment="Top" RowDefinitions="Auto,Auto,Auto,Auto,Auto,*" ColumnDefinitions="Auto,6,*" Width="246">
<Label Target="firstNameEdit" Grid.Row="0" Grid.Column="0" >_First name</Label>
<TextBox Name="firstNameEdit" Grid.Column="2" Grid.Row="0" Text="{Binding FirstName}"></TextBox>
<Label Target="lastNameEdit" Grid.Row="1" Grid.Column="0">_Last name</Label>
<TextBox Name="lastNameEdit" Grid.Column="2" Grid.Row="1" Text="{Binding LastName}"></TextBox>
<Label Target="bannedCheck" Grid.Row="2" Grid.Column="0">_Banned</Label>
<CheckBox Name="bannedCheck" Grid.Column="2" Grid.Row="2" IsChecked="{Binding IsBanned}"></CheckBox>
</Grid>

</UserControl>
13 changes: 13 additions & 0 deletions src/Consolonia.Gallery/Gallery/GalleryViews/GalleryLabel.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Avalonia.Controls;

namespace Consolonia.Gallery.Gallery.GalleryViews
{
public partial class GalleryLabel : UserControl
{
public GalleryLabel()
{
InitializeComponent();
}

}
}
6 changes: 3 additions & 3 deletions src/Consolonia.Gallery/View/ControlsListView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</DataGrid.Columns>
</DataGrid>
<Grid Grid.Row="1" RowDefinitions="Auto Auto" ColumnDefinitions="Auto *" Margin="0 0 0 1">
<Label Content="Theme" />
<Label Content="_Theme" />
<ComboBox Grid.Column="1" x:Name="ThemeCombo" SelectionChanged="ComboBox_SelectionChanged" IsTabStop="false" HorizontalContentAlignment="Stretch" >
<ComboBoxItem Content="Material" IsSelected="True" />
<ComboBoxItem Content="Fluent"/>
Expand All @@ -36,8 +36,8 @@
BorderThickness="1"
BorderBrush="{DynamicResource ThemeBorderBrush}" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="1">
<Button Click="OnShowXaml" IsTabStop="False" HorizontalAlignment="Right">Show XAML</Button>
<Button Click="Exit_Click" IsTabStop="False">Exit</Button>
<Button Click="OnShowXaml" IsTabStop="False" HorizontalAlignment="Right">_Show XAML</Button>
<Button Click="Exit_Click" IsTabStop="False">E_xit</Button>
</StackPanel>
</Grid>
</DockPanel>
Expand Down
5 changes: 4 additions & 1 deletion src/Consolonia.PlatformSupport/WindowsConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ private void HandleKeyInput(WindowsConsole.InputRecord inputRecord)
char character = keyEvent.UnicodeChar;
RawInputModifiers modifiers =
ModifiersFlagTranslator.Translate(keyEvent.dwControlKeyState);
RaiseKeyPress(DefaultNetConsole.ConvertToKey((ConsoleKey)keyEvent.wVirtualKeyCode),
var key = DefaultNetConsole.ConvertToKey((ConsoleKey)keyEvent.wVirtualKeyCode);
if (key == Avalonia.Input.Key.LeftAlt || key == Avalonia.Input.Key.RightAlt)
modifiers |= RawInputModifiers.Alt;
RaiseKeyPress(key,
character, modifiers, keyEvent.bKeyDown, (ulong)Stopwatch.GetTimestamp());
}

Expand Down

0 comments on commit 732b8c7

Please sign in to comment.