add visibility options for the tab close button
This commit is contained in:
@@ -14,6 +14,7 @@ namespace FlaxEditor.GUI.Docking
|
|||||||
public class DockPanelProxy : ContainerControl
|
public class DockPanelProxy : ContainerControl
|
||||||
{
|
{
|
||||||
private DockPanel _panel;
|
private DockPanel _panel;
|
||||||
|
private InterfaceOptions.TabCloseButtonVisibility closeButtonVisibility;
|
||||||
private double _dragEnterTime = -1;
|
private double _dragEnterTime = -1;
|
||||||
private float _tabHeight = Editor.Instance.Options.Options.Interface.TabHeight;
|
private float _tabHeight = Editor.Instance.Options.Options.Interface.TabHeight;
|
||||||
private bool _useMinimumTabWidth = Editor.Instance.Options.Options.Interface.UseMinimumTabWidth;
|
private bool _useMinimumTabWidth = Editor.Instance.Options.Options.Interface.UseMinimumTabWidth;
|
||||||
@@ -74,6 +75,14 @@ namespace FlaxEditor.GUI.Docking
|
|||||||
_panel = panel;
|
_panel = panel;
|
||||||
AnchorPreset = AnchorPresets.StretchAll;
|
AnchorPreset = AnchorPresets.StretchAll;
|
||||||
Offsets = Margin.Zero;
|
Offsets = Margin.Zero;
|
||||||
|
|
||||||
|
Editor.Instance.Options.OptionsChanged += OnEditorOptionsChanged;
|
||||||
|
OnEditorOptionsChanged(Editor.Instance.Options.Options);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnEditorOptionsChanged(EditorOptions options)
|
||||||
|
{
|
||||||
|
closeButtonVisibility = options.Interface.ShowTabCloseButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
private DockWindow GetTabAtPos(Float2 position, out bool closeButton)
|
private DockWindow GetTabAtPos(Float2 position, out bool closeButton)
|
||||||
@@ -87,8 +96,8 @@ namespace FlaxEditor.GUI.Docking
|
|||||||
var crossRect = new Rectangle(Width - DockPanel.DefaultButtonsSize - DockPanel.DefaultButtonsMargin, (HeaderRectangle.Height - DockPanel.DefaultButtonsSize) / 2, DockPanel.DefaultButtonsSize, DockPanel.DefaultButtonsSize);
|
var crossRect = new Rectangle(Width - DockPanel.DefaultButtonsSize - DockPanel.DefaultButtonsMargin, (HeaderRectangle.Height - DockPanel.DefaultButtonsSize) / 2, DockPanel.DefaultButtonsSize, DockPanel.DefaultButtonsSize);
|
||||||
if (HeaderRectangle.Contains(position))
|
if (HeaderRectangle.Contains(position))
|
||||||
{
|
{
|
||||||
closeButton = crossRect.Contains(position);
|
|
||||||
result = _panel.GetTab(0);
|
result = _panel.GetTab(0);
|
||||||
|
closeButton = crossRect.Contains(position) && IsCloseButtonVisible(result, closeButtonVisibility);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -97,9 +106,7 @@ namespace FlaxEditor.GUI.Docking
|
|||||||
for (int i = 0; i < tabsCount; i++)
|
for (int i = 0; i < tabsCount; i++)
|
||||||
{
|
{
|
||||||
var tab = _panel.GetTab(i);
|
var tab = _panel.GetTab(i);
|
||||||
var titleSize = tab.TitleSize;
|
float width = CalculateTabWidth(tab, closeButtonVisibility);
|
||||||
var iconWidth = tab.Icon.IsValid ? DockPanel.DefaultButtonsSize + DockPanel.DefaultLeftTextMargin : 0;
|
|
||||||
var width = titleSize.X + DockPanel.DefaultButtonsSize + 2 * DockPanel.DefaultButtonsMargin + DockPanel.DefaultLeftTextMargin + DockPanel.DefaultRightTextMargin + iconWidth;
|
|
||||||
|
|
||||||
if (_useMinimumTabWidth && width < _minimumTabWidth)
|
if (_useMinimumTabWidth && width < _minimumTabWidth)
|
||||||
width = _minimumTabWidth;
|
width = _minimumTabWidth;
|
||||||
@@ -109,7 +116,7 @@ namespace FlaxEditor.GUI.Docking
|
|||||||
if (isMouseOver)
|
if (isMouseOver)
|
||||||
{
|
{
|
||||||
var crossRect = new Rectangle(x + width - DockPanel.DefaultButtonsSize - DockPanel.DefaultButtonsMargin, (HeaderRectangle.Height - DockPanel.DefaultButtonsSize) / 2, DockPanel.DefaultButtonsSize, DockPanel.DefaultButtonsSize);
|
var crossRect = new Rectangle(x + width - DockPanel.DefaultButtonsSize - DockPanel.DefaultButtonsMargin, (HeaderRectangle.Height - DockPanel.DefaultButtonsSize) / 2, DockPanel.DefaultButtonsSize, DockPanel.DefaultButtonsSize);
|
||||||
closeButton = crossRect.Contains(position);
|
closeButton = crossRect.Contains(position) && IsCloseButtonVisible(tab, closeButtonVisibility);
|
||||||
result = tab;
|
result = tab;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -120,6 +127,24 @@ namespace FlaxEditor.GUI.Docking
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool IsCloseButtonVisible(DockWindow win, InterfaceOptions.TabCloseButtonVisibility visibilityMode)
|
||||||
|
{
|
||||||
|
return visibilityMode != InterfaceOptions.TabCloseButtonVisibility.Never &&
|
||||||
|
(visibilityMode == InterfaceOptions.TabCloseButtonVisibility.Always ||
|
||||||
|
(visibilityMode == InterfaceOptions.TabCloseButtonVisibility.SelectedTab && _panel.SelectedTab == win));
|
||||||
|
}
|
||||||
|
|
||||||
|
private float CalculateTabWidth(DockWindow win, InterfaceOptions.TabCloseButtonVisibility visibilityMode)
|
||||||
|
{
|
||||||
|
var iconWidth = win.Icon.IsValid ? DockPanel.DefaultButtonsSize + DockPanel.DefaultLeftTextMargin : 0;
|
||||||
|
var width = win.TitleSize.X + DockPanel.DefaultLeftTextMargin + DockPanel.DefaultRightTextMargin + iconWidth;
|
||||||
|
|
||||||
|
if (IsCloseButtonVisible(win, visibilityMode))
|
||||||
|
width += 2 * DockPanel.DefaultButtonsMargin + DockPanel.DefaultButtonsSize;
|
||||||
|
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
private void GetTabRect(DockWindow win, out Rectangle bounds)
|
private void GetTabRect(DockWindow win, out Rectangle bounds)
|
||||||
{
|
{
|
||||||
FlaxEngine.Assertions.Assert.IsTrue(_panel.ContainsTab(win));
|
FlaxEngine.Assertions.Assert.IsTrue(_panel.ContainsTab(win));
|
||||||
@@ -137,7 +162,7 @@ namespace FlaxEditor.GUI.Docking
|
|||||||
{
|
{
|
||||||
var tab = _panel.GetTab(i);
|
var tab = _panel.GetTab(i);
|
||||||
var titleSize = tab.TitleSize;
|
var titleSize = tab.TitleSize;
|
||||||
float width = titleSize.X + DockPanel.DefaultButtonsSize + 2 * DockPanel.DefaultButtonsMargin + DockPanel.DefaultLeftTextMargin + DockPanel.DefaultRightTextMargin;
|
float width = CalculateTabWidth(tab, closeButtonVisibility);
|
||||||
if (tab == win)
|
if (tab == win)
|
||||||
{
|
{
|
||||||
bounds = new Rectangle(x, 0, width, HeaderRectangle.Height);
|
bounds = new Rectangle(x, 0, width, HeaderRectangle.Height);
|
||||||
@@ -234,12 +259,15 @@ namespace FlaxEditor.GUI.Docking
|
|||||||
TextAlignment.Near,
|
TextAlignment.Near,
|
||||||
TextAlignment.Center);
|
TextAlignment.Center);
|
||||||
|
|
||||||
// Draw cross
|
if (IsCloseButtonVisible(tab, closeButtonVisibility))
|
||||||
var crossRect = new Rectangle(Width - DockPanel.DefaultButtonsSize - DockPanel.DefaultButtonsMargin, (HeaderRectangle.Height - DockPanel.DefaultButtonsSize) / 2, DockPanel.DefaultButtonsSize, DockPanel.DefaultButtonsSize);
|
{
|
||||||
bool isMouseOverCross = isMouseOver && crossRect.Contains(MousePosition);
|
// Draw cross
|
||||||
if (isMouseOverCross)
|
var crossRect = new Rectangle(Width - DockPanel.DefaultButtonsSize - DockPanel.DefaultButtonsMargin, (HeaderRectangle.Height - DockPanel.DefaultButtonsSize) / 2, DockPanel.DefaultButtonsSize, DockPanel.DefaultButtonsSize);
|
||||||
Render2D.FillRectangle(crossRect, (containsFocus ? style.BackgroundSelected : style.LightBackground) * 1.3f);
|
bool isMouseOverCross = isMouseOver && crossRect.Contains(MousePosition);
|
||||||
Render2D.DrawSprite(style.Cross, crossRect, isMouseOverCross ? style.Foreground : style.ForegroundGrey);
|
if (isMouseOverCross)
|
||||||
|
Render2D.FillRectangle(crossRect, (containsFocus ? style.BackgroundSelected : style.LightBackground) * 1.3f);
|
||||||
|
Render2D.DrawSprite(style.Cross, crossRect, isMouseOverCross ? style.Foreground : style.ForegroundGrey);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -253,10 +281,9 @@ namespace FlaxEditor.GUI.Docking
|
|||||||
// Cache data
|
// Cache data
|
||||||
var tab = _panel.GetTab(i);
|
var tab = _panel.GetTab(i);
|
||||||
var tabColor = Color.Black;
|
var tabColor = Color.Black;
|
||||||
var titleSize = tab.TitleSize;
|
|
||||||
var iconWidth = tab.Icon.IsValid ? DockPanel.DefaultButtonsSize + DockPanel.DefaultLeftTextMargin : 0;
|
var iconWidth = tab.Icon.IsValid ? DockPanel.DefaultButtonsSize + DockPanel.DefaultLeftTextMargin : 0;
|
||||||
|
|
||||||
var width = titleSize.X + DockPanel.DefaultButtonsSize + 2 * DockPanel.DefaultButtonsMargin + DockPanel.DefaultLeftTextMargin + DockPanel.DefaultRightTextMargin + iconWidth;
|
float width = CalculateTabWidth(tab, closeButtonVisibility);
|
||||||
|
|
||||||
if (_useMinimumTabWidth && width < _minimumTabWidth)
|
if (_useMinimumTabWidth && width < _minimumTabWidth)
|
||||||
width = _minimumTabWidth;
|
width = _minimumTabWidth;
|
||||||
@@ -303,7 +330,7 @@ namespace FlaxEditor.GUI.Docking
|
|||||||
TextAlignment.Center);
|
TextAlignment.Center);
|
||||||
|
|
||||||
// Draw cross
|
// Draw cross
|
||||||
if (isSelected || isMouseOver)
|
if (IsCloseButtonVisible(tab, closeButtonVisibility))
|
||||||
{
|
{
|
||||||
var crossRect = new Rectangle(x + width - DockPanel.DefaultButtonsSize - DockPanel.DefaultButtonsMargin, (HeaderRectangle.Height - DockPanel.DefaultButtonsSize) / 2, DockPanel.DefaultButtonsSize, DockPanel.DefaultButtonsSize);
|
var crossRect = new Rectangle(x + width - DockPanel.DefaultButtonsSize - DockPanel.DefaultButtonsMargin, (HeaderRectangle.Height - DockPanel.DefaultButtonsSize) / 2, DockPanel.DefaultButtonsSize, DockPanel.DefaultButtonsSize);
|
||||||
bool isMouseOverCross = isMouseOver && crossRect.Contains(MousePosition);
|
bool isMouseOverCross = isMouseOver && crossRect.Contains(MousePosition);
|
||||||
@@ -312,7 +339,7 @@ namespace FlaxEditor.GUI.Docking
|
|||||||
Render2D.DrawSprite(style.Cross, crossRect, isMouseOverCross ? style.Foreground : style.ForegroundGrey);
|
Render2D.DrawSprite(style.Cross, crossRect, isMouseOverCross ? style.Foreground : style.ForegroundGrey);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move
|
// Set the start position for the next tab
|
||||||
x += width;
|
x += width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,6 +76,25 @@ namespace FlaxEditor.Options
|
|||||||
DockBottom = DockState.DockBottom
|
DockBottom = DockState.DockBottom
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Options for the visibility status of the tab close button.
|
||||||
|
/// </summary>
|
||||||
|
public enum TabCloseButtonVisibility
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Never show the close button.
|
||||||
|
/// </summary>
|
||||||
|
Never,
|
||||||
|
/// <summary>
|
||||||
|
/// Show the close button on tabs that are currently selected.
|
||||||
|
/// </summary>
|
||||||
|
SelectedTab,
|
||||||
|
/// <summary>
|
||||||
|
/// Show the close button on all tabs that can be closed.
|
||||||
|
/// </summary>
|
||||||
|
Always
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Options for the action taken by the play button.
|
/// Options for the action taken by the play button.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -295,6 +314,13 @@ namespace FlaxEditor.Options
|
|||||||
[EditorDisplay("Tabs & Windows", "New Window Location"), EditorOrder(150), Tooltip("Define the opening method for new windows, open in a new tab by default.")]
|
[EditorDisplay("Tabs & Windows", "New Window Location"), EditorOrder(150), Tooltip("Define the opening method for new windows, open in a new tab by default.")]
|
||||||
public DockStateProxy NewWindowLocation { get; set; } = DockStateProxy.Float;
|
public DockStateProxy NewWindowLocation { get; set; } = DockStateProxy.Float;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating when the tab close button should be visible.
|
||||||
|
/// </summary>
|
||||||
|
[DefaultValue(TabCloseButtonVisibility.SelectedTab)]
|
||||||
|
[EditorDisplay("Tabs & Windows"), EditorOrder(151)]
|
||||||
|
public TabCloseButtonVisibility ShowTabCloseButton { get; set; } = TabCloseButtonVisibility.SelectedTab;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the timestamps prefix mode for output log messages.
|
/// Gets or sets the timestamps prefix mode for output log messages.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user