Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ControlsType.AlwaysOn for controls that should always be visible #21

Merged
merged 3 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions site/Site/Pages/Documentation/Controls/Overview.razor
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
// Initialize
var node1Controls = Diagram.Controls.AddFor(Node1); // OnSelection default
var node2Controls = Diagram.Controls.AddFor(Node2, ControlsType.OnHover);
var node3Controls = Diagram.Controls.AddFor(Node2, ControlsType.AlwaysOn); // Control always visible

// Add
node1Controls.Add(new SomeControl());
Expand Down
4 changes: 4 additions & 0 deletions src/Blazor.Diagrams.Core/Controls/ControlsContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public ControlsContainer(Model model, ControlsType type = ControlsType.OnSelecti
{
Model = model;
Type = type;
if (type == ControlsType.AlwaysOn)
{
Visible = true;
}
}

public Model Model { get; }
Expand Down
3 changes: 2 additions & 1 deletion src/Blazor.Diagrams.Core/Controls/ControlsType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ namespace Blazor.Diagrams.Core.Controls;
public enum ControlsType
{
OnHover,
OnSelection
OnSelection,
AlwaysOn
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Blazor.Diagrams.Core.Controls;
using Blazor.Diagrams.Core.Events;
using Blazor.Diagrams.Core.Models;
using Xunit;

namespace Blazor.Diagrams.Core.Tests.Controls
{
public class ControlsContainerTests
{
[Fact]
public void AlwaysOnControlType_AlwaysVisible()
{
// Arrange
var diagram = new TestDiagram();
var node = diagram.Nodes.Add(new NodeModel());
var controls = diagram.Controls.AddFor(node, ControlsType.AlwaysOn);

// Assert
Assert.True(controls.Visible);

node.Selected = true;
Assert.True(controls.Visible);

diagram.TriggerPointerEnter(node, new PointerEventArgs(0, 0, 0, 0, false, false, false, 0, 0, 0, 0, 0, 0, string.Empty, true));
Assert.True(controls.Visible);
}
}
}
Loading