Skip to content

Commit

Permalink
- Fix Position
Browse files Browse the repository at this point in the history
- Improve display
  • Loading branch information
Damien LEROY committed Dec 29, 2022
1 parent a374b3e commit 663d590
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 14 deletions.
5 changes: 5 additions & 0 deletions PowerAccent.Core/Models/Rect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,9 @@ public Rect(Point coord, Size size)
}
return new Rect(rect.X / divider.X, rect.Y / divider.Y, rect.Width / divider.Width, rect.Height / divider.Height);
}

public override string ToString()
{
return $"X: {X}, Y: {Y}, Width: {Width}, Height: {Height}";
}
}
5 changes: 5 additions & 0 deletions PowerAccent.Core/Models/Size.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ public Size(int width, int height)
}
return new Size(size.Width / divider.Width, size.Height / divider.Height);
}

public override string ToString()
{
return $"Width: {Width}, Height: {Height}";
}
}
11 changes: 11 additions & 0 deletions PowerAccent.Core/PowerAccent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public Point GetDisplayCoordinates(Size window, double primaryDpi)
Rect screen = new Rect(activeDisplay.Location, activeDisplay.Size) / primaryDpi;
Position position = _settingService.Position;

Debug.WriteLine($"Window {window} - Screen {screen}");
Debug.WriteLine($"Primary Dpi: {primaryDpi} - Screen Dpi: {activeDisplay.Dpi}");

if (!_settingService.UseCaretPosition)
Expand All @@ -72,6 +73,16 @@ public char[] GetLettersFromKey(LetterKey letter)
return _settingService.GetLetterKey(letter);
}

public bool? IsLeftPosition()
{
return _settingService.Position switch
{
Position.Left or Position.TopLeft or Position.BottomLeft => true,
Position.Right or Position.TopRight or Position.BottomRight => false,
_ => null
};
}

public void ReloadSettings()
{
_settingService.Reload();
Expand Down
4 changes: 3 additions & 1 deletion PowerAccent.UI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Size = PowerAccent.Core.Size;
using Application = System.Windows.Application;
using System.Collections.Generic;
using System.Diagnostics;

namespace PowerAccent.UI;

Expand Down Expand Up @@ -38,8 +39,8 @@ private void PowerAccent_OnChangeDisplay(bool isActive, char[] chars)
if (isActive)
{
Selector selector = new Selector(chars);
CenterWindow(selector);
selector.Show();
CenterWindow(selector);
_selectorStack.Push(selector);
_selector = selector;
}
Expand All @@ -58,6 +59,7 @@ private void CenterWindow(Selector selector)
double primaryDPI = Screen.PrimaryScreen.Bounds.Width / SystemParameters.PrimaryScreenWidth;
Point position = _powerAccent.GetDisplayCoordinates(window, primaryDPI);
selector.SetPosition(position.X, position.Y);
selector.SetBorderWindowAlignment(_powerAccent.IsLeftPosition());
}

#region TaskBar
Expand Down
19 changes: 8 additions & 11 deletions PowerAccent.UI/Selector.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="IsHitTestVisible" Value="False" />
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<VirtualizingStackPanel IsItemsHost="False" Orientation="Horizontal" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="IsHitTestVisible" Value="True" />
<Setter Property="BorderThickness" Value="0" />
</Style>

<Style TargetType="ListBoxItem">
Expand All @@ -42,8 +36,7 @@
Margin="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
SnapsToDevicePixels="true"
Style="{DynamicResource borderContent}">
SnapsToDevicePixels="true">
<Rectangle
x:Name="SelectionIndicator"
Margin="7"
Expand All @@ -54,7 +47,6 @@
RadiusY="4"
Visibility="Collapsed" />
<ContentPresenter Margin="12" />

</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
Expand Down Expand Up @@ -84,6 +76,11 @@
<Grid>
<Border Background="{DynamicResource PrimaryBackgroundBrush}" CornerRadius="8">
<ListBox x:Name="characters">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel IsItemsHost="False" Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</Border>
</Grid>
Expand Down
14 changes: 13 additions & 1 deletion PowerAccent.UI/Selector.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Windows;
using PowerAccent.Core.Services;
using PowerAccent.Core;
using System.Windows;

namespace PowerAccent.UI;

Expand All @@ -23,4 +25,14 @@ public void SetPosition(double left, double top)
this.Left = left;
this.Top = top;
}

public void SetBorderWindowAlignment(bool? isLeft)
{
gridBorder.HorizontalAlignment = isLeft switch
{
true => HorizontalAlignment.Left,
false => HorizontalAlignment.Right,
_ => HorizontalAlignment.Center,
};
}
}
2 changes: 1 addition & 1 deletion PowerAccent.Wix/PowerAccent.Wix.SelfContained.wixproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<DoNotHarvest>True</DoNotHarvest>
<RefProjectOutputGroups>Binaries;Content;Satellites</RefProjectOutputGroups>
<RefTargetDir>INSTALLFOLDER</RefTargetDir>
<TargetFrameworkIdentifier>net6.0-windows</TargetFrameworkIdentifier>
<TargetFrameworkIdentifier>net6.0-windows10.0.19041.0</TargetFrameworkIdentifier>
<Runtime>win-x64</Runtime>
</ProjectReference>
</ItemGroup>
Expand Down

0 comments on commit 663d590

Please sign in to comment.