So, I finally implemented it and played around with it some more. Something I’ve noticed with allocating a Gtk.TextView
with a GskTransform
is, that since there is the “Bin”-Widget that does the allocating and transforming between the Gtk.ScrolledWindow
and the TextView.
Thus, by default the ScrolledWindow will put the “ZoomWidget” inside a Viewport. This results in the scrolling of the TextView working, since the the Viewport will just be whatever size the TextView is. However that leads the TextView to believe that it has infinite space and thus it won’t scroll the the view when the cursor is outside the viewable space since the view isn’t aware of the available space.
What is necessary is to “proxy” the Gtk.Scrollable
interface from the TextView to the “ZoomWidget”. However this doesn’t seem just as easy as simply taking the “[hv]adjustment” property from the TextView each time the the get/set_property method is called, since this GtkAdjustment
doesn’t appear to respect the GskTransformation
the TextView was allocated with.
This means, I need to adopt Adjustment changes from the TextView, rescale them and put changes into a “ZoomWidget” specific Adjustment, that the ScrolledWindow will then use. When the “ZoomWidgets” adjustment value changes, it needs to be back-scaled for the TextView. I’ve tried to implement this, however I was so far unsuccessful doing it properly. (i.e. I never seem to be able to scroll fully to the bottom, etc.).
static void mdnotebook_zoomview_vadjustment_cb(GtkAdjustment* vadj, MdNotebookZoomView* self) {
MdNotebookZoomViewPrivate* priv;
g_return_if_fail(MDNOTEBOOK_IS_ZOOMVIEW(self));
priv = mdnotebook_zoomview_get_instance_private(self);
g_return_if_fail(GTK_IS_SCROLLABLE(priv->child));
GtkAdjustment* childvadj = gtk_scrollable_get_vadjustment((GtkScrollable*)priv->child);
gtk_adjustment_set_value(childvadj, gtk_adjustment_get_value(vadj) / priv->zoom);
}
void mdnotebook_zoomview_child_vadjustment_update(MdNotebookZoomView* self) {
GtkAdjustment* childv;
MdNotebookZoomViewPrivate* priv = mdnotebook_zoomview_get_instance_private(self);
g_return_if_fail(GTK_IS_SCROLLABLE(priv->child));
childv = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(priv->child));
gtk_adjustment_set_value(priv->vadjustment, gtk_adjustment_get_value(childv) * priv->zoom);
gtk_adjustment_set_lower(priv->vadjustment, gtk_adjustment_get_lower(childv) * priv->zoom);
gtk_adjustment_set_upper(priv->vadjustment, gtk_adjustment_get_upper(childv) * priv->zoom);
gtk_adjustment_set_page_size(priv->vadjustment, gtk_adjustment_get_page_size(childv));
gtk_adjustment_set_page_increment(priv->vadjustment, gtk_adjustment_get_page_increment(childv));
gtk_adjustment_set_step_increment(priv->vadjustment, gtk_adjustment_get_step_increment(childv));
}
where mdnotebook_zoomview_vadjustment_cb
is connected to the “value-changed” of the "ZoomWidget"s vadjustment, and mdnotebook_zoomview_child_vadjustment_update
gets called when the child TextView’s vadjustment emits “changed” or the “ZoomWidgets” zoom property gets changed.
Is there any way I could make this work, either by properly multiplications/divisions of the zoom
(I haven’t fully understood Gtk.Scrollable
interface yet) or is there maybe an altogether different method (maybe somehow appling the Transform onto the Adjustment aswell).