Skip to content
This repository was archived by the owner on May 24, 2025. It is now read-only.
This repository was archived by the owner on May 24, 2025. It is now read-only.

Menus & Context #98

@charlie22c

Description

@charlie22c

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions