feat(ui): persist retained window layouts
This commit is contained in:
parent
a8e9503d2e
commit
921c388e2c
22 changed files with 705 additions and 141 deletions
|
|
@ -24,7 +24,7 @@ namespace AcDream.App.UI.Layout;
|
|||
/// and bound in place.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public sealed class ChatWindowController
|
||||
public sealed class ChatWindowController : IRetainedWindowStateController
|
||||
{
|
||||
public const uint LayoutId = 0x21000006u;
|
||||
|
||||
|
|
@ -364,13 +364,16 @@ public sealed class ChatWindowController
|
|||
_normalHeight = frame.Height;
|
||||
|
||||
float expansion = parentHeight / 2f;
|
||||
float targetTop = frame.Top;
|
||||
float targetHeight = frame.Height + expansion;
|
||||
if (frame.Top + targetHeight > parentHeight || frame.Top >= parentHeight / 2f)
|
||||
targetTop = MathF.Max(0f, frame.Top - expansion);
|
||||
|
||||
float targetHeight = Math.Clamp(
|
||||
MathF.Min(frame.Height + expansion, parentHeight),
|
||||
frame.MinHeight,
|
||||
frame.MaxHeight);
|
||||
bool growUp = frame.Top + targetHeight > parentHeight
|
||||
|| frame.Top >= parentHeight / 2f;
|
||||
float targetTop = growUp
|
||||
? MathF.Max(0f, frame.Top - (targetHeight - frame.Height))
|
||||
: frame.Top;
|
||||
targetHeight = MathF.Min(targetHeight, parentHeight - targetTop);
|
||||
targetHeight = Math.Clamp(targetHeight, frame.MinHeight, frame.MaxHeight);
|
||||
|
||||
_maximized = true;
|
||||
_maxMinButton?.TrySetRetailState(RetailUiStateIds.Maximized);
|
||||
|
|
@ -378,6 +381,21 @@ public sealed class ChatWindowController
|
|||
handle.MoveTo(frame.Left, targetTop);
|
||||
}
|
||||
|
||||
public RetainedWindowState CaptureWindowState()
|
||||
=> new(
|
||||
Maximized: _maximized,
|
||||
PersistedTop: _maximized ? _normalTop : null,
|
||||
PersistedHeight: _maximized ? _normalHeight : null);
|
||||
|
||||
public void RestoreWindowState(RetainedWindowState state)
|
||||
{
|
||||
if (state.Maximized != _maximized)
|
||||
ToggleMaximize();
|
||||
else
|
||||
_maxMinButton?.TrySetRetailState(
|
||||
_maximized ? RetailUiStateIds.Maximized : RetailUiStateIds.Minimized);
|
||||
}
|
||||
|
||||
private static ElementInfo? FindInfo(ElementInfo node, uint id)
|
||||
{
|
||||
if (node.Id == id) return node;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue