threads / patch / 40942

patch, 2 partsgitk: match ttk fonts to gitk fonts

Subject: [PATCH 1/2] gitk: match ttk fonts to gitk fonts

## tl;dr

8 messages between Dec 6, 2015 and Dec 19, 2015. Diffs are folded; open one to read it.

replies: 7people: 3as markdown or json

Giuseppe Bilotta· Dec 6, 2015, 12:25 UTC · lore

[PATCH 0/2] gitk spacing/sizing tuning for HiDPI

On my HiDPI monitor, most elements in gitk are correctly rendered, with two exceptions:

* when using ttk, some elements do not use the same fonts as gitk would use
  without, and since ttk picks _unscaled_ sizes this is very noticeable (and
borderline illegible); the first patch fixes this;
* the spacing between the checkboxes on top of the diff window are a little too
  tightly-spaced; the second patch adds a little bit of breathing space.
Giuseppe Bilotta (2):
  gitk: match ttk fonts to gitk fonts
  gitk: let .bleft.mid widgets 'breathe'
 gitk | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
-- 
2.6.3.659.gfdd8f28
Giuseppe Bilotta· Dec 6, 2015, 12:25 UTC · re: Giuseppe Bilotta · lore

The fonts set in setoptions aren't consistently picked up by ttk, who uses its own predefined fonts. This is noticeable when switching between using and not using ttk with custom fonts or in HiDPI settings (where the default TTK fonts do _not_ respect tk sclaing).

Fix by mapping the ttk fontset to the one used by gitk internally.
---
 gitk | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
