Work in progress.

This commit is contained in:
Michael Lazar
2016-04-14 18:40:28 -07:00
parent 26d1f0efcb
commit e69c59baa8
3 changed files with 31 additions and 13 deletions

View File

@@ -316,7 +316,7 @@ class Navigator(object):
page_index=0,
cursor_index=0,
inverted=False,
top_height=None):
top_item_height=None):
"""
Params:
valid_page_callback (func): This function, usually `Content.get`,
@@ -332,12 +332,16 @@ class Navigator(object):
inverted - The page is drawn from the bottom of the screen,
starting with the page index, up to the top of the
screen.
top_item_height (int): If this is set to a non-null value
The number of columns that the top-most item
should utilize if non-inverted. This is used for a special mode
where all items are drawn non-inverted except for the top one.
"""
self.page_index = page_index
self.cursor_index = cursor_index
self.inverted = inverted
self.top_height = top_height
self.top_item_height = top_item_height
self._page_cb = valid_page_cb
@property
@@ -398,17 +402,21 @@ class Navigator(object):
# Flip the orientation and reset the cursor
self.flip(self.cursor_index)
self.cursor_index = 0
self.top_height = None
self.top_item_height = None
redraw = True
else:
if self.cursor_index > 0:
self.cursor_index -= 1
if self.top_item_height and self.cursor_index == 0:
# Selecting the partially displayed item
self.top_item_height = None
redraw = True
else:
self.page_index -= self.step
if self._is_valid(self.absolute_index):
# We have reached the beginning of the page - move the
# index
self.top_height = None
self.top_item_height = None
redraw = True
else:
self.page_index += self.step
@@ -482,6 +490,7 @@ class Navigator(object):
self.page_index += (self.step * n_windows)
self.cursor_index = n_windows - self.cursor_index
self.inverted = not self.inverted
self.top_item_height = None
def _is_valid(self, page_index):
"""

View File

@@ -328,8 +328,7 @@ class Page(object):
# 4.) Otherwise, this should ensure that the bottom element is always
# full visible and the cursor doesn't jump lines.
# Note: Should also disable drawing inverted if only one element
# Note: If only one comment, add (Not enough space to display)
# TODO: If only one comment, add (Not enough space to display)
n_rows, n_cols = self.term.stdscr.getmaxyx()
window = self.term.stdscr.derwin(
@@ -347,20 +346,24 @@ class Page(object):
cancel_inverted = True
current_row = (win_n_rows - 1) if inverted else 0
available_rows = (win_n_rows - 1) if inverted else win_n_rows
top_height = self.nav.top_height if not inverted else None
top_item_height = None if inverted else self.nav.top_item_height
for data in self.content.iterate(page_index, step, win_n_cols - 2):
subwin_n_rows = min(available_rows, data['n_rows'])
if top_height:
subwin_n_rows = min(subwin_n_rows, top_height)
subwin_inverted = inverted
if top_item_height is not None:
# Special case when top_item_height is given. This will only
# be applied to the first item that is drawn.
subwin_n_rows = min(subwin_n_rows, top_item_height)
subwin_inverted = True
top_item_height = None
subwin_n_cols = win_n_cols - data['offset']
start = current_row - subwin_n_rows if inverted else current_row
subwindow = window.derwin(
subwin_n_rows, subwin_n_cols, start, data['offset'])
attr = self._draw_item(subwindow, data, top_height or inverted)
self._subwindows.append((subwindow, attr, subwin_n_rows))
attr = self._draw_item(subwindow, data, subwin_inverted)
self._subwindows.append((subwindow, attr))
available_rows -= (subwin_n_rows + 1) # Add one for the blank line
current_row += step * (subwin_n_rows + 1)
top_height = None
if available_rows <= 0:
# Indicate the page is full and we can keep the inverted screen.
cancel_inverted = False

View File

@@ -34,8 +34,14 @@ class SubmissionPage(Page):
current_index = self.nav.absolute_index
self.content.toggle(current_index)
if self.nav.inverted:
self.nav.top_height = self._subwindows[-1][2]
# Special case when inverted and toggling a comment. We want to
# ensure that when we re-draw the page, the cursor stays at its
# current absolute position. Do this by turning off inversion and
# applying an offset to the top item.
window = self._subwindows[-1]
n_rows, _ = window.getmaxyx()
self.nav.flip(len(self._subwindows) - 1)
self.nav.top_item_height = n_rows
@SubmissionController.register(Command('SUBMISSION_EXIT'))
def exit_submission(self):