-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into is-prioritised-positional
- Loading branch information
Showing
3 changed files
with
90 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
#nullable disable | ||
|
||
using System; | ||
using System.Linq; | ||
using NUnit.Framework; | ||
using osu.Framework.Extensions; | ||
using osu.Framework.Extensions.ObjectExtensions; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Containers; | ||
using osu.Framework.Graphics.Cursor; | ||
|
@@ -23,10 +22,10 @@ namespace osu.Framework.Tests.Visual.UserInterface | |
{ | ||
public partial class TestScenePopoverContainer : ManualInputManagerTestScene | ||
{ | ||
private Container[,] cells; | ||
private Container popoverWrapper; | ||
private PopoverContainer popoverContainer; | ||
private GridContainer gridContainer; | ||
private Container[,] cells = null!; | ||
private Container popoverWrapper = null!; | ||
private PopoverContainer popoverContainer = null!; | ||
private GridContainer gridContainer = null!; | ||
|
||
[SetUpSteps] | ||
public void SetUpSteps() | ||
|
@@ -296,7 +295,7 @@ public void TestInteractiveContent() | |
[Test] | ||
public void TestAutomaticLayouting() | ||
{ | ||
DrawableWithPopover target = null; | ||
DrawableWithPopover target = null!; | ||
|
||
AddStep("add button", () => popoverContainer.Child = target = new DrawableWithPopover | ||
{ | ||
|
@@ -316,25 +315,25 @@ public void TestAutomaticLayouting() | |
|
||
AddSliderStep("move X", 0f, 1, 0, x => | ||
{ | ||
if (target != null) | ||
if (target.IsNotNull()) | ||
target.X = x; | ||
}); | ||
|
||
AddSliderStep("move Y", 0f, 1, 0, y => | ||
{ | ||
if (target != null) | ||
if (target.IsNotNull()) | ||
target.Y = y; | ||
}); | ||
|
||
AddSliderStep("container width", 0f, 1, 1, width => | ||
{ | ||
if (popoverWrapper != null) | ||
if (popoverWrapper.IsNotNull()) | ||
popoverWrapper.Width = width; | ||
}); | ||
|
||
AddSliderStep("container height", 0f, 1, 1, height => | ||
{ | ||
if (popoverWrapper != null) | ||
if (popoverWrapper.IsNotNull()) | ||
popoverWrapper.Height = height; | ||
}); | ||
} | ||
|
@@ -369,15 +368,15 @@ public void TestAutoSize() | |
|
||
AddSliderStep("change content height", 100, 500, 200, height => | ||
{ | ||
if (popoverContainer?.Children.Count == 1) | ||
if (popoverContainer.IsNotNull() && popoverContainer.Children.Count == 1) | ||
popoverContainer.Child.Height = height; | ||
}); | ||
} | ||
|
||
[Test] | ||
public void TestExternalPopoverControl() | ||
{ | ||
TextBoxWithPopover target = null; | ||
TextBoxWithPopover target = null!; | ||
|
||
AddStep("create content", () => | ||
{ | ||
|
@@ -403,7 +402,7 @@ public void TestExternalPopoverControl() | |
[Test] | ||
public void TestPopoverCleanupOnTargetDisposal() | ||
{ | ||
DrawableWithPopover target = null; | ||
DrawableWithPopover target = null!; | ||
|
||
AddStep("add button", () => popoverContainer.Child = target = new DrawableWithPopover | ||
{ | ||
|
@@ -435,7 +434,7 @@ public void TestPopoverCleanupOnTargetDisposal() | |
[Test] | ||
public void TestPopoverCleanupOnTargetHide() | ||
{ | ||
DrawableWithPopover target = null; | ||
DrawableWithPopover target = null!; | ||
|
||
AddStep("add button", () => popoverContainer.Child = target = new DrawableWithPopover | ||
{ | ||
|
@@ -467,8 +466,8 @@ public void TestPopoverCleanupOnTargetHide() | |
[Test] | ||
public void TestPopoverEventHandling() | ||
{ | ||
EventHandlingContainer eventHandlingContainer = null; | ||
DrawableWithPopover target = null; | ||
EventHandlingContainer eventHandlingContainer = null!; | ||
DrawableWithPopover target = null!; | ||
|
||
AddStep("add button", () => popoverContainer.Child = eventHandlingContainer = new EventHandlingContainer | ||
{ | ||
|
@@ -522,6 +521,56 @@ public void TestPopoverEventHandling() | |
AddAssert("container received click", () => eventHandlingContainer.ClickReceived); | ||
} | ||
|
||
[Test] | ||
public void TestAllowableAnchors() | ||
{ | ||
DrawableWithPopover target = null!; | ||
|
||
AddStep("add button", () => popoverContainer.Child = target = new DrawableWithPopover | ||
{ | ||
Width = 200, | ||
Height = 30, | ||
Anchor = Anchor.TopLeft, | ||
Origin = Anchor.TopLeft, | ||
RelativePositionAxes = Axes.Both, | ||
Text = "open", | ||
}); | ||
|
||
AddStep("allow popover to only show above & below", () => | ||
{ | ||
target.HidePopover(); | ||
target.CreateContent = _ => new BasicPopover | ||
{ | ||
AllowableAnchors = new[] { Anchor.TopCentre, Anchor.BottomCentre }, | ||
Child = new SpriteText { Text = "This popover can only be shown above or below" } | ||
}; | ||
target.ShowPopover(); | ||
}); | ||
|
||
AddStep("allow popover to only show to the sides", () => | ||
{ | ||
target.HidePopover(); | ||
target.CreateContent = _ => new BasicPopover | ||
{ | ||
AllowableAnchors = new[] { Anchor.CentreLeft, Anchor.CentreRight }, | ||
Child = new SpriteText { Text = "This popover can only be shown to the sides" } | ||
}; | ||
target.ShowPopover(); | ||
}); | ||
|
||
AddSliderStep("move X", 0f, 1, 0, x => | ||
{ | ||
if (target.IsNotNull()) | ||
target.X = x; | ||
}); | ||
|
||
AddSliderStep("move Y", 0f, 1, 0, y => | ||
{ | ||
if (target.IsNotNull()) | ||
target.Y = y; | ||
}); | ||
} | ||
|
||
private void createContent(Func<DrawableWithPopover, Popover> creationFunc) | ||
=> AddStep("create content", () => | ||
{ | ||
|
@@ -554,7 +603,7 @@ private partial class AnimatedPopover : BasicPopover | |
|
||
private partial class DrawableWithPopover : CircularContainer, IHasPopover | ||
{ | ||
public Func<DrawableWithPopover, Popover> CreateContent { get; set; } | ||
public Func<DrawableWithPopover, Popover>? CreateContent { get; set; } | ||
|
||
public string Text | ||
{ | ||
|
@@ -585,7 +634,7 @@ public DrawableWithPopover() | |
}; | ||
} | ||
|
||
public Popover GetPopover() => CreateContent.Invoke(this); | ||
public Popover? GetPopover() => CreateContent?.Invoke(this); | ||
|
||
protected override bool OnClick(ClickEvent e) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters