mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
Refinements.
Added OnAccept call to Sliser
This commit is contained in:
@@ -272,6 +272,10 @@ public class DimAuto () : Dim
|
||||
{
|
||||
View v = subviews [i];
|
||||
|
||||
if (autoMax == int.MaxValue)
|
||||
{
|
||||
autoMax = superviewContentSize;
|
||||
}
|
||||
if (dimension == Dimension.Width)
|
||||
{
|
||||
v.SetRelativeLayout (new Size (autoMax - subviewsSize, 0));
|
||||
|
||||
@@ -70,9 +70,6 @@ public class Shortcut : View
|
||||
// Only the Shortcut should be able to have focus, not any subviews
|
||||
KeyView.CanFocus = false;
|
||||
|
||||
// Right align the text in the keyview
|
||||
KeyView.TextAlignment = Alignment.End;
|
||||
|
||||
SetKeyViewDefaultLayout ();
|
||||
Add (KeyView);
|
||||
|
||||
@@ -88,9 +85,7 @@ public class Shortcut : View
|
||||
|
||||
void OnInitialized (object sender, EventArgs e)
|
||||
{
|
||||
ShowHide (CommandView);
|
||||
ShowHide (HelpView);
|
||||
ShowHide (KeyView);
|
||||
ShowHide ();
|
||||
|
||||
// Force Width to DimAuto to calculate natural width and then set it back
|
||||
Dim savedDim = Width;
|
||||
@@ -120,7 +115,7 @@ public class Shortcut : View
|
||||
// When one of the subviews is "empty" we don't want to show it. So we
|
||||
// Use Add/Remove. We need to be careful to add them in the right order
|
||||
// so Pos.Align works correctly.
|
||||
private void ShowHide (View subView)
|
||||
private void ShowHide ()
|
||||
{
|
||||
RemoveAll ();
|
||||
if (!string.IsNullOrEmpty (CommandView.Text))
|
||||
@@ -366,8 +361,8 @@ public class Shortcut : View
|
||||
_commandView.CanFocus = false;
|
||||
|
||||
// Bar will set the width of all CommandViews to the width of the widest CommandViews.
|
||||
_commandView.Width = Dim.Auto (DimAutoStyle.Text);
|
||||
_commandView.Height = Dim.Auto (DimAutoStyle.Text);
|
||||
_commandView.Width = Dim.Auto ();
|
||||
_commandView.Height = Dim.Auto ();
|
||||
_commandView.X = Pos.Align (Alignment.End, AlignmentModes.IgnoreFirstOrLast);
|
||||
_commandView.Y = 0; //Pos.Center ();
|
||||
|
||||
@@ -394,7 +389,7 @@ public class Shortcut : View
|
||||
Remove (KeyView);
|
||||
Add (_commandView, HelpView, KeyView);
|
||||
|
||||
ShowHide (_commandView);
|
||||
ShowHide ();
|
||||
UpdateKeyBinding ();
|
||||
|
||||
return;
|
||||
@@ -404,7 +399,7 @@ public class Shortcut : View
|
||||
void CommandViewTextChanged (object sender, StateEventArgs<string> e)
|
||||
{
|
||||
Title = _commandView.Text;
|
||||
ShowHide (_commandView);
|
||||
ShowHide ();
|
||||
}
|
||||
|
||||
void CommandViewAccept (object sender, CancelEventArgs e)
|
||||
@@ -445,10 +440,12 @@ public class Shortcut : View
|
||||
{
|
||||
HelpView.Margin.Thickness = new (1, 0, 1, 0);
|
||||
HelpView.X = Pos.Align (Alignment.End, AlignmentModes.IgnoreFirstOrLast);
|
||||
HelpView.Y = 0; //Pos.Center (),
|
||||
HelpView.Y = 0; //Pos.Center (),
|
||||
HelpView.Width = Dim.Auto (DimAutoStyle.Text);
|
||||
HelpView.Height = Dim.Auto (DimAutoStyle.Text);
|
||||
HelpView.Height = Dim.Height(CommandView);
|
||||
HelpView.Visible = true;
|
||||
HelpView.VerticalTextAlignment = Alignment.Center;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -463,7 +460,7 @@ public class Shortcut : View
|
||||
if (HelpView != null)
|
||||
{
|
||||
HelpView.Text = value;
|
||||
ShowHide (HelpView);
|
||||
ShowHide ();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -479,7 +476,7 @@ public class Shortcut : View
|
||||
if (HelpView != null)
|
||||
{
|
||||
HelpView.Text = value;
|
||||
ShowHide (HelpView);
|
||||
ShowHide ();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -508,7 +505,7 @@ public class Shortcut : View
|
||||
UpdateKeyBinding ();
|
||||
|
||||
KeyView.Text = Key == Key.Empty ? string.Empty : $"{Key}";
|
||||
ShowHide (KeyView);
|
||||
ShowHide ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -563,10 +560,13 @@ public class Shortcut : View
|
||||
{
|
||||
KeyView.Margin.Thickness = new (1, 0, 1, 0);
|
||||
KeyView.X = Pos.Align (Alignment.End, AlignmentModes.IgnoreFirstOrLast);
|
||||
KeyView.Y = 0; //Pos.Center (),
|
||||
//KeyView.Y = Pos.Center ();
|
||||
KeyView.Width = Dim.Auto (DimAutoStyle.Text, minimumContentDim: Dim.Func(GetMinimumKeyViewSize));
|
||||
KeyView.Height = Dim.Auto (DimAutoStyle.Text);
|
||||
KeyView.Height = Dim.Height(CommandView);
|
||||
KeyView.Visible = true;
|
||||
// Right align the text in the keyview
|
||||
KeyView.TextAlignment = Alignment.End;
|
||||
KeyView.VerticalTextAlignment = Alignment.Center;
|
||||
}
|
||||
|
||||
private void UpdateKeyBinding ()
|
||||
|
||||
@@ -1650,6 +1650,8 @@ public class Slider<T> : View
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException (_config._type.ToString ());
|
||||
}
|
||||
OnAccept ();
|
||||
|
||||
}
|
||||
|
||||
internal bool ExtendPlus ()
|
||||
@@ -1735,7 +1737,6 @@ public class Slider<T> : View
|
||||
internal bool Set ()
|
||||
{
|
||||
SetFocusedOption ();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ public class Shortcuts : Scenario
|
||||
ListView eventLog = new ListView ()
|
||||
{
|
||||
X = Pos.AnchorEnd (),
|
||||
Width = 50,
|
||||
Width = 40,
|
||||
Height = Dim.Fill (),
|
||||
ColorScheme = Colors.ColorSchemes ["Toplevel"],
|
||||
Source = new ListWrapper<string> (eventSource)
|
||||
@@ -44,10 +44,11 @@ public class Shortcuts : Scenario
|
||||
|
||||
var shortcut1 = new Shortcut
|
||||
{
|
||||
//Width =30,
|
||||
X = 20,
|
||||
Width = 30,
|
||||
Title = "Zi_gzag",
|
||||
Key = Key.F1,
|
||||
Text = "Gonna zig zag",
|
||||
Text = "Width is 30",
|
||||
KeyBindingScope = KeyBindingScope.Application,
|
||||
BorderStyle = LineStyle.Dotted
|
||||
};
|
||||
@@ -61,14 +62,20 @@ public class Shortcuts : Scenario
|
||||
|
||||
var shortcut2 = new Shortcut
|
||||
{
|
||||
X = 20,
|
||||
Y = Pos.Bottom (shortcut1),
|
||||
Width = Dim.Width (shortcut1),
|
||||
Title = "_Two",
|
||||
Key = Key.F2.WithAlt,
|
||||
Text = "Number two",
|
||||
Key = Key.F2,
|
||||
Text = "Width is ^",
|
||||
KeyBindingScope = KeyBindingScope.HotKey,
|
||||
BorderStyle = LineStyle.Dotted
|
||||
BorderStyle = LineStyle.Dotted,
|
||||
CommandView = new RadioGroup ()
|
||||
{
|
||||
Orientation = Orientation.Vertical,
|
||||
RadioLabels = ["One", "Two", "Three", "Four"],
|
||||
},
|
||||
};
|
||||
|
||||
shortcut2.Border.Thickness = new Thickness (1, 0, 1, 0);
|
||||
shortcut2.Accept += (s, e) =>
|
||||
{
|
||||
@@ -79,11 +86,12 @@ public class Shortcuts : Scenario
|
||||
|
||||
var shortcut3 = new Shortcut
|
||||
{
|
||||
X = 20,
|
||||
Y = Pos.Bottom (shortcut2),
|
||||
Width = Dim.Width (shortcut1),
|
||||
CommandView = new CheckBox () { Text = "_Align" },
|
||||
Key = Key.F3,
|
||||
HelpText = "Alignment",
|
||||
HelpText = "Width is Fill",
|
||||
Width = Dim.Fill () - Dim.Width (eventLog),
|
||||
KeyBindingScope = KeyBindingScope.HotKey,
|
||||
BorderStyle = LineStyle.Dotted
|
||||
};
|
||||
@@ -124,40 +132,19 @@ public class Shortcuts : Scenario
|
||||
};
|
||||
Application.Top.Add (shortcut3);
|
||||
|
||||
|
||||
var shortcutH = new Shortcut
|
||||
{
|
||||
Y = Pos.Top (shortcut3),
|
||||
X = Pos.Right (shortcut3),
|
||||
Title = "Horizo_ntal",
|
||||
Key = Key.F10,
|
||||
Text = "Hey!",
|
||||
KeyBindingScope = KeyBindingScope.HotKey,
|
||||
BorderStyle = LineStyle.Dotted
|
||||
};
|
||||
shortcutH.Border.Thickness = new Thickness (0, 0, 1, 0);
|
||||
shortcutH.Accept += (s, e) =>
|
||||
{
|
||||
eventSource.Add ($"Accept: {s}");
|
||||
eventLog.MoveDown ();
|
||||
};
|
||||
Application.Top.Add (shortcutH);
|
||||
|
||||
var shortcut4 = new Shortcut
|
||||
{
|
||||
X = 20,
|
||||
Y = Pos.Bottom (shortcut3),
|
||||
Width = Dim.Fill (50),
|
||||
Width = Dim.Width (shortcut3),
|
||||
Title = "C",
|
||||
Text = "H",
|
||||
HelpText = "Width is Fill",
|
||||
Key = Key.K,
|
||||
KeyBindingScope = KeyBindingScope.HotKey,
|
||||
// Command = Command.Accept,
|
||||
BorderStyle = LineStyle.Dotted
|
||||
};
|
||||
shortcut4.Border.Thickness = new Thickness (1, 0, 1, 0);
|
||||
shortcut4.Margin.Thickness = new Thickness (0, 1, 0, 0);
|
||||
View.Diagnostics = ViewDiagnosticFlags.Ruler;
|
||||
|
||||
shortcut4.Accept += (s, e) =>
|
||||
{
|
||||
@@ -171,16 +158,15 @@ public class Shortcuts : Scenario
|
||||
{
|
||||
X = 20,
|
||||
Y = Pos.Bottom (shortcut4),
|
||||
Width = Dim.Fill (50),
|
||||
Width = Dim.Width (shortcut4),
|
||||
|
||||
Title = "Fi_ve",
|
||||
Key = Key.F5.WithCtrl.WithAlt.WithShift,
|
||||
Text = "Help text",
|
||||
HelpText = "Width is Fill",
|
||||
KeyBindingScope = KeyBindingScope.HotKey,
|
||||
BorderStyle = LineStyle.Dotted
|
||||
};
|
||||
shortcut5.Border.Thickness = new Thickness (1, 0, 1, 0);
|
||||
shortcut5.Margin.Thickness = new Thickness (0, 1, 0, 0);
|
||||
View.Diagnostics = ViewDiagnosticFlags.Ruler;
|
||||
|
||||
shortcut5.Accept += (s, e) =>
|
||||
{
|
||||
@@ -190,9 +176,40 @@ public class Shortcuts : Scenario
|
||||
Application.Top.Add (shortcut5);
|
||||
|
||||
|
||||
var shortcutSlider = new Shortcut
|
||||
{
|
||||
X = 20,
|
||||
Y = Pos.Bottom (shortcut5),
|
||||
Key = Key.F5,
|
||||
HelpText = "Width is Fill",
|
||||
Width = Dim.Width (shortcut5),
|
||||
|
||||
KeyBindingScope = KeyBindingScope.HotKey,
|
||||
BorderStyle = LineStyle.Dotted,
|
||||
CommandView = new Slider<string> ()
|
||||
{
|
||||
Orientation = Orientation.Vertical,
|
||||
AllowEmpty = false,
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
((Slider<string>)shortcutSlider.CommandView).Options = new List<SliderOption<string>> ()
|
||||
{ new () { Legend = "A" }, new () { Legend = "B" }, new () { Legend = "C" } };
|
||||
((Slider<string>)shortcutSlider.CommandView).SetOption (0);
|
||||
shortcutSlider.Border.Thickness = new Thickness (1, 0, 1, 0);
|
||||
|
||||
shortcutSlider.Accept += (s, e) =>
|
||||
{
|
||||
eventSource.Add ($"Accept: {s}");
|
||||
eventLog.MoveDown ();
|
||||
};
|
||||
Application.Top.Add (shortcutSlider);
|
||||
;
|
||||
((CheckBox)shortcut3.CommandView).OnToggled ();
|
||||
|
||||
//shortcut1.SetFocus ();
|
||||
//View.Diagnostics = ViewDiagnosticFlags.Ruler;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user