FLTK 1.3.x C Wrapper (obsolete)

User contributed sources that have become inactive, deprecated, or generally unusable. But ... we don't really want to throw them away either.
Post Reply
Lothar Schirm
Posts: 491
Joined: Sep 28, 2013 15:08
Location: Germany

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by Lothar Schirm »

Thank you for the lates version of FLTK!

To be honest: I am a little bit frustrated. In "Beginners" http://www.freebasic.net/forum/viewtopi ... =2&t=23186 there is a long discussion about GUI programming in FreeBasic, and RockTheSchock points out that GUI coding in FreeBasic is (or can be) very cryptical. I understand your code, but it looks very tricky to avoid global variable names in FLTK. I was also stumbling over the callback function of your example in the thread in "Beginners":

Code: Select all

#include once "fltk-c.bi"

sub InputCB cdecl (byval self as FL_WIDGET ptr,byval arg as any ptr)
  dim as Fl_Input ptr ptr in = arg
  dim as double a = val(*Fl_Input_GetValue(in[0]))
  dim as double b = val(*Fl_Input_GetValue(in[1]))
  Fl_Input_SetValue  in[2], str(a+b)
end sub
'
' main
'
var win  = Fl_WindowNew(250,100,"add")
dim as any ptr in(...) = {Fl_Float_InputNew(40, 10, 200, 20,"a"), _
                          Fl_Float_InputNew(40, 40, 200, 20,"b"), _
                          Fl_Float_InputNew(40, 70, 200, 20,"a+b=") }
Fl_WidgetSetCallbackArg in(0),@InputCB,@in(0)
Fl_WidgetSetCallbackArg in(1),@InputCB,@in(0)
Fl_Input_SetReadonly    in(2),1
Fl_WindowShow win
Fl_Run
"dim as Fl_Input ptr ptr in = arg": What does this mean? A pointer pointing to a pointer? What is a ptr ptr?

I cannot see in the moment how a complex GUI code with many different widget types can be written in a clearly readable way without using global variables. In this example, you can only pass widgets of the same type as argument to the callback function within an array, not widgets of different types. Using an array means that you cannot give individual names to these widgets, but you have to use indexes which makes the code more difficult to write and to read if you have a larger number of widgets.

In the other example above you can handle only three widgets in the callback function, using "byval self as Fl_Widget Ptr", "byval other as any ptr" and "Fl_WidgetSetUserData / Fl_WidgetGetUserData" (self and other - a very special trick!).

Is there a general and simple method to avoid global variables?
SARG
Posts: 1877
Joined: May 27, 2005 7:15
Location: FRANCE

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by SARG »

Hi,
"dim as Fl_Input ptr ptr in = arg": What does this mean? A pointer pointing to a pointer? What is a ptr ptr?
As in() is already a ptr when you use its adress '@in()' you obviously get a ptr ptr.

The use of same names 'in() and in' in the main proc and in the sub with different types (fl_XXX ptr and fl_XXXX ptr ptr) is misleading. But after in[] is used to access the in() array defined in the main proc.....

@D.J.
By the way I understand that using shared variables is not a good way.
But how doing a such thing :
Suppose you have 10 buttons activated or deactivated according to an other element.
When the element changes how modify (in a sub) the state of the buttons without keeping somewhere (shared variable) an information for accessing them ?
D.J.Peters
Posts: 8631
Joined: May 28, 2005 3:28
Contact:

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by D.J.Peters »

@Lothar if I personally think something are very easy that must not be true for beginners or new FreeBASIC users.
If an array of widget pointers as param are to difficult feel free and use shared vars.

@SARG Do you know how VB4,5,6 handled such things you are asked for ?

If not I try to bring some light in dargness.

pseudo code:

Code: Select all

dim as Form Me ' (hidden for the user)
sub Button1.Pressed
  Listbox4.caption = "pressed"
end sub

sub ScrollBar3.changed
  Form1.MyPictureBox.move 0,Me.ScrollBar3.value,100,100
