ocarina: Scroll treeview to current song
I do this whenever the current song changes.
This commit is contained in:
parent
64aff6a849
commit
01b6df4f47
|
@ -1,6 +1,8 @@
|
|||
#ifndef OCARINA_LIBRARY_H
|
||||
#define OCARINA_LIBRARY_H
|
||||
|
||||
#include <libsaria/track.h>
|
||||
|
||||
namespace ocarina
|
||||
{
|
||||
namespace library
|
||||
|
@ -9,6 +11,7 @@ namespace ocarina
|
|||
void init();
|
||||
void refresh();
|
||||
void refilter();
|
||||
void scroll_to(Track &);
|
||||
|
||||
}
|
||||
};
|
||||
|
|
|
@ -63,6 +63,7 @@ class SongList : public libsaria::SourceModel
|
|||
void clear();
|
||||
void refilter();
|
||||
void list_selected_ids(list<ino_t> &);
|
||||
void scroll_to(Track &);
|
||||
|
||||
gint right_click(guint, guint64);
|
||||
};
|
||||
|
|
|
@ -48,10 +48,16 @@ void cb_refilter()
|
|||
ocarina::library::refilter();
|
||||
}
|
||||
|
||||
void cb_track_loaded_helper(Track &track)
|
||||
{
|
||||
change_footer(track);
|
||||
ocarina::library::scroll_to(track);
|
||||
}
|
||||
|
||||
void cb_track_loaded()
|
||||
{
|
||||
println("Ocarina TRACK_LOADED callback!");
|
||||
libsaria::current_track(change_footer);
|
||||
libsaria::current_track(cb_track_loaded_helper);
|
||||
}
|
||||
|
||||
void setup_callbacks()
|
||||
|
|
|
@ -49,4 +49,9 @@ namespace ocarina
|
|||
ocarina::library::refresh();
|
||||
}
|
||||
|
||||
void library::scroll_to(Track &track)
|
||||
{
|
||||
library_list.scroll_to(track);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -66,3 +66,54 @@ void SongList::set_label_text()
|
|||
|
||||
gtk_label_set_text(GTK_LABEL(label), res.c_str());
|
||||
}
|
||||
|
||||
struct scroll_data {
|
||||
ino_t inode;
|
||||
GtkWidget *treeview;
|
||||
GdkRectangle rect;
|
||||
};
|
||||
|
||||
static int scroll_to_check_row(GtkTreeModel *model, GtkTreePath *path,
|
||||
GtkTreeIter *iter, gpointer data)
|
||||
{
|
||||
struct scroll_data *scroll = (struct scroll_data *)data;
|
||||
ino_t current;
|
||||
GtkTreeViewColumn *col;
|
||||
GtkTreePath *target;
|
||||
GdkRectangle area;
|
||||
int n;
|
||||
|
||||
gtk_tree_model_get(model, iter, 0, ¤t, -1);
|
||||
if (current != scroll->inode)
|
||||
return FALSE;
|
||||
|
||||
col = gtk_tree_view_get_column(GTK_TREE_VIEW(scroll->treeview), 0);
|
||||
gtk_tree_view_get_cell_area(GTK_TREE_VIEW(scroll->treeview), path, col, &area);
|
||||
target = gtk_tree_path_copy(path);
|
||||
if (area.height > 0) {
|
||||
n = scroll->rect.height / area.height;
|
||||
for (int i = 0; i < (n / 2); i++)
|
||||
gtk_tree_path_prev(target);
|
||||
}
|
||||
|
||||
gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(scroll->treeview),
|
||||
target, NULL, TRUE, 0, 0);
|
||||
gtk_tree_view_set_cursor_on_cell(GTK_TREE_VIEW(scroll->treeview),
|
||||
path, NULL, NULL, FALSE);
|
||||
gtk_tree_path_free(target);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void SongList::scroll_to(Track &track)
|
||||
{
|
||||
struct scroll_data data;
|
||||
data.inode = track.get_inode();
|
||||
data.treeview = treeview;
|
||||
|
||||
gtk_tree_view_get_visible_rect(GTK_TREE_VIEW(treeview), &data.rect);
|
||||
/* Widget not realized yet */
|
||||
if (data.rect.height == 0)
|
||||
return;
|
||||
|
||||
gtk_tree_model_foreach(filter, scroll_to_check_row, &data);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue