Sign in to follow this  
Followers 0
mistersquirrle

Updating label height

16 posts in this topic

I've been searching for a while now for an answer to my problem, but I haven't been able to find anything that fits my needs or that I can get to work. What I'm looking for is a way to change the height of a label to fit the amount of text that's in it, after it's been changed. In my GUI when you press a button a random string is displayed in a label and it's usually a couple lines, but some times it can be a lot more than a couple, and I want to have my button kinda float beneath the label, at the bottom of the text.

so what I'm asking is, is there an easy way to resize the label after the new text is put in, and then get bottom coordinate of the label?

thanks


RAWR! I'm hungry :( Feed the panda squirrle

Share this post


Link to post
Share on other sites



Is it multi line text?

Like

Text & @CRLF and more text?

if so then just count the lines etc.

There are other methods, search around for dynamic labels.

Cheers

Brett

Share this post


Link to post
Share on other sites

no, I have a set width, so it wraps around at some point and creates lines that way, and then sometimes has line breaks.

I'll search for that in the morning, thanks for the reply


RAWR! I'm hungry :( Feed the panda squirrle

Share this post


Link to post
Share on other sites

mistersquirrle,

Try this UDF I wrote some time ago - I think it is just what you are looking for. You pass it the text of the label, details of the font to use (same parameters as GUICtrlSetFont) and an optional maximum width. It returns an array with the text ready formatted and the size of the label needed to display it. Let me know what you think:

#include-once

#include <WindowsConstants.au3>
#include <SendMessage.au3>
#include <WinAPI.au3>

; #FUNCTION# =======================================================================================
;
; Name...........: _StringSize
; Description ...: Returns size of rectangle required to display string - width can be chosen
; Syntax ........: _StringSize($sText[, $iSize[, $iWeight[, $iAttrib[, $sName[, $iWidth]]]]])
; Parameters ....: $sText   - String to display
;                 $iSize   - Font size in points - default AutoIt GUI default
;                 $iWeight - Font weight (400 = normal) - default AutoIt GUI default
;                 $iAttrib - Font attribute (0-Normal, 2-Italic, 4-Underline, 8 Strike - default AutoIt
;                 $sName   - Font name - default AutoIt GUI default
;                 $iWidth  - [optional] Width of rectangle - default is unwrapped width of string
; Requirement(s) : v3.2.12.1 or higher
; Return values .: Success - Returns array with details of rectangle required for text:
;                 |$array[0] = String formatted with @CRLF at required wrap points
;                 |$array[1] = Height of single line in selected font
;                 |$array[2] = Width of rectangle required to hold formatted string
;                 |$array[3] = Height of rectangle required to hold formatted string
;                 Failure - Returns 0 and sets @error:
;                 |1 - Incorrect parameter type (@extended = parameter index)
;                 |2 - Failure to create GUI to test label size
;                 |3 - Failure of _WinAPI_SelectObject
;                 |4 - Font too large for chosen width - longest word will not fit
; Author ........: Melba23
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
;===================================================================================================


Func _StringSize($sText, $iSize = Default, $iWeight = Default, $iAttrib = Default, $sName = Default, $iWidth = 0)
    
    Local $hWnd, $hFont, $hDC, $oFont, $tSize, $hGUI, $hText_Label, $sTest_Line
    Local $iLine_Count, $iLine_Width, $iWrap_Count, $iLast_Word
    Local $asLines[1], $avSize_Info[4], $aiPos[4]
    
; Check parameters are correct type
    If Not IsString($sText) Then Return SetError(1, 1, 0)
    If Not IsNumber($iSize) And $iSize <> Default   Then Return SetError(1, 2, 0)
    If Not IsInt($iWeight)  And $iWeight <> Default Then Return SetError(1, 3, 0)
    If Not IsInt($iAttrib)  And $iAttrib <> Default Then Return SetError(1, 4, 0)
    If Not IsString($sName) And $sName <> Default   Then Return SetError(1, 5, 0)
    If Not IsNumber($iWidth) Then Return SetError(1, 6, 0)

; Create GUI to contain test labels, set to passed font parameters 
    $hGUI = GUICreate("", 1200, 500, 10, 10)
        If $hGUI = 0 Then Return SetError(2, 0, 0)
        GUISetFont($iSize, $iWeight, $iAttrib, $sName)
    
; Store unwrapped text
    $avSize_Info[0] = $sText
    
; Ensure EoL is @CRLF and break text into lines
    If StringInStr($sText, @CRLF) = 0 Then StringRegExpReplace($sText, "[x0a|x0d]", @CRLF)
    $asLines = StringSplit($sText, @CRLF, 1)
        
; Draw label with unwrapped lines to check on max width
    $hText_Label = GUICtrlCreateLabel($sText, 10, 10)
    $aiPos = ControlGetPos($hGUI, "", $hText_Label)
    GUICtrlDelete($hText_Label)
    
; Store line height for this font size after removing label padding (always 8)
    $avSize_Info[1] = ($aiPos[3] - 8)/ $asLines[0]
; Store width and height of this label
    $avSize_Info[2] = $aiPos[2]
    $avSize_Info[3] = $aiPos[3] - 4; Reduce margin
    
; Check if wrapping is required
    If $aiPos[2] > $iWidth And $iWidth > 0 Then
        
    ; Set returned text element to null
        $avSize_Info[0] = ""
        
    ; Set width element to max allowed
        $avSize_Info[2] = $iWidth
        
    ; Set line count to zero
        $iLine_Count = 0
        
    ; Take each line in turn
        For $j = 1 To $asLines[0]
            
        ; Size this line unwrapped
            $hText_Label = GUICtrlCreateLabel($asLines[$j], 10, 10)
            $aiPos = ControlGetPos($hGUI, "", $hText_Label)
            GUICtrlDelete($hText_Label)
            
        ; Check wrap status
            If $aiPos[2] < $iWidth Then
            ; No wrap needed so count line and store
                $iLine_Count += 1
                $avSize_Info[0] &= $asLines[$j] & @CRLF
            Else
            ; Wrap needed so need to count wrapped lines
                
            ; Create label to hold line as it grows
                $hText_Label = GUICtrlCreateLabel("", 0, 0)
            ; Initialise Point32 method
                $hWnd = ControlGetHandle($hGui, "", $hText_Label)
                $hFont = _SendMessage($hWnd, $WM_GETFONT)
                $hDC = _WinAPI_GetDC($hWnd)
                $oFont = _WinAPI_SelectObject($hDC, $hFont)
                If $oFont = 0 Then Return SetError(3, 0, 0)
                
            ; Zero counter
                $iWrap_Count = 0

                While 1
                    
                ; Set line width to 0
                    $iLine_Width = 0
                ; Initialise pointer for end of word
                    $iLast_Word = 0
                    
                    For $i = 1 To StringLen($asLines[$j])

                    ; Is this just past a word ending?
                        If StringMid($asLines[$j], $i, 1) = " " Then $iLast_Word = $i - 1
                    ; Increase line by one character
                        $sTest_Line = StringMid($asLines[$j], 1, $i)
                    ; Place line in label
                        GUICtrlSetData($hText_Label, $sTest_Line)
                    ; Get line length
                        $tSize = _WinAPI_GetTextExtentPoint32($hDC, $sTest_Line)
                        $iLine_Width = DllStructGetData($tSize, "X")
                        
                    ; If too long exit the loop
                        If $iLine_Width >= $iWidth - Int($iSize / 2) Then ExitLoop
                    Next
                        
                ; End of the line of text?
                    If $i > StringLen($asLines[$j]) Then
                    ; Yes, so add final line to count
                        $iWrap_Count += 1
                    ; Store line
                        $avSize_Info[0] &= $sTest_Line & @CRLF
                        ExitLoop
                    Else
                    ; No, but add line just completed to count
                        $iWrap_Count += 1
                    ; Check at least 1 word completed or return error
                        If $iLast_Word = 0 Then
                            GUIDelete($hGUI)
                            Return SetError(4, 0, 0)
                        EndIf
                    ; Store line up to end of last word
                        $avSize_Info[0] &= StringLeft($sTest_Line, $iLast_Word) & @CRLF
                    ; Strip string to point reached
                        $asLines[$j] = StringTrimLeft($asLines[$j], $iLast_Word)
                    ; Trim leading whitespace
                        $asLines[$j] = StringStripWS($asLines[$j], 1)
                    ; Repeat with remaining characters in line
                    EndIf
                    
                WEnd
                
            ; Add the number of wrapped lines to the count
                $iLine_Count += $iWrap_Count
                
            ; Clean up
                _WinAPI_ReleaseDC($hWnd, $hDC)
                GUICtrlDelete($hText_Label)
                
            EndIf
            
        Next
        
    ; Convert lines to pixels and add reduced margin
        $avSize_Info[3] = ($iLine_Count * $avSize_Info[1]) + 4
        
    EndIf

; Clean up
    GUIDelete($hGUI)
    
; Return array
    Return $avSize_Info

EndFunc; => _StringSize

#cs

; StringSize Test example ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Global $aFont[4] = ["Arial", "Tahoma", "Courier New", "Comic Sans MS"]
Global $aSize[4] = [9, 12, 10, 15]
Global $aWeight[4] = [200, 400, 600, 800]
Global $aAttrib[4] = [0, 2, 4, 0]
Global $aMaxWidth[4] = [250, 300, 400, 500]
Global $aColour[4] = [0xFFFF88, 0xBBFF88, 0xBB88FF, 0xFF88FF]
Global $aButMsg[4] = ["Press for next example", "Click here", "Please push", "And the next one please..."]

$sLabelMsg  = "This is a message with very long lines which are unlikely to fit within the maximum width specified.  " & _
"This UDF will return the size of rectangle needed to display it in a selected font and size." & @CRLF & @CRLF & _
"The GUI can then be sized to fit and accurately placed on screen.  Other controls, such as the automatically " & _
"sized button under this label, can also be accurately positioned relative to the text."

GUICreate("String Sizing Test", 500, 500)
GUISetState()

While 1
    
    $sFont = $aFont[Random(0, 3, 1)]
    $iSize = $aSize[Random(0, 3, 1)]
    $iWeight = $aWeight[Random(0, 3, 1)]
    $iAttrib = $aAttrib[Random(0, 3, 1)]
    $iMaxWidth = Random(200, 850, 1)
    $iColour = $aColour[Random(0, 3, 1)]
    $sButMsg = $aButMsg[Random(0, 3, 1)]
    
    $aButReturn = _StringSize($sButMsg)
    $aMsgReturn = _StringSize($sLabelMsg, $iSize, $iWeight, $iAttrib, $sFont, $iMaxWidth)
    $iError = @error
    
    If IsArray($aMsgReturn) = 1 Then
        
        WinMove("String Sizing Test", "", (@DesktopWidth - ($aMsgReturn[2] + 25)) / 2, (@DesktopHeight - ($aMsgReturn[3] + 85)) / 2, $aMsgReturn[2] + 25, $aMsgReturn[3] + 85 )
        
        $hLabel = GUICtrlCreateLabel($aMsgReturn[0], 10, 10, $aMsgReturn[2], $aMsgReturn[3], 1)
            GUICtrlSetFont(-1, $iSize, $iWeight, $iAttrib, $sFont)
            GUICtrlSetBkColor(-1, $iColour)
        $hNext = GUICtrlCreateButton($sButMsg, ($aMsgReturn[2] - $aButReturn[2]) / 2, $aMsgReturn[3] + 20, $aButReturn[2] + 20, 30)
        
        While 1
    
        $iMsg = GUIGetMsg()
        
        If $iMsg = -3 Then Exit
        
        If $iMsg = $hNext Then ExitLoop
    
        WEnd

        GUICtrlDelete($hNext)
        GUICtrlDelete($hLabel)
    Else
        MsgBox(0, "Error", "Code = " & $iError)
    EndIf

WEnd

Exit

; End of example ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#ce

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Thanks Melba, that works pretty good. it took me a while to figure out how to use it in my script, and it's a little slow when there's a lot of text, but it'll work great :)

is there a way to make it so that it doesn't have to delete the ctrl, and then remake it though? like just a way to update it?


RAWR! I'm hungry :( Feed the panda squirrle

Share this post


Link to post
Share on other sites

mistersquirrle,

Glad you like it - I will accept "pretty good" as a colonial attempt at English understatement! ;-)

The deletion of the GUI is just for the example script. There is nothing to stop you using ControlMove to move and resize your label.

How big a string are you using? I have never noticed it being overly long for message box style strings - which is what is was designed for.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

The longest string that I have with the set width is about 23 lines, and even when the string doesn't change and just updates it (through deleting the ctrl and remaking it) it goes blank for a little while, not to long. It also goes blank for a bit on some sorter ones, it's not consistent though. It's a very nice script that you wrote either way :)

I didn't know about ControlMove, since I was only looking in the GUI section of the help file, thanks for the tip

edit:

so I did it with the ControlMove and it doesn't go blank, it just flickers once or twice, and it looks like that it's speeding it up bit

Edited by mistersquirrle

RAWR! I'm hungry :( Feed the panda squirrle

Share this post


Link to post
Share on other sites

mistersquirrle,

Could you post the code you are using when you run this UDF and an example of the text you want to display. I will see if I can do anything to help speed it all up.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Zedna,

That is what the UDF uses - thanks to an earlier suggestion from you.

m23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Yeah I'd be happy to. I'll have to post an example of my script a bit later though, I'm about to go out on my motorcycle to a friends house, so I'll post it when I get there. :)


RAWR! I'm hungry :( Feed the panda squirrle

Share this post


Link to post
Share on other sites

Zedna,

That is what the UDF uses - thanks to an earlier suggestion from you.

m23

Sorry Melba.

I quickly looked through your script and overlooked this API call.

So I posted link to my older answer for similar problem.

Your script is quite long for that ;-)

Share this post


Link to post
Share on other sites

Zedna,

LOL! But I am a mere apprentice while you are a MVP!

Seriously, the script does a bit more than the examples you linked to. However, if you would care to offer any improvements I would be delighted read them.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Prepare to be blinded by my awesome script :)

CODE
#include-once

#include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

#include "Label resizing.au3" ;your script

Global $GUI = GUICreate("woof", 1025, 500, -1, -1)

GUISetBkColor(0x000000)

Global $Pic1 = GUICtrlCreatePic("", 16, 24, -1, -1, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))

Global $Patroling = GUICtrlCreateGroup("Patroling", 8, 8, 1001, 423)

Global $MD = GUICtrlCreateLabel("Action", 192, 32, 609, 27)

GUICtrlSetFont($MD, 14, 800, 0, "Verdana")

GUICtrlSetColor($MD, 0xFFcc66)

Global $AD = GUICtrlCreateLabel("Action Description", 192, 56, 796, 500)

GUICtrlSetFont($AD, 10, 400, 0, "Verdana")

GUICtrlSetColor($AD, 0x999999)

Global $Opt1 = GUICtrlCreateButton("Continue Patrol", 16, 398, 107, 22, $BS_CENTER)

GUICtrlSetFont($Opt1, 7, 400, 0, "Verdana")

GUICtrlSetColor($Opt1, 0xEFE8CF)

GUICtrlSetBkColor($Opt1, 0x444444)

GUISetState(@SW_SHOW)

While 1

$Msg = GUIGetMsg()

Select

Case $Msg = $GUI_EVENT_CLOSE

Exit

Case $Msg = $Opt1

