Skip adjusting sizes that are already known

This commit is contained in:
Peter Kirmeier 2020-09-20 11:14:20 +02:00
parent bec1b3ff28
commit 713ae57f70

View file

@ -859,34 +859,46 @@ namespace SystemTrayMenu.Business
private void AdjustMenusSizeAndLocation()
{
Menu menuPredecessor = menus[0];
Menu menuPredecessor = null;
int widthPredecessors = -1; // -1 padding
bool directionToRight = false;
List<Menu> list = AsList;
Menu menu;
menus[0].AdjustSizeAndLocation(screenHeight, screenRight, taskbarHeight);
foreach (Menu menu in AsEnumerable.Where(m => m.Level > 0))
for (int i = 0; i < list.Count; i++)
{
int newWith = menu.Width - menu.Padding.Horizontal + menuPredecessor.Width;
if (directionToRight)
{
if (widthPredecessors - menus[0].Width - menu.Width < 0)
{
directionToRight = false;
menu = list[i];
// skip calculation based on the predecessor for the very first menu
if (menuPredecessor != null)
{
int newWidth = menu.Width - menu.Padding.Horizontal + menuPredecessor.Width;
if (directionToRight)
{
if (widthPredecessors - menus[0].Width - menu.Width < 0)
{
directionToRight = false;
}
else
{
widthPredecessors -= newWidth;
}
}
else if (screenWidth < widthPredecessors + menus[0].Width + menu.Width)
{
directionToRight = true;
widthPredecessors -= newWidth;
}
else
{
widthPredecessors -= newWith;
}
}
else if (screenWidth < widthPredecessors + menus[0].Width + menu.Width)
{
directionToRight = true;
widthPredecessors -= newWith;
widthPredecessors += menu.Width - menu.Padding.Left;
}
// only last one has to be updated as all previous one were already updated in the past
if (list.Count - 1 == i)
{
menu.AdjustSizeAndLocation(screenHeight, screenRight, taskbarHeight, menuPredecessor, directionToRight);
}
menu.AdjustSizeAndLocation(screenHeight, screenRight, taskbarHeight, menuPredecessor, directionToRight);
widthPredecessors += menu.Width - menu.Padding.Left;
menuPredecessor = menu;
}
}