- add: Autoscroller think

This commit is contained in:
2025-01-19 12:55:39 +03:00
parent 2e3e50e7af
commit 46d17b98b2
3 changed files with 86 additions and 23 deletions

View File

@@ -93,7 +93,7 @@ public partial class ServerEntryModelView : ViewModelBase
{ {
Description = "Server of meow girls! Nya~ \nNyaMeow\nOOOINK!!"; Description = "Server of meow girls! Nya~ \nNyaMeow\nOOOINK!!";
ServerHubInfo = new ServerHubInfo("ss14://localhost", ServerHubInfo = new ServerHubInfo("ss14://localhost",
new ServerStatus("Ameba", "Locala", ["rp:hrp", "18+"], "Antag", 15, 5, 1, false, DateTime.Now, 100), ["meow:rp"]); new ServerStatus("Ameba", "Locala meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow ", ["rp:hrp", "18+"], "Antag", 15, 5, 1, false, DateTime.Now, 100), ["meow:rp"]);
} }
protected override void Initialise() protected override void Initialise()

View File

@@ -6,18 +6,21 @@
x:DataType="viewModels:ServerEntryModelView" x:DataType="viewModels:ServerEntryModelView"
xmlns="https://github.com/avaloniaui" xmlns="https://github.com/avaloniaui"
xmlns:asyncImageLoader="clr-namespace:AsyncImageLoader;assembly=AsyncImageLoader.Avalonia" xmlns:asyncImageLoader="clr-namespace:AsyncImageLoader;assembly=AsyncImageLoader.Avalonia"
xmlns:converters="clr-namespace:Nebula.Launcher.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:system="clr-namespace:System;assembly=System.Runtime" xmlns:system="clr-namespace:System;assembly=System.Runtime"
xmlns:viewModels="clr-namespace:Nebula.Launcher.ViewModels" xmlns:viewModels="clr-namespace:Nebula.Launcher.ViewModels"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
xmlns:converters="clr-namespace:Nebula.Launcher.Converters">
<Design.DataContext> <Design.DataContext>
<viewModels:ServerEntryModelView /> <viewModels:ServerEntryModelView />
</Design.DataContext> </Design.DataContext>
<Border CornerRadius="10" Margin="0,5,0,5"> <Border
<Grid ColumnDefinitions="30,*,80,90" RowDefinitions="35,*,*"> BorderThickness="0,0,0,0"
CornerRadius="10"
Margin="0,5,0,5">
<Grid ColumnDefinitions="30,*,80,50" RowDefinitions="35,*,*">
<Border <Border
BorderThickness="0,0,0,2" BorderThickness="0,0,0,2"
CornerRadius="10" CornerRadius="10"
@@ -25,6 +28,7 @@
Grid.ColumnSpan="2" Grid.ColumnSpan="2"
Grid.Row="0" Grid.Row="0"
IsVisible="{Binding ExpandInfo}" /> IsVisible="{Binding ExpandInfo}" />
<Button <Button
Command="{Binding ExpandInfoRequired}" Command="{Binding ExpandInfoRequired}"
CornerRadius="10,0,0,10" CornerRadius="10,0,0,10"
@@ -32,12 +36,15 @@
Grid.Row="0" Grid.Row="0"
Grid.RowSpan="3" Grid.RowSpan="3"
VerticalAlignment="Stretch"> VerticalAlignment="Stretch">
<Label VerticalAlignment="Bottom" Margin="5,0,5,2">i</Label> <Label Margin="5,0,5,0" VerticalAlignment="Bottom">i</Label>
</Button> </Button>
<ScrollViewer <ScrollViewer
Grid.Column="1" Grid.Column="1"
Grid.Row="0" Grid.Row="0"
Margin="5"> HorizontalScrollBarVisibility="Hidden"
Margin="10,0,0,0"
VerticalScrollBarVisibility="Disabled"
x:Name="AutoScrollViewer">
<Label VerticalAlignment="Center"> <Label VerticalAlignment="Center">
<TextBlock Text="{Binding ServerHubInfo.StatusData.Name}" /> <TextBlock Text="{Binding ServerHubInfo.StatusData.Name}" />
</Label> </Label>
@@ -57,6 +64,7 @@
</Label> </Label>
</StackPanel> </StackPanel>
<Panel <Panel
Grid.Column="3" Grid.Column="3"
Grid.Row="0" Grid.Row="0"
@@ -67,26 +75,15 @@
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
IsVisible="{Binding RunVisible}" IsVisible="{Binding RunVisible}"
VerticalAlignment="Stretch"> VerticalAlignment="Stretch">
<Svg Path="/Assets/svg/play.svg"/> <Svg Margin="4" Path="/Assets/svg/play.svg" />
</Button> </Button>
<Grid ColumnDefinitions="*,*" <Grid ColumnDefinitions="*" IsVisible="{Binding !RunVisible}">
IsVisible="{Binding !RunVisible}">
<Button <Button
Command="{Binding ReadLog}" Command="{Binding ReadLog}"
CornerRadius="10,0,0,10" CornerRadius="10"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
Margin="0,0,2,0"
VerticalAlignment="Stretch"> VerticalAlignment="Stretch">
<Svg Path="/Assets/svg/newspaper.svg"/> <Svg Margin="4" Path="/Assets/svg/newspaper.svg" />
</Button>
<Button
Command="{Binding StopInstance}"
CornerRadius="0,10,10,0"
Grid.Column="1"
HorizontalAlignment="Stretch"
Margin="2,0,0,0"
VerticalAlignment="Stretch">
<Svg Path="/Assets/svg/stop.svg"/>
</Button> </Button>
</Grid> </Grid>
</Panel> </Panel>
@@ -99,7 +96,7 @@
IsVisible="{Binding ExpandInfo}" IsVisible="{Binding ExpandInfo}"
Margin="5"> Margin="5">
<Label FontSize="12"> <Label FontSize="12">
<TextBlock Text="{Binding Description}" /> <TextBlock Text="{Binding Description}" TextWrapping="Wrap" />
</Label> </Label>
</Border> </Border>
<Border <Border
@@ -168,6 +165,22 @@
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
</Border> </Border>
<StackPanel
Grid.Column="3"
Grid.Row="1"
IsVisible="{Binding ExpandInfo}"
Margin="5,5,0,0"
Spacing="5">
<Button
Command="{Binding StopInstance}"
CornerRadius="10"
Height="35"
HorizontalAlignment="Stretch"
IsVisible="{Binding !RunVisible}"
VerticalAlignment="Stretch">
<Svg Margin="4" Path="/Assets/svg/stop.svg" />
</Button>
</StackPanel>
</Grid> </Grid>
</Border> </Border>
</UserControl> </UserControl>

View File

@@ -1,19 +1,69 @@
using System;
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml;
using Avalonia.Threading;
using Nebula.Launcher.ViewModels; using Nebula.Launcher.ViewModels;
namespace Nebula.Launcher.Views; namespace Nebula.Launcher.Views;
public partial class ServerEntryView : UserControl public partial class ServerEntryView : UserControl
{ {
private DispatcherTimer _scrollTimer;
private bool _scrollingDown = true;
public ServerEntryView() public ServerEntryView()
{ {
InitializeComponent(); InitializeComponent();
StartAutoScrolling();
} }
public ServerEntryView(ServerEntryModelView modelView) : this() public ServerEntryView(ServerEntryModelView modelView) : this()
{ {
DataContext = modelView; DataContext = modelView;
} }
private void StartAutoScrolling()
{
_scrollTimer = new DispatcherTimer
{
Interval = TimeSpan.FromMilliseconds(50) // Adjust the interval for scroll speed
};
_scrollTimer.Tick += AutoScroll;
_scrollTimer.Start();
}
private void AutoScroll(object? sender, EventArgs e)
{
// Get the current offset and extent
var currentOffset = AutoScrollViewer.Offset.X;
var maxOffset = AutoScrollViewer.Extent.Width - AutoScrollViewer.Viewport.Width;
if (_scrollingDown)
{
// Scroll down
if (currentOffset < maxOffset)
{
AutoScrollViewer.Offset = new Avalonia.Vector(currentOffset + 2, AutoScrollViewer.Offset.Y); // Adjust speed
}
else
{
// Reverse direction when reaching the bottom
_scrollingDown = false;
}
}
else
{
// Scroll up
if (currentOffset > 0)
{
AutoScrollViewer.Offset = new Avalonia.Vector(currentOffset - 2, AutoScrollViewer.Offset.Y); // Adjust speed
}
else
{
// Reverse direction when reaching the top
_scrollingDown = true;
}
}
}
} }