Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve DocumentControl styling capabilities #2605

Merged
97 changes: 79 additions & 18 deletions src/Eto/Forms/ThemedControls/ThemedDocumentControlHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,25 @@ public class ThemedDocumentControlHandler : ThemedContainerHandler<TableLayout,
Panel contentPanel;
Font font;

Color backgroundColor;
Color disabledForegroundColor;
Color closeBackgroundColor;
Color closeHighlightBackgroundColor;
Color closeForegroundColor;
Color closeHighlightForegroundColor;
Color tabBackgroundColor;
Color tabHighlightBackgroundColor;
Color tabHoverBackgroundColor;
Color tabForegroundColor;
Color tabHighlightForegroundColor;
Color tabHoverForegroundColor;

int closeCornerRadius;

static Padding DefaultTabPadding = 6;

static readonly object TabPadding_Key = new object();
private int minImageSquareSide = 16;
int minImageSquareSide = 16;

/// <summary>
/// Gets or sets the padding inside each tab around the text.
Expand Down Expand Up @@ -75,6 +80,17 @@ public Font Font
}
}

/// <inheritdoc />
public override Color BackgroundColor
{
get => backgroundColor;
set
{
backgroundColor = value;
tabDrawable.Invalidate();
}
}

/// <summary>
/// Gets or sets the disabled foreground color.
/// </summary>
Expand Down Expand Up @@ -117,6 +133,20 @@ public Color CloseHighlightBackgroundColor
}
}

/// <summary>
/// Gets or sets the corner radius of the close button.
/// </summary>
/// <value>The corner radius of the close button.</value>
public int CloseCornerRadius
{
get { return closeCornerRadius; }
set
{
closeCornerRadius = value;
tabDrawable.Invalidate();
}
}

/// <summary>
/// Gets or sets the foreground color for the close button.
/// </summary>
Expand Down Expand Up @@ -160,9 +190,9 @@ public Color TabBackgroundColor
}

/// <summary>
/// Gets or sets the highlight background color for the highlighted tab.
/// Gets or sets the highlight background color for the highlighted or selected tab.
/// </summary>
/// <value>The highlight background color for the close highlighted tab.</value>
/// <value>The highlight background color for the highlighted or selected tab.</value>
public Color TabHighlightBackgroundColor
{
get { return tabHighlightBackgroundColor; }
Expand All @@ -173,6 +203,20 @@ public Color TabHighlightBackgroundColor
}
}

/// <summary>
/// Gets or sets the background color for the tab under mouse.
/// </summary>
/// <value>The background color for the tab under mouse.</value>
public Color TabHoverBackgroundColor
{
get { return tabHoverBackgroundColor; }
set
{
tabHoverBackgroundColor = value;
tabDrawable.Invalidate();
}
}

/// <summary>
/// Gets or sets the foreground color for the tab.
/// </summary>
Expand All @@ -188,9 +232,9 @@ public Color TabForegroundColor
}

/// <summary>
/// Gets or sets the highlight foreground color for the close button.
/// Gets or sets the highlight foreground color for the highlighted or selected tab.
/// </summary>
/// <value>The highlight foreground color for the close button.</value>
/// <value>The foreground color for the highlighted or selected tab.</value>
public Color TabHighlightForegroundColor
{
get { return tabHighlightForegroundColor; }
Expand All @@ -201,6 +245,19 @@ public Color TabHighlightForegroundColor
}
}

/// <summary>
/// Gets or sets the foreground color for the tab under mouse.
/// </summary>
/// <value>The foreground color for the tab under mouse.</value>
public Color TabHoverForegroundColor
{
get { return tabHoverForegroundColor; }
set
{
tabHoverForegroundColor = value;
tabDrawable.Invalidate();
}
}

/// <summary>
/// Gets or sets a value indicating whether to use a fixed tab height.
Expand Down Expand Up @@ -229,15 +286,18 @@ public ThemedDocumentControlHandler()
nextPrevWidth = 0;
startx = 0;
font = SystemFonts.Default();
backgroundColor = SystemColors.Control;
disabledForegroundColor = SystemColors.DisabledText;
closeBackgroundColor = SystemColors.Control;
closeHighlightBackgroundColor = SystemColors.Highlight;
closeForegroundColor = SystemColors.ControlText;
closeHighlightForegroundColor = SystemColors.HighlightText;
tabBackgroundColor = SystemColors.Control;
tabHighlightBackgroundColor = SystemColors.Highlight;
tabHoverBackgroundColor = new Color(SystemColors.Highlight, 0.8f);
tabForegroundColor = SystemColors.ControlText;
tabHighlightForegroundColor = SystemColors.HighlightText;
tabHoverForegroundColor = SystemColors.HighlightText;

