IceDesign GUI designer

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
Inner
PureBasic Expert
PureBasic Expert
Posts: 714
Joined: Fri Apr 25, 2003 4:47 pm
Location: New Zealand

Re: IceDesign GUI designer

Post by Inner »

Technical question, when you create a gadget;
1. Does it have it's own event loop (like visual designer)
2. Can you add the Procedure to be called on Gadget events (like visual designer)
.. if yes to above and it's the important part, and reason why I decided to ask ..
3. Can you manage how that procedure is called?

I'll explain because (3) is a bit ambiguous, Visual Designer you add the procedure name to a gadget that you want it to call on an event this is great stuff however it's draw back is it's declared, the problem with this is and maybe little obtuse but if you intend on other parts of code 'reusing' that procedure call with different or more than the prescribed 'eventType' argument it becomes time consuming, because you can do it but you have to constantly replace the 'Declare' with the updated functionality each time you want to make a change to the UI as the declares get over written.
User avatar
ChrisR
Addict
Addict
Posts: 1466
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: IceDesign GUI designer

Post by ChrisR »

I looked again at how it was done in Form Designer, it's been a while since I've used it :wink:

Like in Form Designer, you can assign an event procedure to every gadget but it's not really made in same way.

In IceDessign, Gadget events are linked to a callback using BindGadgetEvent. It allows to have real-time event notifications as the callback can be invoked as soon as an event occurs.
The callback procedure are written here in the generated source :wink: and regular functions like EventGadget(), EventWindow(), EventMenu(), EventType() and EventData() are available to get more information about the event.

How to Bind Gadget in IceDesign:
  • You can do this individually for one or more Gadget(s) by enabling the "Bind Event" checkbox in the gadget properties.
  • Or you can do it for All Gadgets, Menu options, by enabling "Bind All Gadgets Events" checkbox in the settings.
  • And also, you can use the option "Bind Events in an Include File" in the settings, to manage events in a separate source file, which can be useful for organization in large projects.
    The name of the included file is the same as the interface name, followed by "_Event.pb" (ex: MyForm.pb -> MyForm_Event.pb).
Callback procedure names are automatically defined with "Event_" followed by the Gadget constant or variable name (ex: #MyButton -> Event_MyButton())
All this is written in the source file(s) when the code is created, ready to use 8)

#---
If you need to call the callback procedure, outside standard events, you must use PostEvent, ex:
PostEvent(#PB_Event_Gadget, #MyWindow, #MyButton, #PB_EventType_LeftClick)

And you can use EventData to send optional data associated with the event, ex:

Code: Select all

EnableExplicit

Enumeration Window
  #MyWindow
EndEnumeration

Enumeration Gadgets
  #MyButton
EndEnumeration

Structure MyStructure
  Text.s
  State.i
EndStructure

Procedure Event_MyButton()
  Protected *MyData.MyStructure  = EventData()
  Debug "EventWindow()=" + Str(EventWindow()) + " - EventGadget()=" + Str(EventGadget()) + " - EventType()=" + Str(EventType()) + " - EventData()=" + Str(EventData())
  Select EventType()
    Case #PB_EventType_LeftClick
      If *MyData
        SetGadgetText(EventGadget(), *MyData\Text)
        SetGadgetState(EventGadget(), *MyData\State)
      EndIf
  EndSelect
EndProcedure

Procedure Open_Window(X = 0, Y = 0, Width = 280, Height = 100)
  If OpenWindow(#MyWindow, X, Y, Width, Height, "MyTitle", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ButtonGadget(#MyButton, 20, 20, 240, 60, "MyButton", #PB_Button_Toggle)
    BindGadgetEvent(#MyButton, @Event_MyButton())
  EndIf
EndProcedure

Define MyData.MyStructure
Open_Window()

MyData\Text = "Abcdef..."
MyData\State = #True
PostEvent(#PB_Event_Gadget, #MyWindow, #MyButton, #PB_EventType_LeftClick, @MyData.MyStructure)

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow

I'm not sure it really answers your question about "Declare MyButtonEvent(EventType)" as it is done differently here, in IceDesign, using BindGadgetEvent which is made for that.
williamvanhoecke
User
User
Posts: 65
Joined: Wed Jun 07, 2017 10:13 pm

Re: IceDesign GUI designer

Post by williamvanhoecke »

Thanks very much Chris
williamvanhoecke
User
User
Posts: 65
Joined: Wed Jun 07, 2017 10:13 pm

Re: IceDesign GUI designer

Post by williamvanhoecke »

ChrisR wrote: Fri Dec 15, 2023 3:34 pm I looked again at how it was done in Form Designer, it's been a while since I've used it :wink:
I think Inner means somthing like this
I would like that too
Image
User avatar
Inner
PureBasic Expert
PureBasic Expert
Posts: 714
Joined: Fri Apr 25, 2003 4:47 pm
Location: New Zealand

Re: IceDesign GUI designer

Post by Inner »

ChrisR wrote: Fri Dec 15, 2023 3:34 pm #---
If you need to call the callback procedure, outside standard events, you must use PostEvent, ex:
PostEvent(#PB_Event_Gadget, #MyWindow, #MyButton, #PB_EventType_LeftClick)

I'm not sure it really answers your question about "Declare MyButtonEvent(EventType)" as it is done differently here, in IceDesign, using BindGadgetEvent which is made for that.
I'm not sure it does either to be honest; let me give an example.

Add_Task() - is a procedure that adds tasks to a list.

Form Designer when you ask it to attached a procedure to a gadget defines it as;
Declare Add_Task(EventType)

The way I need to call it however because it's a reusable procedure;
Add_Task(eventType,ValueA.s="<value a>",ValueB.s="<value b>",Task.s="(Select)")

Rather than having 2 procedure that do the same thing.
User avatar
ChrisR
Addict
Addict
Posts: 1466
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: IceDesign GUI designer

Post by ChrisR »

BindGadgetEvent in IceDesign may not be more suitable than event procedure in PureForm, for your case.
Except for a Rad like VB, I don't see a Designer giving you the choice for callback procedures parameters.
I guess it has to be handmade.

@williamvanhoecke
To be seen, defining the name of the callback procedure could be a bonus for some people.
But personally, I find it helpful to always have the same name: Event_GadgetName(),
You immediately know that this is the event procedure for this gadget.
williamvanhoecke
User
User
Posts: 65
Joined: Wed Jun 07, 2017 10:13 pm

Re: IceDesign GUI designer

Post by williamvanhoecke »

ChrisR wrote: Fri Dec 15, 2023 8:26 pm BindGadgetEvent in IceDesign may not be more suitable than event procedure in PureForm, for your case.
Except for a Rad like VB, I don't see a Designer giving you the choice for callback procedures parameters.
I guess it has to be handmade.

@williamvanhoecke
To be seen, defining the name of the callback procedure could be a bonus for some people.
But personally, I find it helpful to always have the same name: Event_GadgetName(),
You immediately know that this is the event procedure for this gadget.
Chris,
I was probably not clear, I meant declaring the callback procedure, but not creating it.
This way you can keep the callback procedure even when you make changes to the form.
williamvanhoecke
User
User
Posts: 65
Joined: Wed Jun 07, 2017 10:13 pm

Re: IceDesign GUI designer

Post by williamvanhoecke »

Hi ChrisR
the parameter 'Window_WindowCentered' has only meaning it the parameter 'Parent' is set.
Any chance that you could introduce the option for parent(windowid)
User avatar
ChrisR
Addict
Addict
Posts: 1466
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: IceDesign GUI designer

Post by ChrisR »

Sorry for the delay william, I wasn't at home and without my laptop.
I don't think there's much I can do for the Parent WindowID.
The Windows aren't grouped together in a project in IceDesign and, thus, the preview and generated code wouldn't work out of the box if I included it.
williamvanhoecke
User
User
Posts: 65
Joined: Wed Jun 07, 2017 10:13 pm

Re: IceDesign GUI designer

Post by williamvanhoecke »

Hi ChrisR
Could it not be done like this ?
Image
and then produce

Code: Select all

OpenWindow(#WinSymCommandLight, X, Y, Width, Height, "", #PB_Window_Invisible | #PB_Window_TitleBar, WindowID(AnyName))
User avatar
ChrisR
Addict
Addict
Posts: 1466
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: IceDesign GUI designer

Post by ChrisR »

It would probably be done like that, if I do it.
But I can't, otherwise, it would break an essential function, having the generated code always operational.

If you test it and use Compil/Run (F5), with the debugger's default value, enabled, you'll get this error:

Code: Select all

[ERROR] The specified #Window is not initialised.
williamvanhoecke
User
User
Posts: 65
Joined: Wed Jun 07, 2017 10:13 pm

Re: IceDesign GUI designer

Post by williamvanhoecke »

Mmm.. i undestand,
but I need it this way to enter names of windows that ARE initialized.
I currently alter the line openwindow(....) and put the WindowId(#initializedwindow) there manualy.
Works fine, but everytime I make changes to the form i need to do it again :mrgreen:
User avatar
Inner
PureBasic Expert
PureBasic Expert
Posts: 714
Joined: Fri Apr 25, 2003 4:47 pm
Location: New Zealand

Re: IceDesign GUI designer

Post by Inner »

williamvanhoecke wrote: Wed Jan 03, 2024 10:34 pm Mmm.. i undestand,
but I need it this way to enter names of windows that ARE initialized.
I currently alter the line openwindow(....) and put the WindowId(#initializedwindow) there manualy.
Works fine, but everytime I make changes to the form i need to do it again :mrgreen:
Insert a pre-processor program of the code in the compile tool chain probably at the start problem resolved, you might feel less like a hostage that way.
User avatar
ChrisR
Addict
Addict
Posts: 1466
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: IceDesign GUI designer

Post by ChrisR »

Sorry for the IceDesign mother window ID hostage situation, I hope you'll grant me full immunity :wink:

If I had to do it all over again today, I'd definitely include the ability to manage multi-window projects.
But right now, it would be too much work.

If needed, here is a small snipet, made quickly to add WindowID(#MainWindow)

Code: Select all

FileName$ = OpenFileRequester("Choose  File", GetCurrentDirectory(), "PureBasic (*.pb)|*.pb", 0)
If FileName$
  NewFileName$ = GetPathPart(FileName$) + GetFilePart(FileName$, #PB_FileSystem_NoExtension) + "_New.pb"
  If ReadFile(0, FileName$)
    If OpenFile(1, NewFileName$)
      While Eof(0) = 0
        Line$ = ReadString(0)
        If Left(LTrim(Line$), 14) = "If OpenWindow("
          If Right(Line$, 2) <> "))"   ; if not already done
            Line$ = Left(Line$, Len(Line$) - 1) + ", WindowID(#MainWindow))"
          EndIf
        EndIf
        WriteStringN(1, Line$)
      Wend
      CloseFile(1)
    EndIf
    CloseFile(0)
  EndIf
EndIf
User avatar
Inner
PureBasic Expert
PureBasic Expert
Posts: 714
Joined: Fri Apr 25, 2003 4:47 pm
Location: New Zealand

Re: IceDesign GUI designer

Post by Inner »

ChrisR wrote: Thu Jan 04, 2024 11:26 am Sorry for the IceDesign mother window ID hostage situation, I hope you'll grant me full immunity :wink:
Would like to point out as a lot can be missed with just reading text; the hostage comment was meant as constructive/wit and or humor
Post Reply