Display the zoom level in percent in the document tab label. If the zoom level is changed back to normal size then it will not be shown.
If a user just quickly wants to zoom in and back out then showing the zoom level helps to go back to the normal size without the need of using a keybinding or menu item. IMHO this makes zooming with the mouse wheel more comfortable. The zoom level is displayed in square brackets right beside the file name in a smaller, monospace font, e.g. ```main.c [110%]```.
This is comparable to Firefox which displays the zoom level beside the URL. You can view, comment on, or merge this pull request online at:
https://github.com/geany/geany/pull/1697
-- Commit Summary --
* Show zoom level in document tab label.
-- File Changes --
M src/document.c (18) M src/editor.c (1) M src/sciwrappers.c (15) M src/sciwrappers.h (2)
-- Patch Links --
https://github.com/geany/geany/pull/1697.patch https://github.com/geany/geany/pull/1697.diff
I'm personally not a big fan of having this extra information in the precious tab space. It probably wouldn't be as bad in the status bar (it sort of fits with that information) and it could be turned on/off by the user customizing the statusbar template.
This could also be implemented in a plugin very easily, perhaps even as a feature for the Addons plugin.
Whilst I agree its useful, I agree with @codebrainz that tabs is the wrong place for it, and that status bar is a better place for it, `%z` for zoom perhaps?
b4n requested changes on this pull request.
I agree with @codebrainz and @elextr that the info should probably be somewhere less intrusive than the tab label, and would also think first thing about the status bar.
@@ -322,6 +322,10 @@ void sci_zoom_off(ScintillaObject *sci)
SSM(sci, SCI_SETZOOM, 0, 0); }
+gint sci_zoom_get(ScintillaObject *sci)
should probably be `sci_get_zoom()` for consistency
@@ -954,6 +958,17 @@ void sci_set_font(ScintillaObject *sci, gint style, const gchar *font, gint size
}
+/** Gets the font size for a particular style. + * @param sci Scintilla widget. + * @param style The style. + * @return The font size. */ +GEANY_API_SYMBOL +gint sci_get_fontsize(ScintillaObject *sci, gint style)
`sci_get_font_size()`.
Also, why is it part of the plugin API? Not that I don't want it, but we prefer to have a good reason for adding stuff to the API so we don't have to maintain something useless.
Well, I think it is not that intrusive as it only would be displayed temporarily and disappears as soon as the zoom level gets back to normal size.
Two questions: - @codebrainz @elextr @b4n Do you all agree to better put it in a plugin? - how can a plugin get the zoom notification?
I don't mind it being a status bar option which would be in core, not a plugin, but don't want any more tab space used, tabs don't fit already. So if it continues to modify the tabs then its gotta be in a plugin.
how can a plugin get the zoom notification?
[see](https://www.geany.org/manual/reference/pluginsignals_8c.html#a2982093b5402f0...)
Seems fine to me in core, especially if it just adds a new documented status bar message format placeholder that users can opt-in to (ex. `%z` as @elextr proposed).
@LarsGit223 pushed 4 commits.
853c226 Removed zoom from document tab label. 61f88f8 Minor adjustments to sciwrappers 85585c8 Show zoom in status bar (use specifier %z). abc8eec Updated documenation (geany.txt, section 'Statusbar Templates')
A little update: - I moved the displaying of the zoom level to the status bar, the specifier is **%z** - the behaviour is still the same: - if the zoom level is != 100% then e.g. ```Zoom: 110%``` will be displayed - if the zoom level is == 100% then nothing will be displayed - I updated the documentation (section **Statusbar Templates**)
LGBI
When approved the commits need to be squashed to remove the tab attempt.
@b4n, @codebrainz: ping: any remarks left? If not I will squash commits together to clean up the history.
I squashed the commits, if any more changes are requested please let me know.
LarsGit223 commented on this pull request.
@@ -322,6 +322,10 @@ void sci_zoom_off(ScintillaObject *sci)
SSM(sci, SCI_SETZOOM, 0, 0); }
+gint sci_zoom_get(ScintillaObject *sci)
Done (long time ago).
LarsGit223 commented on this pull request.
@@ -954,6 +958,17 @@ void sci_set_font(ScintillaObject *sci, gint style, const gchar *font, gint size
}
+/** Gets the font size for a particular style. + * @param sci Scintilla widget. + * @param style The style. + * @return The font size. */ +GEANY_API_SYMBOL +gint sci_get_fontsize(ScintillaObject *sci, gint style)
Done (long time ago), no longer part of the API.
Ping. Does this have a chance to be merged sometime?
b4n requested changes on this pull request.
Looks good apart from the comments below
@@ -82,6 +82,7 @@ gchar sci_get_char_at (ScintillaObject *sci, gint pos);
void sci_scroll_caret (ScintillaObject *sci); gint sci_find_text (ScintillaObject *sci, gint flags, struct Sci_TextToFind *ttf); void sci_set_font (ScintillaObject *sci, gint style, const gchar *font, gint size); +gint sci_get_fontsize (ScintillaObject *sci, gint style);
this should be in the `#ifdef GEANY_PRIVATE` section as it's not part of the API
@@ -305,6 +306,21 @@ static gchar *create_statusbar_statistics(GeanyDocument *doc,
g_string_append_printf(stats_str, "%d", sci_get_style_at(doc->editor->sci, pos)); break; + case 'z': + zoom = sci_get_zoom(doc->editor->sci); + if (zoom != 0) + { + gint size, percent; + + size = sci_get_fontsize(doc->editor->sci, STYLE_DEFAULT); + if (size > 0) + { + percent = (size + zoom) * 100 / size; + g_string_append_c(stats_str, ' ');
this should probably use `sp` like other similar replacements above. It also probably should be *after* the actual contents (see for `%r` and `%m`). `%Y` seems to be a little off, and given it's not targeted to the average user and always displays something it's not a good example :)
LarsGit223 commented on this pull request.
@@ -82,6 +82,7 @@ gchar sci_get_char_at (ScintillaObject *sci, gint pos);
void sci_scroll_caret (ScintillaObject *sci); gint sci_find_text (ScintillaObject *sci, gint flags, struct Sci_TextToFind *ttf); void sci_set_font (ScintillaObject *sci, gint style, const gchar *font, gint size); +gint sci_get_fontsize (ScintillaObject *sci, gint style);
Done.
LarsGit223 commented on this pull request.
@@ -305,6 +306,21 @@ static gchar *create_statusbar_statistics(GeanyDocument *doc,
g_string_append_printf(stats_str, "%d", sci_get_style_at(doc->editor->sci, pos)); break; + case 'z': + zoom = sci_get_zoom(doc->editor->sci); + if (zoom != 0) + { + gint size, percent; + + size = sci_get_fontsize(doc->editor->sci, STYLE_DEFAULT); + if (size > 0) + { + percent = (size + zoom) * 100 / size; + g_string_append_c(stats_str, ' ');
Done.
As a follow up, I would like to see that we can also change stuff through the status bar (via a pop-up menu or so), similar to Gedit. Such as the line endings, indentation width, etc. If this also includes the zoom label, then we need a way to show that always I guess. Can we reserve %Z for that purpose?
@kugel-: maybe post that also as an idea/feature request in a separate issue.
@b4n: ping. Could this be merged now?
@LarsGit223 pushed 1 commit.
9ea258374dfb791e19af46c354a01bbdcc4f5a31 Merge branch 'master' into showzoom
Can this be merged? I just resolved the conflicts.
@b4n ping, its your review.
b4n requested changes on this pull request.
Apart from that function name and using fractional sizes, looks pretty good to me.
+gint sci_get_fontsize(ScintillaObject *sci, gint style)
+{ + return (gint) SSM(sci, SCI_STYLEGETSIZE, (uptr_t) style, 0); +}
I would still like to see the function renamed with an underscore between `font` and `size`.
Also, we now are using [SCI_STYLESETSIZEFRACTIONAL](https://scintilla.org/ScintillaDoc.html#SCI_STYLESETSIZEFRACTIONAL), so this should probably be using fractional sizes as well and return a `gdouble`.
Something like that (untested) ```c gdouble sci_get_font_size(ScintillaObject *sci, gint style) { return SSM(sci, SCI_STYLEGETSIZEFRACTIONAL, (uptr_t) style, 0) / (gdouble) SC_FONT_SIZE_MULTIPLIER; } ```
@@ -218,6 +219,8 @@ void sci_move_selected_lines_up (ScintillaObject *sci);
void sci_set_font_fractional (ScintillaObject *sci, gint style, const gchar *font, gdouble size);
+gint sci_get_fontsize (ScintillaObject *sci, gint style);
Rename to `sci_get_font_size()` here as well
I suggest something like this ```diff diff --git a/src/sciwrappers.c b/src/sciwrappers.c index 647c44454..5dc59b93e 100644 --- a/src/sciwrappers.c +++ b/src/sciwrappers.c @@ -968,9 +968,9 @@ void sci_set_font(ScintillaObject *sci, gint style, const gchar *font, gint size }
-gint sci_get_fontsize(ScintillaObject *sci, gint style) +gdouble sci_get_font_size(ScintillaObject *sci, gint style) { - return (gint) SSM(sci, SCI_STYLEGETSIZE, (uptr_t) style, 0); + return SSM(sci, SCI_STYLEGETSIZEFRACTIONAL, (uptr_t) style, 0) / (gdouble) SC_FONT_SIZE_MULTIPLIER; }
diff --git a/src/sciwrappers.h b/src/sciwrappers.h index fca3efa65..fa2a88a29 100644 --- a/src/sciwrappers.h +++ b/src/sciwrappers.h @@ -219,7 +219,7 @@ void sci_move_selected_lines_up (ScintillaObject *sci);
void sci_set_font_fractional (ScintillaObject *sci, gint style, const gchar *font, gdouble size);
-gint sci_get_fontsize (ScintillaObject *sci, gint style); +gdouble sci_get_font_size (ScintillaObject *sci, gint style);
#endif /* GEANY_PRIVATE */
diff --git a/src/ui_utils.c b/src/ui_utils.c index 644259bec..5f3ad4abf 100644 --- a/src/ui_utils.c +++ b/src/ui_utils.c @@ -309,13 +309,13 @@ static gchar *create_statusbar_statistics(GeanyDocument *doc, zoom = sci_get_zoom(doc->editor->sci); if (zoom != 0) { - gint size, percent; + gdouble size, percent;
- size = sci_get_fontsize(doc->editor->sci, STYLE_DEFAULT); - if (size > 0) + size = sci_get_font_size(doc->editor->sci, STYLE_DEFAULT); + if (size > 0.0) { percent = (size + zoom) * 100 / size; - g_string_append_printf(stats_str, _("Zoom: %d%%"), percent); + g_string_append_printf(stats_str, _("Zoom: %.0f%%"), percent); g_string_append(stats_str, sp); } } ```
b4n commented on this pull request.
@@ -304,6 +305,21 @@ static gchar *create_statusbar_statistics(GeanyDocument *doc,
g_string_append_printf(stats_str, "%d", sci_get_style_at(doc->editor->sci, pos)); break; + case 'z': + zoom = sci_get_zoom(doc->editor->sci); + if (zoom != 0) + { + gint size, percent; + + size = sci_get_fontsize(doc->editor->sci, STYLE_DEFAULT); + if (size > 0) + { + percent = (size + zoom) * 100 / size;
Just FTR, this does not ask for any changes:
This will result in "0%" when zooming out 10 times on a 10pt font, but the font will actually still be visible because [Scintilla never shrinks fonts under 2pt](https://scintilla.org/ScintillaDoc.html#Zooming). However, the user will still have to zoom in 10 times to go back to 100%.
So, this comment is merely an "FTR", I think the behavior is good enough, and if we want to do something about it we should rather prevent actually getting the zoom factor under the minimal displayed value.
LarsGit223 commented on this pull request.
@@ -304,6 +305,21 @@ static gchar *create_statusbar_statistics(GeanyDocument *doc,
g_string_append_printf(stats_str, "%d", sci_get_style_at(doc->editor->sci, pos)); break; + case 'z': + zoom = sci_get_zoom(doc->editor->sci); + if (zoom != 0) + { + gint size, percent; + + size = sci_get_fontsize(doc->editor->sci, STYLE_DEFAULT); + if (size > 0) + { + percent = (size + zoom) * 100 / size;
I agree, out-of-scope for this PR.
@LarsGit223 pushed 1 commit.
e7b9ece9256e0f890899eb06aa52313290b7cacf sciwrappers: use fractional size in 'sci_get_font_size()'
LarsGit223 commented on this pull request.
@@ -218,6 +219,8 @@ void sci_move_selected_lines_up (ScintillaObject *sci);
void sci_set_font_fractional (ScintillaObject *sci, gint style, const gchar *font, gdouble size);
+gint sci_get_fontsize (ScintillaObject *sci, gint style);
Done.
LarsGit223 commented on this pull request.
+gint sci_get_fontsize(ScintillaObject *sci, gint style)
+{ + return (gint) SSM(sci, SCI_STYLEGETSIZE, (uptr_t) style, 0); +}
Changed and tested. Now looks like your code snippet below.
b4n approved this pull request.
LGTM, and it works fine.
Only thing is that I'd like to squash the commits I think as part of the second relevant commit is fixups on the first one, but I can also do that when merging if you'd like.
I will try to squash it myself.
Sorry, broke it. Will post another clean PR.
Do not merge this, closing in favor of #2339.
Closed #1697.
Sorry, broke it.
What does that mean? AFAIK you can't break a PR.
@codebrainz: I mixed up the commit history.
Since you managed to fix it (as per #2339), you could've force pushed it back to your fork/remote to update this PR. As long as you push to the same remote branch the PR is made for, Github should update the original PR fine.
#2339 is not a fix of this branch, I just checked out master and applied the changes.
If you name the new branch `showzoom` and force push it, it will update the original PR.
For example:
```bash $ git branch -m showzoom showzoom-messed-up $ git branch -m showzoom2 showzoom $ git push <yourRemote> +showzoom ```
@codebrainz: thanks, did not know that I can rename branches. I'll try to remeber that if I get to the same situation again. Now I got the new PR open anyway so I will keep that.
Now I got the new PR open anyway so I will keep that.
Alternatively, you could close the duplicate PR and update this one which has reviews and comments.
I pushed to showzoom again and I hopefully have restored the branch but I do not see it here since it's already closed.
How can I re-open this PR? Github only let's me create a new PR from ```LarsGit223:showzoom```. Would that re-open this one?
Update: I see the Reopen pull request button but it is grayed out.
Most likely it's done that since you created a second PR with the same branch. You could try and close the second one and I suspect the "Re-open" option will become active again for this PR.
Most likely it's done that since you created a second PR with the same branch. You could try and close the second one and I suspect the "Re-open" option will become active again for this PR.
The second/other PR is from another branch ```showzoom2```. But I already pushed again to ```showzoom``` before trying to re-open this PR.
Bah, forget it. This is dead now. Move on.
But I already pushed again to showzoom before trying to re-open this PR.
For future reference: https://gist.github.com/robertpainsi/2c42c15f1ce6dab03a0675348edd4e2c
Bah, forget it. This is dead now. Move on.
Ok, will wait for #2339 to be merged.
Can anyone please tell me if it's been implemented or not? I'm using Geany 1.33 on Debian 10, and don't see it.
@rodrigo1406: no, it's not merged yet. See #2339.
github-comments@lists.geany.org