mirror of
https://github.com/osukey/osukey.git
synced 2025-08-07 00:23:59 +09:00
Make MaxPages value a bindable
This commit is contained in:
@ -15,35 +15,40 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
typeof(PageSelector)
|
typeof(PageSelector)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private readonly PageSelector pageSelector;
|
||||||
|
|
||||||
public TestScenePageSelector()
|
public TestScenePageSelector()
|
||||||
{
|
{
|
||||||
Child = new PageSelector(200)
|
Child = pageSelector = new PageSelector
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
};
|
};
|
||||||
|
|
||||||
AddStep("1 max pages", () => redraw(1));
|
AddStep("10 max pages", () => setMaxPages(10));
|
||||||
AddStep("10 max pages", () => redraw(10));
|
AddStep("200 max pages, current 199", () =>
|
||||||
AddStep("200 max pages, current 199", () => redraw(200, 199));
|
|
||||||
AddStep("200 max pages, current 201", () => redraw(200, 201));
|
|
||||||
AddStep("200 max pages, current -10", () => redraw(200, -10));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void redraw(int maxPages, int currentPage = 0)
|
|
||||||
{
|
|
||||||
Clear();
|
|
||||||
|
|
||||||
var selector = new PageSelector(maxPages)
|
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
setMaxPages(200);
|
||||||
Origin = Anchor.Centre,
|
setCurrentPage(199);
|
||||||
};
|
});
|
||||||
|
AddStep("200 max pages, current 201", () =>
|
||||||
if (currentPage != 0)
|
{
|
||||||
selector.CurrentPage.Value = currentPage;
|
setMaxPages(200);
|
||||||
|
setCurrentPage(201);
|
||||||
Add(selector);
|
});
|
||||||
|
AddStep("200 max pages, current -10", () =>
|
||||||
|
{
|
||||||
|
setMaxPages(200);
|
||||||
|
setCurrentPage(-10);
|
||||||
|
});
|
||||||
|
AddStep("-10 max pages", () =>
|
||||||
|
{
|
||||||
|
setMaxPages(-10);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setMaxPages(int maxPages) => pageSelector.MaxPages.Value = maxPages;
|
||||||
|
|
||||||
|
private void setCurrentPage(int currentPage) => pageSelector.CurrentPage.Value = currentPage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,17 +20,15 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
public class PageSelector : CompositeDrawable
|
public class PageSelector : CompositeDrawable
|
||||||
{
|
{
|
||||||
public readonly BindableInt CurrentPage = new BindableInt(1);
|
public readonly BindableInt CurrentPage = new BindableInt(1);
|
||||||
|
public readonly BindableInt MaxPages = new BindableInt(1);
|
||||||
|
|
||||||
private readonly int maxPages;
|
|
||||||
private readonly FillFlowContainer itemsFlow;
|
private readonly FillFlowContainer itemsFlow;
|
||||||
|
|
||||||
private readonly Button previousPageButton;
|
private readonly Button previousPageButton;
|
||||||
private readonly Button nextPageButton;
|
private readonly Button nextPageButton;
|
||||||
|
|
||||||
public PageSelector(int maxPages)
|
public PageSelector()
|
||||||
{
|
{
|
||||||
this.maxPages = maxPages;
|
|
||||||
|
|
||||||
AutoSizeAxes = Axes.Both;
|
AutoSizeAxes = Axes.Both;
|
||||||
InternalChild = new FillFlowContainer
|
InternalChild = new FillFlowContainer
|
||||||
{
|
{
|
||||||
@ -59,24 +57,48 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
CurrentPage.BindValueChanged(_ => redraw(), true);
|
MaxPages.BindValueChanged(pagesAmount => onMaxPagesChanged(pagesAmount.NewValue), true);
|
||||||
|
CurrentPage.BindValueChanged(page => onCurrentPageChanged(page.NewValue), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void redraw()
|
private void onMaxPagesChanged(int pagesAmount)
|
||||||
{
|
{
|
||||||
if (CurrentPage.Value > maxPages)
|
if (pagesAmount < 1)
|
||||||
{
|
{
|
||||||
CurrentPage.Value = maxPages;
|
MaxPages.Value = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CurrentPage.Value < 1)
|
if (CurrentPage.Value > pagesAmount)
|
||||||
|
{
|
||||||
|
CurrentPage.Value = pagesAmount;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onCurrentPageChanged(int newPage)
|
||||||
|
{
|
||||||
|
if (newPage > MaxPages.Value)
|
||||||
|
{
|
||||||
|
CurrentPage.Value = MaxPages.Value;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newPage < 1)
|
||||||
{
|
{
|
||||||
CurrentPage.Value = 1;
|
CurrentPage.Value = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void redraw()
|
||||||
|
{
|
||||||
int newPage = CurrentPage.Value;
|
int newPage = CurrentPage.Value;
|
||||||
|
int maxPages = MaxPages.Value;
|
||||||
|
|
||||||
previousPageButton.Enabled.Value = newPage != 1;
|
previousPageButton.Enabled.Value = newPage != 1;
|
||||||
nextPageButton.Enabled.Value = newPage != maxPages;
|
nextPageButton.Enabled.Value = newPage != maxPages;
|
||||||
|
Reference in New Issue
Block a user