Hello,
After applying SetFocus() to TextView the way of switching by Tab elements is changing. For example:
using Terminal.Gui;
namespace UICatalog {
[ScenarioMetadata (Name: "FocusOrder", Description: "Demonstrate change of focus order after SetFocus()")]
[ScenarioCategory ("Bug Repro")]
class FocusOrder : Scenario {
class TextFrame : FrameView {
private TextView textField;
public TextFrame (string title) : base (title) {
textField = new TextView () {
X = 0,
Y = 0,
Width = Dim.Fill () - 15,
Height = Dim.Fill(),
ColorScheme = Colors.Dialog,
Text = "0"
};
var button1 = new Button ("Button 1…") {
X = Pos.Right(textField)+1,
Y = Pos.Top(textField),
Clicked = () => { Button1Handler();}
};
var button2 = new Button ("Button 2…") {
X = Pos.X(button1),
Y = Pos.Y(button1)+2,
Clicked = () => { Button2Handler();}
};
Add(textField, button1, button2);
}
public bool showMessage() {
var d =MessageBox.ErrorQuery("Error", "Error", "Ok");
this.SetFocus(textField);
return true;
}
private void Button1Handler() {
}
private void Button2Handler() {
showMessage();
}
}
public override void Setup () {
var tf = new TextFrame ("Frame") {
X = 0,
Y = 0,
Width = Dim.Fill(),
Height = Dim.Fill() - 3
};
var button3 = new Button("Button 3") {
X = Pos.Percent(50) - 6,
Y = Pos.Bottom(tf) + 1,
};
Win.Add(tf, button3);
}
}
}
When focus changed by "Button 2" to TextView pressing Tab switch focus to "Button 3". Estimated order is "Button 1"
To do this as expected with the fix the call must be like below to send the focus upwards too.
textField.SuperView.SetFocus (textField);
or better
textField.SetFocus ();
Thanks!
The first variant works. The second generate exeption
Thanks!
The first variant works. The second generate exeption
For the second variant works you have to merge the PR #750.
I didn't find how to add PR to the forked repo or download patch from PR
You have to checkout that PR and run your code from there or you can wait until the PR is merged to the master.
Both working; I cloned BDisp:setfocus-order