Simplify view code
Now we beep if selection movement is impossible. It still looks a bit more obfuscated than it needs to be.
This commit is contained in:
parent
e62c41f4a1
commit
7b41ae1658
67
nncmpp.c
67
nncmpp.c
|
@ -1120,7 +1120,6 @@ app_draw_status (void)
|
||||||
static void
|
static void
|
||||||
app_draw_header (void)
|
app_draw_header (void)
|
||||||
{
|
{
|
||||||
// TODO: call app_fix_view_range() if it changes from the previous value
|
|
||||||
g.header_height = 0;
|
g.header_height = 0;
|
||||||
|
|
||||||
g.tabs_offset = -1;
|
g.tabs_offset = -1;
|
||||||
|
@ -1372,22 +1371,9 @@ app_draw_statusbar (void)
|
||||||
app_flush_buffer (&buf, COLS, APP_ATTR (NORMAL));
|
app_flush_buffer (&buf, COLS, APP_ATTR (NORMAL));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
app_on_refresh (void *user_data)
|
|
||||||
{
|
|
||||||
(void) user_data;
|
|
||||||
poller_idle_reset (&g.refresh_event);
|
|
||||||
|
|
||||||
app_draw_header ();
|
/// Checks what items are visible and returns if the range was alright
|
||||||
app_draw_view ();
|
|
||||||
app_draw_statusbar ();
|
|
||||||
|
|
||||||
refresh ();
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Actions -----------------------------------------------------------------
|
|
||||||
|
|
||||||
/// Checks what items are visible and returns if fixes were needed
|
|
||||||
static bool
|
static bool
|
||||||
app_fix_view_range (void)
|
app_fix_view_range (void)
|
||||||
{
|
{
|
||||||
|
@ -1395,7 +1381,6 @@ app_fix_view_range (void)
|
||||||
if (tab->item_top < 0)
|
if (tab->item_top < 0)
|
||||||
{
|
{
|
||||||
tab->item_top = 0;
|
tab->item_top = 0;
|
||||||
app_invalidate ();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1407,12 +1392,27 @@ app_fix_view_range (void)
|
||||||
if (tab->item_top > max_item_top)
|
if (tab->item_top > max_item_top)
|
||||||
{
|
{
|
||||||
tab->item_top = max_item_top;
|
tab->item_top = max_item_top;
|
||||||
app_invalidate ();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
app_on_refresh (void *user_data)
|
||||||
|
{
|
||||||
|
(void) user_data;
|
||||||
|
poller_idle_reset (&g.refresh_event);
|
||||||
|
|
||||||
|
app_draw_header ();
|
||||||
|
app_fix_view_range();
|
||||||
|
app_draw_view ();
|
||||||
|
app_draw_statusbar ();
|
||||||
|
|
||||||
|
refresh ();
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Actions -----------------------------------------------------------------
|
||||||
|
|
||||||
/// Scroll down (positive) or up (negative) @a n items
|
/// Scroll down (positive) or up (negative) @a n items
|
||||||
static bool
|
static bool
|
||||||
app_scroll (int n)
|
app_scroll (int n)
|
||||||
|
@ -1443,11 +1443,11 @@ static bool
|
||||||
app_move_selection (int diff)
|
app_move_selection (int diff)
|
||||||
{
|
{
|
||||||
struct tab *tab = g.active_tab;
|
struct tab *tab = g.active_tab;
|
||||||
int fixed = tab->item_selected += diff;
|
int fixed = tab->item_selected + diff;
|
||||||
fixed = MIN (fixed, (int) tab->item_count - 1);
|
fixed = MIN (fixed, (int) tab->item_count - 1);
|
||||||
fixed = MAX (fixed, 0);
|
fixed = MAX (fixed, 0);
|
||||||
|
|
||||||
bool result = tab->item_selected != fixed;
|
bool result = !diff || tab->item_selected != fixed;
|
||||||
tab->item_selected = fixed;
|
tab->item_selected = fixed;
|
||||||
app_invalidate ();
|
app_invalidate ();
|
||||||
|
|
||||||
|
@ -1696,33 +1696,26 @@ app_process_action (enum action action)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ACTION_GOTO_ITEM_PREVIOUS:
|
case ACTION_GOTO_ITEM_PREVIOUS:
|
||||||
app_move_selection (-1);
|
return app_move_selection (-1);
|
||||||
break;
|
|
||||||
case ACTION_GOTO_ITEM_NEXT:
|
case ACTION_GOTO_ITEM_NEXT:
|
||||||
app_move_selection (1);
|
return app_move_selection (1);
|
||||||
break;
|
|
||||||
|
|
||||||
case ACTION_GOTO_PAGE_PREVIOUS:
|
case ACTION_GOTO_PAGE_PREVIOUS:
|
||||||
app_scroll (-app_visible_items ());
|
app_scroll (-app_visible_items ());
|
||||||
app_move_selection (-app_visible_items ());
|
return app_move_selection (-app_visible_items ());
|
||||||
break;
|
|
||||||
case ACTION_GOTO_PAGE_NEXT:
|
case ACTION_GOTO_PAGE_NEXT:
|
||||||
app_scroll (app_visible_items ());
|
app_scroll (app_visible_items ());
|
||||||
app_move_selection (app_visible_items ());
|
return app_move_selection (app_visible_items ());
|
||||||
break;
|
|
||||||
|
|
||||||
case ACTION_GOTO_VIEW_TOP:
|
case ACTION_GOTO_VIEW_TOP:
|
||||||
g.active_tab->item_selected = g.active_tab->item_top;
|
g.active_tab->item_selected = g.active_tab->item_top;
|
||||||
app_move_selection (0);
|
return app_move_selection (0);
|
||||||
break;
|
|
||||||
case ACTION_GOTO_VIEW_CENTER:
|
case ACTION_GOTO_VIEW_CENTER:
|
||||||
g.active_tab->item_selected = g.active_tab->item_top;
|
g.active_tab->item_selected = g.active_tab->item_top;
|
||||||
app_move_selection (MAX (0, app_visible_items () / 2 - 1));
|
return app_move_selection (MAX (0, app_visible_items () / 2 - 1));
|
||||||
break;
|
|
||||||
case ACTION_GOTO_VIEW_BOTTOM:
|
case ACTION_GOTO_VIEW_BOTTOM:
|
||||||
g.active_tab->item_selected = g.active_tab->item_top;
|
g.active_tab->item_selected = g.active_tab->item_top;
|
||||||
app_move_selection (MAX (0, app_visible_items () - 1));
|
return app_move_selection (MAX (0, app_visible_items () - 1));
|
||||||
break;
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
|
@ -1795,11 +1788,8 @@ app_process_left_mouse_click (int line, int column, bool double_click)
|
||||||
// TODO: handle the scrollbar a bit better than this
|
// TODO: handle the scrollbar a bit better than this
|
||||||
int visible_items = app_visible_items ();
|
int visible_items = app_visible_items ();
|
||||||
if ((int) tab->item_count > visible_items && column == COLS - 1)
|
if ((int) tab->item_count > visible_items && column == COLS - 1)
|
||||||
{
|
|
||||||
tab->item_top = (float) row_index / visible_items
|
tab->item_top = (float) row_index / visible_items
|
||||||
* (int) tab->item_count - visible_items / 2;
|
* (int) tab->item_count - visible_items / 2;
|
||||||
app_fix_view_range ();
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
tab->item_selected = row_index + tab->item_top;
|
tab->item_selected = row_index + tab->item_top;
|
||||||
app_invalidate ();
|
app_invalidate ();
|
||||||
|
@ -1986,7 +1976,6 @@ static void
|
||||||
current_tab_update (void)
|
current_tab_update (void)
|
||||||
{
|
{
|
||||||
g_current_tab.item_count = g.playlist.len;
|
g_current_tab.item_count = g.playlist.len;
|
||||||
app_fix_view_range ();
|
|
||||||
app_invalidate ();
|
app_invalidate ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2221,7 +2210,6 @@ library_tab_on_data (const struct mpd_response *response,
|
||||||
(int (*) (const void *, const void *)) library_tab_compare);
|
(int (*) (const void *, const void *)) library_tab_compare);
|
||||||
g_library_tab.super.item_count = items->len;
|
g_library_tab.super.item_count = items->len;
|
||||||
|
|
||||||
app_fix_view_range ();
|
|
||||||
app_move_selection (0);
|
app_move_selection (0);
|
||||||
app_invalidate ();
|
app_invalidate ();
|
||||||
}
|
}
|
||||||
|
@ -3203,7 +3191,6 @@ app_on_signal_pipe_readable (const struct pollfd *fd, void *user_data)
|
||||||
{
|
{
|
||||||
g_winch_received = false;
|
g_winch_received = false;
|
||||||
update_curses_terminal_size ();
|
update_curses_terminal_size ();
|
||||||
app_fix_view_range ();
|
|
||||||
app_invalidate ();
|
app_invalidate ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue