newt-freebasic header

Headers, Bindings, Libraries for use with FreeBASIC, Please include example of use to help ensure they are tested and usable.
angros47
Posts: 2331
Joined: Jun 21, 2005 19:04

Re: newt-freebasic header

Post by angros47 »

According to this tutorial: https://userswww.pd.infn.it/~saccarol/tutorial.html
newt does not use an event-driven architecture.
....
This means that newt applications look dramatically different from programs written for event-driven architectures such as Motif, gtk, or even Borland's old TurboVision libraries. When you're designing your newt program, keep this differentiation in mind. As long as you plan your application to call a function to get input and then continue (rather then having your program called when input is ready), programming with the newt libraries should be simple.
So, you should not use callbacks (they are there only for very specific uses). You should just use the value returned after you called a form, like:

Code: Select all

#Ifndef NULL
  #Define NULL 0
#Endif

#inclib "newt"
#include "newt.bi"

    dim form as newtComponent
    dim b1 as newtComponent
    dim b2 as newtComponent
    dim p as newtComponent

	sub fCallback()
		newtCls()
		newtDrawRootText(0, 0, strptr("I am in callback!"))
		newtRefresh()
	end sub

    
    newtInit()
    newtCls()

    newtOpenWindow(10, 5, 40, 6, "Button Sample")

    b1 = newtButton(10, 1, "Ok")

    b2 = newtCompactButton(22, 2, "Cancel")
    form = newtForm(NULL, NULL, 0)
    newtFormAddComponents(form, b1, b2, NULL)


    p=newtRunForm(form)
	if p=b1 then fCallback()
	sleep
    newtFormDestroy(form)
    newtFinished()
It's less versatile, but much simpler
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Re: newt-freebasic header

Post by demosthenesk »

angros47 wrote: Oct 06, 2022 17:49 According to this tutorial: https://userswww.pd.infn.it/~saccarol/tutorial.html
newt does not use an event-driven architecture.
....
This means that newt applications look dramatically different from programs written for event-driven architectures such as Motif, gtk, or even Borland's old TurboVision libraries. When you're designing your newt program, keep this differentiation in mind. As long as you plan your application to call a function to get input and then continue (rather then having your program called when input is ready), programming with the newt libraries should be simple.
So, you should not use callbacks (they are there only for very specific uses). You should just use the value returned after you called a form, like:

Code: Select all

#Ifndef NULL
  #Define NULL 0
#Endif

#inclib "newt"
#include "newt.bi"

    dim form as newtComponent
    dim b1 as newtComponent
    dim b2 as newtComponent
    dim p as newtComponent

	sub fCallback()
		newtCls()
		newtDrawRootText(0, 0, strptr("I am in callback!"))
		newtRefresh()
	end sub

    
    newtInit()
    newtCls()

    newtOpenWindow(10, 5, 40, 6, "Button Sample")

    b1 = newtButton(10, 1, "Ok")

    b2 = newtCompactButton(22, 2, "Cancel")
    form = newtForm(NULL, NULL, 0)
    newtFormAddComponents(form, b1, b2, NULL)


    p=newtRunForm(form)
	if p=b1 then fCallback()
	sleep
    newtFormDestroy(form)
    newtFinished()
It's less versatile, but much simpler
Thank you angros47 !
Another newt example was added by you in the project!
https://github.com/demosthenesk/newt-freebasic
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Re: newt-freebasic header

Post by demosthenesk »

angros47 wrote: Oct 06, 2022 17:49 According to this tutorial: https://userswww.pd.infn.it/~saccarol/tutorial.html
newt does not use an event-driven architecture.
....
So, you should not use callbacks (they are there only for very specific uses).
Anybody can understand the use of newtComponentAddCallback() ?

from newt.bi

Code: Select all

declare sub newtComponentAddCallback(byval co as newtComponent, byval f as newtCallback, byval data as any ptr)
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Re: newt-freebasic header

Post by demosthenesk »

i found a man page about newt Perl bindings.
it would be a useful help for learning newt
https://linux.die.net/man/3/newt
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Re: newt-freebasic header

Post by demosthenesk »

Help docs for newt-freebasic are finished.
https://github.com/demosthenesk/newt-freebasic
8)
Post Reply