question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:

  1. Accelerator highlights so the action is discoverable.
  2. 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:closed
  • Created 3 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
tigcommented, Apr 17, 2020

FWIW, I think I have it all working nicely now. Look for a big PR tonight or tomorrow!

0reactions
tigcommented, May 17, 2020

This is fixed. Closing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tk Built-In Commands - menu manual page
When a menu is set as a menubar for a toplevel window, or when a menu is torn off, a clone of the...
Read more >
menu manual page - Tk Built-In Commands
The menu command creates a new top-level window (given by the pathName argument) and makes it into a menu widget. That menu widget...
Read more >
Reset cursor in WM_SETCURSOR handler properly
1) Set the class cursor of the top-level window to LoadCursor(NULL, IDC_ARROW). · 2) Keep track of the position of the mouse cursor...
Read more >
Adding the cursor information bar | Tkinter GUI Application ...
The cursor information bar is simply a small label at the bottom-right corner of the Text widget, which displays the current position of...
Read more >
How to Create an Internet Explorer-Style Menu Bar
Implement menu hot-tracking. With standard menus, once a top level menu item's menu has been displayed, moving the cursor over another top-level item ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found