TinyDialog a simple Windows and Linux user interface.

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Post Reply
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

TinyDialog a simple Windows and Linux user interface.

Post by D.J.Peters »

Often you need some values from user you can learn big libs like wx, Gtk+, IUP or use a tiny solution.

For many tasks TinyDialog can be a very handy tool for you.
(you can use 50 controls per dialog)

ImageImage

Downloads:
Windows and Linux: TinyDialog.zip

If you use a fbgfx screen you can show any dialog via the right mouse button.

(i can post examples if something are unclear)

Joshy

list of all commands: (note: all params are optional and you can resize the dialog via mouse)

Code: Select all

#include once "TinyDialog.bi"
dim as TinyDialog dlg

dlg.addSeperator ["label text"]

id = dlg.addBoolean(["label text"],[0/1],["true text","false text"],["tooltip text"])

id = dlg.addInteger(["label text"],[iValue],["tooltip text"]) 
id = dlg.addIntegerMin(["label text"],[iValue],iMin,["tooltip text"]) 
id = dlg.addIntegerMinMax(["label text"],[iValue],iMin,iMax,["tooltip text"]) 
id = dlg.addIntegerMinMaxStep(["label text"],[iValue],iMin,iMax,iStep,["tooltip text"]) 

id = dlg.addReal(["label text"],[rValue],["tooltip text"]) 
id = dlg.addRealMin(["label text"],[rValue],rMin,["tooltip text"]) 
id = dlg.addRealMinMax(["label text"],[rValue],rMin,rMax,["tooltip text"]) 
id = dlg.addRealMinMaxStep(["label text"],[rValue],rMin,rMax,rStep,["tooltip text"]) 

id = dlg.addAngle(["label text"],[rValue],["tooltip text"]) 
id = dlg.addAngleMin(["label text"],[rValue],rMin,["tooltip text"]) 
id = dlg.addAngleMinMax(["label text"],[rValue],rMin,rMax,["tooltip text"]) 
id = dlg.addAngleMinMaxStep(["label text"],[rValue],rMin,rMax,rStep,["tooltip text"]) 

id = dlg.addString(["label text"],["text"],["tooltip text"])
id = dlg.addMultiLine(["label text"],["text"],["tooltip text"])

id = dlg.addOptions(["label text"],["item1|item2|..."],[selected],["tooltip text"])
id = dlg.addList(["label text"],["item1|item2|..."],[selected],["tooltip text"])

id = dlg.addLoadButton(["label text"],["filename"],["filter"],["start folder"],[iChangedir],[iOverwrite],["tooltip text"])
id = dlg.addSaveButton(["label text"],["filename"],["filter"],["start folder"],[iChangedir],[iOverwrite],["tooltip text"])
id = dlg.addDirButton(["label text"],["pathname"],["start folder"],[iChangedir],[iOverwrite],["tooltip text"])

id = dlg.addColorButton(["label text"],[uiColor],["tooltip text"])
id = dlg.addFontButton(["label text"],[FontName],["tooltip text"])

dlg.Title = "don't look at the bi file ;-)"

dlg.SetOKButtonText("txt")
dlg.SetCancelButtonText("txt") 

var result = dlg.Show()
var iValue = dlg.GetInteger(id)
var rValue = dlg.GetReal(id)
var sValue = dlg.GetString(id)
var uiValue = dlg.GetColor(id)
Last edited by D.J.Peters on Sep 25, 2017 16:31, edited 6 times in total.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: TinyDialog simple but usefull user interface.

Post by D.J.Peters »

Image
Last edited by D.J.Peters on Sep 25, 2017 16:32, edited 1 time in total.
paul22
Posts: 26
Joined: Feb 10, 2007 19:59
Location: Montreal

Re: TinyDialog simple but usefull user interface.

Post by paul22 »

Thank you for this;
I would love to use TinyDialog but I get the following errors with test01.bas.
I am using windows 7 ,Fbedit ,fbc version 23.

Thanks for your help;
Paul

C:\Program Files\freebasic\inc\TinyDialog.bi(106) error 175: Illegal member access, found 'b' in 'case ParamTypes.b,ParamTypes.i,ParamTypes.o,ParamTypes.l:return *cast(integer ptr,params[index])'

C:\Program Files\freebasic\inc\TinyDialog.bi(107) error 175: Illegal member access, found 'a' in 'case ParamTypes.a,ParamTypes.r:return int(*cast(single ptr,params[index]))'

C:\Program Files\freebasic\inc\TinyDialog.bi(113) error 175: Illegal member access, found 'b' in 'case ParamTypes.b,ParamTypes.i,ParamTypes.o,ParamTypes.l:return csng(*cast(integer ptr,params[index]))'

C:\Program Files\freebasic\inc\TinyDialog.bi(114) error 175: Illegal member access, found 'a' in 'case ParamTypes.a,ParamTypes.r:return *cast(single ptr,params[index])'

C:\Program Files\freebasic\inc\TinyDialog.bi(120) error 175: Illegal member access, found 'b' in 'case ParamTypes.b,ParamTypes.i,ParamTypes.o,ParamTypes.l:return str(*cast(integer ptr,params[index]))'

C:\Program Files\freebasic\inc\TinyDialog.bi(121) error 175: Illegal member access, found 'a' in 'case ParamTypes.a,ParamTypes.r:return str(*cast(single ptr,params[index]))'

C:\Program Files\freebasic\inc\TinyDialog.bi(122) error 175: Illegal member access, found 's' in 'case ParamTypes.s,ParamTypes.m,ParamTypes.c,ParamTypes.f:return *cast(zstring ptr,params[index])'

C:\Program Files\freebasic\inc\TinyDialog.bi(129) error 175: Illegal member access, found 'c' in 'if types[index]<>ParamTypes.c then return 0'

C:\Program Files\freebasic\inc\TinyDialog.bi(167) error 175: Illegal member access, found 'b' in 'case ParamTypes.b,ParamTypes.i ' boolean,integer'

C:\Program Files\freebasic\inc\TinyDialog.bi(168) error 175: Illegal member access, found 'b' in 'if t=ParamTypes.b then Items &= "%b" else Items &= "%i"'

C:\Program Files\freebasic\inc\TinyDialog.bi(168) error 123: Too many errors, exiting
phishguy
Posts: 1201
Joined: May 05, 2006 16:12
Location: West Richland, Wa

Re: TinyDialog simple but usefull user interface.

Post by phishguy »

I had the same problem. I was using Freebasic version 0.21.1. I upgraded to 0.24.0 and it compiles and runs OK.

However, I have a question regarding the Test01 example in the zip file. The font string isn't returned in the report for me. Why isn't it? I'm running on Windows 7 Pro - 64 bit.
paul22
Posts: 26
Joined: Feb 10, 2007 19:59
Location: Montreal

Re: TinyDialog simple but usefull user interface.

Post by paul22 »

Thanks;
I dowloaded version .24 and it works great.
Paul
Coolman
Posts: 294
Joined: Nov 05, 2010 15:09

Re: TinyDialog simple but usefull user interface.

Post by Coolman »

nice job but it would be possible to integrate static compile the dll has the executable ?
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: TinyDialog simple but usefull user interface.

Post by D.J.Peters »

phishguy wrote:The font string isn't returned in the report for me.
Thank you for testing.

In file TinyDialog.bi one enum "ParamTypes.n" was missed.

Joshy
Last edited by D.J.Peters on Dec 12, 2012 21:28, edited 2 times in total.
Kwabbernoot
Posts: 79
Joined: Apr 19, 2010 18:23
Location: NL

Re: TinyDialog simple but usefull user interface.

Post by Kwabbernoot »

Great !! Can you also make a ListBox? dlg.addlist is a ComboBox.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: TinyDialog simple but usefull user interface.

Post by D.J.Peters »

Kwabbernoot wrote:Great !! Can you also make a ListBox? dlg.addlist is a ComboBox.
No :-(
Primary the *.bi file is a wrapper to the none documented IupGetParamv() function.

for IupGetParam() (note no "v" in the name)

see here: http://www.tecgraf.puc-rio.br/iup/en/dl ... param.html

Joshy
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: TinyDialog simple but usefull user interface.

Post by D.J.Peters »

added:

dlg.SetOKButtonText("txt")

dlg.SetCancelButtonText("txt")

Joshy
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: TinyDialog simple but usefull user interface.

Post by D.J.Peters »

windows only:
Dialog without the *.bi file doit like a man :lol:

Looks easy like a format string of printf() but you must know the dialog self don't allocate any memory for editable params.
It's up to you to reserve needed space.

For example if you dim a string for a tring or [m]ultline control

dim as string s = "edit me"

If the user types more letters as you dim'ed the result will be a memory access error.
Same for all strings like filenames, path,color and fontnames.

The Tiny Dialog class from *.bi file will allocate and free the right space for you and keeps track of the right order of all param's,
but it's often good know whats going on under the hood.

Joshy

Code: Select all

declare function ShowDialog(title as zstring ptr,Items as zstring ptr, nItems as integer,nExtra as integer,pParams as any ptr) as integer
#inclib "TinyDialog"

dim as integer iValue = 123
dim as single  rValue = 1.23
dim as string  sValue = "edit me" + space(128)

dim as any ptr Params(...) = {@iValue,@rValue,strptr(sValue)}
dim as string Items = !"integer: %i\n" _
                      !"real: %r\n" _
                      !"sep.: %t\n" _
                      !"string: %s\n"
                      
' show dialog with 3 items and 1 seperator
if ShowDialog("without *.bi file!",Items, 3, 1, @params(0)) then
  print "iValue = " & iValue
  print "rValue = " & rValue
  print "sValue = " & sValue
end if
print "..."
sleep
You want more, you get it :-)

Code: Select all

declare function ShowDialog(title as zstring ptr,Items as zstring ptr, nItems as integer,nExtra as integer,pParams as any ptr) as integer
#inclib "TinyDialog"

' pointer of numbers
#define np(n) @##n
' pointer of strings
#define sp(s) strptr(s)

' [b]oolean 1 or 0
dim as integer b = 1
' [i]nteger  
dim as integer i = 123
' [r]eal 
dim as single  r = 3.14
' [s]tring
dim as string  s = "edit me" + space(128)
' [m]ultiline
dim as string  m = !"row 1\nrow 2\n" + space(128)
' [c]olor
dim as string  c = "255 0 0" + space(128)
' fo[n]t
dim as string  n = "Courier, 12" + space(128)
' [o]ptions (the selcted index)
dim as integer o = 2
' dropdown[l]ist (the selcted index)
dim as integer l = 1

' define some controls !"\n" is important label and {tooltip} are optonal
dim as string Items = !"label %b[on,off]{tooltip}\n" _
                      !"label %i{tooltip}\n" _
                      !"label %r{tooltip}\n" _
                      !"label %t\n" _
                      !"label %s{tooltip}\n" _
                      !"label %m{tooltip}\n" _
                      !"label %t\n" _
                      !"label %c{tooltip}\n" _
                      !"label %n{tooltip}\n" _
                      !"label %o[opt1|opt2|opt3]{tooltip}\n" _
                      !"label %l[item1|item2|item3]{tooltip}\n" _

' all addresses of the params must be in the same order of the defined controls
dim as any ptr Params(...) = {np(b),np(i),np(r),sp(s),sp(m),sp(c),sp(n),np(o),np(l)}

' show the dialog with some editable controls and 2 controls without a param (the seperator's)
if ShowDialog("simple",Items, ubound(Params)-1, 2, @Params(0)) then
  ? "b = " & b, "i = " & i, "r = " & r
  ? "s = " & s
  ? "m = " & m
  ? "c = " & c, "n = " & n
  ? "o = " & o, "l = " & l
end if
print "..."
sleep
Last edited by D.J.Peters on Jan 02, 2013 1:26, edited 1 time in total.
Dr_D
Posts: 2451
Joined: May 27, 2005 4:59
Contact:

Re: TinyDialog simple but usefull user interface.

Post by Dr_D »

Nice one. I remember using vb6 to make a stand alone settings dialogue because I was too busy(lazy) to implement a real one. :p
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: TinyDialog simple but usefull user interface.

Post by D.J.Peters »

added:
buildall.bat
TinyDialog.rc
TinyDialog.mainfest
(see first pictures)
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: TinyDialog a simple Windows user interface.

Post by D.J.Peters »

added:

id = dlg.addAngle(["label text"],[rValue],["tooltip text"])
id = dlg.addAngleMin(["label text"],[rValue],rMin,["tooltip text"])
id = dlg.addAngleMinMax(["label text"],[rValue],rMin,rMax,["tooltip text"])
id = dlg.addAngleMinMaxStep(["label text"],[rValue],rMin,rMax,rStep,["tooltip text"])

Image
Last edited by D.J.Peters on Sep 25, 2017 16:27, edited 1 time in total.
relsoft
Posts: 1767
Joined: May 27, 2005 10:34
Location: Philippines
Contact:

Re: TinyDialog a simple Windows user interface.

Post by relsoft »

Awesome!!!! I sure could use this! Bye2x VB6!
Post Reply