Archived
1
0
Fork 0

Highlight active menu item

This commit is contained in:
Braiden Vasco 2017-07-22 16:26:04 +00:00
parent 7859e7949d
commit 570319627a
2 changed files with 43 additions and 11 deletions

View file

@ -11,16 +11,17 @@ class Style
end
def initialize
Curses.init_pair logo_id, logo_color, logo_bg
Curses.init_pair text_id, text_color, text_bg
Curses.init_pair selection_id, selection_color, selection_bg
Curses.init_pair editing_text_id, editing_text_color, editing_text_bg
Curses.init_pair cursor_id, cursor_color, cursor_bg
Curses.init_pair menu_item_id, menu_item_color, menu_item_bg
Curses.init_pair message_time_id, message_time_color, message_time_bg
Curses.init_pair message_author_id, message_author_color, message_author_bg
Curses.init_pair online_mark_id, online_mark_color, online_mark_bg
Curses.init_pair peer_info_name_id, peer_info_name_color, peer_info_name_bg
Curses.init_pair logo_id, logo_color, logo_bg
Curses.init_pair text_id, text_color, text_bg
Curses.init_pair selection_id, selection_color, selection_bg
Curses.init_pair editing_text_id, editing_text_color, editing_text_bg
Curses.init_pair cursor_id, cursor_color, cursor_bg
Curses.init_pair menu_item_id, menu_item_color, menu_item_bg
Curses.init_pair active_menu_item_id, active_menu_item_color, active_menu_item_bg
Curses.init_pair message_time_id, message_time_color, message_time_bg
Curses.init_pair message_author_id, message_author_color, message_author_bg
Curses.init_pair online_mark_id, online_mark_color, online_mark_bg
Curses.init_pair peer_info_name_id, peer_info_name_color, peer_info_name_bg
end
def logo
@ -65,6 +66,13 @@ class Style
Curses.attroff menu_item_attr
end
def active_menu_item
Curses.attron active_menu_item_attr
yield
ensure
Curses.attroff active_menu_item_attr
end
def message_time
Curses.attron message_time_attr
yield
@ -119,6 +127,10 @@ private
Curses.color_pair menu_item_id
end
def active_menu_item_attr
Curses.color_pair active_menu_item_id
end
def message_time_attr
Curses.color_pair message_time_id
end
@ -159,6 +171,10 @@ private
@menu_item_id ||= self.class.counter
end
def active_menu_item_id
@active_menu_item_id ||= self.class.counter
end
def message_time_id
@message_time_id ||= self.class.counter
end
@ -223,6 +239,14 @@ private
Curses::COLOR_CYAN
end
def active_menu_item_color
Curses::COLOR_BLACK
end
def active_menu_item_bg
Curses::COLOR_BLUE
end
def message_time_color
Curses::COLOR_CYAN
end

View file

@ -11,6 +11,14 @@ module Widgets
SIDE_PADDING = 3
attr_reader :active
def initialize(*)
super
@active = 0
end
def draw
ITEMS.each_with_index do |item, index|
draw_item index, item
@ -18,7 +26,7 @@ module Widgets
end
def draw_item(index, name)
Style.default.menu_item do
Style.default.public_send(index == active ? :active_menu_item : :menu_item) do
setpos SIDE_PADDING, 4 * index + 0
Curses.addstr ' ' * (width - 2 * SIDE_PADDING)