Sign in to follow this  
Followers 0
Hypertrophy

tooltip wrapping

4 posts in this topic

#1 ·  Posted (edited)

how do i wrap my tooltip after i get so many characters in an input. I'm using GUICtrlSetTip for the method of creation.

Edited by Hypertrophy

Share this post


Link to post
Share on other sites



how do i wrap my tooltip after i get so many characters in an input. I'm using GUICtrlSetTip for the method of creation.

This is a rough idea of what I think you mean. Just written to show the idea so it needs a lot of attention.

#include <GUIConstantsEx.au3>
#include <winapi.au3>

Opt('MustDeclareVars', 1)

Example()


Func Example()
    Local $msg, $lbl
    Local $sTT = "This is a sentence which is unnecessarily long just so that I can demonstrate a way to wrap text and doesn't assume a fixed space font"
 
    GUICreate("My GUI control tip") ; will create a dialog box that when displayed is centered

    $lbl = GUICtrlCreateLabel("my label", 10, 20)

    GUISetState()

    SetTipWrapped($lbl, $sTT, 200)
    ; Run the GUI until the dialog is closed
    While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
EndFunc ;==>Example


Func SetTipWrapped($iCtrl, $stext, $iMaxWid)
    Local $n
    GUICtrlSetTip($iCtrl, $stext);no wrapping to start
    $stext = StringReplace($stext, @CRLF, @CR)
    $stext = StringReplace($stext, @LF, @CR)

    Local $hTT = _WinAPI_GetWindowDC(WinGetHandle($stext))
    ConsoleWrite(Hex($hTT) & @CRLF)
    Local $aS = WinGetPos($hTT)
 
    Local $ts = _WinAPI_GetTextExtentPoint32($hTT, $stext)
    

    Local $iLinestart = 1, $iLineLen, $iLastLen
    Local $swrap = ''
    While $iLinestart <= StringLen($stext); + 1

    While $iLineLen + $iLinestart <= StringLen($stext)
    If StringMid($stext, $iLinestart, 1) <> ' ' Then ExitLoop
    $iLinestart += 1
    WEnd
    
    $iLineLen = 1
    $iLastLen = 1
    While $iLineLen + $iLinestart < StringLen($stext) + 1
    If StringMid($stext, $iLinestart + $iLineLen, 1) = ' ' Or $iLineLen + $iLinestart >= StringLen($stext) Then
    
    Local $mid = StringMid($stext, $iLinestart, $iLineLen)
    
    $ts = _WinAPI_GetTextExtentPoint32($hTT, $mid)
    If DllStructGetData($ts, 1) > $iMaxWid Then
    
    If $iLastLen > 1 Then $iLineLen = $iLastLen
    $swrap &= StringMid($stext, $iLinestart, $iLineLen) & @CR
    $iLinestart += $iLineLen + 1
    ExitLoop
    EndIf
    If $iLineLen + $iLinestart >= StringLen($stext) Then
    
    $swrap &= StringMid($stext, $iLinestart, $iLineLen + 1)
    $iLinestart += $iLineLen + 1
    ExitLoop
    EndIf
    $iLastLen = $iLineLen
    ElseIf StringMid($stext, $iLinestart + $iLineLen, 1) = @CR Then
    
    $swrap &= StringMid($stext, $iLinestart, $iLineLen)
    $iLinestart = $iLineLen + 1
    ExitLoop

    EndIf
    $iLineLen += 1
    
    WEnd


    WEnd
    GUICtrlSetTip($iCtrl, $swrap)

EndFunc ;==>SetTipWrapped

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

God bless you martin. Thanks for all your help. Works exactly like I need.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

God bless you martin. Thanks for all your help. Works exactly like I need.

No problem.

But now I look at it I think it is too complicated so here's a simpler version.

#include <GUIConstantsEx.au3>
#include <winapi.au3>

Opt('MustDeclareVars', 1)

Example()


Func Example()
    Local $msg, $lbl
    Local $sTT = "This is a sentence which is unnecessarily long just so that I can demonstrate a way to wrap text and doesn't assume a fixed space font."

    GUICreate("My GUI control tip") ; will create a dialog box that when displayed is centered

    $lbl = GUICtrlCreateLabel("my label", 10, 20)

    GUISetState()

    _SetTipWrapped($lbl, $sTT, 280)
    ; Run the GUI until the dialog is closed
    While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
EndFunc ;==>Example

Func _SetTipWrapped($iCtrl, $stext, $iMaxWid)
    ;by martin
    ;sets a tooltip for the control $iCtrl with the text $stext,
    ; wrapped as needed to keep the tooltip width to $iMaxWid
    ;Line breaks are preserved.
    ;Multiple spaces will be reduced to one space!

    Local $aT
    Local $n
    Local $hTT
    Local $swrap = ''
    Local $iword = 1, $sTemp = '', $fNewLine

    GUICtrlSetTip($iCtrl, $stext);no wrapping to start
    $stext = StringReplace($stext, @CRLF, @CR)
    $stext = StringReplace($stext, @LF, @CR)
    $stext = StringReplace($stext, @CR, @CR & ' ');space added so we can be sure @CR is end of a 'word'

    $hTT = _WinAPI_GetWindowDC(WinGetHandle($stext))
    If _LineLength($hTT, $stext) <= $iMaxWid Then Return;no wrapping needed

    $aT = StringSplit($stext, ' ')
    For $n = 1 To $aT[0];we don't break words so we make sure width is not less than the longest word
    If _LineLength($hTT, ' ' & $aT[$n]) > $iMaxWid Then $iMaxWid = _LineLength($hTT, ' ' & $aT[$n])
    Next

    While $iword <= $aT[0]
    $sTemp = ''
    $fNewLine = True
    While $iword <= $aT[0] And _LineLength($hTT, $sTemp) + _LineLength($hTT, ' ' & $aT[$iword]) <= $iMaxWid

    If $aT[$iword] <> '' Then
    If Not $fNewLine Then $sTemp &= ' '

    $fNewLine = False
    $sTemp &= $aT[$iword]
    EndIf
    $iword += 1
    If StringRight($sTemp, 1) = @CR Then
    ExitLoop
    EndIf
    WEnd

    While StringRight($sTemp, 1) = @CR
    $sTemp = StringTrimRight($sTemp, 1)
    WEnd

    $swrap &= $sTemp & @CR
    $sTemp = ''
    WEnd


    GUICtrlSetTip($iCtrl, StringTrimRight($swrap, 1))

EndFunc ;==>_SetTipWrapped

Func _LineLength($hDC, $sLine)
    Local $ts = _WinAPI_GetTextExtentPoint32($hDC, $sLine)
    Return DllStructGetData($ts, 1);return length in pixels
EndFunc ;==>_LineLength


Func _LineLength($hDC, $sLine)
    Local $ts = _WinAPI_GetTextExtentPoint32($hDC, $sLine)
    Return DllStructGetData($ts, 1)
EndFunc ;==>LineLength

EDIT:Changed then _SetTipWrapped function so that the text to be wrapped can contain line breaks. Didn't end up simpler :) but it is better :)

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0