cvfosammmm / Setzer

LaTeX editor written in Python with Gtk
https://www.cvfosammmm.org/setzer/
Other
388 stars 34 forks source link

Zoom in text editor with Ctrl+Scroll #344

Closed oscfdezdz closed 1 year ago

oscfdezdz commented 1 year ago

Fix #252

cvfosammmm commented 1 year ago

This is a little bit too fast. I think the way to go is to accumulate the deltas until a threshold (then scroll), unless gdk_scroll_event_is_stop is true, then start again (reset the sum of deltas to 0). That seems to be the way Firefox does it.

cvfosammmm commented 1 year ago

I have also just pushed a commit that's relevant to this.

oscfdezdz commented 1 year ago

In my case, and taking gnome-text-editor as a reference, with mouse it worked better as it was. In the case of the touchpad, it was too fast, now it's better. Also, gdk_scroll_event_is_stop ~works fine with touchpad, but not with mouse~ makes scrolling not smooth. That's why, the sum of deltas is being reset after scroll.

Maybe changing the threshold depending on the input device? https://lazka.github.io/pgi-docs/Gdk-3.0/enums.html#Gdk.InputSource Although it could be due to the hardware and not the type of input device.

cvfosammmm commented 1 year ago

The scrolling must not be smooth, text size should increase in discrete steps. In gnome-text-editor it's also much too fast, und hard to control. It's important to be able to go to 100% for example. What's the problem with mouse in case of a threshold?

cvfosammmm commented 1 year ago

I think you have to use gdk_scroll_event_is_stop, otherwise it will never reset the threshold.

cvfosammmm commented 1 year ago

What is the delta with a mouse wheel?

cvfosammmm commented 1 year ago

I get good results with "threshold <= -1", or ">= 1".

Also you have to return True from the outer if statement, to avoid the regular scrolling to take effekt.

cvfosammmm commented 1 year ago

` def on_scroll(self, widget, event): modifiers = Gtk.accelerator_get_default_mod_mask()

    if event.state & modifiers == Gdk.ModifierType.CONTROL_MASK:
        font_manager = ServiceLocator.get_font_manager()

        self.zoom_threshold += event.delta_y
        if event.is_stop:
            self.zoom_threshold = 0

        if self.zoom_threshold <= -1:
            font_manager.zoom_in()
            self.zoom_threshold = 0
        elif self.zoom_threshold >= 1:
            font_manager.zoom_out()
            self.zoom_threshold = 0

        return True`

This works well for me. I have a trackpoint and a touchpad.

cvfosammmm commented 1 year ago

It also works perfectly with a mouse. The wheel on my mouse has a delta of 1 or -1 always.

oscfdezdz commented 1 year ago

It's working perfectly now for both cases with the changes you propose.

cvfosammmm commented 1 year ago

You should not return True in any case, just if the event was handled (ctrl+scroll). Also can you add the delta before checking for is_stop? Otherwise perfect.

oscfdezdz commented 1 year ago

It should be fixed now.

cvfosammmm commented 1 year ago

Cool.