String gadget gets slightly taller after window resize

You need some new stunning features ? Tell us here.
russellm72
User
User
Posts: 17
Joined: Wed Jul 13, 2022 2:04 pm

String gadget gets slightly taller after window resize

Post 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.
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: String gadget gets slightly taller after window resize

Post 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.

:wink:
russellm72
User
User
Posts: 17
Joined: Wed Jul 13, 2022 2:04 pm

Re: String gadget gets slightly taller after window resize

Post 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.
User avatar
mk-soft
Always Here
Always Here
Posts: 6207
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: String gadget gets slightly taller after window resize

Post 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

My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
russellm72
User
User
Posts: 17
Joined: Wed Jul 13, 2022 2:04 pm

Re: String gadget gets slightly taller after window resize

Post 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.
russellm72
User
User
Posts: 17
Joined: Wed Jul 13, 2022 2:04 pm

Re: String gadget gets slightly taller after window resize

Post 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.
User avatar
mk-soft
Always Here
Always Here
Posts: 6207
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: String gadget gets slightly taller after window resize

Post 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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
breeze4me
Enthusiast
Enthusiast
Posts: 633
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: String gadget gets slightly taller after window resize

Post 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
russellm72
User
User
Posts: 17
Joined: Wed Jul 13, 2022 2:04 pm

Re: String gadget gets slightly taller after window resize

Post 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.
Post Reply