Commit 09328e8e authored by Sebastian Ramacher's avatar Sebastian Ramacher
Browse files

use GtkTable for page layout

parent 222bd718
...@@ -46,36 +46,37 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) ...@@ -46,36 +46,37 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data)
// FIXME // FIXME
/* get current adjustment values */ /* get current adjustment values */
/*gdouble lower = gtk_adjustment_get_value(adjustment);*/ gdouble lower = gtk_adjustment_get_value(adjustment);
/*gdouble upper = lower + gtk_adjustment_get_page_size(adjustment);*/ gdouble upper = lower + gtk_adjustment_get_page_size(adjustment);
/* find page that fits */ /* find page that fits */
for (unsigned int page_id = 0; page_id < zathura->document->number_of_pages; page_id++) for (unsigned int page_id = 0; page_id < zathura->document->number_of_pages; page_id++)
{ {
zathura_page_t* page = zathura->document->pages[page_id]; zathura_page_t* page = zathura->document->pages[page_id];
page_offset_t* offset = page_calculate_offset(page);
if (offset) {
fprintf(stderr, "offset: %d %d\n", offset->x, offset->y);
free(offset);
}
/* check for rendered attribute */ /* check for rendered attribute */
if (page->surface != NULL) { if (page->surface != NULL) {
continue; continue;
} }
/*double begin = page->offset;*/ page_offset_t* offset = page_calculate_offset(page);
/*double end = page->offset + page->height;*/ if (offset == NULL) {
continue;
}
double begin = offset->y;
double end = offset->y + page->height;
girara_info("%f %f; %f %f", begin, end, lower, upper);
/*if ( ( (begin >= lower) && (end <= upper) ) [> page is in viewport <]*/ if ( ( (begin >= lower) && (end <= upper) ) /* [> page is in viewport <]*/
/*|| ( (begin <= lower) && (end >= lower) && (end <= upper) ) [> end of the page is in viewport <]*/ || ( (begin <= lower) && (end >= lower) && (end <= upper) ) /* [> end of the page is in viewport <] */
/*|| ( (begin >= lower) && (end >= upper) && (begin <= upper) ) [> begin of the page is in viewport <]*/ || ( (begin >= lower) && (end >= upper) && (begin <= upper) ) /* [> begin of the page is in viewport <] */
/*) {*/ ) {
if (page_id < 10) {
page->visible = true; page->visible = true;
render_page(zathura->sync.render_thread, page); render_page(zathura->sync.render_thread, page);
} }
/*}*/
free(offset);
} }
} }
...@@ -107,7 +107,7 @@ zathura_init(int argc, char* argv[]) ...@@ -107,7 +107,7 @@ zathura_init(int argc, char* argv[])
zathura->ui.index = NULL; zathura->ui.index = NULL;
/* page view */ /* page view */
zathura->ui.page_view = gtk_vbox_new(FALSE, 0); zathura->ui.page_view = gtk_table_new(0, 0, TRUE);
if (!zathura->ui.page_view) { if (!zathura->ui.page_view) {
goto error_free; goto error_free;
} }
...@@ -115,6 +115,9 @@ zathura_init(int argc, char* argv[]) ...@@ -115,6 +115,9 @@ zathura_init(int argc, char* argv[])
gtk_widget_show(zathura->ui.page_view); gtk_widget_show(zathura->ui.page_view);
gtk_box_set_spacing(GTK_BOX(zathura->ui.page_view), 0); gtk_box_set_spacing(GTK_BOX(zathura->ui.page_view), 0);
/* Put the table in the main window */
// gtk_container_add(GTK_CONTAINER (zathura->ui.page_view), table);
/* statusbar */ /* statusbar */
zathura->ui.statusbar.file = girara_statusbar_item_add(zathura->ui.session, TRUE, TRUE, TRUE, NULL); zathura->ui.statusbar.file = girara_statusbar_item_add(zathura->ui.session, TRUE, TRUE, TRUE, NULL);
if (zathura->ui.statusbar.file == NULL) { if (zathura->ui.statusbar.file == NULL) {
...@@ -319,26 +322,23 @@ void ...@@ -319,26 +322,23 @@ void
page_view_set_mode(zathura_t* zathura, unsigned int pages_per_row) page_view_set_mode(zathura_t* zathura, unsigned int pages_per_row)
{ {
/* empty page view */ /* empty page view */
GList* container = gtk_container_get_children(GTK_CONTAINER(zathura->ui.page_view)); /* GList* container = gtk_container_get_children(GTK_CONTAINER(zathura->ui.page_view));
for (GList* child = container; child; child = g_list_next(child)) { for (GList* child = container; child; child = g_list_next(child)) {
gtk_container_remove(GTK_CONTAINER(zathura->ui.page_view), child->data); gtk_container_remove(GTK_CONTAINER(zathura->ui.page_view), child->data);
} }
GtkWidget* row = NULL; GtkWidget* row = NULL; */
/* create blank pages */
gtk_table_resize(GTK_TABLE(zathura->ui.page_view), zathura->document->number_of_pages / pages_per_row + 1, pages_per_row);
for (unsigned int i = 0; i < zathura->document->number_of_pages; i++) for (unsigned int i = 0; i < zathura->document->number_of_pages; i++)
{ {
if (i % pages_per_row == 0) { int x = i % pages_per_row;
row = gtk_hbox_new(FALSE, 0); int y = i / pages_per_row;
} girara_info("x, y, page: %d, %d, %d (%d)", x, y, i, pages_per_row);
gtk_table_attach(GTK_TABLE(zathura->ui.page_view), zathura->document->pages[i]->event_box, x, x + 1, y, y + 1, GTK_EXPAND, GTK_EXPAND, zathura->global.page_padding, zathura->global.page_padding);
/* pack row */
gtk_box_pack_start(GTK_BOX(row), zathura->document->pages[i]->event_box, FALSE, FALSE, 1);
/* pack row to page view */
if ((i + 1) % pages_per_row == 0) {
gtk_box_pack_start(GTK_BOX(zathura->ui.page_view), row, FALSE, FALSE, 1);
}
} }
gtk_widget_show_all(zathura->ui.page_view); gtk_widget_show_all(zathura->ui.page_view);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment