This repository has been archived by the owner on Jul 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial version of the server status page is completed.
- Loading branch information
1 parent
dba8825
commit a5b2316
Showing
6 changed files
with
217 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
namespace LostArkTools.Controls; | ||
|
||
using System; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
|
||
public class AlignableWrapPanel : Panel | ||
{ | ||
public HorizontalAlignment HorizontalContentAlignment | ||
{ | ||
get => (HorizontalAlignment)GetValue(HorizontalContentAlignmentProperty); | ||
set => SetValue(HorizontalContentAlignmentProperty, value); | ||
} | ||
|
||
public static readonly DependencyProperty HorizontalContentAlignmentProperty = | ||
DependencyProperty.Register("HorizontalContentAlignment", typeof(HorizontalAlignment), typeof(AlignableWrapPanel), new FrameworkPropertyMetadata(HorizontalAlignment.Left, FrameworkPropertyMetadataOptions.AffectsArrange)); | ||
|
||
protected override Size MeasureOverride(Size constraint) | ||
{ | ||
var curLineSize = new Size(); | ||
var panelSize = new Size(); | ||
|
||
var children = InternalChildren; | ||
|
||
for (var i = 0; i < children.Count; i++) | ||
{ | ||
var child = children[i] as UIElement; | ||
|
||
// Flow passes its own constraint to children | ||
child.Measure(constraint); | ||
var sz = child.DesiredSize; | ||
|
||
if (curLineSize.Width + sz.Width > constraint.Width) //need to switch to another line | ||
{ | ||
panelSize.Width = Math.Max(curLineSize.Width, panelSize.Width); | ||
panelSize.Height += curLineSize.Height; | ||
curLineSize = sz; | ||
|
||
if (sz.Width > constraint.Width) // if the element is wider then the constraint - give it a separate line | ||
{ | ||
panelSize.Width = Math.Max(sz.Width, panelSize.Width); | ||
panelSize.Height += sz.Height; | ||
curLineSize = new Size(); | ||
} | ||
} | ||
else //continue to accumulate a line | ||
{ | ||
curLineSize.Width += sz.Width; | ||
curLineSize.Height = Math.Max(sz.Height, curLineSize.Height); | ||
} | ||
} | ||
|
||
// the last line size, if any need to be added | ||
panelSize.Width = Math.Max(curLineSize.Width, panelSize.Width); | ||
panelSize.Height += curLineSize.Height; | ||
|
||
return panelSize; | ||
} | ||
|
||
protected override Size ArrangeOverride(Size arrangeBounds) | ||
{ | ||
var firstInLine = 0; | ||
var curLineSize = new Size(); | ||
double accumulatedHeight = 0; | ||
var children = InternalChildren; | ||
|
||
for (var i = 0; i < children.Count; i++) | ||
{ | ||
var sz = children[i].DesiredSize; | ||
|
||
if (curLineSize.Width + sz.Width > arrangeBounds.Width) //need to switch to another line | ||
{ | ||
ArrangeLine(accumulatedHeight, curLineSize, arrangeBounds.Width, firstInLine, i); | ||
|
||
accumulatedHeight += curLineSize.Height; | ||
curLineSize = sz; | ||
|
||
if (sz.Width > arrangeBounds.Width) //the element is wider then the constraint - give it a separate line | ||
{ | ||
ArrangeLine(accumulatedHeight, sz, arrangeBounds.Width, i, ++i); | ||
accumulatedHeight += sz.Height; | ||
curLineSize = new Size(); | ||
} | ||
firstInLine = i; | ||
} | ||
else //continue to accumulate a line | ||
{ | ||
curLineSize.Width += sz.Width; | ||
curLineSize.Height = Math.Max(sz.Height, curLineSize.Height); | ||
} | ||
} | ||
|
||
if (firstInLine < children.Count) | ||
ArrangeLine(accumulatedHeight, curLineSize, arrangeBounds.Width, firstInLine, children.Count); | ||
|
||
return arrangeBounds; | ||
} | ||
|
||
private void ArrangeLine(double y, Size lineSize, double boundsWidth, int start, int end) | ||
{ | ||
var x = HorizontalContentAlignment switch | ||
{ | ||
HorizontalAlignment.Center => (boundsWidth - lineSize.Width) / 2, | ||
HorizontalAlignment.Right => (boundsWidth - lineSize.Width), | ||
_ => 0 | ||
}; | ||
|
||
var children = InternalChildren; | ||
for (var i = start; i < end; i++) | ||
{ | ||
var child = children[i]; | ||
child.Arrange(new Rect(x, y, child.DesiredSize.Width, lineSize.Height)); | ||
x += child.DesiredSize.Width; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
|
||
namespace LostArkTools.Converters; | ||
|
||
public class IsLastItemInContainerConverter : IValueConverter | ||
{ | ||
public object Convert(object value, Type targetType, | ||
object parameter, CultureInfo culture) | ||
{ | ||
var item = (DependencyObject)value; | ||
var ic = ItemsControl.ItemsControlFromItemContainer(item); | ||
var index = ic.ItemContainerGenerator.IndexFromContainer(item); | ||
return index == ic.Items.Count - 1; | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, | ||
object parameter, CultureInfo culture) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,40 @@ | ||
<Grid x:Class="LostArkTools.Features.ServerStatus.ServerStatusView" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:LostArkTools.Features.ServerStatus" | ||
xmlns:s="https://github.com/canton7/Stylet" | ||
mc:Ignorable="d" | ||
d:DataContext="{d:DesignInstance local:ServerStatusViewModel}" | ||
d:DesignHeight="300" d:DesignWidth="300"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto"/> | ||
<RowDefinition Height="*"/> | ||
</Grid.RowDefinitions> | ||
|
||
|
||
<Grid Grid.Row="1"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition/> | ||
<ColumnDefinition Width="Auto"/> | ||
<ColumnDefinition/> | ||
</Grid.ColumnDefinitions> | ||
<ItemsControl ItemsSource="{Binding Regions}" | ||
Grid.Column="1"> | ||
<ItemsControl.ItemTemplate> | ||
<DataTemplate> | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:LostArkTools.Features.ServerStatus" | ||
xmlns:s="https://github.com/canton7/Stylet" | ||
mc:Ignorable="d" | ||
d:DataContext="{d:DesignInstance local:ServerStatusViewModel}" | ||
d:DesignHeight="300" d:DesignWidth="300"> | ||
<ItemsControl ItemsSource="{Binding Regions}" | ||
Margin="0 10 0 0" | ||
Grid.Column="1"> | ||
<ItemsControl.ItemTemplate> | ||
<DataTemplate> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition /> | ||
</Grid.RowDefinitions> | ||
<ContentControl s:View.Model="{Binding}" | ||
Margin="25 0 25 0"/> | ||
</DataTemplate> | ||
</ItemsControl.ItemTemplate> | ||
<ItemsControl.ItemsPanel> | ||
<ItemsPanelTemplate> | ||
<StackPanel Orientation="Horizontal" | ||
HorizontalAlignment="Stretch"/> | ||
</ItemsPanelTemplate> | ||
</ItemsControl.ItemsPanel> | ||
</ItemsControl> | ||
</Grid> | ||
</Grid> | ||
Margin="5 10 5 10" /> | ||
<Separator Grid.Row="1" | ||
x:Name="Separator"/> | ||
</Grid> | ||
<DataTemplate.Triggers> | ||
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource IsLastItemInContainer}}" | ||
Value="True"> | ||
<Setter TargetName="Separator" Property="Visibility" Value="Hidden"/> | ||
</DataTrigger> | ||
</DataTemplate.Triggers> | ||
</DataTemplate> | ||
</ItemsControl.ItemTemplate> | ||
<ItemsControl.ItemsPanel> | ||
<ItemsPanelTemplate> | ||
<StackPanel /> | ||
</ItemsPanelTemplate> | ||
</ItemsControl.ItemsPanel> | ||
</ItemsControl> | ||
</Grid> |