PDA

View Full Version : New UI ... CallBacks options



ErosOlmi
23-08-2013, 23:23
Something you will get into next thinBasic beta (1.9.8.0)

DIALOGS can be samed using Name clause during DIALOG NEW ...
If named option is used, you can use dialog name to create events dialog callbacks function that will be automatically called when such an event is fired
automatic dialog callbacks must be named with the dialog name + underscore + event
so far I've created the following events: *_OnInit, *_OnSize, *_OnMove, *_OnTimer, *_OnCommand, *_OnCallback (can be used to create automatic callback to dialogs)


During this development I discovered it would be very useful to have variables defined with a DIALOG scope, that is variable accessible from any dialog callback of the same dialog. This in order to avoid global variables and keep things all together. I'm thinking about it and how to implement.

Suggestions/ideas are welcome.

Ciao
Eros

Example:


uses "UI"
Uses "console"

Begin ControlID
%IDC_TIMER
%IDC_LABEL
%IDC_Start
%IDC_Stop
End ControlID

%TIMER_DELAY = 10 ' Timer delay (in milliseconds, not very accurate below about 100)


Global TimerValue As Double '---Will be used to calculate timer values


'------------------------------------------------------------------------------
' Main function
'------------------------------------------------------------------------------
FUNCTION TBMain() as long
LOCAL hDlg AS DWORD

Dialog New Name "TimerDialog", 0 , "Timer Example using CallBacks functions", -1, -1, 240, 40, %WS_OVERLAPPEDWINDOW To hDlg


CONTROL ADD BUTTON, hDlg, %IDC_Start, "Start" , 10, 10, 50, 20
CONTROL ADD LABEL , hDlg, %IDC_LABEL, "" , 90, 10, 55, 20, %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER OR %SS_CENTERIMAGE OR %SS_CENTER
CONTROL ADD BUTTON, hDlg, %IDC_Stop , "Stop" , 180, 10, 50, 20

Dialog Show Modal hDlg 'Call MainDialog_OnCallBack

END FUNCTION



'------------------------------------------------------------------------------
' OnCallBack
'------------------------------------------------------------------------------
CallBack Function TimerDialog_OnCallBack() As Long
PrintL Timer, Function_Name, CBMSG
End Function




'------------------------------------------------------------------------------
' OnCommand
'------------------------------------------------------------------------------
CallBack Function TimerDialog_OnCommand() As Long
Select Case CBCTL


'---Check which control as fired the event
Case %IDC_Start
'---If start, than enable/disable relevant buttons and activate the timer
Control Disable CBHNDL, %IDC_Start
Control Enable CBHNDL, %IDC_Stop


TimerValue = 0 '---Set the time counter to zero
Dialog Set Timer CBHNDL, %IDC_TIMER, %TIMER_DELAY


Case %IDC_Stop
'---If sstop, than enable/disable relevant buttons and destroy the timer
Control Disable CBHNDL, %IDC_Stop
Control Enable CBHNDL, %IDC_Start
Dialog Kill Timer CBHNDL, %IDC_TIMER


End Select
End Function

'------------------------------------------------------------------------------
' OnInit
'------------------------------------------------------------------------------
CallBack Function TimerDialog_OnInit() As Long
Control Disable CBHNDL, %IDC_Stop
End Function


'------------------------------------------------------------------------------
' OnTimer
'------------------------------------------------------------------------------
CallBack Function TimerDialog_OnTimer() As Long
'---This event is fired by any timer created on the dialog. We have to check which one

'---CBWPARAM contains the ID of the timer that fired %WM_TIMER event
'---More than one timer can be active sumultaneously
Select Case CBWPARAM
Case %IDC_TIMER
'---Increment and set the test value...
TimerValue += 0.01
Control Set Text CBHNDL, %IDC_LABEL, Format$(TimerValue, "#0.00")
End Select
End Function

'------------------------------------------------------------------------------
' OnSize
'------------------------------------------------------------------------------
CallBack Function TimerDialog_OnSize() As Long
PrintL Timer, "Sizing", CBWPARAM, CBLPARAM
End Function

'------------------------------------------------------------------------------
' OnMove
'------------------------------------------------------------------------------
CallBack Function TimerDialog_OnMove() As Long
PrintL Timer, "Moving", CBWPARAM, CBLPARAM
End Function




PS: this post fired OOP discussion (that I really appreaciated) in this post: http://www.thinbasic.com/community/showthread.php?t=12194
I just wanted to point out that here I'm not discussing OOP but just another approach to Dialog Events CallBacks handling, at least for the more often used events.

ReneMiner
26-08-2013, 21:06
"Private scope" without oop nor globals? Append some pointer to Dialog where to find a datapointer and store data in heap...

ErosOlmi
26-08-2013, 21:33
I'm thinking about that:

STATIC variables created inside a CALLBACK of a Window will be defined inside a Window scope and not FUNCTION scope like it is now
all such variables will be available to all CALLBACKs of the same Window using the Window Handle as discriminant.


Not an usual way of doing things ...
... but something unique.

Petr Schreiber
26-08-2013, 22:08
Hi Eros,

If I may, I would propose to call them slightly differentely than STATICs, to avoid confusion. Maybe SHARED or something similar?
To support encapsulation, what about wild idea of DIALOG FUNCTION:



MainWindow("Ciao")

DIALOG FUNCTION MainWindow( aParam AS STRING ) ' -- Any number/kind of parameters

DIALOG NEW ... TO hDlg

CONTROL ADD ...

DIALOG SHARED myData AS STRING = "They passed" + aParam ' -- Such a variable would be shared with callback functions

DIALOG SHOW MODAL hDlg
END FUNCTION

CALLBACK FUNCTION MainWindow_OnTimer()

PrintL myData ' -- Can be read here, because it is "shared", would print "They passed Ciao" in this case

END FUNCTION


or alternatively, instead of DIALOG FUNCTION, we could have specific block for sharing:


DIALOG SHARED hDlg ' -- For which dialog we share this?
x AS LONG
s AS STRING
...
END SHARED




"Private scope" without oop nor globals? Append some pointer to Dialog where to find a datapointer and store data in heap...

Rene - you can do this even now, via DIALOG SET/GET USER.


Petr

ErosOlmi
26-08-2013, 22:52
I like SHARED idea.

ReneMiner
27-08-2013, 06:21
...
Rene - you can do this even now, via DIALOG SET/GET USER.


Petr

Of course- but there are "only" 4 user-slots and I think they should stay available to the user. I just would hide the "shared" data in heap. As long as the dialog-handle is known the related heap will be easy to find or access. I think it probably will never need to change size nor its pointer - and just changing values inside through some local overlay won't matter as long as the size stays as it is. This needs no additional variables - and it could hide a whole udt, array or a book of the bible.

But anyway - I can't await to get my fingers onto these new functionalities - try out, test and surprise you once more :)

ReneMiner
03-09-2013, 20:11
Not to trash your thread - check this (http://www.thinbasic.com/community/showthread.php?t=12194&page=2&p=89654#post89654) - it's not real oop but ensures a private scope through heap - could be a way straight through between - tB goes it's own way...

ReneMiner
03-09-2013, 20:44
no one cares what sb is made up of... :( - as long as you don't read the linked thread your comment is just... another useless comment.

Petr Schreiber
09-09-2013, 15:04
Hi Eros,

the highlevel devil in my head still talks and I must repost his prophecy: What about adding some more easy to read event parameters overlays?

Take for example OnSize handler - wouldn't it be nice to be able to access OnSize_Width, OnSize_Height pseudovariables instead of Win32ish CBWPARAM, CBLPARAM?


Petr

ErosOlmi
09-09-2013, 22:15
Petr,

you are asking too much but ... who knows :D

In the meantime the following is what will be present in next update. Do you see anything ... new? ;)


uses "UI" Uses "console"

Begin ControlID
%IDC_TIMER
%IDC_LABEL
%IDC_Start
%IDC_Stop
End ControlID

%TIMER_DELAY = 10 '---Timer delay (in milliseconds, not very accurate below about 100)


Global TimerValue As Double '---Will be used to calculate timer values


'------------------------------------------------------------------------------
' Main function
'------------------------------------------------------------------------------
FUNCTION TBMain() as long
LOCAL hDlg AS DWORD

Dialog New Name "TimerDialog", 0 , "Timer Example using CallBacks functions", -1, -1, 240, 40, %WS_OVERLAPPEDWINDOW To hDlg


Control Add Button, Name "cmdStart", hDlg, %IDC_Start, "Start" , 10, 10, 50, 20
Control Add Label , hDlg, %IDC_LABEL, "" , 90, 10, 55, 20, %WS_CHILD Or %WS_VISIBLE Or %WS_BORDER Or %SS_CENTERIMAGE Or %SS_CENTER
Control Add Button, Name "cmdStop" , hDlg, %IDC_Stop , "Stop" , 180, 10, 50, 20

Dialog Show Modal hDlg 'Call MainDialog_OnCallBack

END FUNCTION



'------------------------------------------------------------------------------
' TimerDialog OnCallBack
'------------------------------------------------------------------------------
CallBack Function TimerDialog_OnCallBack() As Long
'PrintL Timer, Function_Name, CBMSG
End Function




'------------------------------------------------------------------------------
' TimerDialog OnCommand
'------------------------------------------------------------------------------
CallBack Function TimerDialog_OnCommand() As Long
' Select Case CBCTL
'
' '---Check which control as fired the event
' Case %IDC_Start
' '---If start, than enable/disable relevant buttons and activate the timer
' Control Disable CBHNDL, %IDC_Start
' Control Enable CBHNDL, %IDC_Stop
'
' TimerValue = 0 '---Set the time counter to zero
' Dialog Set Timer CBHNDL, %IDC_TIMER, %TIMER_DELAY
'
' Case %IDC_Stop
' '---If sstop, than enable/disable relevant buttons and destroy the timer
' Control Disable CBHNDL, %IDC_Stop
' Control Enable CBHNDL, %IDC_Start
' Dialog Kill Timer CBHNDL, %IDC_TIMER
'
' End Select
End Function

'------------------------------------------------------------------------------
' TimerDialog OnInit
'------------------------------------------------------------------------------
CallBack Function TimerDialog_OnLoad() As Long
Control Disable CBHNDL, %IDC_Stop
End Function


'------------------------------------------------------------------------------
' TimerDialog OnTimer
'------------------------------------------------------------------------------
CallBack Function TimerDialog_OnTimer() As Long
'---This event is fired by any timer created on the dialog. We have to check which one

'---CBWPARAM contains the ID of the timer that fired %WM_TIMER event
'---More than one timer can be active sumultaneously
Select Case CBWPARAM
Case %IDC_TIMER
'---Increment and set the test value...
TimerValue += 0.01
Control Set Text CBHNDL, %IDC_LABEL, Format$(TimerValue, "#0.00")
End Select
End Function

'------------------------------------------------------------------------------
' TimerDialog OnSize
'------------------------------------------------------------------------------
CallBack Function TimerDialog_OnSize() As Long
PrintL Timer, "Sizing", CBWPARAM, CBLPARAM
End Function

'------------------------------------------------------------------------------
' TimerDialog OnMove
'------------------------------------------------------------------------------
CallBack Function TimerDialog_OnMove() As Long
PrintL Timer, "Moving", CBWPARAM, CBLPARAM
End Function


'------------------------------------------------------------------------------
' cmdStart OnClick
'------------------------------------------------------------------------------
CallBack Function cmdStart_OnClick() As Long
PrintL Timer, "cmdStart_OnClick"


'---If start, than enable/disable relevant buttons and activate the timer
Control Disable CBHNDL, %IDC_Start
Control Enable CBHNDL, %IDC_Stop

TimerValue = 0 '---Set the time counter to zero
Dialog Set Timer CBHNDL, %IDC_TIMER, %TIMER_DELAY


End Function


'------------------------------------------------------------------------------
' cmdStop OnClick
'------------------------------------------------------------------------------
CallBack Function cmdStop_OnClick() As Long
PrintL Timer, "cmdStop_OnClick"


'---If sstop, than enable/disable relevant buttons and destroy the timer
Control Disable CBHNDL, %IDC_Stop
Control Enable CBHNDL, %IDC_Start
Dialog Kill Timer CBHNDL, %IDC_TIMER


End Function

ReneMiner
10-09-2013, 06:55
That looks good...and it was certainly very difficult to decide which way to go - I'm not sure how I would have decided - either Dialogname_Controlname_OnAction or the way above which is not just shorter name but also allows two dialogs with for example an Exit-button to get handled from same callback-function. Duplicate control/dialog names are possible - I hope? (we still got an "Index" in CBHNDL/CBCTL)

Petr Schreiber
10-09-2013, 12:08
I like it Eros,

it allows the user to define his own convention, if he wants dialog based prefix, he will bake it to string. Good, good, keep it coming please :)


Petr

maxer73
01-10-2013, 16:35
This is beautiful Eros, :o
I can finally use the functions for individual events and all of the controls as I did long ago with VB6, very good, I think that from now on I will always use this new syntax, but is there a way as Rene said, to differentiate the control of more than a single dialog?

ErosOlmi
03-10-2013, 22:47
Sure Max!

Next thinBasic 1.9.9.0 will have Button control improved with new syntax with 4 automatic callback events functions:


Button Automatic Event Callback Function added: <ButtonName>_OnSetFocus
Button Automatic Event Callback Function added: <ButtonName>_OnKillFocus
Button Automatic Event Callback Function added: <ButtonName>_OnDisable
Button Automatic Event Callback Function added: <ButtonName>_OnClick


Than I will change TextBox and .... others

Ciao
Eros

maxer73
03-10-2013, 23:12
Great work Eros !!! :D:D

please if you can, look also to the Visual Designer in future versions, I'm using it but I find so many bugs .... I, coming from VB6, I just can not do without this tool, and add many controls in manual mode, requires a large dispersion of time that could be done in 5 minutes with the help of a visual editor that works well. ..

I was even thinking of writing one from scratch, with the help of good Rene, but the task is very difficult and I think I can not because I'm beginning with TB

All other development environments have a visual designer working, even with editor for menu and messagebox

Ciao
Max

ReneMiner
14-06-2021, 07:19
what an interesting comment. Did you look at the date? You should read the thread where Maxer introduced the finished software a few years ago and maybe tell us if you like it - or what we could improve :)

Or are you just a bot, send to make few posts before starting the advertisements?

;--);--)