mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
better resize policy
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<XamlControlsResources/>
|
||||
<ResourceDictionary Source="ms-appx:///CommunityToolkit.WinUI.Controls.SettingsControls/SettingsCard/SettingsCard.xaml"/>
|
||||
<ResourceDictionary Source="ms-appx:///CommunityToolkit.WinUI.Controls.TokenizingTextBox/TokenizingTextBox.xaml"/>
|
||||
<ResourceDictionary Source="ms-appx:///Control/Loading.xaml"/>
|
||||
<ResourceDictionary Source="ms-appx:///Control/Image/CachedImage.xaml"/>
|
||||
|
||||
@@ -15,6 +15,10 @@ internal static class SettingKeys
|
||||
public const string GuideWindowRect = "GuideWindowRect";
|
||||
public const string IsNavPaneOpen = "IsNavPaneOpen";
|
||||
public const string IsInfoBarToggleChecked = "IsInfoBarToggleChecked";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Infrastructure
|
||||
public const string ExcludedAnnouncementIds = "ExcludedAnnouncementIds";
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -8,10 +8,10 @@ namespace Snap.Hutao.Core.Windowing.NotifyIcon;
|
||||
|
||||
internal sealed partial class NotifyIconContextMenu : Flyout
|
||||
{
|
||||
public NotifyIconContextMenu()
|
||||
public NotifyIconContextMenu(IServiceProvider serviceProvider)
|
||||
{
|
||||
AllowFocusOnInteraction = false;
|
||||
InitializeComponent();
|
||||
Root.DataContext = Ioc.Default.GetRequiredService<NotifyIconViewModel>();
|
||||
Root.DataContext = serviceProvider.GetRequiredService<NotifyIconViewModel>();
|
||||
}
|
||||
}
|
||||
@@ -14,13 +14,15 @@ namespace Snap.Hutao.Core.Windowing.NotifyIcon;
|
||||
[Injection(InjectAs.Singleton)]
|
||||
internal sealed class NotifyIconController : IDisposable
|
||||
{
|
||||
private readonly LazySlim<NotifyIconContextMenu> lazyMenu = new(() => new());
|
||||
private readonly LazySlim<NotifyIconContextMenu> lazyMenu;
|
||||
private readonly NotifyIconXamlHostWindow xamlHostWindow;
|
||||
private readonly NotifyIconMessageWindow messageWindow;
|
||||
private readonly System.Drawing.Icon icon;
|
||||
|
||||
public NotifyIconController()
|
||||
public NotifyIconController(IServiceProvider serviceProvider)
|
||||
{
|
||||
lazyMenu = new(() => new(serviceProvider));
|
||||
|
||||
StorageFile iconFile = StorageFile.GetFileFromApplicationUriAsync("ms-appx:///Assets/Logo.ico".ToUri()).AsTask().GetAwaiter().GetResult();
|
||||
icon = new(iconFile.Path);
|
||||
|
||||
@@ -28,31 +30,11 @@ internal sealed class NotifyIconController : IDisposable
|
||||
|
||||
messageWindow = new()
|
||||
{
|
||||
TaskbarCreated = window =>
|
||||
{
|
||||
NotifyIconMethods.Delete(Id);
|
||||
if (!NotifyIconMethods.Add(Id, window.HWND, "Snap Hutao", NotifyIconMessageWindow.WM_NOTIFYICON_CALLBACK, (HICON)icon.Handle))
|
||||
{
|
||||
HutaoException.InvalidOperation("Failed to recreate NotifyIcon");
|
||||
}
|
||||
},
|
||||
ContextMenuRequested = (window, point) =>
|
||||
{
|
||||
RECT iconRect = NotifyIconMethods.GetRect(Id, window.HWND);
|
||||
xamlHostWindow.ShowFlyoutAt(lazyMenu.Value, new Windows.Foundation.Point(point.X, point.Y), iconRect);
|
||||
},
|
||||
TaskbarCreated = OnRecreateNotifyIconRequested,
|
||||
ContextMenuRequested = OnContextMenuRequested,
|
||||
};
|
||||
|
||||
NotifyIconMethods.Delete(Id);
|
||||
if (!NotifyIconMethods.Add(Id, messageWindow.HWND, "Snap Hutao", NotifyIconMessageWindow.WM_NOTIFYICON_CALLBACK, (HICON)icon.Handle))
|
||||
{
|
||||
HutaoException.InvalidOperation("Failed to create NotifyIcon");
|
||||
}
|
||||
|
||||
if (!NotifyIconMethods.SetVersion(Id, NOTIFYICON_VERSION_4))
|
||||
{
|
||||
HutaoException.InvalidOperation("Failed to set NotifyIcon version");
|
||||
}
|
||||
CreateNotifyIcon();
|
||||
}
|
||||
|
||||
private static ref readonly Guid Id
|
||||
@@ -73,4 +55,38 @@ internal sealed class NotifyIconController : IDisposable
|
||||
|
||||
xamlHostWindow.Dispose();
|
||||
}
|
||||
|
||||
private void OnRecreateNotifyIconRequested(NotifyIconMessageWindow window)
|
||||
{
|
||||
NotifyIconMethods.Delete(Id);
|
||||
if (!NotifyIconMethods.Add(Id, window.HWND, "Snap Hutao", NotifyIconMessageWindow.WM_NOTIFYICON_CALLBACK, (HICON)icon.Handle))
|
||||
{
|
||||
HutaoException.InvalidOperation("Failed to recreate NotifyIcon");
|
||||
}
|
||||
|
||||
if (!NotifyIconMethods.SetVersion(Id, NOTIFYICON_VERSION_4))
|
||||
{
|
||||
HutaoException.InvalidOperation("Failed to set NotifyIcon version");
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateNotifyIcon()
|
||||
{
|
||||
NotifyIconMethods.Delete(Id);
|
||||
if (!NotifyIconMethods.Add(Id, messageWindow.HWND, "Snap Hutao", NotifyIconMessageWindow.WM_NOTIFYICON_CALLBACK, (HICON)icon.Handle))
|
||||
{
|
||||
HutaoException.InvalidOperation("Failed to create NotifyIcon");
|
||||
}
|
||||
|
||||
if (!NotifyIconMethods.SetVersion(Id, NOTIFYICON_VERSION_4))
|
||||
{
|
||||
HutaoException.InvalidOperation("Failed to set NotifyIcon version");
|
||||
}
|
||||
}
|
||||
|
||||
private void OnContextMenuRequested(NotifyIconMessageWindow window, PointUInt16 point)
|
||||
{
|
||||
RECT iconRect = NotifyIconMethods.GetRect(Id, window.HWND);
|
||||
xamlHostWindow.ShowFlyoutAt(lazyMenu.Value, new Windows.Foundation.Point(point.X, point.Y), iconRect);
|
||||
}
|
||||
}
|
||||
@@ -102,9 +102,18 @@ internal sealed class NotifyIconMessageWindow : IDisposable
|
||||
|
||||
switch (lParam2.Low)
|
||||
{
|
||||
case WM_CONTEXTMENU:
|
||||
window.ContextMenuRequested?.Invoke(window, wParam2);
|
||||
break;
|
||||
case WM_MOUSEMOVE:
|
||||
// X: wParam2.X Y: wParam2.Y Low: WM_MOUSEMOVE
|
||||
break;
|
||||
case WM_LBUTTONDOWN:
|
||||
case WM_LBUTTONUP:
|
||||
break;
|
||||
case WM_RBUTTONDOWN:
|
||||
case WM_RBUTTONUP:
|
||||
break;
|
||||
case NIN_SELECT:
|
||||
// X: wParam2.X Y: wParam2.Y Low: NIN_SELECT
|
||||
break;
|
||||
@@ -114,15 +123,6 @@ internal sealed class NotifyIconMessageWindow : IDisposable
|
||||
case NIN_POPUPCLOSE:
|
||||
// X: wParam2.X Y: 0? Low: NIN_POPUPCLOSE
|
||||
break;
|
||||
case WM_LBUTTONDOWN:
|
||||
case WM_LBUTTONUP:
|
||||
break;
|
||||
case WM_RBUTTONDOWN:
|
||||
case WM_RBUTTONUP:
|
||||
break;
|
||||
case WM_CONTEXTMENU:
|
||||
window.ContextMenuRequested?.Invoke(window, wParam2);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.UI.Content;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Snap.Hutao.Core.Setting;
|
||||
using Snap.Hutao.Core.Windowing;
|
||||
@@ -30,8 +31,11 @@ internal sealed partial class MainWindow : Window, IXamlWindowOptionsSource, IMi
|
||||
windowOptions = new(this, TitleBarView.DragArea, new(1200, 741), SettingKeys.WindowRect);
|
||||
this.InitializeController(serviceProvider);
|
||||
|
||||
var policy = this.GetDesktopWindowXamlSource()!.SiteBridge.ResizePolicy;
|
||||
_ = 1;
|
||||
if (this.GetDesktopWindowXamlSource() is { } desktopWindowXamlSource)
|
||||
{
|
||||
DesktopChildSiteBridge desktopChildSiteBridge = desktopWindowXamlSource.SiteBridge;
|
||||
desktopChildSiteBridge.ResizePolicy = ContentSizePolicy.ResizeContentToParentWindow;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -46,7 +46,13 @@
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate x:Key="MonsterBaseValueTemplate">
|
||||
<cwc:SettingsCard Header="{Binding Name}">
|
||||
<cwc:SettingsCard MinHeight="40" Padding="0,0,16,0">
|
||||
<cwc:SettingsCard.Resources>
|
||||
<x:Double x:Key="SettingsCardLeftIndention">16</x:Double>
|
||||
</cwc:SettingsCard.Resources>
|
||||
<cwc:SettingsCard.Header>
|
||||
<TextBlock Text="{Binding Name}" TextWrapping="NoWrap"/>
|
||||
</cwc:SettingsCard.Header>
|
||||
<TextBlock Text="{Binding Value}"/>
|
||||
</cwc:SettingsCard>
|
||||
</DataTemplate>
|
||||
@@ -94,23 +100,6 @@
|
||||
Margin="6,8,0,0"
|
||||
LocalSettingKeySuffixForCurrent="WikiMonsterPage.Monsters"/>
|
||||
</CommandBar.Content>
|
||||
<!--<AppBarElementContainer Visibility="Collapsed">
|
||||
<AutoSuggestBox
|
||||
Width="240"
|
||||
Height="36"
|
||||
Margin="16,6,6,0"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalContentAlignment="Center"
|
||||
PlaceholderText="{shcm:ResourceString Name=ViewPageWiKiMonsterAutoSuggestBoxPlaceHolder}"
|
||||
QueryIcon="{shcm:FontIcon Glyph=}"
|
||||
Text="{Binding FilterText, Mode=TwoWay}">
|
||||
<mxi:Interaction.Behaviors>
|
||||
<mxic:EventTriggerBehavior EventName="QuerySubmitted">
|
||||
<mxic:InvokeCommandAction Command="{Binding FilterCommand}" CommandParameter="{Binding FilterText}"/>
|
||||
</mxic:EventTriggerBehavior>
|
||||
</mxi:Interaction.Behaviors>
|
||||
</AutoSuggestBox>
|
||||
</AppBarElementContainer>-->
|
||||
</CommandBar>
|
||||
</Border>
|
||||
</Border>
|
||||
|
||||
Reference in New Issue
Block a user