Skip to content

Commit b6d3af7

Browse files
add ControlsType.AlwaysOn for controls that should always be visible (#21)
1 parent f1c37b4 commit b6d3af7

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

site/Site/Pages/Documentation/Controls/Overview.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
// Initialize
4141
var node1Controls = Diagram.Controls.AddFor(Node1); // OnSelection default
4242
var node2Controls = Diagram.Controls.AddFor(Node2, ControlsType.OnHover);
43+
var node3Controls = Diagram.Controls.AddFor(Node2, ControlsType.AlwaysOn); // Control always visible
4344

4445
// Add
4546
node1Controls.Add(new SomeControl());

src/Blazor.Diagrams.Core/Controls/ControlsContainer.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ public ControlsContainer(Model model, ControlsType type = ControlsType.OnSelecti
1616
{
1717
Model = model;
1818
Type = type;
19+
if (type == ControlsType.AlwaysOn)
20+
{
21+
Visible = true;
22+
}
1923
}
2024

2125
public Model Model { get; }

src/Blazor.Diagrams.Core/Controls/ControlsType.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ namespace Blazor.Diagrams.Core.Controls;
33
public enum ControlsType
44
{
55
OnHover,
6-
OnSelection
6+
OnSelection,
7+
AlwaysOn
78
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Blazor.Diagrams.Core.Controls;
2+
using Blazor.Diagrams.Core.Events;
3+
using Blazor.Diagrams.Core.Models;
4+
using Xunit;
5+
6+
namespace Blazor.Diagrams.Core.Tests.Controls
7+
{
8+
public class ControlsContainerTests
9+
{
10+
[Fact]
11+
public void AlwaysOnControlType_AlwaysVisible()
12+
{
13+
// Arrange
14+
var diagram = new TestDiagram();
15+
var node = diagram.Nodes.Add(new NodeModel());
16+
var controls = diagram.Controls.AddFor(node, ControlsType.AlwaysOn);
17+
18+
// Assert
19+
Assert.True(controls.Visible);
20+
21+
node.Selected = true;
22+
Assert.True(controls.Visible);
23+
24+
diagram.TriggerPointerEnter(node, new PointerEventArgs(0, 0, 0, 0, false, false, false, 0, 0, 0, 0, 0, 0, string.Empty, true));
25+
Assert.True(controls.Visible);
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)