mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-02 01:03:29 +01:00
ComboBox supports Dim.Fill() Dim.Percent()
This commit is contained in:
@@ -422,26 +422,27 @@ static class Demo {
|
||||
MessageBox.Query (60, 10, "Selected Animals", result == "" ? "No animals selected" : result, "Ok");
|
||||
}
|
||||
|
||||
//static void ComboBoxDemo ()
|
||||
//{
|
||||
// IList<string> items = new List<string> ();
|
||||
// foreach (var dir in new [] { "/etc", @"\windows\System32" }) {
|
||||
// if (Directory.Exists (dir)) {
|
||||
// items = Directory.GetFiles (dir)
|
||||
// .Select (Path.GetFileName)
|
||||
// .Where (x => char.IsLetterOrDigit (x [0]))
|
||||
// .Distinct ()
|
||||
// .OrderBy (x => x).ToList ();
|
||||
// }
|
||||
// }
|
||||
// var list = new ComboBox (0, 0, 36, 7, items);
|
||||
// list.Changed += (object sender, ustring text) => { Application.RequestStop (); };
|
||||
static void ComboBoxDemo ()
|
||||
{
|
||||
IList<string> items = new List<string> ();
|
||||
foreach (var dir in new [] { "/etc", @"\windows\System32" }) {
|
||||
if (Directory.Exists (dir)) {
|
||||
items = Directory.GetFiles (dir)
|
||||
.Select (Path.GetFileName)
|
||||
.Where (x => char.IsLetterOrDigit (x [0]))
|
||||
.Distinct ()
|
||||
.OrderBy (x => x).ToList ();
|
||||
}
|
||||
}
|
||||
var list = new ComboBox () { X = 0, Y = 0, Width = 36, Height = 7 };
|
||||
list.SetSource(items);
|
||||
list.Changed += (object sender, ustring text) => { Application.RequestStop (); };
|
||||
|
||||
// var d = new Dialog ("Select source file", 40, 12) { list };
|
||||
// Application.Run (d);
|
||||
var d = new Dialog ("Select source file", 40, 12) { list };
|
||||
Application.Run (d);
|
||||
|
||||
// MessageBox.Query (60, 10, "Selected file", list.Text.ToString() == "" ? "Nothing selected" : list.Text.ToString(), "Ok");
|
||||
//}
|
||||
MessageBox.Query (60, 10, "Selected file", list.Text.ToString() == "" ? "Nothing selected" : list.Text.ToString(), "Ok");
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -573,7 +574,7 @@ static class Demo {
|
||||
new MenuBarItem ("_List Demos", new MenuItem [] {
|
||||
new MenuItem ("Select _Multiple Items", "", () => ListSelectionDemo (true)),
|
||||
new MenuItem ("Select _Single Item", "", () => ListSelectionDemo (false)),
|
||||
// new MenuItem ("Search Single Item", "", ComboBoxDemo)
|
||||
new MenuItem ("Search Single Item", "", ComboBoxDemo)
|
||||
}),
|
||||
new MenuBarItem ("A_ssorted", new MenuItem [] {
|
||||
new MenuItem ("_Show text alignments", "", () => ShowTextAlignments ()),
|
||||
|
||||
@@ -361,7 +361,7 @@ namespace Terminal.Gui {
|
||||
return 0;
|
||||
}
|
||||
|
||||
class DimFactor : Dim {
|
||||
internal class DimFactor : Dim {
|
||||
float factor;
|
||||
|
||||
public DimFactor (float n)
|
||||
|
||||
@@ -171,9 +171,6 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NStack.Core" Version="0.14.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Remove="Views\ComboBox.cs" />
|
||||
</ItemGroup>
|
||||
<!--<ItemGroup>
|
||||
<Reference Include="NStack">
|
||||
<HintPath>..\..\..\Users\miguel\.nuget\packages\nstack.core\0.14.0\lib\netstandard2.0\NStack.dll</HintPath>
|
||||
|
||||
@@ -40,8 +40,8 @@ namespace Terminal.Gui {
|
||||
/// </summary>
|
||||
public ComboBox () : base()
|
||||
{
|
||||
search = new TextField ("") { LayoutStyle = LayoutStyle.Computed };
|
||||
listview = new ListView () { LayoutStyle = LayoutStyle.Computed, CanFocus = true /* why? */ };
|
||||
search = new TextField ("");
|
||||
listview = new ListView () { LayoutStyle = LayoutStyle.Computed, CanFocus = true };
|
||||
|
||||
Initialize ();
|
||||
}
|
||||
@@ -62,7 +62,7 @@ namespace Terminal.Gui {
|
||||
height = h;
|
||||
width = w;
|
||||
|
||||
search = new TextField (x, y, w, "");
|
||||
search = new TextField ("") { X = x, Y = y, Width = w };
|
||||
|
||||
listview = new ListView (new Rect (x, y + 1, w, 0), listsource.ToList ()) {
|
||||
LayoutStyle = LayoutStyle.Computed,
|
||||
@@ -81,7 +81,7 @@ namespace Terminal.Gui {
|
||||
};
|
||||
|
||||
// TODO: LayoutComplete event breaks cursor up/down. Revert to Application.Loaded
|
||||
Application.Loaded += (sender, a) => {
|
||||
Application.Loaded += (object sender, Application.ResizedEventArgs a) => {
|
||||
// Determine if this view is hosted inside a dialog
|
||||
for (View view = this.SuperView; view != null; view = view.SuperView) {
|
||||
if (view is Dialog) {
|
||||
@@ -102,18 +102,25 @@ namespace Terminal.Gui {
|
||||
else
|
||||
listview.Y = Pos.Bottom (search);
|
||||
|
||||
if (Width == null)
|
||||
if (Width == null) {
|
||||
listview.Width = CalculateWidth ();
|
||||
else {
|
||||
width = GetDimAsInt (Width);
|
||||
search.Width = width;
|
||||
} else {
|
||||
width = GetDimAsInt (Width, a, vertical: false);
|
||||
search.Width = width;
|
||||
listview.Width = CalculateWidth ();
|
||||
}
|
||||
|
||||
if (Height == null)
|
||||
listview.Height = CalculatetHeight ();
|
||||
else {
|
||||
height = GetDimAsInt (Height);
|
||||
if (Height == null) {
|
||||
var h = CalculatetHeight ();
|
||||
listview.Height = h;
|
||||
this.Height = h + 1; // adjust view to account for search box
|
||||
} else {
|
||||
if (height == 0)
|
||||
height = GetDimAsInt (Height, a, vertical: true);
|
||||
|
||||
listview.Height = CalculatetHeight ();
|
||||
this.Height = height + 1; // adjust view to account for search box
|
||||
}
|
||||
|
||||
if (this.Text != null)
|
||||
@@ -161,8 +168,7 @@ namespace Terminal.Gui {
|
||||
///<inheritdoc/>
|
||||
public override bool ProcessKey(KeyEvent e)
|
||||
{
|
||||
if (e.Key == Key.Tab)
|
||||
{
|
||||
if (e.Key == Key.Tab) {
|
||||
base.ProcessKey(e);
|
||||
return false; // allow tab-out to next control
|
||||
}
|
||||
@@ -295,18 +301,18 @@ namespace Terminal.Gui {
|
||||
/// Get DimAbsolute as integer value
|
||||
/// </summary>
|
||||
/// <param name="dim"></param>
|
||||
/// <param name="a"></param>
|
||||
/// <param name="vertical"></param>
|
||||
/// <returns></returns>
|
||||
private int GetDimAsInt(Dim dim)
|
||||
private int GetDimAsInt (Dim dim, Application.ResizedEventArgs a, bool vertical)
|
||||
{
|
||||
if (!(dim is Dim.DimAbsolute))
|
||||
throw new ArgumentException ("Dim must be an absolute value");
|
||||
if (dim is Dim.DimAbsolute)
|
||||
return dim.Anchor (0);
|
||||
|
||||
// Anchor in the case of DimAbsolute returns absolute value. No documentation on what Anchor() does so not sure if this will change in the future.
|
||||
//
|
||||
// TODO: Does Dim need:-
|
||||
// public static implicit operator int (Dim d)
|
||||
//
|
||||
return dim.Anchor (0);
|
||||
if (dim is Dim.DimFill || dim is Dim.DimFactor)
|
||||
return vertical ? dim.Anchor (a.Rows) : dim.Anchor (a.Cols);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,17 +22,20 @@ namespace UICatalog.Scenarios {
|
||||
}
|
||||
}
|
||||
|
||||
Dim width = 30;
|
||||
|
||||
// ListView
|
||||
var lbListView = new Label ("Listview") {
|
||||
ColorScheme = Colors.TopLevel,
|
||||
X = 0,
|
||||
Width = 30
|
||||
Width = width
|
||||
};
|
||||
|
||||
var listview = new ListView (items) {
|
||||
X = 0,
|
||||
Y = Pos.Bottom (lbListView) + 1,
|
||||
Width = 30
|
||||
Height = Dim.Fill(2),
|
||||
Width = width
|
||||
};
|
||||
listview.OpenSelectedItem += (object sender, ListViewItemEventArgs e) => lbListView.Text = items [listview.SelectedItem];
|
||||
Win.Add (lbListView, listview);
|
||||
@@ -41,14 +44,14 @@ namespace UICatalog.Scenarios {
|
||||
var lbComboBox = new Label ("ComboBox") {
|
||||
ColorScheme = Colors.TopLevel,
|
||||
X = Pos.Right (lbListView) + 1,
|
||||
Width = 30
|
||||
Width = width
|
||||
};
|
||||
|
||||
var comboBox = new ComboBox() {
|
||||
X = Pos.Right(listview) + 1 ,
|
||||
Y = Pos.Bottom (lbListView) +1,
|
||||
Height = 10,
|
||||
Width = 30
|
||||
var comboBox = new ComboBox () {
|
||||
X = Pos.Right (listview) + 1,
|
||||
Y = Pos.Bottom (lbListView) + 1,
|
||||
Height = Dim.Fill (2),
|
||||
Width = width
|
||||
};
|
||||
comboBox.SetSource (items);
|
||||
|
||||
|
||||
@@ -35,16 +35,18 @@ namespace UICatalog {
|
||||
var checkBox = new CheckBox (" ~ s gui.cs master ↑10") { X = 15, Y = Pos.Y (label), Width = Dim.Percent (50) };
|
||||
Win.Add (checkBox);
|
||||
|
||||
//label = new Label ("ComboBox:") { X = Pos.X (label), Y = Pos.Bottom (label) + 1 };
|
||||
//Win.Add (label);
|
||||
//var comboBox = new ComboBox (1, 1, 30, 5, new List<string> () { "item #1", " ~ s gui.cs master ↑10", "Со_хранить" }) {
|
||||
// X = 15,
|
||||
// Y = Pos.Y (label),
|
||||
// Width = 30,
|
||||
// ColorScheme = Colors.Error
|
||||
//};
|
||||
//Win.Add (comboBox);
|
||||
//comboBox.Text = " ~ s gui.cs master ↑10";
|
||||
label = new Label ("ComboBox:") { X = Pos.X (label), Y = Pos.Bottom (label) + 1 };
|
||||
Win.Add (label);
|
||||
var comboBox = new ComboBox () {
|
||||
X = 15,
|
||||
Y = Pos.Y (label),
|
||||
Width = Dim.Percent (50),
|
||||
ColorScheme = Colors.Error
|
||||
};
|
||||
comboBox.SetSource (new List<string> () { "item #1", " ~ s gui.cs master ↑10", "Со_хранить" });
|
||||
|
||||
Win.Add (comboBox);
|
||||
comboBox.Text = " ~ s gui.cs master ↑10";
|
||||
|
||||
label = new Label ("HexView:") { X = Pos.X (label), Y = Pos.Bottom (label) + 2 };
|
||||
Win.Add (label);
|
||||
|
||||
@@ -7,10 +7,6 @@
|
||||
<AssemblyVersion>1.0.0.1</AssemblyVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Scenarios\ListsAndCombos.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Terminal.Gui\Terminal.Gui.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user