Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menus & Context #98

Open
charlie22c opened this issue Oct 23, 2014 · 2 comments
Open

Menus & Context #98

charlie22c opened this issue Oct 23, 2014 · 2 comments

Comments

@charlie22c
Copy link

Great project. I just started playing around with the Menu feature. I wanted to see how I could reuse the "next" & "prev" key commands to navigate different menus that appear in the same interface (like child menus that drill down as you make selections along the way). I quickly got the following code to work and wanted to see if there was a better approach that I'm missing. Is there a built-in way to get context for key triggers/events? Do you think that some kind of 'system of related menus' might be in vedeu's future?

class MenuApp
  include Vedeu

  Vedeu.menu 'game_menu' do
    items [:game1, :game2, :game3]
  end

  Vedeu.menu 'help_menu' do
    items [:help1, :help2, :help3]
  end

  event(:_initialize_) do
    trigger(:show_game_menu)
  end

  event :show_help_menu do
    @active_menu = 'help_menu'
    HelpView.new.show
    trigger(:_refresh_)
  end

  event :show_game_menu do
    @active_menu = 'game_menu'
    GameView.new.show
    trigger(:_refresh_)
  end

  event :menu_prev_event do
    trigger(:move_menu_prev, {menu: @active_menu} )
    trigger("show_#{@active_menu}".to_sym)
  end

  event :move_menu_prev do |hash_args|
    trigger(:_menu_prev_, hash_args[:menu])
  end

  event :menu_next_event do
    trigger(:move_menu_next, {menu: @active_menu} )
    trigger("show_#{@active_menu}".to_sym)
  end

  event :move_menu_next do |hash_args|
    trigger(:_menu_next_, hash_args[:menu])
  end

  keys do
    key('k') do
      trigger(:menu_prev_event)
    end
    key('j') do
      trigger(:menu_next_event)
    end
    key('h') do
      trigger(:show_help_menu)
    end
    key('g') do
      trigger(:show_game_menu)
    end
  end
  ...
end
@gavinlaking
Copy link
Owner

Hi,

Wow, I hadn't really thought about sub-menus and how they might work. 👍 Off the cuff, I'm liking your idea, so Vedeu definitely needs a 'system of related menus'.

I think the next step would be to implement some sort of parent/child relationship between individual menu instances. Thinking forward, this relationship might "cross" the interface "boundary"; i.e. A menu option in one interface may affect the menu of another interface elsewhere or it could trigger the showing of a submenu in the same interface, as you have in your approach.

I'll have to have a bit more of a think about how this might work, but you of course are welcome to have a bit of a hack around and submit a pull-request with a possible implementation. In the meantime, I think what you are doing seems ok in the short term, but would be so much better if Vedeu handled this instead of you having to do the legwork.

I guess the challenge for you is to come up with a solution before I do! 😀

Thank you very much, this is a great suggestion,

Gav

@charlie22c
Copy link
Author

I'm creating related menus that basically traverse resources in an API. I'm starting with the idea that each menu item needs a displayable name in the menu and an action to perform when selected. In my case I'm firing off network calls and then using the response to populate the next submenu. I'll see if I can distill something that might be suitable for a pull-request....

Charlie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants