Skip to content

Commit 9f670d4

Browse files
author
tznind
committed
Setup linear range sensible default options
1 parent e589b03 commit 9f670d4

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

src/TTypes.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static IEnumerable<Type> GetSupportedTTypesForGenericViewOfType(Type view
4343
{
4444
if (viewType == typeof(LinearRange<>))
4545
{
46-
return new[] { typeof(int), typeof(string), typeof(int), typeof(double), typeof(bool) };
46+
return new[] { typeof(int), typeof(string),typeof(double), typeof(bool) };
4747
}
4848

4949
if (viewType == typeof(NumericUpDown<>))

src/ViewFactory.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@ public static T Create<T>(int? width = null, int? height = null, string? text =
309309
case null:
310310
throw new InvalidOperationException( $"Unexpected null result from type {typeof( T ).Name} constructor." );
311311
}
312+
313+
SetupLinearRangeOptions(newView);
312314

313315
return newView;
314316

@@ -325,6 +327,48 @@ static void SetDefaultDimensionsDimAuto(T v)
325327
}
326328
}
327329

330+
private static void SetupLinearRangeOptions<T>(T newView) where T : View, new()
331+
{
332+
if (newView is LinearRange<bool> lrb)
333+
{
334+
lrb.Options = new List<LinearRangeOption<bool>>([
335+
new LinearRangeOption<bool>("True", new System.Text.Rune('T'), true),
336+
new LinearRangeOption<bool>("False", new System.Text.Rune('F'), false),
337+
]);
338+
lrb.Width = 10;
339+
lrb.Height = 2;
340+
}
341+
else if (newView is LinearRange<int> lri)
342+
{
343+
lri.Options = new List<LinearRangeOption<int>>([
344+
new LinearRangeOption<int>("One", new System.Text.Rune('1'), 1),
345+
new LinearRangeOption<int>("Two", new System.Text.Rune('2'), 2),
346+
new LinearRangeOption<int>("Three", new System.Text.Rune('3'), 3),
347+
]);
348+
lri.Width = 10;
349+
lri.Height = 2;
350+
}
351+
else if (newView is LinearRange<double> lrd)
352+
{
353+
lrd.Options = new List<LinearRangeOption<double>>([
354+
new LinearRangeOption<double>("Low", new System.Text.Rune('L'), 0.0),
355+
new LinearRangeOption<double>("Mid", new System.Text.Rune('M'), 0.5),
356+
new LinearRangeOption<double>("High", new System.Text.Rune('H'), 1.0),
357+
]);
358+
lrd.Width = 18;
359+
lrd.Height = 2;
360+
}
361+
else if (newView is LinearRange<string> lrs)
362+
{
363+
lrs.Options = new List<LinearRangeOption<string>>([
364+
new LinearRangeOption<string>("Option 1", new System.Text.Rune('1'), "Option 1"),
365+
new LinearRangeOption<string>("Option 2", new System.Text.Rune('2'), "Option 2"),
366+
new LinearRangeOption<string>("Option 3", new System.Text.Rune('3'), "Option 3"),
367+
]);
368+
lrs.Width = 25;
369+
lrs.Height = 2;
370+
}
371+
}
328372

329373
/// <summary>
330374
/// Creates a new instance of <see cref="View" /> of <see cref="Type" /> <paramref name="requestedType" /> with

0 commit comments

Comments
 (0)