Vul_Outpost_11() ;normally a random event, but this is the longest one that I have I think, I could add the random ones you can see how it does when it's constantly changing to random things

Resize() ;resizing of buttons and labels

EndSelect

WEnd

Func Resize() ;for label and button resizing

Global $Labelsize = _StringSize(GUICtrlRead($AD), 10, 400, 0, "Verdana", 796) ; your crazy function

GUICtrlSetData($AD, $Labelsize[0]) ;setting the label with the line breaks

ControlMove("", "", $AD, 192, 56, 796, $Labelsize[3]) ;resizing the label

$PosAD = ControlGetPos("", "", $AD) ;to make the buttons float beneath the text

;~ If GUICtrlGetState($Opt1) = 80 Or GUICtrlGetState($Opt1) = 144 Then

;~ _SetWidth2Text($GUI, "", $Opt1, 5) ;another script by resnullius, it's called _Control_SetWidth2Text (I believe), I just shorted the function name

; used it to resize the buttons but I don't think I could get it to work with labels

If $PosAD[3] + 75 > 170 Then ; button positioning

ControlMove("", "", $Opt1, $PosAD[0], $PosAD[3] + 65)

Else

ControlMove("", "", $Opt1, $PosAD[0], 155)

EndIf

$PosOpt1 = ControlGetPos("", "", $Opt1)

;~ EndIf

EndFunc ;==>Resize

;what happens when the button is pressed, it's from a game

Func Vul_Outpost_11() ;Outpost Earn Mercreds

;~ GUICtrlSetImage($Pic1, "C:\Documents and Settings\Snaples\Desktop\images\db\outland\vulcore\repair_vulcore.jpg") ;don't worry about the image >_>

GUICtrlSetData($MD, "Available Missions")

GUICtrlSetData($AD, 'Banking: We require an escort for a Tag Droid run. We use the droids to deliver encrypted credit caches which can only be deciphered at our Outposts. Unfortunately that does not stop attacks on them by Renegades and Scaven.' & @CRLF & 'Safely escort the droid to the next outpost and receive your reward of 3 Mercreds."' & @CRLF & '' & @CRLF & 'Cave Crystals: One of our outside contacts requires Crixiano Crystals. These crystals are very rare and identifiable only through chemical analysis.' & @CRLF & 'Take one of our Surveyer bots and search for the crystals inside caves. If any crystals are discovered, return with the Surveyer for a reward of 5 Mercreds per crystal.' & @CRLF & '' & @CRLF & 'Matriarch Crowns: The Scaven are causing trouble for us. They have been raiding our salvager and tag-droid routes, and basically costing us a fortune in lost equipment. We know that the scaven are ruled by females known as Matriarchs, and that they rule from the safety of forts and small settlements within the scaven borders. Hunt these Matriarchs down and return with their Crowns.' & @CRLF & 'A bounty of 10 Mercreds will be paid for each Crown.' & @CRLF & '' & @CRLF & 'Sulphur Anomaly: CCU probes have been unable to successfully map and analyse the new areas where sulphur anomalies have been detected. Investigate the region and return with any relevant information for a reward.' & @CRLF & 'Early reports indicate a strong hostile renegade presence in the area, information about the strength and type of renegades in the area will also be rewarded.' & @CRLF & '' & @CRLF & 'Sulpher Anomaly mission is currently off limits: Requires 750k battle merit.') ;Banking ;Cave Crystals ;Matriarch Crowns ;Sulpher Anomaly ;Cancel (Options not availible if you don't have enough BM)

GUICtrlSetData($Opt1, "Banking")

GUICtrlSetState($Opt1, $GUI_SHOW)

EndFunc ;==>Vul_Outpost_11

edit:

I took a bunch out of the script to shorten it up, just ask and I'll pm you more of the script so you can see it

Edited by mistersquirrle

RAWR! I'm hungry :( Feed the panda squirrle

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

mistersquirrle,

Fortunately my sight survived, but thanks for the warning!

The label rewrite is taking a bit of time (and flickering) because you are writing the text to the label twice. The first time in Func Vul_Outpost_11() - GUICtrlSetData($AD, ....) and then again in Func Resize() - GUICtrlSetData($AD, ....).

Try running Func Resize() from within Func Vul_Outpost_11() as shown in the attached script. That way you only rewrite the label once - you do not gain a massive amount of time, but it does not flicker - which to my subjective eye makes it look far better. I also changed your code to rewrite the Header label after the Main label had changed - that way all the labels and buttons change withina few lines of code and you are less aware of the "very slight" wait while my "crazy", or as I prefer "very clever and well-coded", function does its thing. Coded this way, it is timing out about 1/5 sec to do the whole process on my machine (including the timer code) - so perhaps you need a faster PC! ;-)