Show changes to gitk +18 −0
diff --git a/gitk b/gitk
index fcc606e..e04264b 100755
--- a/gitk
+++ b/gitk
@@ -1943,6 +1943,8 @@ proc confirm_popup {msg {owner .}} {
 }
 
 proc setoptions {} {
+    global use_ttk
+
     if {[tk windowingsystem] ne "win32"} {
         option add *Panedwindow.showHandle 1 startupFile
         option add *Panedwindow.sashRelief raised startupFile
@@ -1965,6 +1967,18 @@ proc setoptions {} {
     option add *Listbox.font mainfont startupFile
 }
 
+proc setttkstyle {} {
+    eval font configure TkDefaultFont [fontflags mainfont]
+    eval font configure TkTextFont [fontflags textfont]
+    eval font configure TkHeadingFont [fontflags mainfont]
+    eval font configure TkCaptionFont [fontflags mainfont] -weight bold
+    eval font configure TkTooltipFont [fontflags uifont]
+    eval font configure TkFixedFont   [fontflags textfont]
+    eval font configure TkIconFont    [fontflags uifont]
+    eval font configure TkMenuFont    [fontflags uifont]
+    eval font configure TkSmallCaptionFont [fontflags uifont]
+}
+
 # Make a menu and submenus.
 # m is the window name for the menu, items is the list of menu items to add.
 # Each item is a list {mc label type description options...}
@@ -12356,6 +12370,10 @@ if {![info exists have_ttk]} {
 set use_ttk [expr {$have_ttk && $want_ttk}]
 set NS [expr {$use_ttk ? "ttk" : ""}]
 
+if {$use_ttk} {
+    setttkstyle
+}
+
 regexp {^git version ([\d.]*\d)} [exec git version] _ git_version
 
 set show_notes {}
-- 
2.6.3.659.gfdd8f28
Giuseppe Bilotta· Dec 6, 2015, 12:25 UTC · re: Giuseppe Bilotta · lore

[PATCH 2/2] gitk: let .bleft.mid widgets 'breathe'

The widgets on top of the diff window are very tightly packed. Make
them breathe a little by adding an 'i'-spaced padding between them.
---
 gitk | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
Show changes to gitk +6 −2
diff --git a/gitk b/gitk
index e04264b..b621762 100755
--- a/gitk
+++ b/gitk
@@ -2361,6 +2361,9 @@ proc makewindow {} {
     ${NS}::frame .bleft.mid
     ${NS}::frame .bleft.bottom
 
+    # gap between sub-widgets
+    set wgap [font measure uifont "i"]
+
     ${NS}::button .bleft.top.search -text [mc "Search"] -command dosearch
     pack .bleft.top.search -side left -padx 5
     set sstring .bleft.top.sstring
@@ -2375,8 +2378,9 @@ proc makewindow {} {
 	-command changediffdisp -variable diffelide -value {0 1}
     ${NS}::radiobutton .bleft.mid.new -text [mc "New version"] \
 	-command changediffdisp -variable diffelide -value {1 0}
+
     ${NS}::label .bleft.mid.labeldiffcontext -text "      [mc "Lines of context"]: "
-    pack .bleft.mid.diff .bleft.mid.old .bleft.mid.new -side left
+    pack .bleft.mid.diff .bleft.mid.old .bleft.mid.new -side left -ipadx $wgap
     spinbox .bleft.mid.diffcontext -width 5 \
 	-from 0 -increment 1 -to 10000000 \
 	-validate all -validatecommand "diffcontextvalidate %P" \
@@ -2384,7 +2388,7 @@ proc makewindow {} {
     .bleft.mid.diffcontext set $diffcontext
     trace add variable diffcontextstring write diffcontextchange
     lappend entries .bleft.mid.diffcontext
-    pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext -side left
+    pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext -side left -ipadx $wgap
     ${NS}::checkbutton .bleft.mid.ignspace -text [mc "Ignore space change"] \
 	-command changeignorespace -variable ignorespace
     pack .bleft.mid.ignspace -side left -padx 5
-- 
2.6.3.659.gfdd8f28
Eric Sunshine· Dec 7, 2015, 04:09 UTC · re: Giuseppe Bilotta · lore

Re: [PATCH 0/2] gitk spacing/sizing tuning for HiDPI

On Sun, Dec 6, 2015 at 7:25 AM, Giuseppe Bilotta <giuseppe.bilotta@gmail.com> wrote:

Show 8 quoted lines
> On my HiDPI monitor, most elements in gitk are correctly rendered, with two
> exceptions:
>
> * when using ttk, some elements do not use the same fonts as gitk would use
>   without, and since ttk picks _unscaled_ sizes this is very noticeable (and
> borderline illegible); the first patch fixes this;
> * the spacing between the checkboxes on top of the diff window are a little too
>   tightly-spaced; the second patch adds a little bit of breathing space.
Both patches are missing your Signed-off-by:.
Giuseppe Bilotta· Dec 8, 2015, 07:05 UTC · re: Eric Sunshine · lore

The fonts set in setoptions aren't consistently picked up by ttk, who uses its own predefined fonts. This is noticeable when switching between using and not using ttk with custom fonts or in HiDPI settings (where the default TTK fonts do _not_ respect tk sclaing).

Fix by mapping the ttk fontset to the one used by gitk internally.
Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
---
 gitk | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
Show changes to gitk +18 −0
diff --git a/gitk b/gitk
index fcc606e..e04264b 100755
--- a/gitk
+++ b/gitk
@@ -1943,6 +1943,8 @@ proc confirm_popup {msg {owner .}} {
 }
 
 proc setoptions {} {
+    global use_ttk
+
     if {[tk windowingsystem] ne "win32"} {
         option add *Panedwindow.showHandle 1 startupFile
         option add *Panedwindow.sashRelief raised startupFile
@@ -1965,6 +1967,18 @@ proc setoptions {} {
     option add *Listbox.font mainfont startupFile
 }
 
+proc setttkstyle {} {
+    eval font configure TkDefaultFont [fontflags mainfont]
+    eval font configure TkTextFont [fontflags textfont]
+    eval font configure TkHeadingFont [fontflags mainfont]
+    eval font configure TkCaptionFont [fontflags mainfont] -weight bold
+    eval font configure TkTooltipFont [fontflags uifont]
+    eval font configure TkFixedFont   [fontflags textfont]
+    eval font configure TkIconFont    [fontflags uifont]
+    eval font configure TkMenuFont    [fontflags uifont]
+    eval font configure TkSmallCaptionFont [fontflags uifont]
+}
+
 # Make a menu and submenus.
 # m is the window name for the menu, items is the list of menu items to add.
 # Each item is a list {mc label type description options...}
@@ -12356,6 +12370,10 @@ if {![info exists have_ttk]} {
 set use_ttk [expr {$have_ttk && $want_ttk}]
 set NS [expr {$use_ttk ? "ttk" : ""}]
 
+if {$use_ttk} {
+    setttkstyle
+}
+
 regexp {^git version ([\d.]*\d)} [exec git version] _ git_version
 
 set show_notes {}
-- 
2.6.3.659.gfdd8f28
Giuseppe Bilotta· Dec 8, 2015, 07:05 UTC · re: Giuseppe Bilotta · lore

[PATCH 2/2] gitk: let .bleft.mid widgets 'breathe'

The widgets on top of the diff window are very tightly packed. Make them breathe a little by adding an 'i'-spaced padding between them.

Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
---
 gitk | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
Show changes to gitk +6 −2
diff --git a/gitk b/gitk
index e04264b..b621762 100755
--- a/gitk
+++ b/gitk
@@ -2361,6 +2361,9 @@ proc makewindow {} {
     ${NS}::frame .bleft.mid
     ${NS}::frame .bleft.bottom
 
+    # gap between sub-widgets
+    set wgap [font measure uifont "i"]
+
     ${NS}::button .bleft.top.search -text [mc "Search"] -command dosearch
     pack .bleft.top.search -side left -padx 5
     set sstring .bleft.top.sstring
@@ -2375,8 +2378,9 @@ proc makewindow {} {
 	-command changediffdisp -variable diffelide -value {0 1}
     ${NS}::radiobutton .bleft.mid.new -text [mc "New version"] \
 	-command changediffdisp -variable diffelide -value {1 0}
+
     ${NS}::label .bleft.mid.labeldiffcontext -text "      [mc "Lines of context"]: "
-    pack .bleft.mid.diff .bleft.mid.old .bleft.mid.new -side left
+    pack .bleft.mid.diff .bleft.mid.old .bleft.mid.new -side left -ipadx $wgap
     spinbox .bleft.mid.diffcontext -width 5 \
 	-from 0 -increment 1 -to 10000000 \
 	-validate all -validatecommand "diffcontextvalidate %P" \
@@ -2384,7 +2388,7 @@ proc makewindow {} {
     .bleft.mid.diffcontext set $diffcontext
     trace add variable diffcontextstring write diffcontextchange
     lappend entries .bleft.mid.diffcontext
-    pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext -side left
+    pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext -side left -ipadx $wgap
     ${NS}::checkbutton .bleft.mid.ignspace -text [mc "Ignore space change"] \
 	-command changeignorespace -variable ignorespace
     pack .bleft.mid.ignspace -side left -padx 5
-- 
2.6.3.659.gfdd8f28
Paul Mackerras· Dec 19, 2015, 02:26 UTC · re: Giuseppe Bilotta · lore

Re: [PATCH 1/2] gitk: match ttk fonts to gitk fonts

On Tue, Dec 08, 2015 at 08:05:50AM +0100, Giuseppe Bilotta wrote:
Show 8 quoted lines
> The fonts set in setoptions aren't consistently picked up by ttk, who
> uses its own predefined fonts. This is noticeable when switching
> between using and not using ttk with custom fonts or in HiDPI settings
> (where the default TTK fonts do _not_ respect tk sclaing).
> 
> Fix by mapping the ttk fontset to the one used by gitk internally.
> 
> Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
Thanks, applied both this and the following patch.
Paul.
Giuseppe Bilotta· Dec 8, 2015, 07:08 UTC · re: Eric Sunshine · lore

Re: [PATCH 0/2] gitk spacing/sizing tuning for HiDPI

On Mon, Dec 7, 2015 at 5:09 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:
>
> Both patches are missing your Signed-off-by:.
Doh sorry, resending now.
-- 
Giuseppe "Oblomov" Bilotta

← back to recent threads