tabDrawable = new Drawable();

Expand Down Expand Up @@ -494,7 +554,7 @@ void Drawable_MouseDown(object sender, MouseEventArgs e)
}
else
SelectedIndex = i;

break;
}
}
Expand Down Expand Up @@ -596,7 +656,7 @@ void Drawable_Paint(object sender, PaintEventArgs e)
{
var g = e.Graphics;

g.Clear(SystemColors.Control);
g.Clear(BackgroundColor);

var posx = nextPrevWidth + startx;

Expand Down Expand Up @@ -633,7 +693,7 @@ void CalculateTab(ThemedDocumentPageHandler tab, int i, ref float posx)
size.Width += textoffset;
}

var closesize = tabDrawable.Height / 2;
var closesize = (int)Math.Floor(tabDrawable.Height * 0.6);
var tabRect = new RectangleF(posx, 0, size.Width + (tab.Closable ? closesize + tabPadding.Horizontal + tabPadding.Right : tabPadding.Horizontal), tabDrawable.Height);

if (i == selectedIndex && draggingLocation != null)
Expand All @@ -643,7 +703,7 @@ void CalculateTab(ThemedDocumentPageHandler tab, int i, ref float posx)

tab.Rect = tabRect;

tab.CloseRect = new RectangleF(tabRect.X + tab.Rect.Width - tabPadding.Right - closesize, tabDrawable.Height / 4, closesize, closesize);
tab.CloseRect = new RectangleF(tabRect.X + tab.Rect.Width - tabPadding.Right - closesize, (tabDrawable.Height - closesize) / 2, closesize, closesize);
tab.TextRect = new RectangleF(tabRect.X + tabPadding.Left + textoffset, (tabDrawable.Height - size.Height) / 2, textSize.Width, textSize.Height);

posx += tab.Rect.Width;
Expand All @@ -662,22 +722,19 @@ void DrawTab(Graphics g, ThemedDocumentPageHandler tab, int i)
var tabRect = tab.Rect;
var textRect = tab.TextRect;
var closerect = tab.CloseRect;
var closemargin = closerect.Height / 3;
var size = tabRect.Size;
var closemargin = closerect.Height / 4;

var textcolor = Enabled ? TabForegroundColor : DisabledForegroundColor;
var backcolor = TabBackgroundColor;
if (selectedIndex >= 0 && i == selectedIndex)
{
textcolor = Enabled ? TabHighlightForegroundColor : DisabledForegroundColor;
backcolor = TabHighlightBackgroundColor;
backcolor.A *= 0.8f;
}

if (draggingLocation == null && tabRect.Contains(mousePos) && prevnextsel && !closeSelected && Enabled)
else if (draggingLocation == null && tabRect.Contains(mousePos) && prevnextsel && Enabled)
ievgen-baida marked this conversation as resolved.
Show resolved Hide resolved
{
textcolor = TabHighlightForegroundColor;
backcolor = TabHighlightBackgroundColor;
textcolor = TabHoverForegroundColor;
backcolor = TabHoverBackgroundColor;
}

g.FillRectangle(backcolor, tabRect);
Expand All @@ -692,12 +749,16 @@ void DrawTab(Graphics g, ThemedDocumentPageHandler tab, int i)

if (tab.Closable)
{
g.FillRectangle(closeSelected ? CloseHighlightBackgroundColor : CloseBackgroundColor, closerect);
var closeBackground = closeSelected ? CloseHighlightBackgroundColor : CloseBackgroundColor;
if (closeCornerRadius > 0)
g.FillPath(closeBackground, GraphicsPath.GetRoundRect(closerect, closeCornerRadius));
else
g.FillRectangle(closeBackground, closerect);

var closeForeground = Enabled ? closeSelected ? CloseHighlightForegroundColor : CloseForegroundColor : DisabledForegroundColor;
g.DrawLine(closeForeground, closerect.X + closemargin, closerect.Y + closemargin, closerect.X + closerect.Width - 1 - closemargin, closerect.Y + closerect.Height - 1 - closemargin);
g.DrawLine(closeForeground, closerect.X + closemargin, closerect.Y + closerect.Height - 1 - closemargin, closerect.X + closerect.Width - 1 - closemargin, closerect.Y + closemargin);
}

}

/// <summary>
Expand Down
Loading