mIRC Home    About    Download    Register    News    Help

Print Thread
#230565 14/03/11 04:45 PM
Joined: Apr 2010
Posts: 969
F
Hoopy frood
OP Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
Would be nice if there was a way to tell if a specified window has a side listbox(/window -lN) or not.

I suggest an added prop of .lbstate to $window() which returns the number of characters wide the listbox is, or null if there is no side listbox


I am SReject
My Stuff
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Certainly would be handy. I could swear there was already a way to do that but I can't see it.

Not that this affects the validity of your suggestion, but if you just need to know if a window has a side-listbox or not you can use something like:
Code:
alias has_side_listbox return $iif($window($1).type == custom && $line($1, 0, 1) !== $null, $true, $false)


Of course that's far from an obvious and convenient way to get that information and it still doesn't provide the actual width of the listbox so a $window() property would be very useful.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
An even less obvious/convenient way of getting the listbox char width is the following:
Code:
sidelbw {
  var %@ = @test $+ $ticks, %f = $window($1).font, %fs = $window($1).fontsize, %cw = $width(A,%f,%fs)
  window -fhl1 %@ -1 -1 $window($1).dw 100 $qt(%f) %fs
  var %w = $window(%@).w
  close -@ %@
  return $int($calc(($window($1).w - %w) / %cw + 1))
}
Usage: $sidelbw(@window)


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
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
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Nice smile I thought there might be issues with variable-width fonts but assumed that mIRC would size the side listbox as N*<max char width>. I know <max char width> is problematic with Unicode double-width chars and whatnot and was hoping it would be defined as the "widest latin char", and that "A" would do. All wrong assumptions that I was too lazy to test...


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com

Link Copied to Clipboard