# [PATCH] gitk: Add horizontal scrollbar to the diff view

7 messages from 2008-03-05 to 2008-03-08. Participants: Pekka Kaitaniemi, Junio C Hamano, Paul Mackerras, Shawn O. Pearce.
Thread: https://gitlist.dev/t/12528

## Pekka Kaitaniemi, 2008-03-05 22:51

Subject: [PATCH] gitk: Add horizontal scrollbar to the diff view
Message-ID: <20080305225123.GA8485@localdomain>
URL: https://gitlist.dev/e/20080305225123.GA8485%40localdomain

```
Adding horizontal scroll bar makes the scrolling feature more
discoverable to the users.

Signed-off-by: Pekka Kaitaniemi <kaitanie@cc.helsinki.fi>
---
Here is a patch that adds horizontal scroll bar to the gitk diff
pane. It makes the scrolling feature a bit more discoverable and
accessible. The only downside is that it uses some screen real estate.

 gitk |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/gitk b/gitk
index f1f21e9..817e0ce 100755
--- a/gitk
+++ b/gitk
@@ -857,14 +857,17 @@ proc makewindow {} {
     set ctext .bleft.ctext
     text $ctext -background $bgcolor -foreground $fgcolor \
 	-state disabled -font textfont \
-	-yscrollcommand scrolltext -wrap none
+	-yscrollcommand scrolltext  -wrap none \
+	-xscrollcommand ".bleft.sbhorizontal set"
     if {$have_tk85} {
 	$ctext conf -tabstyle wordprocessor
     }
     scrollbar .bleft.sb -command "$ctext yview"
+    scrollbar .bleft.sbhorizontal -command "$ctext xview" -orient h
     pack .bleft.top -side top -fill x
     pack .bleft.mid -side top -fill x
     pack .bleft.sb -side right -fill y
+    pack .bleft.sbhorizontal -side bottom -fill x -in .bleft
     pack $ctext -side left -fill both -expand 1
     lappend bglist $ctext
     lappend fglist $ctext
-- 
1.5.4.3


```

## Junio C Hamano, 2008-03-06 06:18

Subject: Re: [PATCH] gitk: Add horizontal scrollbar to the diff view
Message-ID: <7vy78wgyu1.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vy78wgyu1.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <20080305225123.GA8485@localdomain>

```
Pekka Kaitaniemi <kaitanie@cc.helsinki.fi> writes:

> Adding horizontal scroll bar makes the scrolling feature more
> discoverable to the users.
>
> Signed-off-by: Pekka Kaitaniemi <kaitanie@cc.helsinki.fi>
> ---
> Here is a patch that adds horizontal scroll bar to the gitk diff
> pane. It makes the scrolling feature a bit more discoverable and
> accessible. The only downside is that it uses some screen real estate.

An obvious solution is to show the scrollbar on-demand (i.e. when the
lines are overlong), but I do not talk Tcl/Tk and do not know if you can
do that easily.



```

## Paul Mackerras, 2008-03-06 10:30

Subject: Re: [PATCH] gitk: Add horizontal scrollbar to the diff view
Message-ID: <18383.51154.695501.543720@cargo.ozlabs.ibm.com>
URL: https://gitlist.dev/e/18383.51154.695501.543720%40cargo.ozlabs.ibm.com
In-Reply-To: <7vy78wgyu1.fsf@gitster.siamese.dyndns.org>

```
Junio C Hamano writes:

> An obvious solution is to show the scrollbar on-demand (i.e. when the
> lines are overlong), but I do not talk Tcl/Tk and do not know if you can
> do that easily.

I don't know of any extremely easy way to do it; it's certainly
possible, but I think I would have to calculate the length of each
line as it is put in, so as to get the maximum, and then have a
handler for when the pane is resized, and pack and unpack the
scrollbar as necessary.

I think it's reasonable to have the scroll bar there always.  I think
that pane could look better using the grid geometry manager (instead
of pack), but that can be a separate patch.

Paul.

```

## Pekka Kaitaniemi, 2008-03-06 11:53

Subject: Re: [PATCH] gitk: Add horizontal scrollbar to the diff view
Message-ID: <20080306115347.GA11808@localdomain>
URL: https://gitlist.dev/e/20080306115347.GA11808%40localdomain
In-Reply-To: <18383.51154.695501.543720@cargo.ozlabs.ibm.com>

```
Hi,

On Thu, Mar 06, 2008 at 09:30:42PM +1100, Paul Mackerras wrote:
> Junio C Hamano writes:
> 
> > An obvious solution is to show the scrollbar on-demand (i.e. when the
> > lines are overlong), but I do not talk Tcl/Tk and do not know if you can
> > do that easily.
> 
> I don't know of any extremely easy way to do it; it's certainly
> possible, but I think I would have to calculate the length of each
> line as it is put in, so as to get the maximum, and then have a
> handler for when the pane is resized, and pack and unpack the
> scrollbar as necessary.

I have spent some time today looking for examples on Tk scrollbar
handling (I'm not really a Tcl/Tk guru) and I haven't found any really
easy ways either.

> I think it's reasonable to have the scroll bar there always.  I think
> that pane could look better using the grid geometry manager (instead
> of pack), but that can be a separate patch.

I have modified the patch a bit to make the horizontal scrollbar a bit
narrower so the impact on screen real estate should be smaller
now.

The grid layout manager would probably be a bit better than pack for
the left pane. At least most examples of "text and two scrollbars"
case seem to be using it. Maybe I can try to prepare a patch that
converts the diff pane from pack to grid layout.

An interesting side effect of Tk scrollbars is that by default the
"elevator" size changes depending on the _visible_ content. So the
horizontal scrollbar "elevator" changes as the user scrolls the view
up and down.

Pekka


```

## Shawn O. Pearce, 2008-03-08 01:53

Subject: Re: [PATCH] gitk: Add horizontal scrollbar to the diff view
Message-ID: <20080308015357.GU8410@spearce.org>
URL: https://gitlist.dev/e/20080308015357.GU8410%40spearce.org
In-Reply-To: <18383.51154.695501.543720@cargo.ozlabs.ibm.com>

```
Paul Mackerras <paulus@samba.org> wrote:
> Junio C Hamano writes:
> > An obvious solution is to show the scrollbar on-demand (i.e. when the
> > lines are overlong), but I do not talk Tcl/Tk and do not know if you can
> > do that easily.
> 
> I don't know of any extremely easy way to do it; it's certainly
> possible, but I think I would have to calculate the length of each
> line as it is put in, so as to get the maximum, and then have a
> handler for when the pane is resized, and pack and unpack the
> scrollbar as necessary.
> 
> I think it's reasonable to have the scroll bar there always.  I think
> that pane could look better using the grid geometry manager (instead
> of pack), but that can be a separate patch.

git-gui does this scrollbar on-demand thing in its revision list meta-widget,
which is lib/choose_rev.tcl.  The procedure in question is this, and it gets
installed as:

      listbox $w_list \
        -font font_diff \
        -width 50 \
        -height 10 \
        -selectmode browse \
        -exportselection false \
        -xscrollcommand [cb _sb_set $w.list.sbx h] \
        -yscrollcommand [cb _sb_set $w.list.sby v]


method _sb_set {sb orient first last} {
    set old_focus [focus -lastfor $w]
       
    if {$first == 0 && $last == 1} {
        if {[winfo exists $sb]} {
            destroy $sb
            if {$old_focus ne {}} {
                update
                focus $old_focus
            }
        }
        return
    }
       
    if {![winfo exists $sb]} {
        if {$orient eq {h}} {
            scrollbar $sb -orient h -command [list $w_list xview]
            pack $sb -fill x -side bottom -before $w_list
        } else {
            scrollbar $sb -orient v -command [list $w_list yview]
            pack $sb -fill y -side right -before $w_list
        }
        if {$old_focus ne {}} {
            update
            focus $old_focus
        }
    }
       
    catch {$sb set $first $last}
}


-- 
Shawn.

```

## Paul Mackerras, 2008-03-08 05:41

Subject: Re: [PATCH] gitk: Add horizontal scrollbar to the diff view
Message-ID: <18386.9974.50409.525039@cargo.ozlabs.ibm.com>
URL: https://gitlist.dev/e/18386.9974.50409.525039%40cargo.ozlabs.ibm.com
In-Reply-To: <20080308015357.GU8410@spearce.org>

```
Shawn O. Pearce writes:

> git-gui does this scrollbar on-demand thing in its revision list meta-widget,
> which is lib/choose_rev.tcl.  The procedure in question is this, and it gets
> installed as:

That's a nice idea, doing it in _sb_set.  However, since the text
widget adjusts the horizontal scroll bar depending on what's visible,
that would mean the scroll bar would appear and disappear as you
scrolled vertically through the text, which would be disconcerting.
So for a text I think it's better to have the scrollbar there
permanently.

Also, I wonder if you could use pack forget instead of destroying the
scrollbar?

Paul.

```

## Shawn O. Pearce, 2008-03-08 05:51

Subject: Re: [PATCH] gitk: Add horizontal scrollbar to the diff view
Message-ID: <20080308055157.GA8410@spearce.org>
URL: https://gitlist.dev/e/20080308055157.GA8410%40spearce.org
In-Reply-To: <18386.9974.50409.525039@cargo.ozlabs.ibm.com>

```
Paul Mackerras <paulus@samba.org> wrote:
> Shawn O. Pearce writes:
> 
> > git-gui does this scrollbar on-demand thing in its revision list meta-widget,
> > which is lib/choose_rev.tcl.  The procedure in question is this, and it gets
> > installed as:
> 
> That's a nice idea, doing it in _sb_set.  However, since the text
> widget adjusts the horizontal scroll bar depending on what's visible,
> that would mean the scroll bar would appear and disappear as you
> scrolled vertically through the text, which would be disconcerting.
> So for a text I think it's better to have the scrollbar there
> permanently.

Yea.  For a list it looks a little funny too, but its better than
not having the scrollbar there at all and looking at a chopped name
that you can't tell apart from another chopped name.  Which was a
bug I suffered from in the early dark ages of git-gui at my day
job.  Imagine Aunt Tillies blindly merging branches because they
cannot see the full branch names.  :-)
 
> Also, I wonder if you could use pack forget instead of destroying the
> scrollbar?

Because I didn't even know about that option to pack.  I'll have to
look into switching the code to do that.  Thanks for the suggestion.

-- 
Shawn.

```
