mirror of
https://github.com/Leonmmcoset/CMLeonOS.git
synced 2026-04-21 19:24:00 +00:00
Dropdown增加动画
This commit is contained in:
@@ -1 +1 @@
|
|||||||
2026-03-25 21:37:54
|
2026-03-25 21:44:57
|
||||||
@@ -1 +1 @@
|
|||||||
d009660
|
b964430
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using CMLeonOS.UILib.Animations;
|
||||||
|
|
||||||
namespace CMLeonOS.Gui.UILib
|
namespace CMLeonOS.Gui.UILib
|
||||||
{
|
{
|
||||||
@@ -16,6 +17,7 @@ namespace CMLeonOS.Gui.UILib
|
|||||||
private readonly Window hostWindow;
|
private readonly Window hostWindow;
|
||||||
private Window popupWindow;
|
private Window popupWindow;
|
||||||
private Table popupTable;
|
private Table popupTable;
|
||||||
|
private bool closeAnimationRunning = false;
|
||||||
|
|
||||||
internal Action<int, string> SelectionChanged;
|
internal Action<int, string> SelectionChanged;
|
||||||
|
|
||||||
@@ -173,13 +175,31 @@ namespace CMLeonOS.Gui.UILib
|
|||||||
|
|
||||||
internal void Collapse()
|
internal void Collapse()
|
||||||
{
|
{
|
||||||
if (!Expanded)
|
if (!Expanded || closeAnimationRunning)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (popupWindow == null)
|
||||||
|
{
|
||||||
Expanded = false;
|
Expanded = false;
|
||||||
|
Render();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
closeAnimationRunning = true;
|
||||||
|
|
||||||
|
int currentHeight = popupWindow.Height;
|
||||||
|
MovementAnimation animation = new MovementAnimation(popupWindow)
|
||||||
|
{
|
||||||
|
From = new Rectangle(popupWindow.X, popupWindow.Y, popupWindow.Width, currentHeight),
|
||||||
|
To = new Rectangle(popupWindow.X, popupWindow.Y, popupWindow.Width, 1),
|
||||||
|
Duration = 8,
|
||||||
|
EasingType = EasingType.Sine,
|
||||||
|
EasingDirection = EasingDirection.In
|
||||||
|
};
|
||||||
|
animation.Completed = () =>
|
||||||
|
{
|
||||||
if (popupTable != null)
|
if (popupTable != null)
|
||||||
{
|
{
|
||||||
WM.RemoveWindow(popupTable);
|
WM.RemoveWindow(popupTable);
|
||||||
@@ -191,7 +211,11 @@ namespace CMLeonOS.Gui.UILib
|
|||||||
popupWindow = null;
|
popupWindow = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Expanded = false;
|
||||||
|
closeAnimationRunning = false;
|
||||||
Render();
|
Render();
|
||||||
|
};
|
||||||
|
animation.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PopupSelected(int index)
|
private void PopupSelected(int index)
|
||||||
@@ -236,12 +260,11 @@ namespace CMLeonOS.Gui.UILib
|
|||||||
int visibleItems = Math.Max(1, Math.Min(MaxVisibleItems, Math.Max(1, Items.Count)));
|
int visibleItems = Math.Max(1, Math.Min(MaxVisibleItems, Math.Max(1, Items.Count)));
|
||||||
int popupHeight = Math.Max(24, visibleItems * 22);
|
int popupHeight = Math.Max(24, visibleItems * 22);
|
||||||
|
|
||||||
popupWindow = new Window(Process, hostWindow, X, Y + Height, Width, popupHeight);
|
popupWindow = new Window(Process, hostWindow, X, Y + Height, Width, 1);
|
||||||
popupWindow.Clear(UITheme.Surface);
|
popupWindow.Clear(UITheme.Surface);
|
||||||
popupWindow.DrawRectangle(0, 0, popupWindow.Width, popupWindow.Height, Border);
|
|
||||||
WM.AddWindow(popupWindow);
|
WM.AddWindow(popupWindow);
|
||||||
|
|
||||||
popupTable = new Table(popupWindow, 0, 0, popupWindow.Width, popupWindow.Height);
|
popupTable = new Table(popupWindow, 0, 0, popupWindow.Width, popupHeight);
|
||||||
popupTable.AllowDeselection = false;
|
popupTable.AllowDeselection = false;
|
||||||
popupTable.CellHeight = 22;
|
popupTable.CellHeight = 22;
|
||||||
popupTable.Background = UITheme.Surface;
|
popupTable.Background = UITheme.Surface;
|
||||||
@@ -260,6 +283,30 @@ namespace CMLeonOS.Gui.UILib
|
|||||||
popupTable.SelectedCellIndex = _selectedIndex;
|
popupTable.SelectedCellIndex = _selectedIndex;
|
||||||
popupTable.Render();
|
popupTable.Render();
|
||||||
WM.AddWindow(popupTable);
|
WM.AddWindow(popupTable);
|
||||||
|
|
||||||
|
MovementAnimation animation = new MovementAnimation(popupWindow)
|
||||||
|
{
|
||||||
|
From = new Rectangle(popupWindow.X, popupWindow.Y, popupWindow.Width, 1),
|
||||||
|
To = new Rectangle(popupWindow.X, popupWindow.Y, popupWindow.Width, popupHeight),
|
||||||
|
Duration = 8,
|
||||||
|
EasingType = EasingType.Sine,
|
||||||
|
EasingDirection = EasingDirection.Out
|
||||||
|
};
|
||||||
|
animation.Completed = () =>
|
||||||
|
{
|
||||||
|
if (popupWindow != null)
|
||||||
|
{
|
||||||
|
popupWindow.Clear(UITheme.Surface);
|
||||||
|
popupWindow.DrawRectangle(0, 0, popupWindow.Width, popupWindow.Height, Border);
|
||||||
|
WM.Update(popupWindow);
|
||||||
|
}
|
||||||
|
if (popupTable != null)
|
||||||
|
{
|
||||||
|
popupTable.MoveAndResize(0, 0, popupWindow.Width, popupWindow.Height, sendWMEvent: false);
|
||||||
|
popupTable.Render();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
animation.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override void Render()
|
internal override void Render()
|
||||||
|
|||||||
Reference in New Issue
Block a user