Skip to content

Commit

Permalink
[Editor] - Added functionality to work around issue with ribbon group…
Browse files Browse the repository at this point in the history
…s that have long names, and not enough content that ended up clipping the group text.
  • Loading branch information
Tape-Worm committed Sep 21, 2021
1 parent b339f67 commit eb34774
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions Tools/Editor/Gorgon.Editor/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,7 @@ public FormMain()

RibbonMain.AllowFormIntegrate = false;
PanelProject.MainRibbon = RibbonMain;
_ribbonMerger.FixGroupWidths();
}

/// <summary>Initializes a new instance of the <see cref="FormMain"/> class.</summary>
Expand Down
22 changes: 22 additions & 0 deletions Tools/Editor/Gorgon.Editor/RibbonMerger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Windows.Forms;
using Drawing = System.Drawing;
using Gorgon.Math;
using Krypton.Ribbon;

Expand Down Expand Up @@ -346,6 +348,8 @@ public void Merge(KryptonRibbon ribbon)
// Restore the selected tab.
TargetRibbon.SelectedContext = selectedContext;
TargetRibbon.SelectedTab = selectedTab;

FixGroupWidths();
}

/// <summary>
Expand Down Expand Up @@ -378,6 +382,24 @@ public void Unmerge(KryptonRibbon ribbon)
TargetRibbon.ResetSelectedTab();
}
}

/// <summary>
/// Function to correct the clipping for groups that have long names, but little content.
/// </summary>
public void FixGroupWidths()
{
using Drawing.Graphics g = Drawing.Graphics.FromHwnd(TargetRibbon.Parent.Handle);
double dpi = g.DpiY / 96.0;

foreach (KryptonRibbonTab tab in TargetRibbon.RibbonTabs)
{
foreach (KryptonRibbonGroup grp in tab.Groups)
{
Drawing.Size size = TextRenderer.MeasureText(g, grp.TextLine1 + (string.IsNullOrWhiteSpace(grp.TextLine2) ? " " + grp.TextLine2 : string.Empty), TargetRibbon.Parent.Font);
grp.MinimumWidth = size.Width + (int)(8 * dpi);
}
}
}
#endregion

#region Constructor/Finalizer.
Expand Down

0 comments on commit eb34774

Please sign in to comment.