Skip to content
This repository has been archived by the owner on Mar 6, 2018. It is now read-only.

Commit

Permalink
Add Enabled property to UI Button (#193)
Browse files Browse the repository at this point in the history
This allows buttons to be disabled, in which case they will consume mouse clicks but not fire their click handler.
  • Loading branch information
hach-que committed Jun 4, 2017
1 parent 09c7b4f commit 6e0601e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Protogame/UserInterface/Control/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class Button : IContainer
public Button()
{
State = ButtonUIState.None;
Enabled = true;
}

public event EventHandler<ProtogameEventArgs> Click;
Expand All @@ -33,6 +34,8 @@ public Button()

public bool Toggled { get; set; }

public bool Enabled { get; set; }

public virtual void Render(IRenderContext context, ISkinLayout skinLayout, ISkinDelegator skinDelegator, Rectangle layout)
{
skinDelegator.Render(context, layout, this);
Expand Down Expand Up @@ -87,6 +90,12 @@ public bool HandleEvent(ISkinLayout skin, Rectangle layout, IGameContext context

if (layout.Contains(x, y))
{
if (!Enabled)
{
// Consume the event but don't do anything because the button is not enabled.
return true;
}

if (mouseMoveEvent != null)
{
if (_shouldAppearPressedWhenMouseIsOver)
Expand Down

0 comments on commit 6e0601e

Please sign in to comment.