class BBS::Widgets::ListBox
A scrolling list of items with one selected.
Attributes
- items
-
the Array of items shown
- selected
-
index of the selected item
- scroll
-
index of the item on the top row
on_select-
callable invoked as
call(item, listbox)when the selection moves to another item on_activate-
callable invoked as
call(item, listbox)on Enter; its result is returned fromhandle_event - label
-
callable turning an item into its display text;
niluses the item’sto_s
- items
-
the Array of items shown
- selected
-
index of the selected item
- scroll
-
index of the item on the top row
on_select-
callable invoked as
call(item, listbox)when the selection moves to another item on_activate-
callable invoked as
call(item, listbox)on Enter; its result is returned fromhandle_event - label
-
callable turning an item into its display text;
niluses the item’sto_s
- items
-
the Array of items shown
- selected
-
index of the selected item
- scroll
-
index of the item on the top row
on_select-
callable invoked as
call(item, listbox)when the selection moves to another item on_activate-
callable invoked as
call(item, listbox)on Enter; its result is returned fromhandle_event - label
-
callable turning an item into its display text;
niluses the item’sto_s
- items
-
the Array of items shown
- selected
-
index of the selected item
- scroll
-
index of the item on the top row
on_select-
callable invoked as
call(item, listbox)when the selection moves to another item on_activate-
callable invoked as
call(item, listbox)on Enter; its result is returned fromhandle_event - label
-
callable turning an item into its display text;
niluses the item’sto_s
- items
-
the Array of items shown
- selected
-
index of the selected item
- scroll
-
index of the item on the top row
on_select-
callable invoked as
call(item, listbox)when the selection moves to another item on_activate-
callable invoked as
call(item, listbox)on Enter; its result is returned fromhandle_event - label
-
callable turning an item into its display text;
niluses the item’sto_s
- items
-
the Array of items shown
- selected
-
index of the selected item
- scroll
-
index of the item on the top row
on_select-
callable invoked as
call(item, listbox)when the selection moves to another item on_activate-
callable invoked as
call(item, listbox)on Enter; its result is returned fromhandle_event - label
-
callable turning an item into its display text;
niluses the item’sto_s
Public Class Methods
# File lib/bbs/widgets/list_box.rb, line 21 def initialize(items: [], on_select: nil, on_activate: nil, label: nil, **kw) super(**kw) @items = items @selected = 0 @scroll = 0 @on_select = on_select @on_activate = on_activate @label = label end
Creates a list of items with the first one selected.
BBS::Widget::new
Public Instance Methods
Source
# File lib/bbs/widgets/list_box.rb, line 32 def focusable? = true
True: a list takes the focus.
Source
# File lib/bbs/widgets/list_box.rb, line 49 def handle_event(event) return nil unless enabled return key(event.key) if event.key? return click(event.y - bounds.y) if Widgets.click_in?(event, bounds) rows = Widgets.wheel(event, bounds) rows && select_index(@selected + rows) end
Moves the selection with Up, Down, Page Up, Page Down, Home and End (calling on_select when it changes), calls on_activate on Enter, selects the clicked item on a left click and scrolls the selection by three on the mouse wheel. Returns :handled (or on_activate‘s result on Enter), and nil for other events or when disabled.
Source
# File lib/bbs/widgets/list_box.rb, line 38 def render(frame) return if no_room? bounds.height.times { |r| draw_row(frame, r) } end
Draws the visible items into the bounds of frame, the selected one highlighted (more strongly when the list has the focus).
Source
# File lib/bbs/widgets/list_box.rb, line 34 def selected_item = @items[@selected]
The selected item, or nil when the list is empty.