Skip to content

Commit

Permalink
Make showing the navigation button on DocumentControl configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
eng-myousif committed Nov 14, 2023
1 parent d32ec56 commit 7862d01
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
26 changes: 23 additions & 3 deletions src/Eto/Forms/ThemedControls/ThemedDocumentControlHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class ThemedDocumentControlHandler : ThemedContainerHandler<TableLayout,
List<DocumentPage> pages = new List<DocumentPage>();
ThemedDocumentPageHandler tabPrev, tabNext;

bool allowNavigationButtons;
PointF mousePos;
int selectedIndex;
float nextPrevWidth;
Expand Down Expand Up @@ -43,6 +44,21 @@ public Padding TabPadding
set => Widget.Properties.Set(TabPadding_Key, value, DefaultTabPadding);
}

/// <summary>
/// Gets or sets a value indicating the tabs can be navigated by next and previous buttons.
/// </summary>
/// <value><c>true</c> if can be navigated by next and previous buttons; otherwise, <c>false</c>.</value>
public bool AllowNavigationButtons
{
get { return allowNavigationButtons; }
set
{
allowNavigationButtons = value;
Calculate();
tabDrawable.Invalidate();
}
}

/// <summary>
/// Gets or sets the font for the tab text.
/// </summary>
Expand Down Expand Up @@ -206,6 +222,7 @@ public ThemedDocumentControlHandler()
{
mousePos = new PointF(-1, -1);
selectedIndex = -1;
allowNavigationButtons = true;
nextPrevWidth = 0;
startx = 0;
font = SystemFonts.Default();
Expand Down Expand Up @@ -541,7 +558,7 @@ void CalculateTabs(bool force = false)
if (!force && !Widget.Loaded)
return;
var posx = 0f;
if (nextPrevWidth == 0f)
if (allowNavigationButtons && nextPrevWidth == 0f)
{
CalculateTab(tabPrev, -1, ref posx);
CalculateTab(tabNext, -1, ref posx);
Expand Down Expand Up @@ -578,8 +595,11 @@ void Drawable_Paint(object sender, PaintEventArgs e)

posx = 0;

DrawTab(g, tabPrev, -1);
DrawTab(g, tabNext, -1);
if (allowNavigationButtons)
{
DrawTab(g, tabPrev, -1);
DrawTab(g, tabNext, -1);
}
}

void CalculateTab(ThemedDocumentPageHandler tab, int i, ref float posx)
Expand Down
22 changes: 20 additions & 2 deletions test/Eto.Test/Sections/Controls/DocumentControlSection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Eto.Test.Sections.Controls
using Eto.Forms.ThemedControls;

namespace Eto.Test.Sections.Controls
{
[Section("Controls", typeof(DocumentControl))]
public class DocumentControlSection : Panel
Expand Down Expand Up @@ -29,7 +31,14 @@ public virtual Control Create()
new StackLayout
{
Orientation = Orientation.Horizontal,
Items = { AddPage(), RemovePage(), SelectPage(), allowReorder, enabled, null }
Items = {
AddPage(),
RemovePage(),
SelectPage(),
tabControl.Handler is ThemedDocumentControlHandler ? HasNavigationButtonsCheckBox() : null,
allowReorder,
enabled,
null }
},
new StackLayoutItem(tabControl, expand: true)
}
Expand Down Expand Up @@ -77,6 +86,15 @@ Control SelectPage()
return control;
}

Control HasNavigationButtonsCheckBox()
{
var control = new CheckBox { Text = "Has navigation buttons" };
control.Checked = ((ThemedDocumentControlHandler)tabControl.Handler).AllowNavigationButtons;
control.CheckedChanged += (sender, args) => ((ThemedDocumentControlHandler)tabControl.Handler).AllowNavigationButtons =
((CheckBox)sender).Checked ?? false;
return control;
}

DocumentControl DefaultTabs()
{
var control = CreateDocumentControl();
Expand Down

0 comments on commit 7862d01

Please sign in to comment.