Page 35 of 49
Re: IceDesign GUI designer
Posted: Fri Dec 15, 2023 1:19 am
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.
Re: IceDesign GUI designer
Posted: Fri Dec 15, 2023 3:34 pm
by ChrisR
I looked again at how it was done in Form Designer, it's been a while since I've used it
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

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
#---
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.
Re: IceDesign GUI designer
Posted: Fri Dec 15, 2023 3:53 pm
by williamvanhoecke
Thanks very much Chris
Re: IceDesign GUI designer
Posted: Fri Dec 15, 2023 4:56 pm
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
I think
Inner means somthing like this
I would like that too

Re: IceDesign GUI designer
Posted: Fri Dec 15, 2023 5:02 pm
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.
Re: IceDesign GUI designer
Posted: Fri Dec 15, 2023 8:26 pm
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.
Re: IceDesign GUI designer
Posted: Fri Dec 15, 2023 11:13 pm
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.
Re: IceDesign GUI designer
Posted: Sat Dec 23, 2023 8:34 pm
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)
Re: IceDesign GUI designer
Posted: Wed Dec 27, 2023 2:44 pm
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.
Re: IceDesign GUI designer
Posted: Tue Jan 02, 2024 10:13 pm
by williamvanhoecke
Hi ChrisR
Could it not be done like this ?

and then produce
Code: Select all
OpenWindow(#WinSymCommandLight, X, Y, Width, Height, "", #PB_Window_Invisible | #PB_Window_TitleBar, WindowID(AnyName))
Re: IceDesign GUI designer
Posted: Tue Jan 02, 2024 10:56 pm
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.
Re: IceDesign GUI designer
Posted: Wed Jan 03, 2024 10:34 pm
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

Re: IceDesign GUI designer
Posted: Wed Jan 03, 2024 11:30 pm
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
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.
Re: IceDesign GUI designer
Posted: Thu Jan 04, 2024 11:26 am
by ChrisR
Sorry for the IceDesign mother window ID hostage situation, I hope you'll grant me full immunity
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
Re: IceDesign GUI designer
Posted: Thu Jan 04, 2024 10:59 pm
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
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