[NoNeed] Resize[Window/Gadget]: Params should be optional

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 559
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

[NoNeed] Resize[Window/Gadget]: Params should be optional

Post by Sicro »

Code: Select all

ResizeWindow(Window, 100)
ResizeWindow(Window, #PB_Ignore, 100)
ResizeWindow(Window, #PB_Ignore, #PB_Ignore, 100, #PB_Ignore)
ResizeWindow(Window, #PB_Ignore, #PB_Ignore, #PB_Ignore, 100)

Code: Select all

ResizeGadget(Gadget, 100)
ResizeGadget(Gadget, #PB_Ignore, 100)
ResizeGadget(Gadget, #PB_Ignore, #PB_Ignore, 100)
ResizeGadget(Gadget, #PB_Ignore, #PB_Ignore, #PB_Ignore, 100)
Last edited by Sicro on Wed Mar 23, 2016 2:17 pm, edited 3 times in total.
Image
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
Julian
Enthusiast
Enthusiast
Posts: 276
Joined: Tue May 24, 2011 1:36 pm

Re: ResizeWindow()/ResizeGadget(): Parameters should be opti

Post by Julian »

Optional params can be awkward, specifying #PB_Ignore is clearer, for the sake of a couple of keystokes...

ResizeGadget already does it:
The new position and dimensions of the gadget. To ease the building of real-time resizable Graphical User Interfaces (GUIs), #PB_Ignore can be passed as any parameter (x, y, Width or Height) and this parameter will not be changed.
ResizeWindow half does it:
The new window position, in pixels. If 'x' or 'y' is set to #PB_Ignore, the current value of 'x' or 'y' won't be changed.
The new window size, in pixels. If 'Width' or 'Height' is set to #PB_Ignore, the current value of 'Width' or 'Height' won't be changed.
Can't you just do ResizeWindow(0, newX, WindowY(0), #PB_Ignore, #PB_Ignore) ?
Last edited by Julian on Tue Mar 15, 2016 4:43 pm, edited 1 time in total.
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

Re: ResizeWindow()/ResizeGadget(): Parameters should be opti

Post by mestnyi »

More importantly , I think getting the event of early changes and the end of Gadget and windows if this is added it would be very good. :)
Julian
Enthusiast
Enthusiast
Posts: 276
Joined: Tue May 24, 2011 1:36 pm

Re: ResizeWindow()/ResizeGadget(): Parameters should be opti

Post by Julian »

mestnyi wrote:More importantly , I think getting the event of early changes and the end of Gadget and windows if this is added it would be very good. :)
If you use BindEvent and BindGadgetEvent you get the event as it happens, if that is what you mean?
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

Re: ResizeWindow()/ResizeGadget(): Parameters should be opti

Post by mestnyi »

and in part , :) it will only work for the windows and no start and end (#PB_Event_SizeWindowStart; #PB_Event_SizeWindowEnd) and for the gadget at all and there is no :D
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 559
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: ResizeWindow()/ResizeGadget(): Parameters should be opti

Post by Sicro »

Julian wrote:Optional params can be awkward, specifying #PB_Ignore is clearer, for the sake of a couple of keystokes...

ResizeGadget already does it:
The new position and dimensions of the gadget. To ease the building of real-time resizable Graphical User Interfaces (GUIs), #PB_Ignore can be passed as any parameter (x, y, Width or Height) and this parameter will not be changed.
ResizeWindow half does it:
The new window position, in pixels. If 'x' or 'y' is set to #PB_Ignore, the current value of 'x' or 'y' won't be changed.
The new window size, in pixels. If 'Width' or 'Height' is set to #PB_Ignore, the current value of 'Width' or 'Height' won't be changed.
Can't you just do ResizeWindow(0, newX, WindowY(0), #PB_Ignore, #PB_Ignore) ?
Apparently you have misunderstood me. I have my first post provided with better example codes.
Julian wrote:ResizeWindow half does it:
Why "half does it"? In ResizeWindow() and ResizeGadget(), the parameters can be set identical.
Look here:

Code: Select all

OpenWindow(0, 0, 0, 200, 200, "test", #PB_Window_SystemMenu)

AddWindowTimer(0, 0, 2000)

Define.i event, state

Repeat
  event = WaitWindowEvent()
  If event = #PB_Event_Timer
    Select state
      Case 0
        ResizeWindow(0, 100, #PB_Ignore, #PB_Ignore, #PB_Ignore)
        state = 1
      Case 1
        ResizeWindow(0, #PB_Ignore, 100, #PB_Ignore, #PB_Ignore)
        state = 2
      Case 2
        ResizeWindow(0, #PB_Ignore, #PB_Ignore, 400, #PB_Ignore)
        state = 3
      Case 3
        ResizeWindow(0, #PB_Ignore, #PB_Ignore, #PB_Ignore, 400)
        RemoveWindowTimer(0, 0)
        CloseWindow(0)
        Break
    EndSelect
  EndIf
ForEver
Image
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
Julian
Enthusiast
Enthusiast
Posts: 276
Joined: Tue May 24, 2011 1:36 pm

Re: ResizeWindow()/ResizeGadget(): Parameters should be opti

Post by Julian »

Sicro wrote:Apparently you have misunderstood me. I have my first post provided with better example codes.
I understood you fine, which is why I said:
Julian wrote:Optional params can be awkward, specifying #PB_Ignore is clearer, for the sake of a couple of keystokes...
Sicro wrote:
Julian wrote:ResizeWindow half does it:
Why "half does it"? In ResizeWindow() and ResizeGadget(), the parameters can be set identical.
I said ResizeWindow only half does it because the manual mentions
If 'x' or 'y' is set to #PB_Ignore, the current value of 'x' or 'y' won't be changed.
and
If 'Width' or 'Height' is set to #PB_Ignore, the current value of 'Width' or 'Height' won't be changed.
Which would seem is an error in the documentation.

As I said originally, Optional params can be awkward, specifying #PB_Ignore is clearer, for the sake of a couple of keystokes. They are awkward because you still need to specify a value (100 or #PB_Ignore) for the optional params before you get to the last one. Let me elaborate:

ResizeWindow(0, 100, #PB_Ignore, #PB_Ignore, #PB_Ignore) can only be reduced to ResizeWindow(0, 100) if you want to change x
ResizeWindow(0, #PB_Ignore, 100, #PB_Ignore, #PB_Ignore) can only be reduced to ResizeWindow(0, #PB_Ignore, 100) if you want to change y
ResizeWindow(0, #PB_Ignore, #PB_Ignore, 100, #PB_Ignore) can only be reduced to ResizeWindow(0, #PB_Ignore, #PB_Ignore, 100) if you want to change w
ResizeWindow(0, #PB_Ignore, #PB_Ignore, #PB_Ignore, 100) can only be reduced to ResizeWindow(0, #PB_Ignore, #PB_Ignore, #PB_Ignore, 100) if you want to change h

I assume you want this so you can just change single params on their own? If you want to change single params only their own why dont you make 4 macros?

Code: Select all

Macro ResizeWindowX(Window, X)
  ResizeWindow(Window, X, #PB_Ignore, #PB_Ignore, #PB_Ignore)
EndMacro
Macro ResizeWindowY(Window, Y)
  ResizeWindow(Window, #PB_Ignore, Y, #PB_Ignore, #PB_Ignore)
EndMacro
Macro ResizeWindowW(Window, W)
  ResizeWindow(Window, #PB_Ignore, #PB_Ignore, W, #PB_Ignore)
EndMacro
Macro ResizeWindowH(Window, H)
  ResizeWindow(Window, #PB_Ignore, #PB_Ignore, #PB_Ignore, H)
EndMacro
Now you have all the time saving of your requested optional params. In fact, its a lot simpler because you don't have to specify a load of #PB_Ignore's :)

Code: Select all

Macro ResizeWindowX(Window, X)
  ResizeWindow(Window, X, #PB_Ignore, #PB_Ignore, #PB_Ignore)
EndMacro
Macro ResizeWindowY(Window, Y)
  ResizeWindow(Window, #PB_Ignore, Y, #PB_Ignore, #PB_Ignore)
EndMacro
Macro ResizeWindowW(Window, W)
  ResizeWindow(Window, #PB_Ignore, #PB_Ignore, W, #PB_Ignore)
EndMacro
Macro ResizeWindowH(Window, H)
  ResizeWindow(Window, #PB_Ignore, #PB_Ignore, #PB_Ignore, H)
EndMacro

OpenWindow(0, 0, 0, 200, 200, "test", #PB_Window_SystemMenu)

AddWindowTimer(0, 0, 2000)

Define.i event, state

Repeat
  event = WaitWindowEvent()
  If event = #PB_Event_Timer
    Select state
      Case 0
        ;ResizeWindow(0, 100, #PB_Ignore, #PB_Ignore, #PB_Ignore)
        ResizeWindowX(0, 100)
        state = 1
      Case 1
        ;ResizeWindow(0, #PB_Ignore, 100, #PB_Ignore, #PB_Ignore)
        ResizeWindowY(0, 100)
        state = 2
      Case 2
        ;ResizeWindow(0, #PB_Ignore, #PB_Ignore, 400, #PB_Ignore)
        ResizeWindowW(0, 400)
        state = 3
      Case 3
        ;ResizeWindow(0, #PB_Ignore, #PB_Ignore, #PB_Ignore, 400)
        ResizeWindowH(0, 400)
        state = 4
      Case 4
        RemoveWindowTimer(0, 0)
        CloseWindow(0)
        Break
    EndSelect
  EndIf
ForEver
PS. I added case4 so you can see the last test.
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

Re: ResizeWindow()/ResizeGadget(): Parameters should be opti

Post by mestnyi »

I would add this capability already available functions and it would be logical. Since we have a function ; HideWindow () and do not have ; ShowWindow () :D

Code: Select all

Procedure __WindowX(Window, X = #PB_Ignore, Mode = #PB_Window_FrameCoordinate)
  If X = #PB_Ignore
    ProcedureReturn WindowX(Window, Mode ) 
  Else
    ResizeWindow(Window, X, #PB_Ignore, #PB_Ignore, #PB_Ignore)
  EndIf
EndProcedure
Macro WindowX( Window, X = #PB_Ignore, Mode = #PB_Window_FrameCoordinate)
  __WindowX(Window, X, Mode)
EndMacro



OpenWindow(0, 0, 0, 200, 200, "test", #PB_Window_SystemMenu)

AddWindowTimer(0, 0, 2000)

Define.i event, state

Repeat
  event = WaitWindowEvent()
  If event = #PB_Event_Timer
    Select state
      Case 0
        ;ResizeWindow(0, 100, #PB_Ignore, #PB_Ignore, #PB_Ignore)
        Debug "WindowX "+WindowX(0)
        Debug "WindowX InnerCoordinate "+WindowX(0,#PB_Ignore, #PB_Window_InnerCoordinate)
        WindowX(0, 100)
        Debug "WindowX "+WindowX(0)
        Debug "WindowX InnerCoordinate "+WindowX(0,#PB_Ignore, #PB_Window_InnerCoordinate)
        state = 1
;       Case 1
;         ;ResizeWindow(0, #PB_Ignore, 100, #PB_Ignore, #PB_Ignore)
;         WindowY(0, 100)
;         state = 2
;       Case 2
;         ;ResizeWindow(0, #PB_Ignore, #PB_Ignore, 400, #PB_Ignore)
;         WindowW(0, 400)
;         state = 3
;       Case 3
;         ;ResizeWindow(0, #PB_Ignore, #PB_Ignore, #PB_Ignore, 400)
;         WindowH(0, 400)
;         state = 4
      Case 4
        RemoveWindowTimer(0, 0)
        CloseWindow(0)
        Break
    EndSelect
  EndIf
ForEver
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 559
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: ResizeWindow()/ResizeGadget(): Parameters should be opti

Post by Sicro »

mestnyi wrote:More importantly , I think getting the event of early changes and the end of Gadget and windows if this is added it would be very good. :)
That is another topic, but why you need start / stop events at windows and gadgets? For drag & drop, there are already events. To draw the canvas gadget has mouse is pressed / released events.
Julian wrote:As I said originally, Optional params can be awkward, specifying #PB_Ignore is clearer, for the sake of a couple of keystokes. They are awkward because you still need to specify a value (100 or #PB_Ignore) for the optional params before you get to the last one.
Thank you for your detailed explanation. You're right. When I look at this now again, it really awkwardly. :lol:
It would be better if an extra procedure would exist for each parameter (for example SetWindowX and as a counterpart GetWindowX).
Julian wrote:I assume you want this so you can just change single params on their own? If you want to change single params only their own why dont you make 4 macros?
Yes, I can create a workaround for the missing feature. That is perhaps better.
mestnyi wrote:I would add this capability already available functions and it would be logical.
That's good. Thanks. But that would be more understandable: GetWindowX / SetWindowsX
Image
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
Post Reply