Skip to content

Commit

Permalink
Fix hex box
Browse files Browse the repository at this point in the history
  • Loading branch information
chkr1011 committed Feb 19, 2024
1 parent 03810c3 commit ff79012
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 231 deletions.
9 changes: 9 additions & 0 deletions Source/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
<ResourceInclude Source="/Assets/VectorIcons.axaml" />
</ResourceDictionary.MergedDictionaries>

<!--
Monospace fonts per OS:
- Linux = Ubuntu Mono
- Windows = Lucida Console
- macOS = SF Mono
- Fallback = Courier New
-->
<FontFamily x:Key="MonospaceFontFamily">Ubuntu Mono,Lucida Console,SF Mono,Courier New</FontFamily>

<SolidColorBrush x:Key="AppLightGreen">#2200EE00</SolidColorBrush>

<system:Double x:Key="ControlContentThemeFontSize">12</system:Double>
Expand Down
301 changes: 139 additions & 162 deletions Source/Controls/HexBox.axaml

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions Source/Controls/HexBox.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void Dump()

contentBuilder.Append(byteHex);

if (@byte > 0x0020 && @byte < 0x007F)
if (@byte is > 0x0020 and < 0x007F)
{
previewBuilder.Append((char)@byte);
}
Expand Down Expand Up @@ -144,13 +144,15 @@ static string GetBits(byte @byte)
void SetValue(string textBoxName, byte[] buffer, int bufferMinLength, Func<byte[], string> valueProvider)
{
var textBox = (TextBox)this.GetTemplateChild(textBoxName);

if (buffer.Length < bufferMinLength)
{
textBox.Text = string.Empty;
return;
}

textBox.Text = valueProvider(buffer);
else
{
textBox.Text = valueProvider(buffer);
}
}

void SetValue(string textBoxName, object value)
Expand All @@ -161,7 +163,7 @@ void SetValue(string textBoxName, object value)

