Drawing cursor on top-level MenuBar?
See original GitHub issue@BDisp this is really a question for you; starting a new thread on a slightly different topic from our other convo…
I noticed MenuBar.PositionCursor
doesn’t actually do anything today. It’s dead code.
public override void Redraw (Rect region)
{
Move (0, 0);
Driver.SetAttribute (Colors.Menu.Normal);
for (int i = 0; i < Frame.Width; i++)
Driver.AddRune (' ');
Move (1, 0);
int pos = 1;
for (int i = 0; i < Menus.Length; i++) {
var menu = Menus [i];
Move (pos, 0);
Attribute hotColor, normalColor;
if (i == selected) {
hotColor = i == selected ? ColorScheme.HotFocus : ColorScheme.HotNormal;
normalColor = i == selected ? ColorScheme.Focus : ColorScheme.Normal;
} else {
hotColor = Colors.Base.Focus;
normalColor = Colors.Base.Focus;
}
DrawHotString (" " + menu.Title + " " + " ", hotColor, normalColor);
pos += menu.TitleLength + 3;
}
PositionCursor ();
}
You can comment out PositionCursor()
and there is no behavior change (that I could find).
In addition, the not-selected case above means the accelerator key hints (after _
) don’t get drawn.
My questions: Was it intentional that
a) Accelerator hints aren’t drawn for top-level menu bar items?
b) Did you ever try to get PositionCursor()
to work? It appears it worked at some point because it’s mostly correct.
The reason I’m asking is I want to add support for top-level MenuBar
items to be actions (not a menu that drops down, but just a single action).
Imagine this menu:
menu = new MenuBar (new MenuBarItem [] { new MenuBarItem (“_File”, new MenuItem [] { new MenuItem (“_New”, “Creates new file”, NewFile), new MenuItem (“_Open”, “”, Open), new MenuItem (“_Close”, “”, () => Close ()), null, new MenuItem (“_Quit”, “”, () => { if (Quit ()) top.Running = false; }) }), new MenuBarItem (“_About…”, “help”, () => MessageBox.ErrorQuery (50, 7, “About Demo”, “This is a demo app for gui.cs”, “Ok”)), }
(note last MenuBarItem
takes an action)
For this to work, we need:
- Accelerator highlights so the action is discoverable.
- The cursor to show on the “A” of “_About” when the menu is active (just as the cursor shows on drop-down menu items).
I’ve already fixed #1 (which was easy; just use the right ColorScheme
colors for hotColor/normalColor
.
But #2 is proving tricky … as you indicated dealing with all the cursor Move(x,y)
stuff is challenging.
I just don’t want go any further into this blindly if you have any thoughts already.
Thanks.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8
Top GitHub Comments
FWIW, I think I have it all working nicely now. Look for a big PR tonight or tomorrow!
This is fixed. Closing.