Class: UI::Pad

Inherits:
Widget show all
Defined in:
lib/ektoplayer/ui/widgets.rb

Instance Attribute Summary collapse

Attributes inherited from Widget

#pos, #size

Instance Method Summary collapse

Methods inherited from Widget

#display, #draw, #events, #invisible!, #invisible?, #key_press, #keys, #lock, #mouse, #mouse_event_transform, #mouse_section, #on_key_press, #on_widget_raise, #raise_widget, #sub, #unlock, #visible!, #visible=, #visible?, #want_layout, #want_redraw, #want_refresh, #with_lock

Constructor Details

#initialize(**opts) ⇒ Pad

Returns a new instance of Pad.



171
172
173
174
175
176
177
178
179
# File 'lib/ektoplayer/ui/widgets.rb', line 171

def initialize(**opts)
   super(**opts)
   @win = ICurses.newpad(@size.height, @size.width)
   @win.keypad(true)
   @win.idlok(true)
   @win.leaveok(true)
   @win.bkgdset(UI::Colors.init_pair_cached(:default, :default))
   @pad_minrow = @pad_mincol = 0
end

Instance Attribute Details

#winObject (readonly)

Returns the value of attribute win.



169
170
171
# File 'lib/ektoplayer/ui/widgets.rb', line 169

def win
  @win
end

Instance Method Details

#bottomObject



203
204
205
# File 'lib/ektoplayer/ui/widgets.rb', line 203

def bottom
   self.pad_minrow=(@win.height - @size.height)
end

#down(n = 1) ⇒ Object



212
213
214
215
# File 'lib/ektoplayer/ui/widgets.rb', line 212

def down(n=1)
   new_minrow = (@pad_minrow + n).clamp(0, (@win.height - @size.height)) rescue 0
   self.pad_minrow=(new_minrow)
end

#layoutObject



195
196
197
# File 'lib/ektoplayer/ui/widgets.rb', line 195

def layout
   @win.pos=(@pos)
end

#mouse_click(mevent) ⇒ Object



234
235
236
237
238
239
240
241
# File 'lib/ektoplayer/ui/widgets.rb', line 234

def mouse_click(mevent)
   if ev = mouse_event_transform(mevent)
      ev.x += @pad_mincol
      ev.y += @pad_minrow
      trigger(@mouse, ev)
      trigger(@mouse_section, ev)
   end
end

#noutrefreshObject



251
252
253
254
255
256
257
# File 'lib/ektoplayer/ui/widgets.rb', line 251

def noutrefresh
   @win.pnoutrefresh(
      @pad_minrow, @pad_mincol,
      @pos.y, @pos.x,
      @pos.y + @size.height - 1, @pos.x + @size.width - 1
   )
end

#pad_mincol=(n) ⇒ Object



186
187
188
189
# File 'lib/ektoplayer/ui/widgets.rb', line 186

def pad_mincol=(n)
   return if @pad_mincol == n
   with_lock { @pad_mincol = n; want_refresh }
end

#pad_minrow=(n) ⇒ Object



181
182
183
184
# File 'lib/ektoplayer/ui/widgets.rb', line 181

def pad_minrow=(n)
   return if @pad_minrow == n
   with_lock { @pad_minrow = n; want_refresh }
end

#pad_size=(s) ⇒ Object



191
192
193
# File 'lib/ektoplayer/ui/widgets.rb', line 191

def pad_size=(s)
   @win.size=(s)
end

#page_downObject



201
# File 'lib/ektoplayer/ui/widgets.rb', line 201

def page_down;   self.down(@size.height / 2)         end

#page_upObject



200
# File 'lib/ektoplayer/ui/widgets.rb', line 200

def page_up;     self.up(@size.height / 2)           end

#refreshObject



243
244
245
246
247
248
249
# File 'lib/ektoplayer/ui/widgets.rb', line 243

def refresh
   @win.prefresh(
      @pad_minrow, @pad_mincol,
      @pos.y, @pos.x,
      @pos.y + @size.height - 1, @pos.x + @size.width - 1
   )
end

#topObject



199
# File 'lib/ektoplayer/ui/widgets.rb', line 199

def top;         self.pad_minrow=(0)                 end

#up(n = 1) ⇒ Object



207
208
209
210
# File 'lib/ektoplayer/ui/widgets.rb', line 207

def up(n=1)
   new_minrow = (@pad_minrow - n).clamp(0, @win.height)
   self.pad_minrow=(new_minrow)
end

#with_mouse_section_eventObject



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/ektoplayer/ui/widgets.rb', line 217

def with_mouse_section_event
   start_cursor = @win.cursor; yield

   start_pos = UI::Point.new(
      y: [start_cursor.y, @win.cursor.y].min,
      x: [start_cursor.x, @win.cursor.x].min,
   )
   stop_pos = UI::Point.new(
      y: [start_cursor.y, @win.cursor.y].max,
      x: [start_cursor.x, @win.cursor.x].max
   )

   ev = UI::MouseSectionEvent.new(start_pos, stop_pos)
   mouse_section.add(ev)
   ev
end