void UpdateValues()
{
var lineBreaks = Regex.Matches(_contentTextBox?.Text?.Substring(0, CaretIndex) ?? "", Environment.NewLine).Count;
var lineBreaks = Regex.Matches(_contentTextBox?.Text?[..CaretIndex] ?? string.Empty, Environment.NewLine).Count;

var offset = (CaretIndex - lineBreaks) / 3;
var length = Value?.Length ?? 0;
Expand All @@ -173,8 +175,10 @@ void UpdateValues()

var buffer = Value?.Skip(offset).ToArray() ?? Array.Empty<byte>();

SetValue("Length", length.ToString(CultureInfo.InvariantCulture));
SetValue("ValueOffset", offset.ToString(CultureInfo.InvariantCulture));
SetValue("ValueRemaining", remaining.ToString(CultureInfo.InvariantCulture));
SetValue("ValueHex", buffer, 1, b => BitConverter.ToString(b, 0, 1));
SetValue("Value8Bit", buffer, 1, b => GetBits(b[0]));
SetValue("ValueBoolean", buffer, 1, b => (b[0] > 0).ToString(CultureInfo.InvariantCulture));
SetValue("ValueInt8", buffer, 1, b => b[0].ToString(CultureInfo.InvariantCulture));
Expand Down
51 changes: 28 additions & 23 deletions Source/Pages/Info/InfoPageView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@

<Style Selector="TextBlock.version_text">
<Setter Property="Margin"
Value="0,0,10,0" />
Value="10,0,10,0" />
</Style>

<Style Selector="Label.version_text">
<Setter Property="Margin"
Value="10,0,10,0" />
</Style>

<Style Selector="Label.h1 AccessText">
Expand All @@ -23,12 +28,12 @@
Value="Bold" />
</Style>

<Style Selector="TextBlock.no_update_available">
<Style Selector="Label.no_update_available">
<Setter Property="Foreground"
Value="Green" />
</Style>

<Style Selector="TextBlock.update_available">
<Style Selector="Label.update_available">
<Setter Property="Foreground"
Value="Orange" />
</Style>
Expand Down Expand Up @@ -99,51 +104,51 @@
ColumnDefinitions="Auto,Auto,Auto"
RowDefinitions="Auto,Auto,Auto,Auto">

<Label Classes="caption"
<Label Classes="value caption"
Grid.Column="0"
Grid.Row="0"
Content="App version" />
<TextBlock Text="{Binding CurrentAppVersion}"
Classes="value version_text code_text"
Grid.Column="1"
Grid.Row="0" />
<Label Content="{Binding CurrentAppVersion}"
Classes="value version_text code_text"
Grid.Column="1"
Grid.Row="0" />

<StackPanel Orientation="Horizontal"
Grid.Column="2"
Grid.Row="0">
<TextBlock Text="Latest version:" />
<TextBlock Classes.no_update_available="{Binding !IsUpdateAvailable}"
<Label Content="Latest version:" />
<Label Classes.no_update_available="{Binding !IsUpdateAvailable}"
Classes.update_available="{Binding IsUpdateAvailable}"
Margin="10,0,0,0"
Cursor="Hand"
PointerPressed="OnLatestVersionClicked"
Text="{Binding LatestAppVersion}"
Content="{Binding LatestAppVersion}"
Classes="value version_text code_text" />
</StackPanel>

<Label Classes="caption"
<Label Classes="caption value"
Grid.Column="0"
Grid.Row="1"
Content="MQTTnet version" />
<TextBlock Text="{Binding MqttNetVersion}"
Classes="value version_text code_text"
Grid.Row="1"
Grid.Column="1" />
<Label Content="{Binding MqttNetVersion}"
Classes="value version_text code_text"
Grid.Row="1"
Grid.Column="1" />

<Label Classes="caption"
<Label Classes="caption value"
Grid.Column="0"
Grid.Row="2"
Content="Avalonia version" />
<TextBlock Text="{Binding AvaloniaVersion}"
Classes="value version_text code_text"
Grid.Row="2"
Grid.Column="1" />
<Label Content="{Binding AvaloniaVersion}"
Classes="value version_text code_text"
Grid.Row="2"
Grid.Column="1" />

<Label Classes="caption"
<Label Classes="caption value"
Grid.Column="0"
Grid.Row="3"
Content=".NET Framework version" />
<TextBlock Text="{Binding DotNetVersion}"
<Label Content="{Binding DotNetVersion}"
Classes="value version_text code_text"
Grid.Column="1"
Grid.Row="3" />
Expand Down
11 changes: 0 additions & 11 deletions Source/Pages/PacketInspector/PacketDetailsView.axaml

This file was deleted.

17 changes: 0 additions & 17 deletions Source/Pages/PacketInspector/PacketDetailsView.axaml.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Source/Pages/PacketInspector/PacketInspectorPageView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
Background="Black">
<Label Margin="5,0"
Classes="tool_bar_label"
Content="Selected MQTT packet" />
Content="Selected packet" />
</Border>

<controls:BufferInspectorView Grid.Row="1"
Expand Down
10 changes: 8 additions & 2 deletions Source/Pages/PacketInspector/PacketInspectorPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.ObjectModel;
using System;
using System.Collections.ObjectModel;
using Avalonia.Threading;
using mqttMultimeter.Common;
using mqttMultimeter.Services.Mqtt;
Expand All @@ -15,6 +16,11 @@ public sealed class PacketInspectorPageViewModel : BasePageViewModel

public PacketInspectorPageViewModel(MqttClientService mqttClientService)
{
if (mqttClientService == null)
{
throw new ArgumentNullException(nameof(mqttClientService));
}

mqttClientService.RegisterMessageInspectorHandler(ProcessPacket);
}

Expand Down Expand Up @@ -96,7 +102,7 @@ void ProcessPacket(InspectMqttPacketEventArgs eventArgs)
IsInbound = eventArgs.Direction == MqttPacketFlowDirection.Inbound
};

Dispatcher.UIThread.InvokeAsync(() =>
Dispatcher.UIThread.Invoke(() =>
{
Packets.Add(viewModel);

Expand Down
2 changes: 1 addition & 1 deletion Source/Styles/Badges.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<Setter Property="Foreground"
Value="White" />
<Setter Property="FontFamily"
Value="Consolas" />
Value="{StaticResource MonospaceFontFamily}" />
</Style>

<Style Selector="Border.badge_retain">
Expand Down
14 changes: 5 additions & 9 deletions Source/Styles/Text.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@

<Styles.Resources>
<x:Double x:Key="TextControlThemeMinHeight">26</x:Double>

<!--
Monospace fonts per OS:
- Linux = Ubuntu Mono
- Windows = Lucida Console
- macOS = SF Mono
- Fallback = Courier New
-->
<FontFamily x:Key="MonospaceFontFamily">Ubuntu Mono,Lucida Console,SF Mono,Courier New</FontFamily>
</Styles.Resources>

<Style Selector="TextBlock">
Expand Down Expand Up @@ -54,6 +45,11 @@
<Setter Property="FontFamily"
Value="{StaticResource MonospaceFontFamily}" />
</Style>

<Style Selector="Label.code_text">
<Setter Property="FontFamily"
Value="{StaticResource MonospaceFontFamily}" />
</Style>

<Style Selector="avaloniaEdit|TextEditor.code_text">
<Setter Property="FontFamily"
Expand Down

0 comments on commit ff79012

Please sign in to comment.