Page 1 of 1

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

Posted: Tue Mar 15, 2016 1:59 pm
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)

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

Posted: Tue Mar 15, 2016 4:41 pm
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) ?

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

Posted: Tue Mar 15, 2016 4:42 pm
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. :)

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

Posted: Tue Mar 15, 2016 4:44 pm
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?

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

Posted: Tue Mar 15, 2016 5:35 pm
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

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

Posted: Tue Mar 15, 2016 9:32 pm
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

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

Posted: Wed Mar 16, 2016 2:54 pm
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.

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

Posted: Wed Mar 16, 2016 3:20 pm
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

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

Posted: Wed Mar 23, 2016 2:08 pm
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