Browse Source

FLUID: Adds template for tutorial.

Tutorial still to be written.
Also adds convenience methods to Fl_Input_
for getting and setting numeric values.
pull/833/head
Matthias Melcher 2 years ago
parent
commit
d7768b76d0
  1. 10
      FL/Fl_Input_.H
  2. 24
      fluid/template_panel.cxx
  3. 30
      fluid/template_panel.fl
  4. 2
      fluid/widget_panel.cxx
  5. 8
      fluid/widget_panel.fl
  6. 48
      src/Fl_Input_.cxx

10
FL/Fl_Input_.H

@ -238,6 +238,12 @@ public:
/* Changes the widget text. */ /* Changes the widget text. */
int value(const char*, int); int value(const char*, int);
/* Changes the widget text. */
int value(int value);
/* Changes the widget text. */
int value(double value);
/* Changes the widget text. */ /* Changes the widget text. */
int static_value(const char*); int static_value(const char*);
@ -256,6 +262,10 @@ public:
*/ */
const char* value() const {return value_;} const char* value() const {return value_;}
int ivalue() const;
int dvalue() const;
/* Returns the Unicode character at index \p i. */ /* Returns the Unicode character at index \p i. */
unsigned int index(int i) const; unsigned int index(int i) const;

24
fluid/template_panel.cxx

@ -140,9 +140,9 @@ Fl_Double_Window* make_template_panel() {
template_browser->align(Fl_Align(FL_ALIGN_TOP_LEFT)); template_browser->align(Fl_Align(FL_ALIGN_TOP_LEFT));
template_browser->when(FL_WHEN_CHANGED | FL_WHEN_NOT_CHANGED); template_browser->when(FL_WHEN_CHANGED | FL_WHEN_NOT_CHANGED);
} // Fl_Browser* template_browser } // Fl_Browser* template_browser
{ template_preview = new Fl_Box(200, 28, 250, 250); { template_preview = new Fl_Box(200, 28, 250, 250, "no preview...");
template_preview->box(FL_THIN_DOWN_BOX); template_preview->box(FL_THIN_DOWN_BOX);
template_preview->align(Fl_Align(69|FL_ALIGN_INSIDE)); template_preview->align(Fl_Align(FL_ALIGN_CLIP|FL_ALIGN_INSIDE));
Fl_Group::current()->resizable(template_preview); Fl_Group::current()->resizable(template_preview);
} // Fl_Box* template_preview } // Fl_Box* template_preview
{ template_name = new Fl_Input(198, 288, 252, 25, "Template Name:"); { template_name = new Fl_Input(198, 288, 252, 25, "Template Name:");
@ -221,7 +221,7 @@ void template_load() {
int sample_templates_generated = 0; int sample_templates_generated = 0;
fluid_prefs.get("sample_templates_generated", sample_templates_generated, 0); fluid_prefs.get("sample_templates_generated", sample_templates_generated, 0);
if (!sample_templates_generated) { if (sample_templates_generated < 2) {
strcpy(filename, path); strcpy(filename, path);
strcat(filename, "/FLTK_License.fl"); strcat(filename, "/FLTK_License.fl");
FILE *f = fopen(filename, "wb"); FILE *f = fopen(filename, "wb");
@ -237,7 +237,23 @@ void template_load() {
"er\n}\n", f); "er\n}\n", f);
fclose(f); fclose(f);
} }
sample_templates_generated = 1; strcpy(filename, path);
strcat(filename, "/1of7GUIs.fl");
f = fopen(filename, "wb");
if (f) {
fputs(
"# data file for the Fltk User Interface Designer (fluid)\n version 1.0400\n header_name {.h}\n"
"code_name {.cxx}\n comment {\n1 of 7GUIs\n\n7GUIs was been created as a spin-off of the master’s\n"
"thesis Comparison of Object-Oriented and Functional\nProgramming for GUI Development by Eugen Kiss at the\n"
"Human-Computer Interaction group of the Leibniz\nUniversität Hannover in 2014.\n\n"
"https://7guis.github.io/7guis/\n} {selected in_source not_in_header\n}\n\nFunction {} {open\n"
"} {\nFl_Window {} {\nlabel Counter open\nxywh {486 292 194 55} type Double resizable visible\n"
"} {\nFl_Output counter_widget {\nxywh {15 15 80 22}\ncode0 {counter_widget->value(0);}\n"
"}\nFl_Button {} {\nlabel Count\ncallback {int i = counter_widget->ivalue();\ni++;\n"
"counter_widget->value(i);}\nxywh {99 15 80 22}\n}\n}\n}\n", f);
fclose(f);
}
sample_templates_generated = 2;
fluid_prefs.set("sample_templates_generated", sample_templates_generated); fluid_prefs.set("sample_templates_generated", sample_templates_generated);
fluid_prefs.flush(); fluid_prefs.flush();
} }

30
fluid/template_panel.fl

@ -68,7 +68,7 @@ template_preview->image(0);
template_browser->deselect(); template_browser->deselect();
template_name->value(""); template_name->value("");
template_instance->value(""); template_instance->value("");
template_panel->hide();} template_panel->hide();} open
xywh {478 284 460 355} type Double resizable modal visible xywh {478 284 460 355} type Double resizable modal visible
} { } {
Fl_Browser template_browser { Fl_Browser template_browser {
@ -120,7 +120,8 @@ if (img) {
xywh {10 28 180 250} type Hold labelfont 1 align 5 when 3 xywh {10 28 180 250} type Hold labelfont 1 align 5 when 3
} }
Fl_Box template_preview { Fl_Box template_preview {
xywh {200 28 250 250} box THIN_DOWN_BOX align 85 resizable label {no preview...} selected
xywh {200 28 250 250} box THIN_DOWN_BOX align 80 resizable
} }
Fl_Input template_name { Fl_Input template_name {
label {Template Name:} label {Template Name:}
@ -134,7 +135,7 @@ if (img) {
label {Instance Name:} label {Instance Name:}
xywh {198 288 252 25} labelfont 1 textfont 4 hide xywh {198 288 252 25} labelfont 1 textfont 4 hide
} }
Fl_Group {} { Fl_Group {} {open
xywh {10 323 440 25} xywh {10 323 440 25}
} { } {
Fl_Button template_delete { Fl_Button template_delete {
@ -217,7 +218,7 @@ strlcat(path, "templates", sizeof(path));
int sample_templates_generated = 0; int sample_templates_generated = 0;
fluid_prefs.get("sample_templates_generated", sample_templates_generated, 0); fluid_prefs.get("sample_templates_generated", sample_templates_generated, 0);
if (!sample_templates_generated) { if (sample_templates_generated < 2) {
strcpy(filename, path); strcpy(filename, path);
strcat(filename, "/FLTK_License.fl"); strcat(filename, "/FLTK_License.fl");
FILE *f = fopen(filename, "wb"); FILE *f = fopen(filename, "wb");
@ -233,7 +234,23 @@ if (!sample_templates_generated) {
"er\\n}\\n", f); "er\\n}\\n", f);
fclose(f); fclose(f);
} }
sample_templates_generated = 1; strcpy(filename, path);
strcat(filename, "/1of7GUIs.fl");
f = fopen(filename, "wb");
if (f) {
fputs(
"\# data file for the Fltk User Interface Designer (fluid)\\n version 1.0400\\n header_name {.h}\\n"
"code_name {.cxx}\\n comment {\\n1 of 7GUIs\\n\\n7GUIs was been created as a spin-off of the master’s\\n"
"thesis Comparison of Object-Oriented and Functional\\nProgramming for GUI Development by Eugen Kiss at the\\n"
"Human-Computer Interaction group of the Leibniz\\nUniversität Hannover in 2014.\\n\\n"
"https://7guis.github.io/7guis/\\n} {selected in_source not_in_header\\n}\\n\\nFunction {} {open\\n"
"} {\\nFl_Window {} {\\nlabel Counter open\\nxywh {486 292 194 55} type Double resizable visible\\n"
"} {\\nFl_Output counter_widget {\\nxywh {15 15 80 22}\\ncode0 {counter_widget->value(0);}\\n"
"}\\nFl_Button {} {\\nlabel Count\\ncallback {int i = counter_widget->ivalue();\\ni++;\\n"
"counter_widget->value(i);}\\nxywh {99 15 80 22}\\n}\\n}\\n}\\n", f);
fclose(f);
}
sample_templates_generated = 2;
fluid_prefs.set("sample_templates_generated", sample_templates_generated); fluid_prefs.set("sample_templates_generated", sample_templates_generated);
fluid_prefs.flush(); fluid_prefs.flush();
} }
@ -259,6 +276,5 @@ for (i = 0; i < num_files; i ++) {
free(files[i]); free(files[i]);
} }
if (num_files > 0) free(files);} {selected if (num_files > 0) free(files);} {}
}
} }

2
fluid/widget_panel.cxx

@ -573,7 +573,6 @@ Fl_Double_Window* make_widget_panel() {
o->labelsize(11); o->labelsize(11);
o->callback((Fl_Callback*)propagate_load); o->callback((Fl_Callback*)propagate_load);
o->when(FL_WHEN_NEVER); o->when(FL_WHEN_NEVER);
o->hide();
{ Fl_Group* o = new Fl_Group(95, 40, 309, 20, "Label:"); { Fl_Group* o = new Fl_Group(95, 40, 309, 20, "Label:");
o->labelfont(1); o->labelfont(1);
o->labelsize(11); o->labelsize(11);
@ -1667,6 +1666,7 @@ access the Widget pointer and \'v\' to access the user value.");
{ widget_tab_grid = new Fl_Group(10, 30, 400, 330, "Grid"); { widget_tab_grid = new Fl_Group(10, 30, 400, 330, "Grid");
widget_tab_grid->labelsize(11); widget_tab_grid->labelsize(11);
widget_tab_grid->callback((Fl_Callback*)propagate_load); widget_tab_grid->callback((Fl_Callback*)propagate_load);
widget_tab_grid->hide();
{ Fl_Group* o = new Fl_Group(95, 60, 315, 20, "Grid Layout:"); { Fl_Group* o = new Fl_Group(95, 60, 315, 20, "Grid Layout:");
o->labelfont(1); o->labelfont(1);
o->labelsize(11); o->labelsize(11);

8
fluid/widget_panel.fl

@ -44,7 +44,7 @@ decl {extern void set_modflag(int mf, int mfc=-1);} {private local
} }
Function {make_widget_panel()} { Function {make_widget_panel()} {
comment {Create a panel that can be used with all known widgets} open selected comment {Create a panel that can be used with all known widgets} open
} { } {
Fl_Window {} { Fl_Window {} {
comment {Use a Double Window to avoid flickering.} open comment {Use a Double Window to avoid flickering.} open
@ -58,8 +58,8 @@ Function {make_widget_panel()} {
} { } {
Fl_Group {} { Fl_Group {} {
label GUI label GUI
callback propagate_load callback propagate_load selected
xywh {10 30 400 330} labelsize 11 when 0 hide resizable xywh {10 30 400 330} labelsize 11 when 0 resizable
} { } {
Fl_Group {} { Fl_Group {} {
label {Label:} label {Label:}
@ -1053,7 +1053,7 @@ wCallback->do_callback(wCallback, v);} open
Fl_Group widget_tab_grid { Fl_Group widget_tab_grid {
label Grid label Grid
callback propagate_load open callback propagate_load open
xywh {10 30 400 330} labelsize 11 xywh {10 30 400 330} labelsize 11 hide
} { } {
Fl_Group {} { Fl_Group {} {
label {Grid Layout:} label {Grid Layout:}

48
src/Fl_Input_.cxx

@ -1462,6 +1462,54 @@ int Fl_Input_::value(const char* str) {
return value(str, str ? (int) strlen(str) : 0); return value(str, str ? (int) strlen(str) : 0);
} }
/**
Changes the widget text to a signed integer number.
\param [in] v the new value
\return non-zero if the new value is different than the current one
\see Fl_Input_::value(const char* str), Fl_Input_::ivalue()
*/
int Fl_Input_::value(int v) {
char buf[64];
snprintf(buf, sizeof(buf)-1, "%d", v);
return value(buf);
}
/**
Changes the widget text to a floating point number ("%g").
\param [in] v the new value
\return non-zero if the new value is different than the current one
\see Fl_Input_::value(const char* str), Fl_Input_::ivalue()
*/
int Fl_Input_::value(double v) {
char buf[64];
snprintf(buf, sizeof(buf)-1, "%g", v);
return value(buf);
}
/**
Returns the widget text interpreted as a signed integer.
\return signed integer value
\see Fl_Input_::dvalue()
\see Fl_Input_::value(int)
*/
int Fl_Input_::ivalue() const {
return atoi(value());
}
/**
Returns the widget text interpreted as a floating point number.
\return double precision floating point value
\see Fl_Input_::ivalue()
\see Fl_Input_::value(double)
*/
int Fl_Input_::dvalue() const {
return atof(value());
}
/** /**
Changes the size of the widget. Changes the size of the widget.
This call updates the text layout so that the cursor is visible. This call updates the text layout so that the cursor is visible.

Loading…
Cancel
Save