end sub
The Form (Fl_Window) "Me" is an container of controls same as a FL_Group with Fl_Widgets in fltk-c

sometimes I write:
var Me = Fl_WidgetAsGroub(win)
or
var Me = Fl_Window(Fl_WidgetWindow(AnyWidget))
...

sub Button1.Pressed
end sub


in fltk-c is it: (cdecl)
sub ButtonCB(button1 as Fl_Widget)
end sub


"Listbox4" inside the Button1 event handler:

Code: Select all

sub Button1.Pressed
  Listbox4.caption = "pressed"
end sub
Looks like a global var on module level of Form1 for the user
but it isn't the GUI designer add hidden code for the compiler.

In real it is: (remember pseudo code)
Form1.Listbox4.caption = "The pirate says ahoy the captain says it's tea time."

or the User helps the compiler and the GUI designer does nothing.
Me.Listbox4.caption = "FB needs a real BOOL class for C++ GUI libs"
same as:
Form1.Listbox4.caption

Code: Select all

sub ScrollBar3.changed
  MyPictureBox.move 0,Me.ScrollBar3.value,100,100
end sub
Is Form1.MyPictureBox or Me.MyPictureBox

Normaly in FLTK C++ you can write:
MyWindow.MyGroup.MyButton.Label = "She say let me be your slave for free."

We could do it with an FLTK oop environment in FreeBASIC also.
(oop wrapper from c wrapper what a f...)

Without the oop.dotted.syntax we must give our widgets names or individual ID's to find any child widget inside of any callback.

I will give it a try if i'm back home.

Joshy
SARG
Posts: 1877
Joined: May 27, 2005 7:15
Location: FRANCE

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by SARG »

@D.J.

I never used VB. Sorry I don't understand and I was not clear....

In fbdebugger when there is not a running debuggee some buttons are deactivated. And when a debuggee is running the same buttons must be activated. And other ones are always activated. So I need to do something like that :

Code: Select all

sub activate_button(prunning as integer)
If prunning then
  activate(button1)
  activate(button3)
  activate(button7)
else
  deactivate(button1)
  deactivate(button3)
  deactivate(button7)
endif
end sub
I could use an array of these buttons and give its address as parameter. But the sub is called in nested subs so it's not "clean"passing the address from sub to sub.

I look forward to seeing your example :-)
D.J.Peters
Posts: 8631
Joined: May 28, 2005 3:28
Contact:

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by D.J.Peters »

SARG wrote:I never used VB.
A life without VB6 is possible but useless. :lol:

Here are two test of using all widgets and windows without global vars
test1: on Form callback and one widget callback for all widgets
test2: on Form callback and one widget callback per Form

I know a visual debuger is an app with many Windows so I would use a GUI design like in test2.

Note: in Form1.ShowForm2.Pressed you can use any window or any widget inside any callback.

And again my friends used global vars if it makes your life easier.

Joshy

Code: Select all

' file: No_Global_Vars01.bas
' test of one Event handler for all widgets

#include once "fltk-c.bi"

enum ' you can use any names here
  Form1
  Form1_Button1
  Form1_Button2
  Form1_ShowForm2
  Form2
  Form2_Input
  Form2_Button
  Form3
  Form3_Slider
  LastItem = Form3_Slider
end enum
type WidgetList as any ptr ptr

sub FormCB cdecl (byval self as Fl_Widget ptr)
  print *Fl_WidgetGetLabel(self) & ".Close"
  Fl_WidgetHide self
end sub

sub WidgetCB cdecl (byval self as Fl_Widget ptr,byval index as long)
  var Me = Fl_WidgetWindow(self)
  dim as WidgetList List = Fl_WidgetGetUserdata(Me)
  print *Fl_WidgetGetLabel(Me) & ".";
  select case as const index
  case Form1_Button1     : print "Button" & index & ".Pressed"
  case Form1_Button2     : print "Button" & index & ".Pressed"
  case Form1_ShowForm2   : print "ShowForm2.Pressed" : Fl_WindowShow List[Form2]
  case Form2_Input       : print "Input.Changed"
  case Form2_Button      : print "Button.Pressed" : Fl_WidgetHide(Me)
  case Form3_Slider      : print "Slider.Changed"
  end select
