Skip to content

Commit

Permalink
Fixes #437
Browse files Browse the repository at this point in the history
  • Loading branch information
rds1983 committed Nov 13, 2023
1 parent 9188797 commit a5d720f
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 54 deletions.
2 changes: 1 addition & 1 deletion src/Myra/Graphics2D/UI/Simple/ButtonBase2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public override IBrush GetCurrentBackground()
{
result = PressedBackground;
}
else if (IsMouseInside && OverBackground != null)
else if (UseOverBackground && OverBackground != null)
{
result = OverBackground;
}
Expand Down
22 changes: 16 additions & 6 deletions src/Myra/Graphics2D/UI/Simple/CheckButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Myra.Graphics2D.UI.Styles;
using System.ComponentModel;
using System;
using System.Xml.Serialization;


#if MONOGAME || FNA
Expand All @@ -21,11 +22,11 @@ public enum CheckPosition
}

[StyleTypeName("CheckBox")]
public class CheckButton: ButtonBase2
public class CheckButton : ButtonBase2
{
private class CheckImage: Image
private class CheckImageInternal : Image
{
public override bool IsMouseInside
protected override bool UseOverBackground
{
get
{
Expand All @@ -42,7 +43,7 @@ public override bool IsMouseInside

private readonly StackPanelLayout _layout = new StackPanelLayout(Orientation.Horizontal);
private CheckPosition _checkPosition = CheckPosition.Left;
private readonly CheckImage _check = new CheckImage
private readonly CheckImageInternal _check = new CheckImageInternal
{
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center,
Expand Down Expand Up @@ -95,6 +96,10 @@ public override Widget Content
}
}

[Browsable(false)]
[XmlIgnore]
public Image CheckImage => _check;

public event EventHandler IsCheckedChanged
{
add
Expand Down Expand Up @@ -149,7 +154,14 @@ public override void OnKeyDown(Keys k)

protected override void InternalSetStyle(Stylesheet stylesheet, string name)
{
base.InternalSetStyle(stylesheet, name);

var style = stylesheet.CheckBoxStyles.SafelyGetStyle(name);
ApplyCheckButtonStyle(style);
}

public void ApplyCheckButtonStyle(ImageTextButtonStyle style)
{
ApplyButtonStyle(style);

if (style.ImageStyle != null)
Expand All @@ -158,8 +170,6 @@ protected override void InternalSetStyle(Stylesheet stylesheet, string name)
}

CheckContentSpacing = style.ImageTextSpacing;

ApplyButtonStyle(stylesheet.CheckBoxStyles.SafelyGetStyle(name));
}

private void UpdateChildren()
Expand Down
24 changes: 3 additions & 21 deletions src/Myra/Graphics2D/UI/Simple/RadioButton.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
using System.ComponentModel;
using System.Linq;
using System.Xml.Serialization;
using Myra.Graphics2D.UI.Styles;

namespace Myra.Graphics2D.UI
{
public class RadioButton : ImageTextButton
public class RadioButton : CheckButton
{
[Browsable(false)]
[XmlIgnore]
[Category("Behavior")]
[DefaultValue(true)]
public override bool Toggleable
{
get
{
return base.Toggleable;
}
set
{
base.Toggleable = value;
}
}

public override bool IsPressed
{
get => base.IsPressed;
Expand Down Expand Up @@ -61,14 +44,13 @@ public override bool IsPressed

public RadioButton(string styleName = Stylesheet.DefaultStyleName): base(styleName)
{
Toggleable = true;
}

public override void OnPressedChanged()
{
base.OnPressedChanged();

if (!IsPressed)
if (Parent == null || !IsPressed)
{
return;
}
Expand All @@ -89,7 +71,7 @@ public override void OnPressedChanged()

protected override void InternalSetStyle(Stylesheet stylesheet, string name)
{
ApplyImageTextButtonStyle(stylesheet.RadioButtonStyles.SafelyGetStyle(name));
ApplyCheckButtonStyle(stylesheet.RadioButtonStyles.SafelyGetStyle(name));
}
}
}
2 changes: 1 addition & 1 deletion src/Myra/Graphics2D/UI/Widget.Input.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ partial class Widget: IInputEventsProcessor

[Browsable(false)]
[XmlIgnore]
public virtual bool IsMouseInside => _localMousePosition != null;
public bool IsMouseInside => _localMousePosition != null;

[Browsable(false)]
[XmlIgnore]
Expand Down
6 changes: 4 additions & 2 deletions src/Myra/Graphics2D/UI/Widget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,8 @@ internal Transform Transform
}
}

protected virtual bool UseOverBackground => IsMouseInside;

[Browsable(false)]
[XmlIgnore]
public Action<RenderContext> BeforeRender, AfterRender;
Expand All @@ -787,7 +789,7 @@ public virtual IBrush GetCurrentBackground()
{
result = FocusedBackground;
}
else if (IsMouseInside && OverBackground != null)
else if (UseOverBackground && OverBackground != null)
{
result = OverBackground;
}
Expand Down Expand Up @@ -1411,7 +1413,7 @@ public virtual Widget HitTest(Point p)
}

var localPos = ToLocal(p);
if (result == null && !InputFallsThrough(localPos))
if (result == null && !InputFallsThrough(localPos))
{
result = this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/MyraPad/Studio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class Studio : Game
private static readonly string[] SimpleWidgets = new[]
{
"ImageTextButton",
"RadioButton",
"SpinButton",
"HorizontalProgressBar",
"VerticalProgressBar",
Expand All @@ -52,6 +51,7 @@ public class Studio : Game
"Button",
"ToggleButton",
"CheckButton",
"RadioButton",
"Window",
"Grid",
"Panel",
Expand Down
51 changes: 39 additions & 12 deletions src/MyraPad/UI/NewProjectWizard.Generated.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Generated by MyraPad at 10/23/2023 7:09:21 AM */
/* Generated by MyraPad at 11/13/2023 10:44:41 PM */
using Myra;
using Myra.Graphics2D;
using Myra.Graphics2D.TextureAtlases;
Expand Down Expand Up @@ -26,41 +26,68 @@ partial class NewProjectWizard: Dialog
{
private void BuildUI()
{
var label1 = new Label();
label1.Text = "Grid";

_radioButtonGrid = new RadioButton();
_radioButtonGrid.Text = "Grid";
_radioButtonGrid.Id = "_radioButtonGrid";
_radioButtonGrid.Content = label1;

var label2 = new Label();
label2.Text = "HorizontalStackPanel";

_radioButtonHorizontalStackPanel = new RadioButton();
_radioButtonHorizontalStackPanel.Text = "HorizontalStackPanel";
_radioButtonHorizontalStackPanel.Id = "_radioButtonHorizontalStackPanel";
_radioButtonHorizontalStackPanel.Content = label2;

var label3 = new Label();
label3.Text = "VerticalStackPanel";

_radioButtonVerticalStackPanel = new RadioButton();
_radioButtonVerticalStackPanel.Text = "VerticalStackPanel";
_radioButtonVerticalStackPanel.Id = "_radioButtonVerticalStackPanel";
_radioButtonVerticalStackPanel.Content = label3;

var label4 = new Label();
label4.Text = "Panel";

_radioButtonPanel = new RadioButton();
_radioButtonPanel.Text = "Panel";
_radioButtonPanel.Id = "_radioButtonPanel";
_radioButtonPanel.Content = label4;

var label5 = new Label();
label5.Text = "ScrollViewer";

_radioButtonScrollViewer = new RadioButton();
_radioButtonScrollViewer.Text = "ScrollViewer";
_radioButtonScrollViewer.Id = "_radioButtonScrollViewer";
_radioButtonScrollViewer.Content = label5;

var label6 = new Label();
label6.Text = "HorizontalSplitPane";

_radioButtonHorizontalSplitPane = new RadioButton();
_radioButtonHorizontalSplitPane.Text = "HorizontalSplitPane";
_radioButtonHorizontalSplitPane.Id = "_radioButtonHorizontalSplitPane";
_radioButtonHorizontalSplitPane.Content = label6;

var label7 = new Label();
label7.Text = "VerticalSplitPane";

_radioButtonVerticalSplitPane = new RadioButton();
_radioButtonVerticalSplitPane.Text = "VerticalSplitPane";
_radioButtonVerticalSplitPane.Id = "_radioButtonVerticalSplitPane";
_radioButtonVerticalSplitPane.Content = label7;

var label8 = new Label();
label8.Text = "Window";

_radioButtonWindow = new RadioButton();
_radioButtonWindow.Text = "Window";
_radioButtonWindow.Id = "_radioButtonWindow";
_radioButtonWindow.Content = label8;

var label9 = new Label();
label9.Text = "Dialog";

_radioButtonDialog = new RadioButton();
_radioButtonDialog.Text = "Dialog";
_radioButtonDialog.Id = "_radioButtonDialog";
_radioButtonDialog.Content = label9;

var verticalStackPanel1 = new VerticalStackPanel();
verticalStackPanel1.Widgets.Add(_radioButtonGrid);
Expand All @@ -75,8 +102,8 @@ private void BuildUI()


Title = "Choose Root Container";
Left = 1162;
Top = 540;
Left = 425;
Top = 74;
Content = verticalStackPanel1;
}

Expand Down
38 changes: 28 additions & 10 deletions src/MyraPad/UI/newProjectWizard.xmmp
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
<Project>
<Project.ExportOptions Namespace="MyraPad.UI" Class="NewProjectWizard" OutputPath="D:\Projects\Myra\src\MyraPad\UI" />
<Dialog Title="Choose Root Container" Left="383" Top="95">
<Dialog Title="Choose Root Container" Left="762" Top="246">
<VerticalStackPanel>
<RadioButton Text="Grid" Id="_radioButtonGrid" />
<RadioButton Text="HorizontalStackPanel" Id="_radioButtonHorizontalStackPanel" />
<RadioButton Text="VerticalStackPanel" Id="_radioButtonVerticalStackPanel" />
<RadioButton Text="Panel" Id="_radioButtonPanel" />
<RadioButton Text="ScrollViewer" Id="_radioButtonScrollViewer" />
<RadioButton Text="HorizontalSplitPane" Id="_radioButtonHorizontalSplitPane" />
<RadioButton Text="VerticalSplitPane" Id="_radioButtonVerticalSplitPane" />
<RadioButton Text="Window" Id="_radioButtonWindow" />
<RadioButton Text="Dialog" Id="_radioButtonDialog" />
<RadioButton Id="_radioButtonGrid">
<Label Text="Grid" />
</RadioButton>
<RadioButton Id="_radioButtonHorizontalStackPanel">
<Label Text="HorizontalStackPanel" />
</RadioButton>
<RadioButton Id="_radioButtonVerticalStackPanel">
<Label Text="VerticalStackPanel" />
</RadioButton>
<RadioButton Id="_radioButtonPanel">
<Label Text="Panel" />
</RadioButton>
<RadioButton Id="_radioButtonScrollViewer">
<Label Text="ScrollViewer" />
</RadioButton>
<RadioButton Id="_radioButtonHorizontalSplitPane">
<Label Text="HorizontalSplitPane" />
</RadioButton>
<RadioButton Id="_radioButtonVerticalSplitPane">
<Label Text="VerticalSplitPane" />
</RadioButton>
<RadioButton Id="_radioButtonWindow">
<Label Text="Window" />
</RadioButton>
<RadioButton Id="_radioButtonDialog">
<Label Text="Dialog" />
</RadioButton>
</VerticalStackPanel>
</Dialog>
</Project>

0 comments on commit a5d720f

Please sign in to comment.