Page 1 of 1
String gadget gets slightly taller after window resize
Posted: Wed Jul 13, 2022 2:33 pm
by russellm72
Hello!
I'm new to PB. Just trying to get familiar with it and learn enough to remake one of my smaller current projects in it. I'm using PureBasic 6.00 LTS (Windows - x64).
I've added a string gadget to a form. I've made its height 24 and I've locked the left, right, and bottom. When I resize the window, the string gadget gets just a little bit taller which doesn't make much sense to me because when I switch to the code view, I see the following:
Code: Select all
Procedure ResizeGadgetsWindow_0()
Protected FormWindowWidth, FormWindowHeight
FormWindowWidth = WindowWidth(Window_0)
FormWindowHeight = WindowHeight(Window_0)
ResizeGadget(Button_0, 8, FormWindowHeight - 30, 144, 20)
ResizeGadget(String_0, 8, FormWindowHeight - 60, FormWindowWidth - 24, 24)
ResizeGadget(Text_0, 8, 10, FormWindowWidth - 24, FormWindowHeight - 90)
EndProcedure
So, it appears to me that the ResizeGadget call for this String_0 gadget is also attempting to set the height to 24.
Is there possibly a bug or have I overlooked something or done something wrong?
Thanks in advance.
Re: String gadget gets slightly taller after window resize
Posted: Wed Jul 13, 2022 3:37 pm
by Marc56us
Hi,
If you lock only bottom of a gadget, it will be resized
If you lock bottom AND top of a gadget, height will not change
If you NOT lock none of both, il will not resize
Sample:
Code: Select all
EnableExplicit
Enumeration FormWindow
#Window_0
EndEnumeration
Enumeration FormGadget
#Button_0
#Text_0
#Text_1
EndEnumeration
Declare ResizeGadgetsWindow_0()
Procedure OpenWindow_0(x = 0, y = 0, width = 665, height = 485)
OpenWindow(#Window_0, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
ButtonGadget(#Button_0, 10, 10, 100, 25, "Quit")
TextGadget(#Text_0, 10, 40, 645, 25, "")
SetGadgetColor(#Text_0, #PB_Gadget_BackColor,#Green)
TextGadget(#Text_1, 10, 70, 645, 405, "")
SetGadgetColor(#Text_1, #PB_Gadget_BackColor,#Yellow)
EndProcedure
Procedure ResizeGadgetsWindow_0()
Protected FormWindowWidth, FormWindowHeight
FormWindowWidth = WindowWidth(#Window_0)
FormWindowHeight = WindowHeight(#Window_0)
ResizeGadget(#Text_0, 10, 40, FormWindowWidth - 20, 25)
ResizeGadget(#Text_1, 10, 70, FormWindowWidth - 20, FormWindowHeight - 80)
EndProcedure
OpenWindow_0()
Repeat
Select WaitWindowEvent()
Case #PB_Event_SizeWindow
ResizeGadgetsWindow_0()
Case #PB_Event_CloseWindow
End
Case #PB_Event_Gadget
If EventGadget() = #Button_0 : End : EndIf
EndSelect
ForEver
End
Yes, The PureBasic Form Designer handles this very well. As soon as #PB_Window_SizeGadget is checked for the window, the resize procedure is generated.

Re: String gadget gets slightly taller after window resize
Posted: Wed Jul 13, 2022 3:56 pm
by russellm72
Marc56us wrote: Wed Jul 13, 2022 3:37 pm
If you lock bottom AND top of a gadget, height will not change
Hmm. When I lock the top and the bottom, the string gadget does resize. It gets big instead of just keeping its position relative to the bottom of the window.
Re: String gadget gets slightly taller after window resize
Posted: Wed Jul 13, 2022 6:21 pm
by mk-soft
StringGadget also works the lock Top and Bottom at the same time.
However, this makes no sense, as the StringGadget is always single-line. Only makes sense with the EditorGadget
TestForm.pbf
Code: Select all
;
; This code is automatically generated by the FormDesigner.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures needs to be put in another source file.
;
Enumeration FormWindow
#Window_0
EndEnumeration
Enumeration FormGadget
#String_0
#Button_0
EndEnumeration
Declare ResizeGadgetsWindow_0()
Procedure OpenWindow_0(x = 0, y = 0, width = 600, height = 400)
OpenWindow(#Window_0, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)
StringGadget(#String_0, 10, 10, 580, 180, "Lock Top and Bottom")
ButtonGadget(#Button_0, 10, 200, 180, 40, "Lock Bottom")
EndProcedure
Procedure ResizeGadgetsWindow_0()
Protected FormWindowWidth, FormWindowHeight
FormWindowWidth = WindowWidth(#Window_0)
FormWindowHeight = WindowHeight(#Window_0)
ResizeGadget(#String_0, 10, 10, 580, FormWindowHeight - 220)
ResizeGadget(#Button_0, 10, FormWindowHeight - 200, 180, 40)
EndProcedure
Procedure Window_0_Events(event)
Select event
Case #PB_Event_SizeWindow
ResizeGadgetsWindow_0()
Case #PB_Event_CloseWindow
ProcedureReturn #False
Case #PB_Event_Menu
Select EventMenu()
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
EndSelect
EndSelect
ProcedureReturn #True
EndProcedure
Re: String gadget gets slightly taller after window resize
Posted: Wed Jul 13, 2022 7:38 pm
by russellm72
So, here's my form:
Code: Select all
;
; This code is automatically generated by the FormDesigner.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures needs to be put in another source file.
;
Global Window_0
Global Button_0, String_0, Text_0
Declare ResizeGadgetsWindow_0()
Declare buttonEvent(EventType)
Procedure OpenWindow_0(x = 0, y = 0, width = 480, height = 320)
Window_0 = OpenWindow(#PB_Any, x, y, width, height, "My Window", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
Button_0 = ButtonGadget(#PB_Any, 8, 296, 144, 16, "Click Me")
String_0 = StringGadget(#PB_Any, 8, 272, 456, 19, "")
Text_0 = TextGadget(#PB_Any, 8, 8, 456, 248, "This is a label...")
EndProcedure
Procedure ResizeGadgetsWindow_0()
Protected FormWindowWidth, FormWindowHeight
FormWindowWidth = WindowWidth(Window_0)
FormWindowHeight = WindowHeight(Window_0)
ResizeGadget(Button_0, 8, FormWindowHeight - 30, 144, 20)
ResizeGadget(String_0, 8, FormWindowHeight - 60, FormWindowWidth - 24, 24)
ResizeGadget(Text_0, 8, 10, FormWindowWidth - 24, FormWindowHeight - 90)
EndProcedure
Procedure Window_0_Events(event)
Select event
Case #PB_Event_SizeWindow
ResizeGadgetsWindow_0()
Case #PB_Event_CloseWindow
ProcedureReturn #False
Case #PB_Event_Menu
Select EventMenu()
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case Button_0
buttonEvent(EventType())
EndSelect
EndSelect
ProcedureReturn #True
EndProcedure
I've had a chance to test this on Windows 10, macOS, & Linux. On Mac & Linux, it functions as expected with the string gadget remaining the specified size. But, on Windows 10, the string gadget grows by 1 or 2 pixels in height the first time the window is resized and remains that way.
Re: String gadget gets slightly taller after window resize
Posted: Thu Jul 14, 2022 4:18 pm
by russellm72
So, I just discovered that this behavior on Windows 10 only happens when Windows display settings are set to use scaling. I had my display set to scale to 125%. If I set the scale to 100%, this odd behavior goes away.
Re: String gadget gets slightly taller after window resize
Posted: Thu Jul 14, 2022 9:26 pm
by mk-soft
Your form work fine here with 100% and 125%, with and without compiler Option DPI
I don't known were is the problem
Re: String gadget gets slightly taller after window resize
Posted: Fri Jul 15, 2022 6:11 am
by breeze4me
It looks like a bug related to DPI.
Code: Select all
String_0 = StringGadget(#PB_Any, 8, 272, 456, 19, "") ; height = 19
Code: Select all
ResizeGadget(String_0, 8, FormWindowHeight - 60, FormWindowWidth - 24, 24) ; new height = 24
The string gadget is created with the height of 19, but the height changes to 24 when the size of the window changes.
At 125% dpi, the height should be set to 24 instead of 19 when the originally designed gadget height is 24.
There is no minimum value for the string gadget height in Windows, so there is a problem.
A window made at 125% dpi as a test.
When designing, the string gadget height was set to 24. However, it is created as 19. (lock: left/bottom)
Code: Select all
Procedure OpenWindow_0(x = 0, y = 0, width = 480, height = 320)
OpenWindow(#Window_0, x, y, width, height, "", #PB_Window_SystemMenu)
StringGadget(#String_0, 124, 268, 164, 19, "")
EndProcedure
Procedure ResizeGadgetsWindow_0()
Protected FormWindowWidth, FormWindowHeight
FormWindowWidth = WindowWidth(#Window_0)
FormWindowHeight = WindowHeight(#Window_0)
ResizeGadget(#String_0, 124, FormWindowHeight - 65, 164, 24)
EndProcedure
Re: String gadget gets slightly taller after window resize
Posted: Fri Jul 15, 2022 5:03 pm
by russellm72
breeze4me wrote: Fri Jul 15, 2022 6:11 am
It looks like a bug related to DPI.
Thanks for the confirmation. I guess it looks like the solution, for the time being, is to set screen to 100% scaling when using the Form Designer.