Implement focus for messenger
This commit is contained in:
parent
f6c0b1dd87
commit
32643aba17
7 changed files with 58 additions and 3 deletions
|
@ -11,6 +11,9 @@ Metrics/LineLength:
|
||||||
Style/Documentation:
|
Style/Documentation:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
|
Style/DoubleNegation:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
Style/TrailingCommaInArguments:
|
Style/TrailingCommaInArguments:
|
||||||
EnforcedStyleForMultiline: comma
|
EnforcedStyleForMultiline: comma
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,8 @@ private
|
||||||
|
|
||||||
@menu = Widgets::Menu.new menu_left, 0, menu_width, Curses.stdscr.maxy
|
@menu = Widgets::Menu.new menu_left, 0, menu_width, Curses.stdscr.maxy
|
||||||
@messenger = Widgets::Messenger.new messenger_left, 0, messenger_width, Curses.stdscr.maxy
|
@messenger = Widgets::Messenger.new messenger_left, 0, messenger_width, Curses.stdscr.maxy
|
||||||
|
|
||||||
|
@messenger.focused = true
|
||||||
end
|
end
|
||||||
|
|
||||||
def render
|
def render
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
module Widgets
|
module Widgets
|
||||||
class Chat
|
class Chat
|
||||||
attr_reader :x, :y, :width, :height
|
attr_reader :x, :y, :width, :height
|
||||||
|
attr_accessor :focused
|
||||||
attr_reader :messages
|
attr_reader :messages
|
||||||
|
|
||||||
def initialize(x, y, width, height)
|
def initialize(x, y, width, height)
|
||||||
|
@ -12,6 +13,8 @@ module Widgets
|
||||||
@width = width
|
@width = width
|
||||||
@height = height
|
@height = height
|
||||||
|
|
||||||
|
@focused = false
|
||||||
|
|
||||||
@messages = 1.upto(100).map do
|
@messages = 1.upto(100).map do
|
||||||
{
|
{
|
||||||
time: Faker::Time.forward,
|
time: Faker::Time.forward,
|
||||||
|
@ -64,5 +67,7 @@ module Widgets
|
||||||
|
|
||||||
offset + 1 + lines
|
offset + 1 + lines
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def trigger(event); end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
module Widgets
|
module Widgets
|
||||||
class List
|
class List
|
||||||
attr_reader :x, :y, :width, :height, :active, :top, :items
|
attr_reader :x, :y, :width, :height, :active, :top, :items
|
||||||
|
attr_accessor :focused
|
||||||
|
|
||||||
def initialize(x, y, width, height)
|
def initialize(x, y, width, height)
|
||||||
@x = x
|
@x = x
|
||||||
|
@ -14,6 +15,8 @@ module Widgets
|
||||||
@active = 0
|
@active = 0
|
||||||
@top = 0
|
@top = 0
|
||||||
|
|
||||||
|
@focused = false
|
||||||
|
|
||||||
@items = 1.upto(height - 1 + 10).map do
|
@items = 1.upto(height - 1 + 10).map do
|
||||||
Faker::Name.name
|
Faker::Name.name
|
||||||
end
|
end
|
||||||
|
@ -23,7 +26,7 @@ module Widgets
|
||||||
items[top...(top + height)].each_with_index.each do |item, offset|
|
items[top...(top + height)].each_with_index.each do |item, offset|
|
||||||
index = top + offset
|
index = top + offset
|
||||||
|
|
||||||
if index == active
|
if index == active && focused
|
||||||
Curses.attron Curses.color_pair 2
|
Curses.attron Curses.color_pair 2
|
||||||
else
|
else
|
||||||
Curses.attron Curses.color_pair 1
|
Curses.attron Curses.color_pair 1
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
module Widgets
|
module Widgets
|
||||||
class Messenger
|
class Messenger
|
||||||
attr_reader :x, :y, :width, :height
|
attr_reader :x, :y, :width, :height
|
||||||
|
attr_reader :focused, :focus
|
||||||
|
|
||||||
def initialize(x, y, width, height)
|
def initialize(x, y, width, height)
|
||||||
@x = x
|
@x = x
|
||||||
|
@ -19,6 +20,9 @@ module Widgets
|
||||||
|
|
||||||
@peers = Widgets::Peers.new x + peers_left, y, peers_width, height
|
@peers = Widgets::Peers.new x + peers_left, y, peers_width, height
|
||||||
@chat = Widgets::Chat.new x + chat_left, y, chat_width, height
|
@chat = Widgets::Chat.new x + chat_left, y, chat_width, height
|
||||||
|
|
||||||
|
@focused = false
|
||||||
|
@focus = @peers
|
||||||
end
|
end
|
||||||
|
|
||||||
def render
|
def render
|
||||||
|
@ -27,7 +31,33 @@ module Widgets
|
||||||
end
|
end
|
||||||
|
|
||||||
def trigger(event)
|
def trigger(event)
|
||||||
@peers.trigger event
|
case event
|
||||||
|
when Events::Window::Left
|
||||||
|
left
|
||||||
|
when Events::Window::Right
|
||||||
|
right
|
||||||
|
else
|
||||||
|
@focus.trigger event
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def left
|
||||||
|
self.focus = @peers
|
||||||
|
end
|
||||||
|
|
||||||
|
def right
|
||||||
|
self.focus = @chat
|
||||||
|
end
|
||||||
|
|
||||||
|
def focused=(value)
|
||||||
|
@focused = !!value
|
||||||
|
focus.focused = focused
|
||||||
|
end
|
||||||
|
|
||||||
|
def focus=(child)
|
||||||
|
focus.focused = false
|
||||||
|
@focus = child
|
||||||
|
focus.focused = true if focused
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,11 @@
|
||||||
|
|
||||||
module Widgets
|
module Widgets
|
||||||
class Peers
|
class Peers
|
||||||
|
attr_reader :focused
|
||||||
|
|
||||||
def initialize(x, y, width, height)
|
def initialize(x, y, width, height)
|
||||||
|
@focused = false
|
||||||
|
|
||||||
@search = Widgets::Search.new x, y, width, 1
|
@search = Widgets::Search.new x, y, width, 1
|
||||||
@list = Widgets::List.new x, y + 1, width, height - 1
|
@list = Widgets::List.new x, y + 1, width, height - 1
|
||||||
end
|
end
|
||||||
|
@ -20,5 +24,11 @@ module Widgets
|
||||||
@search.trigger event
|
@search.trigger event
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def focused=(value)
|
||||||
|
@focused = !!value
|
||||||
|
@list.focused = focused
|
||||||
|
@search.focused = focused
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
module Widgets
|
module Widgets
|
||||||
class Search
|
class Search
|
||||||
attr_reader :x, :y, :width, :height, :text, :cursor_pos
|
attr_reader :x, :y, :width, :height, :text, :cursor_pos
|
||||||
|
attr_accessor :focused
|
||||||
|
|
||||||
def initialize(x, y, width, height)
|
def initialize(x, y, width, height)
|
||||||
@x = x
|
@x = x
|
||||||
|
@ -11,6 +12,7 @@ module Widgets
|
||||||
@height = height
|
@height = height
|
||||||
@text = ''
|
@text = ''
|
||||||
@cursor_pos = 0
|
@cursor_pos = 0
|
||||||
|
@focused = false
|
||||||
end
|
end
|
||||||
|
|
||||||
def render
|
def render
|
||||||
|
@ -28,7 +30,7 @@ module Widgets
|
||||||
Curses.attron Curses.color_pair 3
|
Curses.attron Curses.color_pair 3
|
||||||
Curses.addstr before_cursor
|
Curses.addstr before_cursor
|
||||||
|
|
||||||
Curses.attron Curses.color_pair 4
|
Curses.attron Curses.color_pair 4 if focused
|
||||||
Curses.addstr under_cursor
|
Curses.addstr under_cursor
|
||||||
|
|
||||||
Curses.attron Curses.color_pair 3
|
Curses.attron Curses.color_pair 3
|
||||||
|
|
Reference in a new issue