Skip to content

Commit a2897a2

Browse files
authored
Features/dialog updates (#57)
* Updating menu styles + licence year * Reinstating label height * Continued * Switching to relative sizes * Removing popup
1 parent 80fbfe3 commit a2897a2

File tree

15 files changed

+156
-53
lines changed

15 files changed

+156
-53
lines changed

ReadableExpressions.UnitTests/WhenFormattingCode.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,8 @@ public void ShouldLeaveABlankLineAfterAMultipleLineExpression()
815815

816816
var longChainblock = Block(longCallChain.Body, longCallChain.Body);
817817

818+
var translated = ToReadableString(longChainblock);
819+
818820
const string EXPECTED = @"
819821
list
820822
.Select(i => i * 2)
@@ -828,8 +830,6 @@ public void ShouldLeaveABlankLineAfterAMultipleLineExpression()
828830
.Select(i => i * 4)
829831
.ToArray();";
830832

831-
var translated = ToReadableString(longChainblock);
832-
833833
translated.ShouldBe(EXPECTED.TrimStart());
834834
}
835835

@@ -844,15 +844,14 @@ public void ShouldLeaveABlankLineBeforeAnIfStatement()
844844

845845
var block = Block(new[] { intVariable }, ifIntEqualsZeroDoNothing);
846846

847+
var translated = ToReadableString(block);
848+
847849
const string EXPECTED = @"
848850
int i;
849851
850852
if (i == 0)
851853
{
852854
}";
853-
854-
var translated = ToReadableString(block);
855-
856855
translated.ShouldBe(EXPECTED.TrimStart());
857856
}
858857

@@ -870,6 +869,8 @@ public void ShouldNotLeaveDoubleBlankLinesBetweenIfStatements()
870869
ifIntEqualsOneDoNothing,
871870
ifIntEqualsOneDoNothing);
872871

872+
var translated = ToReadableString(block);
873+
873874
const string EXPECTED = @"
874875
int i;
875876
@@ -880,9 +881,6 @@ public void ShouldNotLeaveDoubleBlankLinesBetweenIfStatements()
880881
if (i == 1)
881882
{
882883
}";
883-
884-
var translated = ToReadableString(block);
885-
886884
translated.ShouldBe(EXPECTED.TrimStart());
887885
}
888886

@@ -907,6 +905,8 @@ public void ShouldNotLeaveDoubleBlankLinesBetweenInitAndIfStatements()
907905

908906
var block = Block(memoryStreamInit, ifIntEqualsOneDoNothing);
909907

908+
var translated = ToReadableString(block);
909+
910910
const string EXPECTED = @"
911911
new MemoryStream
912912
{
@@ -921,9 +921,6 @@ public void ShouldNotLeaveDoubleBlankLinesBetweenInitAndIfStatements()
921921
if (i == 1)
922922
{
923923
}";
924-
925-
var translated = ToReadableString(block);
926-
927924
translated.ShouldBe(EXPECTED.TrimStart());
928925
}
929926

@@ -953,6 +950,8 @@ public void ShouldTranslateMultilineBlockSingleMethodArguments()
953950
var collectionVariable = Variable(typeof(ICollection<int>), "ints");
954951
var addMethod = collectionVariable.Type.GetPublicInstanceMethod("Add");
955952
var addMethodCall = Call(collectionVariable, addMethod, tryCatch);
953+
954+
var translated = ToReadableString(addMethodCall);
956955

957956
const string EXPECTED = @"
958957
ints.Add(
@@ -971,9 +970,6 @@ public void ShouldTranslateMultilineBlockSingleMethodArguments()
971970
return 0;
972971
}
973972
})";
974-
975-
var translated = ToReadableString(addMethodCall);
976-
977973
translated.ShouldBe(EXPECTED.TrimStart());
978974
}
979975

