Add scenario support for flipping button order

This commit is contained in:
tznind
2023-09-21 06:38:57 +01:00
parent 4036fb9926
commit 14fab61d35
2 changed files with 41 additions and 4 deletions

View File

@@ -648,11 +648,16 @@ namespace Terminal.Gui {
this.btnToggleSplitterCollapse.Text = this.GetToggleSplitterText (false);
if(Style.FlipOkCancelButtonLayoutOrder) {
var p1 = btnOk.X;
var p2 = btnCancel.X;
btnCancel.X = Pos.Function(this.CalculateOkButtonPosX);
btnOk.X = Pos.Right (btnCancel) + 1;
btnOk.X = p2;
btnCancel.X = p1;
// Flip tab order too for consistency
var p1 = this.btnOk.TabIndex;
var p2 = this.btnCancel.TabIndex;
this.btnOk.TabIndex = p2;
this.btnCancel.TabIndex = p1;
}
tbPath.Caption = Style.PathCaption;

View File

@@ -25,6 +25,9 @@ namespace UICatalog.Scenarios {
private RadioGroup rgIcons;
private RadioGroup rgAllowedTypes;
private TextField tbOkButton;
private TextField tbCancelButton;
private CheckBox cbFlipButtonOrder;
public override void Setup ()
{
var y = 0;
@@ -110,6 +113,25 @@ namespace UICatalog.Scenarios {
rgAllowedTypes.RadioLabels = new string [] { "Any", "Csv (Recommended)", "Csv (Strict)" };
Win.Add (rgAllowedTypes);
y = 5;
x = 45;
Win.Add (new LineView (Orientation.Vertical) {
X = x++,
Y = y + 1,
Height = 4
});
Win.Add (new Label ("Buttons") { X = x++, Y = y++ });
Win.Add(new Label("Ok Text:") { X = x, Y = y++ });
tbOkButton = new TextField () { X = x, Y = y++, Width = 12 };
Win.Add (tbOkButton);
Win.Add (new Label ("Cancel Text:") { X = x, Y = y++ });
tbCancelButton = new TextField () { X = x, Y = y++, Width = 12 };
Win.Add (tbCancelButton);
cbFlipButtonOrder = new CheckBox ("Flip Order") { X = x, Y = y++};
Win.Add (cbFlipButtonOrder);
var btn = new Button ($"Run Dialog") {
X = 1,
Y = 9
@@ -178,6 +200,16 @@ namespace UICatalog.Scenarios {
}
if (!string.IsNullOrWhiteSpace (tbOkButton.Text)) {
fd.Style.OkButtonText = tbOkButton.Text;
}
if (!string.IsNullOrWhiteSpace (tbCancelButton.Text)) {
fd.Style.CancelButtonText= tbCancelButton.Text;
}
if(cbFlipButtonOrder.Checked ?? false) {
fd.Style.FlipOkCancelButtonLayoutOrder = true;
}
Application.Run (fd);
if (fd.Canceled) {