mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-29 11:36:01 +01:00
wrap gtk_adjustment_set_value
This commit is contained in:
parent
a2b92e6440
commit
c6403ec097
4 changed files with 26 additions and 13 deletions
19
shortcuts.c
19
shortcuts.c
|
@ -167,7 +167,6 @@ sc_goto(girara_session_t* session, girara_argument_t* argument, girara_event_t*
|
|||
} else {
|
||||
if (t == 0) {
|
||||
page_set(zathura, zathura->document->number_of_pages - 1);
|
||||
return true;
|
||||
} else {
|
||||
page_set(zathura, t - 1);
|
||||
}
|
||||
|
@ -359,24 +358,24 @@ sc_scroll(girara_session_t* session, girara_argument_t* argument,
|
|||
|
||||
switch(argument->n) {
|
||||
case FULL_UP:
|
||||
new_value = (value - view_size) < 0 ? 0 : (value - view_size);
|
||||
new_value = value - view_size;
|
||||
break;
|
||||
case FULL_DOWN:
|
||||
new_value = (value + view_size) > max ? max : (value + view_size);
|
||||
new_value = value + view_size;
|
||||
break;
|
||||
case HALF_UP:
|
||||
new_value = (value - (view_size / 2)) < 0 ? 0 : (value - (view_size / 2));
|
||||
new_value = value - (view_size / 2);
|
||||
break;
|
||||
case HALF_DOWN:
|
||||
new_value = (value + (view_size / 2)) > max ? max : (value + (view_size / 2));
|
||||
new_value = value + (view_size / 2);
|
||||
break;
|
||||
case LEFT:
|
||||
case UP:
|
||||
new_value = (value - scroll_step) < 0 ? 0 : (value - scroll_step);
|
||||
new_value = value - scroll_step;
|
||||
break;
|
||||
case RIGHT:
|
||||
case DOWN:
|
||||
new_value = (value + scroll_step) > max ? max : (value + scroll_step);
|
||||
new_value = value + scroll_step;
|
||||
break;
|
||||
case TOP:
|
||||
new_value = 0;
|
||||
|
@ -388,7 +387,7 @@ sc_scroll(girara_session_t* session, girara_argument_t* argument,
|
|||
new_value = value;
|
||||
}
|
||||
|
||||
gtk_adjustment_set_value(adjustment, new_value);
|
||||
set_adjustment(adjustment, new_value);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -466,8 +465,8 @@ sc_search(girara_session_t* session, girara_argument_t* argument,
|
|||
|
||||
int x = offset.x - gtk_adjustment_get_page_size(view_hadjustment) / 2 + rectangle.x1;
|
||||
int y = offset.y - gtk_adjustment_get_page_size(view_vadjustment) / 2 + rectangle.y1;
|
||||
gtk_adjustment_set_value(view_hadjustment, MAX(view_hadjustment->lower, MIN(view_hadjustment->upper - view_hadjustment->page_size, x)));
|
||||
gtk_adjustment_set_value(view_vadjustment, MAX(view_vadjustment->lower, MIN(view_vadjustment->upper - view_vadjustment->page_size, y)));
|
||||
set_adjustment(view_hadjustment, x);
|
||||
set_adjustment(view_vadjustment, y);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
6
utils.c
6
utils.c
|
@ -226,3 +226,9 @@ recalc_rectangle(zathura_page_t* page, zathura_rectangle_t rectangle)
|
|||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void
|
||||
set_adjustment(GtkAdjustment* adjustment, gdouble value)
|
||||
{
|
||||
gtk_adjustment_set_value(adjustment, MAX(adjustment->lower, MIN(adjustment->upper - adjustment->page_size, value)));
|
||||
}
|
||||
|
|
7
utils.h
7
utils.h
|
@ -82,4 +82,11 @@ void page_calculate_offset(zathura_page_t* page, page_offset_t* offset);
|
|||
*/
|
||||
zathura_rectangle_t recalc_rectangle(zathura_page_t* page, zathura_rectangle_t rectangle);
|
||||
|
||||
/**
|
||||
* Set adjustment of a GtkAdjustment respecting its limits.
|
||||
* @param adjust the GtkAdkustment instance
|
||||
* @param value the new adjustment
|
||||
*/
|
||||
void set_adjustment(GtkAdjustment* adjust, gdouble value);
|
||||
|
||||
#endif // UTILS_H
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <girara/datastructures.h>
|
||||
#include <girara/utils.h>
|
||||
|
@ -576,8 +577,8 @@ page_set(zathura_t* zathura, unsigned int page_id)
|
|||
|
||||
GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
|
||||
GtkAdjustment* view_hadjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
|
||||
gtk_adjustment_set_value(view_hadjustment, offset.x);
|
||||
gtk_adjustment_set_value(view_vadjustment, offset.y);
|
||||
set_adjustment(view_hadjustment, offset.x);
|
||||
set_adjustment(view_vadjustment, offset.y);
|
||||
|
||||
return true;
|
||||
|
||||
|
@ -616,7 +617,7 @@ page_widget_set_mode(zathura_t* zathura, unsigned int pages_per_row)
|
|||
|
||||
gtk_container_foreach(GTK_CONTAINER(zathura->ui.page_widget), remove_page_from_table, (gpointer)0);
|
||||
|
||||
gtk_table_resize(GTK_TABLE(zathura->ui.page_widget), zathura->document->number_of_pages / pages_per_row + 1, pages_per_row);
|
||||
gtk_table_resize(GTK_TABLE(zathura->ui.page_widget), ceil(zathura->document->number_of_pages / pages_per_row), pages_per_row);
|
||||
for (unsigned int i = 0; i < zathura->document->number_of_pages; i++)
|
||||
{
|
||||
int x = i % pages_per_row;
|
||||
|
|
Loading…
Reference in a new issue