Skip to content

Commit

Permalink
Fixes #542 by properly reducing min/max items per row in InRibbonGallery
Browse files Browse the repository at this point in the history
  • Loading branch information
batzen committed Apr 1, 2018
1 parent 99fd3f3 commit 82351d8
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 15 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

- ### Bug fixes
- [#535](../../issues/535) - BorderBush on bottom of RibbonTabItem (and Ribbon)
- [#542](../../issues/542) - InRibbonGallery not reducing properly
- [#543](../../issues/543) - Using images that can't be found during design time crashes designer
A generic "error" image is rendered during design time and an exception is thrown during runtime.
- [#551](../../issues/551) - "Auto" size for ribbon group box header to support custom font sizes (thanks @chrfin)
Expand Down
2 changes: 1 addition & 1 deletion Fluent.Ribbon.Showcase/TestContent.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1883,7 +1883,7 @@
it will reduce all InRibbonGalleries in this group by one item-->
<Fluent:RibbonTabItem Header="Galleries"
KeyTip="GA"
ReduceOrder="(FirstGalleryGroup),(FirstGalleryGroup),(FirstGalleryGroup),(FirstGalleryGroup),(FirstGalleryGroup),(SecondGalleryGroup),(SecondGalleryGroup),(SecondGalleryGroup),(SecondGalleryGroup)">
ReduceOrder="(FirstGalleryGroup),(FirstGalleryGroup),(FirstGalleryGroup),(FirstGalleryGroup),(FirstGalleryGroup),(SecondGalleryGroup),(SecondGalleryGroup),(SecondGalleryGroup),(SecondGalleryGroup),(A),(A),(A),(A),(A),(A),(A),(A),(A),(A)">
<Fluent:RibbonGroupBox Header="Without Grouping"
Name="FirstGalleryGroup">

Expand Down
28 changes: 22 additions & 6 deletions Fluent.Ribbon/Controls/GalleryGroupContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public int MinItemsInRow
/// </summary>
public static readonly DependencyProperty MinItemsInRowProperty =
DependencyProperty.Register(nameof(MinItemsInRow), typeof(int),
typeof(GalleryGroupContainer), new PropertyMetadata(IntBoxes.Zero, OnMaxMinItemsInRowChanged));
typeof(GalleryGroupContainer), new FrameworkPropertyMetadata(IntBoxes.Zero, FrameworkPropertyMetadataOptions.AffectsMeasure, OnMaxMinItemsInRowChanged));

#endregion

Expand All @@ -150,7 +150,7 @@ public int MaxItemsInRow
/// </summary>
public static readonly DependencyProperty MaxItemsInRowProperty =
DependencyProperty.Register(nameof(MaxItemsInRow), typeof(int),
typeof(GalleryGroupContainer), new PropertyMetadata(int.MaxValue, OnMaxMinItemsInRowChanged));
typeof(GalleryGroupContainer), new FrameworkPropertyMetadata(int.MaxValue, FrameworkPropertyMetadataOptions.AffectsMeasure, OnMaxMinItemsInRowChanged));

#endregion

Expand All @@ -166,12 +166,21 @@ private static void OnMaxMinItemsInRowChanged(DependencyObject d, DependencyProp
{
var galleryGroupContainer = (GalleryGroupContainer)d;
galleryGroupContainer.minMaxWidthNeedsToBeUpdated = true;
galleryGroupContainer.UpdateMinAndMaxWidth();
}

#endregion

#region Initialization

/// <summary>
/// Creates a new instance of <see cref="GalleryGroupContainer"/>.
/// </summary>
public GalleryGroupContainer()
{
this.Unloaded += this.HandleUnloaded;
}

/// <summary>
/// Static constructor
/// </summary>
Expand Down Expand Up @@ -227,8 +236,8 @@ private void UpdateMinAndMaxWidth()
if (this.Orientation == Orientation.Vertical)
{
// Min/Max is used for Horizontal layout only
this.RealItemsPanel.MinWidth = 0;
this.RealItemsPanel.MaxWidth = double.PositiveInfinity;
this.MinWidth = 0;
this.MaxWidth = double.PositiveInfinity;
return;
}

Expand All @@ -239,8 +248,8 @@ private void UpdateMinAndMaxWidth()
return;
}

this.RealItemsPanel.MinWidth = (Math.Min(this.Items.Count, this.MinItemsInRow) * itemWidth) + 0.1;
this.RealItemsPanel.MaxWidth = (Math.Min(this.Items.Count, this.MaxItemsInRow) * itemWidth) + 0.1;
this.MinWidth = (Math.Min(this.Items.Count, this.MinItemsInRow) * itemWidth) + 0.1;
this.MaxWidth = (Math.Min(this.Items.Count, this.MaxItemsInRow) * itemWidth) + 0.1;
}

private void HandleLoaded(object sender, RoutedEventArgs e)
Expand All @@ -255,6 +264,13 @@ private void HandleLoaded(object sender, RoutedEventArgs e)
this.InvalidateMeasure();
}

