Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui: dynamic page allocation to gtk grid #721

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ sources = files(
'zathura/database-sqlite.c',
'zathura/dbus-interface.c',
'zathura/document.c',
'zathura/document-widget.c',
'zathura/file-monitor.c',
'zathura/file-monitor-glib.c',
'zathura/file-monitor-noop.c',
Expand Down
23 changes: 0 additions & 23 deletions zathura/adjustment.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,26 +147,3 @@ void zathura_adjustment_set_value(GtkAdjustment* adjustment, gdouble value) {

gtk_adjustment_set_value(adjustment, MAX(lower, MIN(upper_m_size, value)));
}

gdouble zathura_adjustment_get_ratio(GtkAdjustment* adjustment) {
gdouble lower = gtk_adjustment_get_lower(adjustment);
gdouble upper = gtk_adjustment_get_upper(adjustment);
gdouble page_size = gtk_adjustment_get_page_size(adjustment);
gdouble value = gtk_adjustment_get_value(adjustment);

return (value - lower + page_size / 2.0) / (upper - lower);
}

void zathura_adjustment_set_value_from_ratio(GtkAdjustment* adjustment, gdouble ratio) {
if (ratio == 0.0) {
return;
}

gdouble lower = gtk_adjustment_get_lower(adjustment);
gdouble upper = gtk_adjustment_get_upper(adjustment);
gdouble page_size = gtk_adjustment_get_page_size(adjustment);

gdouble value = (upper - lower) * ratio + lower - page_size / 2.0;

zathura_adjustment_set_value(adjustment, value);
}
22 changes: 0 additions & 22 deletions zathura/adjustment.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,4 @@ bool page_is_visible(zathura_document_t* document, unsigned int page_number);
*/
void zathura_adjustment_set_value(GtkAdjustment* adjustment, gdouble value);

/**
* Compute the adjustment ratio
*
* That is, the ratio between the length from the lower bound to the middle of
* the slider, and the total length of the scrollbar.
*
* @param adjustment Scrollbar adjustment
* @return Adjustment ratio
*/
gdouble zathura_adjustment_get_ratio(GtkAdjustment* adjustment);

/**
* Set the adjustment value from ratio
*
* The ratio is usually obtained from a previous call to
* zathura_adjustment_get_ratio().
*
* @param adjustment Adjustment instance
* @param ratio Ratio from which the adjustment value will be set
*/
void zathura_adjustment_set_value_from_ratio(GtkAdjustment* adjustment, gdouble ratio);

#endif /* ZATHURA_ADJUSTMENT_H */
14 changes: 8 additions & 6 deletions zathura/callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "zathura.h"
#include "render.h"
#include "document.h"
#include "document-widget.h"
#include "utils.h"
#include "shortcuts.h"
#include "page-widget.h"
Expand Down Expand Up @@ -97,7 +98,7 @@ void cb_view_hadjustment_value_changed(GtkAdjustment* adjustment, gpointer data)
update_visible_pages(zathura);

zathura_document_t* document = zathura_get_document(zathura);
const double position_x = zathura_adjustment_get_ratio(adjustment);
const double position_x = zathura_document_widget_get_ratio(zathura, adjustment, true);
const double position_y = zathura_document_get_position_y(document);
unsigned int page_id = position_to_page_number(document, position_x, position_y);

Expand All @@ -123,7 +124,7 @@ void cb_view_vadjustment_value_changed(GtkAdjustment* adjustment, gpointer data)

zathura_document_t* document = zathura_get_document(zathura);
const double position_x = zathura_document_get_position_x(document);
const double position_y = zathura_adjustment_get_ratio(adjustment);
const double position_y = zathura_document_widget_get_ratio(zathura, adjustment, false);
const unsigned int page_id = position_to_page_number(document, position_x, position_y);

zathura_document_set_position_x(document, position_x);
Expand Down Expand Up @@ -158,7 +159,8 @@ static void cb_view_adjustment_changed(GtkAdjustment* adjustment, zathura_t* zat
/* reset the adjustment, in case bounds have changed */
const double ratio =
width == true ? zathura_document_get_position_x(document) : zathura_document_get_position_y(document);
zathura_adjustment_set_value_from_ratio(adjustment, ratio);

zathura_document_widget_set_value_from_ratio(zathura, adjustment, ratio, width);
}

void cb_view_hadjustment_changed(GtkAdjustment* adjustment, gpointer data) {
Expand Down Expand Up @@ -203,8 +205,8 @@ void cb_refresh_view(GtkWidget* GIRARA_UNUSED(view), gpointer data) {
const double position_x = zathura_document_get_position_x(document);
const double position_y = zathura_document_get_position_y(document);

zathura_adjustment_set_value_from_ratio(vadj, position_y);
zathura_adjustment_set_value_from_ratio(hadj, position_x);
zathura_document_widget_set_value_from_ratio(zathura, vadj, position_y, false);
zathura_document_widget_set_value_from_ratio(zathura, hadj, position_x, true);

statusbar_page_number_update(zathura);
}
Expand Down Expand Up @@ -318,7 +320,7 @@ void cb_page_layout_value_changed(girara_session_t* session, const char* name, g
bool page_right_to_left = false;
girara_setting_get(zathura->ui.session, "page-right-to-left", &page_right_to_left);

page_widget_set_mode(zathura, page_padding, pages_per_row, first_page_column, page_right_to_left);
zathura_document_widget_set_mode(zathura, page_padding, pages_per_row, first_page_column, page_right_to_left);
zathura_document_set_page_layout(zathura_get_document(zathura), page_padding, pages_per_row, first_page_column);
}

Expand Down
Loading