end sub
'
' main
'
dim as WidgetList List(LastItem)
Fl_SetScheme "gleam"
List(Form1)           = Fl_WindowNew2(300,100,320,200,"Form1")
List(Form1_Button1)   = Fl_ButtonNew ( 10, 10,100, 24,"Button1")
List(Form1_Button2)   = Fl_ButtonNew ( 10, 40,100, 24,"Button2")
List(Form1_ShowForm2) = Fl_ButtonNew ( 10, 70,100, 24,"show Form2")

List(Form2)           = Fl_WindowNew (320,200,"Form2")
List(Form2_Input)     = Fl_InputNew  (100, 10,100, 24,"input:")
List(Form2_Button)    = Fl_ButtonNew ( 10, 40,100, 24,"close me")

List(Form3)           = Fl_WindowNew (320,200,"Form3")
List(Form3_Slider)    = Fl_SliderNew ( 10, 10, 24,100,"slider:")

for index as integer = 0 to LastItem
  var item=List(index)
  if Fl_WidgetAsWindow(item) then ' it's a Form
    Fl_WidgetSetCallback0 item,@FormCB
    Fl_WidgetSetUserdata  item,@List(0)
  else ' its a Widget
    Fl_WidgetSetCallback1Arg item,@WidgetCB,index
  end if
next
Fl_WindowShow List(Form1)
Fl_WindowShow List(Form3)
Fl_Run
test2: one callback per window

Code: Select all

' file: No_Global_Vars02.bas
' test of one Event handler per window

#include once "fltk-c.bi"

enum ' you can use any names here
  Form1
  Form1_Button1
  Form1_Button2
  Form1_ShowForm2
  Form2
  Form2_Input
  Form2_Button
  Form3
  Form3_Slider
  LastItem = Form3_Slider
end enum
type WidgetList as any ptr ptr

sub FormCB cdecl (byval self as Fl_Widget ptr)
  print *Fl_WidgetGetLabel(self) & ".Close"
  Fl_WidgetHide self
end sub

sub Form1EventHandler cdecl (byval self as Fl_Widget ptr,byval index as long)
  dim as WidgetList List = Fl_WidgetGetUserdata(Fl_WidgetWindow(self))
  select case as const index
  case Form1_Button1     : print "Form1.Button" & index & ".Pressed"
  case Form1_Button2     : print "Form1.Button" & index & ".Pressed"
  case Form1_ShowForm2   : print "Form1.ShowForm2.Pressed" : Fl_WindowShow List[Form2]
  end select
end sub

sub Form2EventHandler cdecl (byval self as Fl_Widget ptr,byval index as long)
  select case as const index
  case Form2_Input       : print "Form2.Input.Changed" 
  case Form2_Button      : print "Form2.Button.Pressed" : Fl_WidgetHide(Fl_WidgetWindow(self))
  end select
end sub

sub Form3EventHandler cdecl (byval self as Fl_Widget ptr,byval index as long)
  select case as const index
  case Form3_Slider      : print "Form3.Slider.Changed " & int(Fl_ValuatorGetValue(*self)*100)
  end select
end sub

'
' main
'
dim as WidgetList List(LastItem)
Fl_SetScheme "gleam"
List(Form1)           = Fl_WindowNew2(300,100,320,200,"Form1")
List(Form1_Button1)   = Fl_ButtonNew ( 10, 10,100, 24,"Button1")
List(Form1_Button2)   = Fl_ButtonNew ( 10, 40,100, 24,"Button2")
List(Form1_ShowForm2) = Fl_ButtonNew ( 10, 70,100, 24,"show Form2")

List(Form2)           = Fl_WindowNew (320,200,"Form2")
List(Form2_Input)     = Fl_InputNew  (100, 10,100, 24,"input:")
List(Form2_Button)    = Fl_ButtonNew ( 10, 40,100, 24,"close me")

List(Form3)           = Fl_WindowNew (320,200,"Form3")
List(Form3_Slider)    = Fl_SliderNew ( 10, 10, 24,100,"slider:")

for index as integer = 0 to LastItem
  var item = List(index)
  if Fl_WidgetAsWindow(List(index)) then ' it's a Form
    Fl_WidgetSetCallback0 item,@FormCB
    Fl_WidgetSetUserdata  item,@List(0)
  else ' its a Widget
    select case Fl_WidgetWindow(item)
    case List(Form1) :Fl_WidgetSetCallback1Arg item,@Form1EventHandler,index
    case List(Form2) :Fl_WidgetSetCallback1Arg item,@Form2EventHandler,index
    case List(Form3) :Fl_WidgetSetCallback1Arg item,@Form3EventHandler,index
    end select
  end if
next
Fl_WindowShow List(Form1)
Fl_WindowShow List(Form3)
Fl_Run
Last edited by D.J.Peters on Jan 08, 2015 2:06, edited 2 times in total.
Boris the Old
Posts: 139
Joined: Feb 04, 2011 20:34
Location: Ontario, Canada

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by Boris the Old »

SARG wrote:I could use an array of these buttons and give its address as parameter. But the sub is called in nested subs so it's not "clean"passing the address from sub to sub.
Our largest application has 500k lines of code and about 2000 widgets. The only practical way to avoid the issues that you're having is to write very modular code. We use a combination of classes and namespaces to simplify the problem.

We have excapsulated FLTK widgets in our own classes. This allows us to perform many different functions on a single widget, and not have to worry about passing widget pointers.

We use namespaces to modularize our main code. Each widget group is encapsulated in a namespace. For example, each tab panel on a tabbed window has its own namespace. The various widgets on a panel are, in effect, global to all the code in the namespace. There is no need to pass any widget pointers.

Our non-GUI code, such as report writing, file handling, etc, is also modularized using namespaces.

We spent several months figuring out how to get around the same sort of issues that you've been having. The above solutions are what worked for us. But these sort of techniques only work if you spend a lot of time planning the structure of your applications.

Rod
D.J.Peters
Posts: 8631
Joined: May 28, 2005 3:28
Contact:

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by D.J.Peters »

@SARG I forgot your challenge.

Here are how I would do it.

Joshy

Code: Select all

sub activate_button(self as Fl_Widget ptr, running as long)
  dim as WidgetList List = Fl_WidgetGetUserdata(Fl_WidgetWindow(self))
  If running then
    Fl_WidgetActivate(List[button1])
    Fl_WidgetActivate(List[button3])
    Fl_WidgetActivate(List[button7])
  else
    Fl_WidgetDeactivate(List[button1])
    Fl_WidgetDeactivate(List[button3])
    Fl_WidgetDeactivate(List[button7])
  end if
end sub
or if all buttons have the same parent

Code: Select all

sub activate_button(win as Fl_Window ptr, running as long)
  dim as WidgetList List = Fl_WidgetGetUserdata(win)
  If running then
    Fl_WidgetActivate(List[button1])
    Fl_WidgetActivate(List[button3])
    Fl_WidgetActivate(List[button7])
  else
    Fl_WidgetDeactivate(List[button1])
    Fl_WidgetDeactivate(List[button3])
    Fl_WidgetDeactivate(List[button7])
  end if
end sub
or you put widgets in a group and iterate it's childs for De/Activation

Or you makes that a day becomes 32 hours and I write in my new free time a perfect FLTK-C GUI designer for us.
ike
Posts: 387
Joined: Jan 17, 2011 18:59

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by ike »

Rod,

Can you make a simple sample: encapsulation using namespaces
Thx

Ike
D.J.Peters
Posts: 8631
Joined: May 28, 2005 3:28
Contact:

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by D.J.Peters »

Last but not least only one global var makes all callbacks cleaner to read.

By the way the fltk 1.3.3 c wrapper are more than 12,000 hand written lines of codes.
(the comments in the *.bi file not counted "copy and paste")

Joshy

Code: Select all

' file: OneGlobalVar.bas
' test of one global var only

#include once "fltk-c.bi"

#define Fl_IndexCallback(w,c,i) Fl_WidgetSetCallback1Arg w,c,i

enum MyFunkyGUI
  Form1, Button1, Button2, ShowForm2, ShowForm3,
  Form2, Input1,
  Form3, Slider1,
  LastItem = Slider1
end enum
dim shared as any ptr ptr gList(LastItem)

sub Form1CB cdecl (byval self as Fl_Widget ptr,byval index as long)
  select case as const index
  case Form1     : print "Form1.Close"
    Fl_WidgetHide self
  case Button1   : print "Form1.Button1.Pressed"
  case Button2   : print "Form1.Button2.Pressed"
  case ShowForm2 : print "Form1.ShowForm2.Pressed" 
    Fl_WindowShow gList(Form2)
  case ShowForm3 : print "Form1.ShowForm3.Pressed"
    Fl_WindowShow gList(Form3)
  end select
end sub

sub Form2CB cdecl (byval self as Fl_Widget ptr,byval index as long)
  select case as const index
  case Form2     : print "Form2.Close"
    Fl_WidgetHide self
  case Input1    : print "Form2.Input1.Changed ";
   print *Fl_Input_GetValue(gList(Input1))
  end select
end sub

sub Form3CB cdecl (byval self as Fl_Widget ptr,byval index as long)
  select case as const index
  case Form3     : print "Form3.Close"
    Fl_WidgetHide self
  case Slider1   : print "Form3.Slider1.Changed ";
    print int(Fl_ValuatorGetValue(gList(Slider1))*100)
  end select
end sub

'
' main
'
Fl_SetScheme "gleam"
gList(Form1)     = Fl_WindowNew2(300,100,320,200,"Form1")
gList(Button1)   = Fl_ButtonNew ( 10, 10,100, 24,"Button1")
gList(Button2)   = Fl_ButtonNew ( 10, 40,100, 24,"Button2")
gList(ShowForm2) = Fl_ButtonNew ( 10, 70,100, 24,"show Form2")
gList(ShowForm3) = Fl_ButtonNew ( 10,100,100, 24,"show Form3")

gList(Form2)     = Fl_WindowNew(320,200,"Form2")
gList(Input1)    = Fl_Multiline_InputNew(10,10,300,180)
Fl_Input_SetValue gList(Input1),!"type some text here.\n"
Fl_WidgetSetWhen  gList(Input1),FL_WHEN_CHANGED

gList(Form3)     = Fl_WindowNew (320,200,"Form3")
gList(Slider1)   = Fl_SliderNew ( 10, 10, 24,100,"slider:")

for index as integer = 0 to LastItem
  var item = gList(index)
  select case index
  case Form1 : Fl_IndexCallback(item,@Form1CB,index)
  case Form2 : Fl_IndexCallback(item,@Form2CB,index)
  case Form3 : Fl_IndexCallback(item,@Form3CB,index)
  case else 
    select case Fl_WidgetWindow(item)
    case gList(Form1) : Fl_IndexCallback(item,@Form1CB,index)
    case gList(Form2) : Fl_IndexCallback(item,@Form2CB,index)
    case gList(Form3) : Fl_IndexCallback(item,@Form3CB,index)
    end select
  end select
next

Fl_WindowShow gList(Form1)
Fl_Run
ike
Posts: 387
Joined: Jan 17, 2011 18:59

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by ike »

more than 12,000 hand written lines of code
DJ thank you for great work you have done. FLTK wrapper is very good tools.

Maybe, a little bit fine tuning, like your previous post and that is it: best gui 4 FB
D.J.Peters
Posts: 8631
Joined: May 28, 2005 3:28
Contact:

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by D.J.Peters »

Stupid pocket calculator from 1$ store but hey it's resizable. :-)

Joshy
[img]file="Fl_Menu_AddImageLabel.bas"/libs/fltk-c/onedollar.png[/img]

Code: Select all

#include once "fltk-c.bi"

const GAP =  8
const ITM = 48

enum
  Me,Disp,
  Btn0,Btn1,Btn2,Btn3,Btn4,Btn5,Btn6,Btn7,Btn8,Btn9
  BtnAdd,BtnSub,BtnDel,BtnAc,BtnMul,BtnDiv,BtnDot,BtnRes
  LastItem = BtnRes
end enum
dim shared as any ptr ptr gList(LastItem)


sub ButtonCB cdecl (byval self as Fl_Widget ptr,byval index as long)
  static as double     a=0.0
  static as string * 1 o=""
  static as integer    c=0

  select case as const index
  case Me : Fl_WidgetHide gList(Me)
  case BtnDel
    a=0.0:o="":Fl_Input_SetValue gList(Disp),""
  case BtnAc
    Fl_Input_SetValue gList(Disp),""
  case Btn0 to Btn9
    dim as string s 
    if c=0 then s=*Fl_Input_GetValue(gList(Disp)) else c=0
    s &= *Fl_WidgetGetLabel(self)
    Fl_Input_SetValue gList(Disp),s
  case BtnDot
    dim as string s=*Fl_Input_GetValue(gList(Disp))
    If instr(s,".") then return 
    Fl_Input_SetValue gList(Disp),s & "."
  case BtnAdd,BtnSub,BtnMul,BtnDiv
    a=val(*Fl_Input_GetValue(gList(Disp)))
    o=*Fl_WidgetGetLabel(self)
    c=1
  case BtnRes
    dim as double r,b=val(*Fl_Input_GetValue(gList(Disp)))
    if len(o) then
      select case o
      case "+" : r=a+b
      case "-" : r=a-b
      case "*" : r=a*b
      case "/"
       if b<>0.0 then r=a/b else r=0
      end select
      Fl_Input_SetValue gList(Disp),str(r)
      c=1:o=""
    end if
  end select
end sub

'
' main
'
Fl_SetScheme "gleam"
gList(Me)     = Fl_Double_WindowNew (6*GAP+5*ITM,6*GAP+5*ITM,"1$ calculator")

gList(Disp)   = Fl_Float_InputNew(1*GAP+0*ITM,1*GAP+0*ITM,4*GAP+5*ITM,1*ITM)

gList(Btn7)   = Fl_ButtonNew(1*GAP+0*ITM,2*GAP+1*ITM,ITM,ITM,"7")
gList(Btn4)   = Fl_ButtonNew(1*GAP+0*ITM,3*GAP+2*ITM,ITM,ITM,"4")
gList(Btn1)   = Fl_ButtonNew(1*GAP+0*ITM,4*GAP+3*ITM,ITM,ITM,"1")
gList(Btn0)   = Fl_ButtonNew(1*GAP+0*ITM,5*GAP+4*ITM,ITM,ITM,"0")

gList(Btn8)   = Fl_ButtonNew(2*GAP+1*ITM,2*GAP+1*ITM,ITM,ITM,"8")
gList(Btn5)   = Fl_ButtonNew(2*GAP+1*ITM,3*GAP+2*ITM,ITM,ITM,"5")
gList(Btn2)   = Fl_ButtonNew(2*GAP+1*ITM,4*GAP+3*ITM,ITM,ITM,"2")
gList(BtnDot) = Fl_ButtonNew(2*GAP+1*ITM,5*GAP+4*ITM,ITM,ITM,".")

gList(Btn9)   = Fl_ButtonNew(3*GAP+2*ITM,2*GAP+1*ITM,ITM,ITM,"9")
gList(Btn6)   = Fl_ButtonNew(3*GAP+2*ITM,3*GAP+2*ITM,ITM,ITM,"6")
gList(Btn3)   = Fl_ButtonNew(3*GAP+2*ITM,4*GAP+3*ITM,ITM,ITM,"3")
gList(BtnRes) = Fl_ButtonNew(3*GAP+2*ITM,5*GAP+4*ITM,ITM,ITM,"=")

