david-vanderson / dvui

Other
413 stars 33 forks source link

Direct keyboard access to an app's main menu. #112

Closed JosephABudd closed 1 month ago

JosephABudd commented 2 months ago

Developers are probably going to find unique ways of implementing a main menu in their applications. DVUI uses the tab key very nicely, allowing the user to navigate from widget to widget.

I would like to use the [ ☰ ] key to toggle my main menu's opening and closing. Other's may want to use to key to focus and highlight their main menu.

Thoughts?

VisenDev commented 2 months ago

Thoughts?

This might be better implemented in the application than in dvui itself For some backends like raylib, it would be as simple as

if(c.IsKeyPressed(c.KEY_MENU)) {
    show_main_menu = !show_main_menu;
}

You should also be able to get the same keyboard control over dvui widgets this way, eg

if(try dvui.button(@src(), "(p)lay", .{}, .{}) or c.IsKeyPressed(c.KEY_M)) {
    //play
}

Edit: Are you asking how to get keyboard control over your application with dvui, or are you asking how to make dvui process a specific key?

david-vanderson commented 2 months ago

Is that the windows key? I thought an application couldn't change what that does (opening the start menu).

Are you able to get a key event for that button? Is there not a straightforward way to programmatically open a menu? I agree with your desire, but I'm unclear where you are getting stuck.

JosephABudd commented 2 months ago

@VisenDev: I was thinking that DVUI might want to standardize a method is all. I can easily implement your second example. Thanks. @david-vanderson: I was just thinking that DVUI might want to standardize a method. No that is the menu key.

david-vanderson commented 2 months ago

Oh I thought the menu key was supposed to show a context menu (same as right-clicking the mouse). We don't currently support that though.

I think the normal keyboard shortcut for getting to the menu is just pressing alt (on windows). On mac it seems to be ctrl-F2? I'm not sure it makes sense to bake in the concept of a primary menu (might be a menu per subwindow?) - but I could be wrong.

I'm very interested in seeing how it looks if you can do it with what currently exists. Can you try it and point me to the code?

JosephABudd commented 2 months ago

I'm seeing that you are correct about the menu key works relative to what is in focus. I stand corrected. The F10 focuses the main menu. I even wrote that down yesturday. Anyway I'll work on that tomorrow.

JosephABudd commented 1 month ago

VisenDev has it right again. Thank you VisenDev.

I'm don't want to be any more of a distraction so I'm going to let you developers work together.

JosephABudd commented 1 month ago

VisenDev has it right again. Thank you VisenDev.

I'm don't want to be any more of a distraction so I'm going to let you developers work together.