These next points come from a look at the script in isolation. You may have good reasons to do it the way you have coded, but I thought I would bring them up anyway:

- The $PosAD = ControlGetPos("", "", $AD) (line 41) is unnecessary - you have just used ControlMove to position $AD, so you know exactly where it is.

- Similar comment for the $PosOpt1 = ControlGetPos("", "", $Opt1) (line 47) - you used ControlMove to position it in the line before and you do not seem to use the result.

- There is no need to make the $LabelSize array Global in scope - you will only ever use use it in the Resize function.

- It is only my personal preference (your code was not wrong in any way), but look at the use of a Switch group to check GUIGetMsg(). I find it much easier to code like this - particularly if there are lots of controls. SciTE's syntax colouring also helps make the different Case statements stand out quite well.

So have a look at the following and see if it helps at all:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <stringsize.au3>;your script

Global $GUI = GUICreate("woof", 1025, 500, -1, -1)
GUISetBkColor(0x000000)
Global $Pic1 = GUICtrlCreatePic("", 16, 24, -1, -1, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))
Global $Patroling = GUICtrlCreateGroup("Patroling", 8, 8, 1001, 423)
Global $MD = GUICtrlCreateLabel("Action", 192, 32, 609, 27)
GUICtrlSetFont($MD, 14, 800, 0, "Verdana")
GUICtrlSetColor($MD, 0xFFcc66)
Global $AD = GUICtrlCreateLabel("Action Description", 192, 56, 796, 500)
GUICtrlSetFont($AD, 10, 400, 0, "Verdana")
GUICtrlSetColor($AD, 0x999999)
Global $Opt1 = GUICtrlCreateButton("Continue Patrol", 16, 398, 107, 22, $BS_CENTER)
GUICtrlSetFont($Opt1, 7, 400, 0, "Verdana")
GUICtrlSetColor($Opt1, 0xEFE8CF)
GUICtrlSetBkColor($Opt1, 0x444444)
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Opt1
            Vul_Outpost_11()
    EndSwitch
WEnd

Func Resize($AD_Text);for label and button resizing
Global $Labelsize = _StringSize($AD_Text, 10, 400, 0, "Verdana", 796); my very clever and well-coded function
ControlMove("", "", $AD, 192, 56, 796, $Labelsize[3]);resizing the label
GUICtrlSetData($AD, $Labelsize[0]);setting the label with the line breaks
If $Labelsize[3] + 75 > 170 Then                            ;$PosAD[3] replaced with $Labelsize[3]
    ControlMove("", "", $Opt1, 192, $Labelsize[3] + 65)     ;$PosAD[0] replaced with value from ControlMove (192)
Else
    ControlMove("", "", $Opt1, 192, 155)
EndIf
EndFunc;==>Resize

