Skip to content

Commit 170b687

Browse files
Merge pull request #83 from atc-net/feature/Improve-LabelControlsForm-Rendering
Feature/improve label controls form rendering
2 parents ecc87d0 + f930da4 commit 170b687

14 files changed

+345
-33
lines changed

sample/Atc.Wpf.Sample/SamplesWpfControls/DialogBoxes/StandardDialogBoxView.xaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,54 @@
3939
<Button Command="{Binding Path=ShowInfoErrorDialogBoxCommand}" Content="Error" />
4040
<Button Command="{Binding Path=ShowQuestionDialogBoxCommand}" Content="Question" />
4141
<Button Command="{Binding Path=ShowInputDialogBoxCommand}" Content="Input" />
42+
<Grid>
43+
<atc:UniformSpacingPanel
44+
HorizontalAlignment="Center"
45+
ItemWidth="100"
46+
Orientation="Horizontal"
47+
Spacing="10">
48+
<Button
49+
Command="{Binding Path=ShowInputForm1ColumnXFieldVerticalDialogBoxCommand}"
50+
CommandParameter="1"
51+
Content="IF.V. 1col, 1field" />
52+
<Button
53+
Command="{Binding Path=ShowInputForm1ColumnXFieldVerticalDialogBoxCommand}"
54+
CommandParameter="2"
55+
Content="IF.V. 1col, 2field" />
56+
<Button
57+
Command="{Binding Path=ShowInputForm1ColumnXFieldVerticalDialogBoxCommand}"
58+
CommandParameter="3"
59+
Content="IF.V. 1col, 3field" />
60+
<Button
61+
Command="{Binding Path=ShowInputForm1ColumnXFieldVerticalDialogBoxCommand}"
62+
CommandParameter="4"
63+
Content="IF.V. 1col, 4field" />
64+
</atc:UniformSpacingPanel>
65+
</Grid>
66+
<Grid>
67+
<atc:UniformSpacingPanel
68+
HorizontalAlignment="Center"
69+
ItemWidth="100"
70+
Orientation="Horizontal"
71+
Spacing="10">
72+
<Button
73+
Command="{Binding Path=ShowInputForm1ColumnXFieldHorizontalDialogBoxCommand}"
74+
CommandParameter="1"
75+
Content="IF.H. 1col, 1field" />
76+
<Button
77+
Command="{Binding Path=ShowInputForm1ColumnXFieldHorizontalDialogBoxCommand}"
78+
CommandParameter="2"
79+
Content="IF.H. 1col, 2field" />
80+
<Button
81+
Command="{Binding Path=ShowInputForm1ColumnXFieldHorizontalDialogBoxCommand}"
82+
CommandParameter="3"
83+
Content="IF.H. 1col, 3field" />
84+
<Button
85+
Command="{Binding Path=ShowInputForm1ColumnXFieldHorizontalDialogBoxCommand}"
86+
CommandParameter="4"
87+
Content="IF.H. 1col, 4field" />
88+
</atc:UniformSpacingPanel>
89+
</Grid>
4290
<Button Command="{Binding Path=ShowInputForm1ColumnDialogBoxCommand}" Content="Input Form 1 columns" />
4391
<Button Command="{Binding Path=ShowInputForm2ColumnsDialogBoxCommand}" Content="Input Form 2 columns" />
4492
<Button Command="{Binding Path=ShowInputForm3ColumnsDialogBoxCommand}" Content="Input Form 3 columns" />

sample/Atc.Wpf.Sample/SamplesWpfControls/DialogBoxes/StandardDialogBoxViewModel.cs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ public StandardDialogBoxViewModel()
2424

2525
public IRelayCommand ShowInputDialogBoxCommand => new RelayCommand(ShowInputDialogBoxCommandHandler);
2626

27+
public IRelayCommand<int> ShowInputForm1ColumnXFieldVerticalDialogBoxCommand => new RelayCommand<int>(ShowInputForm1ColumnXFieldVerticalDialogBoxCommandHandler);
28+
29+
public IRelayCommand<int> ShowInputForm1ColumnXFieldHorizontalDialogBoxCommand => new RelayCommand<int>(ShowInputForm1ColumnXFieldHorizontalDialogBoxCommandHandler);
30+
2731
public IRelayCommand ShowInputForm1ColumnDialogBoxCommand => new RelayCommand(ShowInputForm1ColumnDialogBoxCommandHandler);
2832

2933
public IRelayCommand ShowInputForm2ColumnsDialogBoxCommand => new RelayCommand(ShowInputForm2ColumnsDialogBoxCommandHandler);
@@ -147,6 +151,78 @@ private void ShowInputDialogBoxCommandHandler()
147151
}
148152
}
149153

154+
private void ShowInputForm1ColumnXFieldVerticalDialogBoxCommandHandler(
155+
int numberOfControls)
156+
{
157+
var labelControls = new List<ILabelControlBase>();
158+
159+
for (var i = 0; i < numberOfControls; i++)
160+
{
161+
labelControls.Add(
162+
new LabelTextBox
163+
{
164+
LabelText = $"Name{i}",
165+
});
166+
}
167+
168+
var labelControlsForm = new LabelControlsForm();
169+
labelControlsForm.AddColumn(labelControls);
170+
171+
var dialogBox = new InputFormDialogBox(
172+
Application.Current.MainWindow!,
173+
labelControlsForm);
174+
175+
dialogBox.Settings.Form.ControlOrientation = Orientation.Vertical;
176+
dialogBox.LabelInputFormPanel.ReRender();
177+
178+
var dialogResult = dialogBox.ShowDialog();
179+
if (dialogResult.HasValue && dialogResult.Value)
180+
{
181+
var data = dialogBox.Data.GetKeyValues();
182+
JsonResult = JsonSerializer.Serialize(data, jsonOptions);
183+
}
184+
else
185+
{
186+
JsonResult = CreateJson(dialogBox.Settings.NegativeButtonText);
187+
}
188+
}
189+
190+
private void ShowInputForm1ColumnXFieldHorizontalDialogBoxCommandHandler(
191+
int numberOfControls)
192+
{
193+
var labelControls = new List<ILabelControlBase>();
194+
195+
for (var i = 0; i < numberOfControls; i++)
196+
{
197+
labelControls.Add(
198+
new LabelTextBox
199+
{
200+
LabelText = $"Name{i}",
201+
});
202+
}
203+
204+
var labelControlsForm = new LabelControlsForm();
205+
labelControlsForm.AddColumn(labelControls);
206+
207+
var dialogBox = new InputFormDialogBox(
208+
Application.Current.MainWindow!,
209+
labelControlsForm);
210+
211+
dialogBox.Settings.Form.ControlOrientation = Orientation.Horizontal;
212+
dialogBox.ReRender();
213+
214+
var dialogResult = dialogBox.ShowDialog();
215+
if (dialogResult.HasValue && dialogResult.Value)
216+
{
217+
var data = dialogBox.Data.GetKeyValues();
218+
JsonResult = JsonSerializer.Serialize(data, jsonOptions);
219+
}
220+
else
221+
{
222+
JsonResult = CreateJson(dialogBox.Settings.NegativeButtonText);
223+
}
224+
}
225+
150226
private void ShowInputForm1ColumnDialogBoxCommandHandler()
151227
{
152228
var labelControls = new List<ILabelControlBase>

sample/Atc.Wpf.Sample/SamplesWpfControls/Viewers/JsonViewerView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
88
xmlns:viewers="clr-namespace:Atc.Wpf.Controls.Viewers;assembly=Atc.Wpf.Controls"
99
xmlns:vm="clr-namespace:Atc.Wpf.Sample.SamplesWpfControls.Viewers"
10-
d:DesignHeight="450"
10+
d:DesignHeight="500"
1111
d:DesignWidth="800"
1212
mc:Ignorable="d">
1313

sample/Atc.Wpf.Sample/SamplesWpfControls/Viewers/JsonViewerViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class JsonViewerViewModel : ViewModelBase
66

77
public JsonViewerViewModel()
88
{
9-
JsonData = "{\r\n \"array\": [\r\n 1,\r\n 2,\r\n 3\r\n ],\r\n \"boolean\": true,\r\n \"color\": \"gold\",\r\n \"null\": null,\r\n \"number\": 123,\r\n \"object\": {\r\n \"a\": \"b\",\r\n \"c\": \"d\"\r\n },\r\n \"string\": \"Hello World\"\r\n}";
9+
JsonData = "{\r\n \"array\": [\r\n 1,\r\n 2,\r\n 3\r\n ],\r\n \"boolean\": true,\r\n \"color\": \"gold\",\r\n \"null\": null,\r\n \"number\": 123,\r\n \"object\": {\r\n \"a\": \"b\",\r\n \"c\": \"d\"\r\n },\r\n \"string\": \"Hello World\",\r\n \"date\": \"2021-11-04T00:00:00\",\r\n \"guid\": \"c0a29e8d-5a6e-4f70-ba54-1b72c7bf9f4f\",\r\n \"url\": \"http://google.com/\"\r\n}";
1010
}
1111

1212
public string JsonData

src/Atc.Wpf.Controls/Constants.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ public static class Constants
88
public const string JTokenHexColorFloat = "#ad7fa8";
99
public const string JTokenHexColorInteger = "#ad7fa8";
1010
public const string JTokenHexColorBoolean = "#c4a000";
11+
public const string JTokenHexColorDate = "#f4a000";
12+
public const string JTokenHexColorGuid = "#f4af00";
13+
public const string JTokenHexColorUri = "#f4a0f0";
1114
public const string JTokenHexColorNull = "#ff6e00";
1215

1316
public static Brush JTokenColorString => (Brush)new BrushConverter().ConvertFrom(JTokenHexColorString)!;
@@ -18,5 +21,11 @@ public static class Constants
1821

1922
public static Brush JTokenColorBoolean => (Brush)new BrushConverter().ConvertFrom(JTokenHexColorBoolean)!;
2023

24+
public static Brush JTokenColorDate => (Brush)new BrushConverter().ConvertFrom(JTokenHexColorDate)!;
25+
26+
public static Brush JTokenColorGuid => (Brush)new BrushConverter().ConvertFrom(JTokenHexColorGuid)!;
27+
28+
public static Brush JTokenColorUri => (Brush)new BrushConverter().ConvertFrom(JTokenHexColorUri)!;
29+
2130
public static Brush JTokenColorNull => (Brush)new BrushConverter().ConvertFrom(JTokenHexColorNull)!;
2231
}

src/Atc.Wpf.Controls/Dialogs/DialogBoxSettings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ public static DialogBoxSettings Create(
141141
DialogBoxType dialogBoxType)
142142
=> new(dialogBoxType);
143143

144+
public override string ToString()
145+
=> $"{nameof(Width)}: {Width}, {nameof(Height)}: {Height}, {nameof(TitleBarText)}: {TitleBarText}, {nameof(Form)}: ({Form})";
146+
144147
private void SetContentSvgImage()
145148
{
146149
switch (dialogBoxType)

src/Atc.Wpf.Controls/Dialogs/InputFormDialogBox.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
</atc:UniformSpacingPanel>
7070
</Border>
7171

72-
<ScrollViewer x:Name="ContentCenter" Padding="30,15">
72+
<ScrollViewer x:Name="ContentCenter" Padding="20">
7373
<ContentControl
7474
HorizontalAlignment="Center"
7575
VerticalAlignment="Center"

src/Atc.Wpf.Controls/Dialogs/InputFormDialogBox.xaml.cs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ public InputFormDialogBox(
3030
this.Settings.TitleBarText = titleBarText;
3131
}
3232

33+
public InputFormDialogBox(
34+
Window owningWindow,
35+
LabelInputFormPanelSettings formPanelSettings,
36+
ILabelControlsForm labelControlsForm)
37+
{
38+
ArgumentNullException.ThrowIfNull(labelControlsForm);
39+
40+
this.OwningWindow = owningWindow;
41+
this.Settings = DialogBoxSettings.Create(DialogBoxType.OkCancel);
42+
this.Width = this.Settings.Width;
43+
this.Height = this.Settings.Height;
44+
this.Settings.Form = formPanelSettings;
45+
46+
InitializeDialogBox(labelControlsForm);
47+
}
48+
3349
public InputFormDialogBox(
3450
Window owningWindow,
3551
DialogBoxSettings settings,
@@ -56,6 +72,13 @@ public InputFormDialogBox(
5672

5773
public ILabelControlsForm Data => LabelInputFormPanel.Data;
5874

75+
public void ReRender()
76+
{
77+
LabelInputFormPanel.ReRender();
78+
79+
UpdateWidthAndHeight();
80+
}
81+
5982
private void InitializeDialogBox(
6083
ILabelControlsForm labelControlsForm)
6184
{
@@ -73,6 +96,11 @@ private void PopulateLabelInputFormPanel(
7396
this.Settings.Form,
7497
labelControlsForm);
7598

99+
UpdateWidthAndHeight();
100+
}
101+
102+
private void UpdateWidthAndHeight()
103+
{
76104
Width = ContentCenter.Padding.Left +
77105
ContentCenter.Padding.Right +
78106
Data.GetMaxWidth() +
@@ -83,14 +111,16 @@ private void PopulateLabelInputFormPanel(
83111
Width = Settings.Form.MaxSize.Width;
84112
}
85113

86-
Height = HeaderControl is null
87-
? Data.GetMaxHeight() +
88-
ScrollBarSize +
89-
ContentButton.Height
90-
: ContentTop.Height +
91-
Data.GetMaxHeight() +
92-
ScrollBarSize +
93-
ContentButton.Height;
114+
Height = ContentCenter.Padding.Top +
115+
ContentCenter.Padding.Bottom +
116+
ContentButton.Height +
117+
Data.GetMaxHeight() +
118+
ScrollBarSize;
119+
120+
if (HeaderControl is not null)
121+
{
122+
Height += ContentTop.Height;
123+
}
94124

95125
if (Height > Settings.Form.MaxSize.Height)
96126
{

src/Atc.Wpf.Controls/LabelControls/LabelControlsForm.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ namespace Atc.Wpf.Controls.LabelControls;
33

44
public class LabelControlsForm : ILabelControlsForm
55
{
6-
private const int GroupBoxMarginWidth = 40;
6+
private const int GroupBoxWidthForSpace = 20;
7+
private const int GroupBoxWidthForMargin = 10;
78

89
public IList<ILabelControlsFormRow>? Rows { get; set; }
910

@@ -149,9 +150,9 @@ public int GetMaxWidth()
149150
controlsWidth = column.ControlWidth;
150151
}
151152

152-
if (numberOfColumnsWithGroupBox > 1)
153+
if (numberOfColumnsWithGroupBox > 0)
153154
{
154-
marginOffset = (numberOfColumnsWithGroupBox - 1) * GroupBoxMarginWidth;
155+
marginOffset += numberOfColumnsWithGroupBox * (GroupBoxWidthForSpace + GroupBoxWidthForMargin);
155156
}
156157
}
157158

@@ -253,4 +254,22 @@ public Dictionary<string, object> GetKeyValues()
253254

254255
return result;
255256
}
257+
258+
public override string ToString()
259+
{
260+
if (Rows is null)
261+
{
262+
return "No LabelControls";
263+
}
264+
265+
var rowLineInfo = new List<string>();
266+
for (var i = 0; i < Rows.Count; i++)
267+
{
268+
var row = Rows[i];
269+
var totalRowHeight = row.Columns?.Sum(x => x.CalculateHeight()) ?? 0;
270+
rowLineInfo.Add($"Row {i}: ColCount={row.Columns?.Count ?? 0}, TotalRowHeight={totalRowHeight}");
271+
}
272+
273+
return string.Join(" # ", rowLineInfo);
274+
}
256275
}

0 commit comments

Comments
 (0)