private void HandleUnloaded(object sender, RoutedEventArgs e)
{
this.itemsPanel = null;

this.minMaxWidthNeedsToBeUpdated = true;
}

/// <summary>
/// Determinates item's size (return Size.Empty in case of it is not possible)
/// </summary>
Expand Down
10 changes: 8 additions & 2 deletions Fluent.Ribbon/Controls/GalleryPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public int MinItemsInRow
/// </summary>
public static readonly DependencyProperty MinItemsInRowProperty =
DependencyProperty.Register(nameof(MinItemsInRow), typeof(int),
typeof(GalleryPanel), new PropertyMetadata(1));
typeof(GalleryPanel), new PropertyMetadata(1, OnMinOrMaxItemsInRowChanged));

#endregion

Expand All @@ -272,7 +272,13 @@ public int MaxItemsInRow
/// </summary>
public static readonly DependencyProperty MaxItemsInRowProperty =
DependencyProperty.Register(nameof(MaxItemsInRow), typeof(int),
typeof(GalleryPanel), new PropertyMetadata(int.MaxValue));
typeof(GalleryPanel), new PropertyMetadata(int.MaxValue, OnMinOrMaxItemsInRowChanged));

private static void OnMinOrMaxItemsInRowChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var galleryPanel = (GalleryPanel)d;
galleryPanel.UpdateMinAndMaxWidth();
}

#endregion

Expand Down
14 changes: 8 additions & 6 deletions Fluent.Ribbon/Controls/InRibbonGallery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1581,10 +1581,11 @@ public void Enlarge()
{
this.IsCollapsed = false;
}
else if (this.galleryPanel.MinItemsInRow < this.MaxItemsInRow)
else if (this.galleryPanel.MinItemsInRow < this.MinItemsInRow
|| this.galleryPanel.MaxItemsInRow < this.MaxItemsInRow)
{
this.galleryPanel.MinItemsInRow++;
this.galleryPanel.MaxItemsInRow = this.galleryPanel.MinItemsInRow;
this.galleryPanel.MinItemsInRow = Math.Min(this.galleryPanel.MinItemsInRow + 1, this.MinItemsInRow);
this.galleryPanel.MaxItemsInRow = Math.Min(this.galleryPanel.MaxItemsInRow + 1, this.MaxItemsInRow);
}
else
{
Expand All @@ -1601,10 +1602,11 @@ public void Enlarge()
/// </summary>
public void Reduce()
{
if (this.galleryPanel.MinItemsInRow > this.MinItemsInRow)
if (this.galleryPanel.MinItemsInRow > 1
|| this.galleryPanel.MaxItemsInRow > 1)
{
this.galleryPanel.MinItemsInRow--;
this.galleryPanel.MaxItemsInRow = this.galleryPanel.MinItemsInRow;
this.galleryPanel.MinItemsInRow = Math.Max(this.galleryPanel.MinItemsInRow - 1, 0);
this.galleryPanel.MaxItemsInRow = Math.Max(this.galleryPanel.MaxItemsInRow - 1, 0);
}
else if (this.CanCollapseToButton
&& this.IsCollapsed == false)
Expand Down

0 comments on commit 82351d8

Please sign in to comment.