TheDcoder

Label's last word automatically shifting down

7 posts in this topic

#1 ·  Posted (edited)

Hello, Please look at this code:

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include "StringSize.au3"

For $i = 1 To 100
    StatusIndicator("Really Loooooong Text", $i)
Next

Func StatusIndicator($sStatus, $sSize = 8.5, $hParent = 0)
    $aDimensions = _StringSize($sStatus, $sSize)
    $hGUI = GUICreate("", 50 + $aDimensions[2], 50 + $aDimensions[3], -1, -1, $WS_POPUP + $WS_BORDER, -1, $hParent)
    GUISetBkColor(0xFFFFFF)
    GUICtrlCreateLabel($sStatus, ((50 +$aDimensions[2]) - $aDimensions[2]) / 2, ((50 +$aDimensions[3]) - $aDimensions[3]) / 2, $aDimensions[2], $aDimensions[3], 0x01)
    GUICtrlSetFont(-1, $sSize)
    GUISetState()
    Sleep(250)
EndFunc

Result: test.thumb.gif.2e0b60a0feef860caf0a685d2

(Fast Forwarded by 250 %)

As you can see, the last word ("Text") is automatically shifting down, How can I prevent this?

 

Thanks in Advance, TD :)

Edited by TheDcoder
Changed Title

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites



TheDcoder,

I would increase the returned width parameter just a little:

Func StatusIndicator($sStatus, $sSize = 8.5, $hParent = 0)
    $aDimensions = _StringSize($sStatus, $sSize)
    $iWidth = $aDimensions[2] * 1.05 ; Increase the width a tad
    $iHeight = $aDimensions[3]
    $hGUI = GUICreate("", 50 + $iWidth, 50 + $iHeight, -1, -1, $WS_POPUP + $WS_BORDER, -1, $hParent)
    GUISetBkColor(0xFFFFFF)
    GUICtrlCreateLabel($sStatus, ((50 + $iWidth) - $iWidth) / 2, ((50 +$iHeight) - $iHeight) / 2, $iWidth, $iHeight, 0x01)
    GUICtrlSetFont(-1, $sSize)
    GUISetState()
    Sleep(250)
EndFunc

In my experience the UDF occasionally returns dimensions which are slightly too small (usually by a single pixel) for some larger font sizes with specific string lengths. Unfortunately I have never been able to find a reliable indicator of when this is likely to occur and so other than adding a random pixel or two to the returned value I cannot do anything about it.

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

With the style setting you used, $SS_CENTER, you can't prevent it, other than to size your label correctly. The stringsize UDF uses Tahoma font as the default, GUICtrlSetFont uses the default GUI font, but I'm not sure what that is.

$SS_CENTER0x01Specifies a simple rectangle and centers the error value text in the rectangle. The control automatically wraps words that extend past the end of a line to the beginning of the next centered line.

If you use the same font in StringSize and GUICtrlSetFont, it works fine.

$aDimensions = _StringSize($sStatus, $sSize, Default, Default, "Segoe UI")
    GUICtrlSetFont(-1, $sSize, 400, 0, "Segoe UI")

 


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

BrewManNH,

Not entirely true - the UDF defaults to Tahoma if it cannot determine the system default, so the 2 should be the same. And even if I set the 2 fonts as you suggested, my system still shows the same symptoms. I might well have to amend the UDF to add a couple of pixels when using larger fonts to try and avoid this problem.

M23

Edit: Apologies - my error to suggest that the results were similar when the font was defined. But my comment about the odd sizing error still stands.

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

I was going by what the header text stated, but in looking at the code I see where you call _StringSize_DefaultFontName to get the default name.

Odd that the default comes back as Segoe UI, but the results are wrong if you don't specify Segoe UI in the GUICtrlSetFont statement. Maybe Segoe UI isn't being used as the actual default font, even though SystemParametersInfo says it is.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

That looks awful but you can try it this way:

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include "StringSize.au3"

$hParent = 0
$iX = @DesktopWidth / 2
$iY = @DesktopHeight / 2
$sText = "Really Loooooong Text"
$aDimensions = _StringSize($sText, 8.5)
$hGUI = GUICreate("", $aDimensions[2], $aDimensions[3], -1, -1, $WS_POPUP + $WS_BORDER, -1, $hParent)
GUISetBkColor(0xFFFFFF)
$iLabel = GUICtrlCreateLabel($sText, 0, 0, $aDimensions[2], $aDimensions[3], 0x201)
GUISetState()

For $i = 10 To 80 Step 0.5
    StatusIndicator($sText, $i)
Next

Func StatusIndicator($sStatus, $sSize = 8.5, $hParent = 0)
    GUICtrlSetFont($iLabel, $sSize)
    $aDimensions = _StringSize($sStatus, $sSize)
    $iW = Int($aDimensions[2] * 1.15)
    $iH = Int($aDimensions[3] * 1.15)
    WinMove($hGUI, "", $iX - $iW / 2, $iY - $iH / 2, $iW, $iH)
    Sleep(10)
EndFunc

 


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Thanks @Melba23 :)


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

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