-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b786675
commit b88e8d5
Showing
26 changed files
with
445 additions
and
130 deletions.
There are no files selected for viewing
104 changes: 83 additions & 21 deletions
104
Client/Rubberduck.UI/Converters/WrapPanelItemWidthConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,112 @@ | ||
using Rubberduck.UI.Shared.Settings.Abstract; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Data; | ||
|
||
namespace Rubberduck.UI.Converters | ||
{ | ||
public class WrapPanelItemWidthConverter : IValueConverter | ||
public class WrapPanelItemWidthMultiConverter : IMultiValueConverter | ||
{ | ||
public double MinItemWidth { get; set; } = 300; | ||
public double MaxItemWidth { get; set; } = 720; | ||
public double Margin { get; set; } = 10; | ||
public double SmallItemWidth { get; set; } = 380; | ||
public double LargeItemWidth { get; set; } = 720; | ||
|
||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
var panelWidth = (double)value; | ||
var items = ((IEnumerable<ISettingViewModel>)((CollectionViewSource)parameter)?.Source)?.Count() ?? 0; | ||
if (items > 1) | ||
var fullPanelWidth = (double)values[0] - Margin; | ||
var items = (IEnumerable<ISettingViewModel>)values[1]; | ||
if (values.Length > 2) | ||
{ | ||
if (panelWidth <= MinItemWidth) | ||
{ | ||
return MinItemWidth; | ||
} | ||
return fullPanelWidth; | ||
} | ||
|
||
var nonGroupingItems = items.Except(items.OfType<ISettingGroupViewModel>()).ToArray(); | ||
var isSingleItem = nonGroupingItems.Length == 1; | ||
|
||
if (isSingleItem || fullPanelWidth <= SmallItemWidth) | ||
{ | ||
return fullPanelWidth; | ||
} | ||
|
||
if (nonGroupingItems.Length >= 4 && fullPanelWidth >= 4 * SmallItemWidth) | ||
{ | ||
return fullPanelWidth / 4d; | ||
} | ||
|
||
if (nonGroupingItems.Length >= 3 && fullPanelWidth >= 3 * SmallItemWidth) | ||
{ | ||
return fullPanelWidth / 3d; | ||
} | ||
|
||
if (nonGroupingItems.Length >= 2 && fullPanelWidth >= 2 * SmallItemWidth) | ||
{ | ||
return fullPanelWidth / 2d; | ||
} | ||
|
||
var maxWidthColumns = panelWidth / MaxItemWidth; | ||
if (maxWidthColumns > 2) | ||
if (nonGroupingItems.Length >= 3 && nonGroupingItems.Length % 3 == 0) | ||
{ | ||
var idealWidth = (int)(fullPanelWidth / 3d); | ||
if (idealWidth < SmallItemWidth) | ||
{ | ||
return panelWidth / (int)maxWidthColumns; | ||
return fullPanelWidth; | ||
} | ||
return idealWidth; | ||
} | ||
|
||
var minWidthColumns = panelWidth / MinItemWidth; | ||
if (minWidthColumns > 1.5) | ||
if (nonGroupingItems.Length >= 2 && nonGroupingItems.Length % 2 == 0) | ||
{ | ||
var idealWidth = (int)(fullPanelWidth / 2d); | ||
if (idealWidth < SmallItemWidth) | ||
{ | ||
return panelWidth / (int)minWidthColumns; | ||
return fullPanelWidth; | ||
} | ||
return idealWidth; | ||
} | ||
|
||
return fullPanelWidth; | ||
} | ||
|
||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
|
||
public class WrapPanelItemWidthConverter : IValueConverter | ||
{ | ||
public double MinItemWidth { get; set; } = 380; | ||
public double MaxItemWidth { get; set; } = 720; | ||
|
||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
var panelWidth = (double)value; | ||
if (panelWidth <= MinItemWidth) | ||
{ | ||
return MinItemWidth; | ||
} | ||
|
||
var maxWidthColumns = panelWidth / MaxItemWidth; | ||
if (maxWidthColumns > 2) | ||
{ | ||
return panelWidth / (int)maxWidthColumns - 32; | ||
} | ||
|
||
var minWidthColumns = panelWidth / MinItemWidth; | ||
if (minWidthColumns > 2) | ||
{ | ||
return panelWidth / (int)minWidthColumns - 32; | ||
} | ||
|
||
|
||
return panelWidth; | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
return value; | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.