;what happens when the button is pressed, it's from a game
Func Vul_Outpost_11();Outpost Earn Mercreds
;~ GUICtrlSetImage($Pic1, "C:\Documents and Settings\Snaples\Desktop\images\db\outland\vulcore\repair_vulcore.jpg");don't worry about the image >_>
$AD_Text = 'Banking: We require an escort for a Tag Droid run. We use the droids to deliver encrypted credit caches which can only be deciphered at our Outposts. Unfortunately that does not stop attacks on them by Renegades and Scaven.' & @CRLF & 'Safely escort the droid to the next outpost and receive your reward of 3 Mercreds."' & @CRLF & '' & @CRLF & 'Cave Crystals: One of our outside contacts requires Crixiano Crystals. These crystals are very rare and identifiable only through chemical analysis.' & @CRLF & 'Take one of our Surveyer bots and search for the crystals inside caves. If any crystals are discovered, return with the Surveyer for a reward of 5 Mercreds per crystal.' & @CRLF & '' & @CRLF & 'Matriarch Crowns: The Scaven are causing trouble for us. They have been raiding our salvager and tag-droid routes, and basically costing us a fortune in lost equipment. We know that the scaven are ruled by females known as Matriarchs, and that they rule from the safety of forts and small settlements within the scaven borders. Hunt these Matriarchs down and return with their Crowns.' & @CRLF & 'A bounty of 10 Mercreds will be paid for each Crown.' & @CRLF & '' & @CRLF & 'Sulphur Anomaly: CCU probes have been unable to successfully map and analyse the new areas where sulphur anomalies have been detected. Investigate the region and return with any relevant information for a reward.' & @CRLF & 'Early reports indicate a strong hostile renegade presence in the area, information about the strength and type of renegades in the area will also be rewarded.' & @CRLF & '' & @CRLF & 'Sulpher Anomaly mission is currently off limits: Requires 750k battle merit.';Banking;Cave Crystals;Matriarch Crowns;Sulpher Anomaly;Cancel (Options not availible if you don't have enough BM)

; Run Resize here - must pass the text as a parameter
Resize($AD_Text)

; Now rewrite the other controls
GUICtrlSetData($MD, "Available Missions")
GUICtrlSetData($Opt1, "Banking")
GUICtrlSetState($Opt1, $GUI_SHOW)
EndFunc;==>Vul_Outpost_11
Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

sorry for replying so slow, I haven't been paying much attention to the forums while I was at my friends house

thanks for looking at the script, but where you said

Func Resize() from within Func Vul_Outpost_11() as shown in the attached script.

would take a lot of work, because then to get the desired effect I'd have to put that into all of my functions which would take forever and I've already spent more time than I've wanted fixing up the functions >_>, so unless I get really motivated it'll probably stay the same. good suggestion though. I might do it for just a couple of the ones with long lines of text.

just a little explaining :) :

These next points come from a look at the script in isolation. You may have good reasons to do it the way you have coded, but I thought I would bring them up anyway:

- The $PosAD = ControlGetPos("", "", $AD) (line 41) is unnecessary - you have just used ControlMove to position $AD, so you know exactly where it is.

I use the ControlGetPos so that I can get the bottom coordinates of the label, so that I can make the button be just below it, or if it isn't to many lines, stay at one position

- Similar comment for the $PosOpt1 = ControlGetPos("", "", $Opt1) (line 47) - you used ControlMove to position it in the line before and you do not seem to use the result.

I use that position to get the position of it, and the width of the button, and then I use that to position the other buttons (which obviously weren't in the shortened code) so that they're always the same distance apart, but I know what you mean. On the last button I don't have that line, because I'll never have a use knowing the things about that last button (as of right now)

- There is no need to make the $LabelSize array Global in scope - you will only ever use use it in the Resize function.

- It is only my personal preference (your code was not wrong in any way), but look at the use of a Switch group to check GUIGetMsg(). I find it much easier to code like this - particularly if there are lots of controls. SciTE's syntax colouring also helps make the different Case statements stand out quite well.

I'm to lazy to make things local variables >_> I don't like them as much as global. if I start to get conflicting variables I might make them local.

I haven't really looked at the switch for GuiGetMsg, I just kinda learned GUI's with select, and it's working for me right now, I'll look into it though thanks for your help Melba :)


RAWR! I'm hungry :( Feed the panda squirrle

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