Resize gadget negative forced to zero

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Resize gadget negative forced to zero

Post by DoubleDutch »

I noticed that in PureBasic LTS 5.21 a gadget size can't be negative. You now get an error.

This can cause major headaches with resizable gadgets as you now have to check for negative sizes and set them to zero, etc...

Would it not be better for the ResizeGadget command to check for a negative height/width and set the value to zero? (not draw the gadget).
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
Kiffi
Addict
Addict
Posts: 1486
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Resize gadget negative forced to zero

Post by Kiffi »

DoubleDutch wrote:I noticed that in PureBasic LTS 5.21 a gadget size can't be negative. You now get an error.
:shock: uh! That's very bad! :(

@PB-Team: Please go back to the old behaviour.

Thanks in advance & Greetings ... Kiffi
Hygge
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Resize gadget negative forced to zero

Post by Fred »

IHMO, you shouldn't have negative size in your code or something is wrong. There is no check at the command level, that's why a debugger check has been introduced to help catching errors. For example, I'm not sure than negative size will work on every OS. If it's only for the ResizeGadget() command, you can still write your own wrapper which check for that.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Resize gadget negative forced to zero

Post by PB »

> That's very bad!

Why? How can a gadget have negative dimensions?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Kiffi
Addict
Addict
Posts: 1486
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Resize gadget negative forced to zero

Post by Kiffi »

PB wrote:Why?
because now i have to write my own wrapper (as Fred wrote).

Simple example: Create a new form with the Visual Designer. Place a Button on the form. Lock the button top, left, right and bottom.

Now the Visual Designer has created the ResizeGadgets[YourForm]() - Procedure you can call on #PB_Event_SizeWindow. But if the Button has negative Dimensions, the code will now (with V5.21) throw an error.

I don't know, how to write a wrapper for it, because i may not change the VD generated code.

Greetings ... Kiffi
Hygge
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Resize gadget negative forced to zero

Post by PB »

I followed your steps but still can't create a gadget with negative dimensions.
How are you creating a gadget with 0 (or less!) pixels in width or height? :shock:
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Kiffi
Addict
Addict
Posts: 1486
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Resize gadget negative forced to zero

Post by Kiffi »

PB wrote:I followed your steps but still can't create a gadget with negative dimensions.
How are you creating a gadget with 0 (or less!) pixels in width or height? :shock:
the button gets negative dimensions by resizing the form (not in the VD but in your code).

Greetings ... Kiffi
Hygge
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Resize gadget negative forced to zero

Post by Fred »

Could you post some examples where it happens ?
User avatar
Kiffi
Addict
Addict
Posts: 1486
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Resize gadget negative forced to zero

Post by Kiffi »

yes, of course.

VD-generated file (save as test.pbf):

Code: Select all

Enumeration FormWindow
  #Window_0
EndEnumeration

Enumeration FormGadget
  #Button_0
EndEnumeration

Declare ResizeGadgetsWindow_0()


Procedure OpenWindow_0(x = 0, y = 0, width = 416, height = 360)
  OpenWindow(#Window_0, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_SizeGadget)
  ButtonGadget(#Button_0, 8, 8, 248, 248, "")
EndProcedure

Procedure ResizeGadgetsWindow_0()
  Protected FormWindowWidth, FormWindowHeight
  FormWindowWidth = WindowWidth(#Window_0)
  FormWindowHeight = WindowHeight(#Window_0)
  ResizeGadget(#Button_0, 8, 8, FormWindowWidth - 168, FormWindowHeight - 112)
EndProcedure
my Code:

Code: Select all

XIncludeFile "test.pbf"

OpenWindow_0()

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_SizeWindow
      ResizeGadgetsWindow_0()
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver
Hygge
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Resize gadget negative forced to zero

Post by Fred »

OK, I see now. The code from the VD should be fixed to avoid such cases.
User avatar
Kiffi
Addict
Addict
Posts: 1486
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Resize gadget negative forced to zero

Post by Kiffi »

Fred wrote:OK, I see now. The code from the VD should be fixed to avoid such cases.
sounds good. Thanks in advance!

Greetings ... Kiffi
Hygge
Post Reply