gList(BtnDel) = Fl_ButtonNew(4*GAP+3*ITM,2*GAP+1*ITM,ITM,ITM,"del")
gList(BtnMul) = Fl_ButtonNew(4*GAP+3*ITM,3*GAP+2*ITM,ITM,ITM,"*")
gList(BtnAdd) = Fl_ButtonNew(4*GAP+3*ITM,4*GAP+3*ITM,ITM,ITM,"+")

gList(BtnAc ) = Fl_ButtonNew(5*GAP+4*ITM,2*GAP+1*ITM,ITM,ITM,"ac")
gList(BtnDiv) = Fl_ButtonNew(5*GAP+4*ITM,3*GAP+2*ITM,ITM,ITM,"/")
gList(BtnSub) = Fl_ButtonNew(5*GAP+4*ITM,4*GAP+3*ITM,ITM,ITM,"-")

for index as integer = 0 to LastItem
  Fl_WidgetSetLabelSize gList(index),ITM/7*5
  Fl_WidgetSetCallback1Arg gList(index),@ButtonCB,index
next
Fl_Input_SetTextSize gList(Disp),ITM/7*5
Fl_WindowSizeRange   gList(Me),Fl_WidgetGetW(gList(Me)),Fl_WidgetGetH(gList(Me))
Fl_GroupSetResizable gList(Me),gList(Me)
Fl_WindowShow        gList(Me)
Fl_Run
Last edited by D.J.Peters on Oct 03, 2017 4:18, edited 1 time in total.
srvaldez
Posts: 3612
Joined: Sep 25, 2005 21:54

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by srvaldez »

hello D.J.Peters
nice example but I can't figure out how it works, I noticed that you can enter numbers either by clicking on the number buttons or hitting the number on the keyboard but it won't accept operators entered from the keyboard and was going to add that functionality, but where in the code do you intercept the keyboard?
also if you enter a number from the keyboard and then try to enter a number by clicking the buttons it won't work until you click in the display area.
D.J.Peters
Posts: 8631
Joined: May 28, 2005 3:28
Contact:

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by D.J.Peters »

@srvaldez I wrote it in 5 minutes and it's a simple Fl_Float_Input widget test.
It's only for numbers you can't type a math operator in this kind of widget.

But you can add it self.

Replace the Fl_Float_Input with a Fl_Input widget.

The problems are:
If you click on any Fl_Button widget your "new" Fl_Input Widget gives the input focus to the the last pressed Button.

Inside the callback you must set back the focus to the Fl_Input widget via Fl_SetFocus gList(Disp).

If you don't get it ask.

Joshy
Last edited by D.J.Peters on Jan 08, 2015 10:52, edited 1 time in total.
Lothar Schirm
Posts: 491
Joined: Sep 28, 2013 15:08
Location: Germany

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by Lothar Schirm »

Ups! A lot of stuff! But thank you all, I think my answer how to pass different types of widgets to a callback function is answered very clearly by D.J. Peters. Nice and simple examples by ike in http://www.freebasic.net/forum/viewtopi ... 6&start=15!
SARG
Posts: 1877
Joined: May 27, 2005 7:15
Location: FRANCE

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by SARG »

D.J.Peters wrote:
SARG wrote:SARG wrote:I never used VB.
A life without VB6 is possible but useless. :lol:
A french advertising agent said if 50 years old and no Rolex your life is failed so no Rolex and no VB......
D.J.Peters wrote:Or you makes that a day becomes 32 hours and I write in my new free time a perfect FLTK-C GUI designer for us.
If I had this power I would have used on myself and we already got a 3D debugger for win/lin 32/64 :-)

About my question I was already using your way : an enum list and an array of widget ptr.
I can't use "user data" associated to a widget as the modifying of state is not triggered by a widget.
By the way I like the "lastitem trick" to define the upper bound of the array.

Anyway, thanks to all for your advices.

Now a new problem : how get a contextual menu (right click) on a tree contained in a tab ? I have associated the fl_menu_button with the tree or the tab without any effect, no popup menu. There is no handlecb for tree to handle fl_event and I hope I don't need to subclass the fl_tree.
Post Reply