ReadableExpressions.UnitTests/WhenTranslatingMemberAccesses.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,30 @@ public void ShouldIncludeAnOutParameterVariableDeclaration()
538538
object value;
539539
ip.TryGet(1, out value);
540540
541+
return value;
542+
}";
543+
translated.ShouldBe(EXPECTED.TrimStart());
544+
}
545+
546+
[Fact]
547+
public void ShouldNotDuplicateAnOutParameterVariableDeclarationType()
548+
{
549+
var helperParameter = Parameter(typeof(IndexedProperty), "ip");
550+
var one = Constant(1);
551+
var valueVariable = Variable(typeof(object), "value");
552+
var tryGetMethod = typeof(IndexedProperty).GetPublicInstanceMethod("TryGet");
553+
var tryGetCall = Call(helperParameter, tryGetMethod, one, valueVariable);
554+
var tryGetBlock = Block(new[] { valueVariable }, tryGetCall, valueVariable);
555+
var tryGetLambda = Lambda<Func<IndexedProperty, object>>(tryGetBlock, helperParameter);
556+
557+
var translated = ToReadableString(tryGetLambda, s => s.ShowLambdaParameterTypes);
558+
559+
const string EXPECTED = @"
560+
(IndexedProperty ip) =>
561+
{
562+
object value;
563+
ip.TryGet(1, out value);
564+
541565
return value;
542566
}";
543567
translated.ShouldBe(EXPECTED.TrimStart());

ReadableExpressions.Visualizers.Core/Controls/MenuItemLabel.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66

77
internal class MenuItemLabel : Label
88
{
9-
private static readonly Font _font = new Font(new FontFamily("Arial"), 10);
10-
119
public MenuItemLabel(
1210
string text,
1311
string tooltip,
1412
int controlWidth,
1513
VisualizerDialog dialog)
1614
{
17-
Size = new Size(MenuWidth - controlWidth, MenuItemHeight);
15+
Size = new SizeF(
16+
(MenuWidth - controlWidth) * dialog.WidthFactor,
17+
MenuItemHeight * dialog.HeightFactor).ToSize();
1818

1919
dialog.RegisterThemeable(this);
2020

21-
base.Font = _font;
21+
base.Font = MenuItemFont;
2222
base.TextAlign = ContentAlignment.MiddleLeft;
2323
base.Text = text;
2424

ReadableExpressions.Visualizers.Core/Controls/MenuItemPanelBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ internal abstract class MenuItemPanelBase : FlowLayoutPanel
77
protected MenuItemPanelBase(VisualizerDialog dialog)
88
{
99
FlowDirection = FlowDirection.LeftToRight;
10-
Size = DialogConstants.MenuItemSize;
10+
Width = (int)(DialogConstants.MenuWidth * dialog.WidthFactor);
1111
Padding = Padding.Empty;
1212
Margin = Padding.Empty;
1313

ReadableExpressions.Visualizers.Core/Controls/SettingCheckBox.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ public SettingCheckBox(
1919
_optionSetter = optionSetter;
2020
_dialog = dialog;
2121

22-
Size = new Size(SettingCheckBoxWidth, MenuItemHeight);
22+
Size = new SizeF(
23+
SettingCheckBoxWidth * dialog.WidthFactor,
24+
MenuItemHeight * dialog.HeightFactor).ToSize();
25+
2326
CheckAlign = ContentAlignment.MiddleRight;
2427

2528
dialog.RegisterThemeable(this);

ReadableExpressions.Visualizers.Core/Controls/ThemeOption.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,40 @@
77

88
internal class ThemeOption : RadioButton
99
{
10+
private readonly ExpressionTranslationTheme _theme;
11+
private readonly VisualizerDialog _dialog;
12+
1013
public ThemeOption(
1114
ExpressionTranslationTheme theme,
1215
VisualizerDialog dialog)
1316
{
14-
Size = new Size(ThemeOptionWidth, MenuItemHeight);
17+
_theme = theme;
18+
_dialog = dialog;
19+
20+
Size = new SizeF(
21+
ThemeOptionWidth * dialog.WidthFactor,
22+
MenuItemHeight * dialog.HeightFactor).ToSize();
23+
1524
Checked = theme.Name == dialog.Theme.Name;
1625

1726
dialog.RegisterThemeable(this);
1827

28+
base.Font = MenuItemFont;
1929
base.TextAlign = ContentAlignment.MiddleLeft;
2030
base.Text = theme.Name;
2131

2232
CheckedChanged += (sender, args) =>
2333
{
24-
if (dialog.ViewerUninitialised)
34+
var option = (ThemeOption)sender;
35+
36+
if (option._dialog.ViewerUninitialised)
2537
{
2638
return;
2739
}
2840

29-
if ((sender == this) && Checked)
41+
if (Checked && (option == this))
3042
{
31-
dialog.OnThemeChanged(theme);
43+
option._dialog.OnThemeChanged(option._theme);
3244
}
3345
};
3446
}
Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
namespace AgileObjects.ReadableExpressions.Visualizers.Core.Controls
22
{
33
using System;
4+
using System.Windows.Forms;
45
using static DialogConstants;
56

67
internal abstract class VisualizerDialogOptionBase : MenuItemPanelBase
78
{
9+
private readonly SettingCheckBox _checkBox;
10+
811
protected VisualizerDialogOptionBase(
912
string labelText,
1013
string labelTooltip,
@@ -14,12 +17,24 @@ protected VisualizerDialogOptionBase(
1417
: base(dialog)
1518
{
1619
var label = new MenuItemLabel(labelText, labelTooltip, SettingCheckBoxWidth, dialog);
17-
var checkbox = new SettingCheckBox(isChecked, optionSetter, dialog);
20+
_checkBox = new SettingCheckBox(isChecked, optionSetter, dialog);
21+
22+
label.Click += (sender, args) =>
23+
{
24+
var control = (Control)sender;
25+
var option = control as VisualizerDialogOptionBase;
26+
27+
while (option == null)
28+
{
29+
control = control.Parent;
30+
option = control as VisualizerDialogOptionBase;
31+
}
1832

19-
label.Click += (sender, args) => checkbox.Checked = !checkbox.Checked;
33+
option._checkBox.Checked = !option._checkBox.Checked;
34+
};
2035

2136
Controls.Add(label);
22-
Controls.Add(checkbox);
37+
Controls.Add(_checkBox);
2338
}
2439
}
2540
}
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
namespace AgileObjects.ReadableExpressions.Visualizers.Core
22
{
33
using System.Drawing;
4+
using static System.Drawing.FontStyle;
45

56
internal static class DialogConstants
67
{
7-
public const int MenuWidth = 550;
8-
public const int ThemeOptionWidth = 100;
9-
public const int SettingCheckBoxWidth = 50;
10-
public const int MenuItemHeight = 44;
8+
public const int MenuWidth = 300;
9+
public const int MenuItemHeight = 16;
10+
public const int ThemeOptionWidth = 40;
11+
public const int SettingCheckBoxWidth = 30;
1112

12-
public static readonly Size MenuItemSize = new Size(MenuWidth, MenuItemHeight);
13+
public static readonly Font MenuItemFont = new Font(
14+
new FontFamily("Segoe UI"),
15+
10,
16+
Regular,
17+
GraphicsUnit.Point,
18+
1,
19+
gdiVerticalFont: false);
1320
}
1421
}

ReadableExpressions.Visualizers.Core/VisualizerDialog.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Controls;
1010
using Theming;
1111
using static System.Windows.Forms.SystemInformation;
12+
using static DialogConstants;
1213

1314
public class VisualizerDialog : Form
1415
{
@@ -40,6 +41,12 @@ public VisualizerDialog(Func<object> translationFactory)
4041
var screenRectangle = RectangleToScreen(ClientRectangle);
4142
_titleBarHeight = screenRectangle.Top - Top;
4243

44+
using (var graphics = CreateGraphics())
45+
{
46+
WidthFactor = graphics.DpiX / 72;
47+
HeightFactor = graphics.DpiY / 72;
48+
}
49+
4350
ToolTip = AddToolTip();
4451
_viewer = AddViewer();
4552
_menuStrip = AddMenuStrip();
@@ -57,6 +64,10 @@ internal ExpressionTranslationTheme Theme
5764
private set => Settings.Theme = value;
5865
}
5966

67+
internal float WidthFactor { get; }
68+
69+
internal float HeightFactor { get; }
70+
6071
internal ToolTip ToolTip { get; }
6172

6273
internal bool ViewerUninitialised { get; private set; }
41.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)