there's the qwerty that i remember ;P marvelous idea!

unfortunately though, variable-width fonts pose a bit of a problem. for example:

Code:
//window -hl15 @a Arial 12 | echo -a $sidelbw(@a) | close -@ @a


produces '12' :S with that font/size, the width of the side listbox is 11px for a character width of 1 and increases by 3px and 11px alternately as the char width increases by one. an average of 7px whereas the width of 'A' is 8px.

a binary search with /window -l would be the easy way out :P

or if it's true in general that the difference between the listbox widths for -lN and -l(N+2) is constant for every font/size, we could go with:

Code:
alias sidelbw_ {
  if ($window($1).fontsize) {
    var %@ = @test $+ $ticks, %@2 = %@ $+ 2, %@3 = %@ $+ 3, %f = $qt($window($1).font), %fs = $v1

    window -fhl1 %@ %f %fs
    window -fhl3 %@2 %f %fs
    window -fhl1 %@3 -1 -1 100 100 FixedSys 9 

    var %cw = $window(%@).dw - $window(%@2).dw, %sb = $window(%@3).w - 108, %w = $window($1).w
    close -@ %@ %@2 %@3

    return $int($calc(2 * (%w - $window($1).dw - %sb) / %cw $iif($window($1).type == channel, - 2)))
  }
}


(added that bit of the end since channel listbox measurements appeared off by 2)

the first two windows are to calculate that constant difference mentioned before, the third window is to help calculate scrollbar width. perhaps there's an elegant way to calc that implicitly but considering that the first character could be variable width was doing my head in :P

edit: ok improved

Code:
alias sidelbw_ {
  if ($window($1).fontsize) {
    var %@ = @test $+ $ticks, %@2 = %@ $+ 2, %f = $qt($window($1).font), %fs = $v1, %w = $window($1).dw

    window -dfhl2 %@ -1 -1 %w 0 %f %fs
    window -dfhl4 %@2 -1 -1 %w 0 %f %fs

    var %w = $window(%@).w, %cw = $window(%@2).w - %w
    close -@ %@ %@2

    return $int($calc(2 * ($window($1).w - %w) / %cw $iif($window($1).type != channel, + 2)))
  }
}

Last edited by jaytea; 15/03/11 10:53 AM.

"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde