void CalculateTab(ThemedDocumentPageHandler tab, int i, ref float posx) { var textSize = string.IsNullOrEmpty(tab.Text) ? Size.Empty : Size.Ceiling(Font.MeasureString(tab.Text)); var size = textSize; var prevnextsel = mousePos.X > nextPrevWidth || i == -1; var textoffset = 0; if (tab.Image != null) { textoffset = tab.Image.Size.Width + TabPadding.Left; size.Width += textoffset; } var closesize = tabDrawable.Height / 2; var tabRect = new RectangleF(posx, 0, size.Width + (tab.Closable ? closesize + TabPadding.Horizontal + TabPadding.Right : TabPadding.Horizontal), tabDrawable.Height); if (i == selectedIndex && draggingLocation != null) { tabRect.Offset(mousePos.X - draggingLocation.Value.X, 0); } tab.Rect = tabRect; tab.CloseRect = new RectangleF(tabRect.X + tab.Rect.Width - tabDrawable.Height / 4 - closesize, tabDrawable.Height / 4, closesize, closesize); tab.TextRect = new RectangleF(tabRect.X + TabPadding.Left + textoffset, (tabDrawable.Height - size.Height) / 2, textSize.Width, textSize.Height); posx += tab.Rect.Width; }
/// <summary> /// Initializes a new instance of the <see cref="T:Eto.Forms.ThemedControls.ThemedDocumentControlHandler"/> class. /// </summary> public ThemedDocumentControlHandler() { mousePos = new PointF(-1, -1); selectedIndex = -1; nextPrevWidth = 0; startx = 0; font = SystemFonts.Default(); tabDrawable = new Drawable(); contentPanel = new Panel(); tabPrev = new ThemedDocumentPageHandler { Text = "<", Closable = false }; tabNext = new ThemedDocumentPageHandler { Text = ">", Closable = false }; tabDrawable.MouseMove += Drawable_MouseMove; tabDrawable.MouseLeave += Drawable_MouseLeave; tabDrawable.MouseDown += Drawable_MouseDown; tabDrawable.Paint += Drawable_Paint; tabDrawable.MouseUp += Drawable_MouseUp; Control = new TableLayout(tabDrawable, contentPanel); Control.SizeChanged += Widget_SizeChanged; }
internal void Update(ThemedDocumentPageHandler handler) { Calculate(); var index = pages.FindIndex(obj => ReferenceEquals(obj.Handler, handler)); if (index != -1) { if (SelectedIndex == index) { SetPageContent(); } else { tabDrawable.Invalidate(); } } }
void DrawTab(Graphics g, ThemedDocumentPageHandler tab, int i) { var prevnextsel = mousePos.X > nextPrevWidth || i == -1; var closeSelected = IsCloseSelected(tab); var tabRect = tab.Rect; var textRect = tab.TextRect; var closerect = tab.CloseRect; var closemargin = closerect.Height / 3; var size = tabRect.Size; var textcolor = Enabled ? SystemColors.ControlText : SystemColors.DisabledText; var backcolor = SystemColors.Control; if (selectedIndex >= 0 && i == selectedIndex) { textcolor = Enabled ? SystemColors.HighlightText : SystemColors.DisabledText; backcolor = SystemColors.Highlight; backcolor.A *= 0.8f; } if (draggingLocation == null && tabRect.Contains(mousePos) && prevnextsel && !closeSelected && Enabled) { textcolor = SystemColors.HighlightText; backcolor = SystemColors.Highlight; } g.FillRectangle(backcolor, tabRect); if (tab.Image != null) { var imageSize = tab.Image.Size; g.DrawImage(tab.Image, tabRect.X + TabPadding.Left + (maxImageSize.Width - imageSize.Width) / 2, (tabDrawable.Height - imageSize.Height) / 2); } g.DrawText(Font, textcolor, textRect.Location, tab.Text); if (tab.Closable) { g.FillRectangle(closeSelected ? SystemColors.Highlight : SystemColors.Control, closerect); var closeForeground = Enabled ? closeSelected ? SystemColors.HighlightText : SystemColors.ControlText : SystemColors.DisabledText; 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); } }
bool IsCloseSelected(ThemedDocumentPageHandler tab) { var prevnextsel = mousePos.X > nextPrevWidth; return(draggingLocation == null && tab.Closable && tab.CloseRect.Contains(mousePos) && prevnextsel && Enabled); }