test-fltk.nut 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. function setAppFont(fontName)
  2. {
  3. local my_font, numfonts, font1, font2;
  4. numfonts=Fl.set_fonts();
  5. for(local i=0; i < numfonts; ++i)
  6. {
  7. my_font=Fl.get_font(i); // get the name of the current font
  8. if( my_font )
  9. {
  10. local font = Fl.get_font_name(i);
  11. //print(my_font_name, my_font_attr)
  12. if( font.name )
  13. {
  14. if( font.name.find(fontName) )
  15. {
  16. if( font.attributes != 0 )
  17. {
  18. if (( font.attributes & FL_BOLD) &&
  19. ( font.attributes & FL_ITALIC))
  20. {
  21. font1 = FL_HELVETICA_BOLD_ITALIC;
  22. font2 = FL_TIMES_BOLD_ITALIC;
  23. }
  24. else if( font.attributes & FL_BOLD )
  25. {
  26. font1 = FL_HELVETICA_BOLD;
  27. font2 = FL_TIMES_BOLD;
  28. }
  29. else if( font.attributes & FL_ITALIC )
  30. {
  31. font1 = FL_HELVETICA_ITALIC;
  32. font2 = FL_TIMES_ITALIC;
  33. }
  34. }
  35. else
  36. {
  37. font1 = FL_HELVETICA;
  38. font2 = FL_TIMES;
  39. }
  40. //print(bit.band(my_font_attr, FL_BOLD), my_font_attr, font1, font2)
  41. Fl.set_font(font1, i);
  42. Fl.set_font(font2, i);
  43. //break
  44. }
  45. }
  46. }
  47. }
  48. }
  49. function widget_focus_changing_Match(widget){
  50. if (widget){
  51. local ttype = widget.classId();
  52. print(ttype);
  53. if (ttype.find("_Input")) return 1;
  54. if (ttype.find("_Browser")) return 2;
  55. if (ttype.find("_Tree")) return false;
  56. if (ttype.find("_Editor")) return 3;
  57. local parent = widget.parent();
  58. if (parent && parent.classId().find("_Choice")){
  59. return 3;
  60. }
  61. }
  62. return false;
  63. }
  64. function fltk_focus_changing(wfrom, wto){
  65. //print(wfrom.classId(), wto.classId());
  66. //print(wfrom, wto);
  67. if (widget_focus_changing_Match(wfrom)){
  68. wfrom.color(FL_WHITE);
  69. wfrom.redraw();
  70. }
  71. local wt = widget_focus_changing_Match(wto);
  72. if (wt) {
  73. wto.color(FL_YELLOW);
  74. wto.redraw();
  75. //if (wt == 1) wto.position(0,10000);
  76. }
  77. return 0;
  78. }
  79. math.number_format_set_dec_point(",");
  80. math.number_format_set_thousand_sep(".");
  81. Fl_Input.default_number_format("\0x02,.");
  82. //Fl:scheme("plastic");
  83. Fl.scheme("gtk+");
  84. //use partial match to find verdana font
  85. Fl.visual(FL_RGB);
  86. //allow arrow keys navigation
  87. Fl.option(Fl.OPTION_ARROW_FOCUS, true);
  88. //setAppFont("erdana");
  89. Fl.add_focus_changing_handler(fltk_focus_changing);
  90. local myWindows = [];
  91. class MyWindow extends Fl_Window {
  92. constructor(px, py, pw, ph, pl){
  93. base.constructor(px, py, pw, ph, pl);
  94. }
  95. function hide(){
  96. print("Before base hide");
  97. base.hide();
  98. Fl.delete_widget(this);
  99. print("After base hide");
  100. }
  101. function on_close(){
  102. print("on_close");
  103. }
  104. }
  105. class MyInput extends Fl_Input {
  106. constructor(px, py, pw, ph, pl){
  107. base.constructor(px, py, pw, ph, pl);
  108. }
  109. function handle(event){
  110. local rc = base.handle(event);
  111. print("After base event", rc, event);
  112. return rc;
  113. }
  114. }
  115. local series = "Series";
  116. function _tr(str) {return str;}
  117. function MyNewWin(){
  118. //local win = Fl_Double_Window(100, 100, 200,400, "My FLTK Window");
  119. local win = new MyWindow(100, 100, 800,500, "My FLTK Window");
  120. //local win = Fl_Window(100, 100, 200,400, "My FLTK Window");
  121. /*
  122. win.callback(function(sender, uwin){
  123. print("mycb", sender, uwin);
  124. //myWindows.push(MyNewWin());
  125. //uwin.hide();
  126. }, win);
  127. */
  128. local btnNew = new Fl_Button(50,20, 80,25, "New Win");
  129. btnNew.callback(function(sender, udata){
  130. //print("mycb", sender, udata);
  131. myWindows.push(MyNewWin());
  132. Fl.add_timeout(1, @(p) print(p), "I'm timeout");
  133. }, "dad");
  134. local btnClose = Fl_Button(50,55, 80,25, "Close Win");
  135. btnClose.callback(function(sender, uwin){
  136. print("mycb", sender, uwin, sender.x());
  137. //myWindows.push(MyNewWin());
  138. uwin.hide();
  139. }, win);
  140. //local input = MyInput(50,85, 80,25, "Name");
  141. local input = Fl_Input(50,85, 80,25, "Name");
  142. local int_input = Fl_Int_Input(50,115, 80,25, "Age");
  143. int_input->color(FL_RED);
  144. //local box = Fl_Box(50,145, 80,25, "Img");
  145. //box.color(FL_RED);
  146. local editor = Fl_Text_Editor_Buffered(10,200, 180,100, "Notes");
  147. editor->value("Hello everybody here we are !");
  148. local btnText = Fl_Button(50,145, 80,25, "Text");
  149. btnText.callback(function(sender, uwin){
  150. print(input.value());
  151. });
  152. local tabs = Fl_Tabs(10,320, 180,40, "Tabs");
  153. local grp = Fl_Group(10,345, 180,20, "Tab1");
  154. grp.end()
  155. grp = Fl_Group(10,345, 180,20, "Tab2");
  156. grp.end()
  157. grp = Fl_Group(10,345, 180,20, "Tab3");
  158. grp.end()
  159. tabs.end();
  160. local o = Fl_Pack(5, 380, 790, 25);
  161. o.type(1);
  162. o.labelsize(16);
  163. o->spacing(5);
  164. o->with_label(1);
  165. {
  166. {
  167. local o = Fl_Input(55, 35, 45, 25, series);
  168. o.textsize(16);
  169. o.labelsize(16);
  170. }
  171. /*
  172. {
  173. local o = Fl_Int_Input(172, 35, 95, 25, _tr("Number"));
  174. o.textsize(16);
  175. o.labelsize(16);
  176. o->use_numeric_format(0);
  177. }
  178. {
  179. local o = Fl_Int_Input(319, 35, 95, 25, _tr("Entity"));
  180. o.textsize(16);
  181. o.labelsize(16);
  182. }
  183. {
  184. local o = Fl_Input(420, 35, 335, 25);
  185. o.textsize(16);
  186. //o.labeltype(FL_NO_LABEL);
  187. o.label("DAD");
  188. o.textfont(1);
  189. o.labelsize(16);
  190. o.tooltip(_tr("Type partal description to search on availlable entities"));
  191. //Fl_Group.current().resizable(o);
  192. }
  193. {
  194. local o = Fl_Button(765, 35, 30, 25, _tr("@<->"));
  195. o.labelcolor(22);
  196. o.labelsize(18);
  197. o.tooltip(_tr("Show entities search window"));
  198. }
  199. */
  200. }
  201. o.end();
  202. win->end();
  203. win->resizable(win);
  204. win->show_main();
  205. return win;
  206. }
  207. MyNewWin();
  208. //Fl.add_idle(@(p) print(p), "I'm idle !");
  209. Fl.run()