summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2023-11-06 19:09:48 +0100
committerMatthias Melcher <github@matthiasm.com>2023-11-07 14:28:22 +0100
commitd7768b76d042eaa6cdce97976e96315d0bceccb2 (patch)
tree92b8c751fa1affc7f5fdb10d980bd4ea4ba1e36e
parent8b31954d6698bded12d6252b1bbc46c6eece7f73 (diff)
FLUID: Adds template for tutorial.
Tutorial still to be written. Also adds convenience methods to Fl_Input_ for getting and setting numeric values.
-rw-r--r--FL/Fl_Input_.H10
-rw-r--r--fluid/template_panel.cxx24
-rw-r--r--fluid/template_panel.fl30
-rw-r--r--fluid/widget_panel.cxx2
-rw-r--r--fluid/widget_panel.fl8
-rw-r--r--src/Fl_Input_.cxx48
6 files changed, 106 insertions, 16 deletions
diff --git a/FL/Fl_Input_.H b/FL/Fl_Input_.H
index a800d7e49..e8ab6508c 100644
--- a/FL/Fl_Input_.H
+++ b/FL/Fl_Input_.H
@@ -239,6 +239,12 @@ public:
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. */
int static_value(const char*);
/* Changes the widget text. */
@@ -256,6 +262,10 @@ public:
*/
const char* value() const {return value_;}
+ int ivalue() const;
+
+ int dvalue() const;
+
/* Returns the Unicode character at index \p i. */
unsigned int index(int i) const;
diff --git a/fluid/template_panel.cxx b/fluid/template_panel.cxx
index 0654724f0..debd92a7b 100644
--- a/fluid/template_panel.cxx
+++ b/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->when(FL_WHEN_CHANGED | FL_WHEN_NOT_CHANGED);
} // 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->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_Box* template_preview
{ template_name = new Fl_Input(198, 288, 252, 25, "Template Name:");
@@ -221,7 +221,7 @@ void template_load() {
int 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);
strcat(filename, "/FLTK_License.fl");
FILE *f = fopen(filename, "wb");
@@ -237,7 +237,23 @@ void template_load() {
"er\n}\n", 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.flush();
}
diff --git a/fluid/template_panel.fl b/fluid/template_panel.fl
index 1f6f801f0..8f063ec75 100644
--- a/fluid/template_panel.fl
+++ b/fluid/template_panel.fl
@@ -68,7 +68,7 @@ template_preview->image(0);
template_browser->deselect();
template_name->value("");
template_instance->value("");
-template_panel->hide();}
+template_panel->hide();} open
xywh {478 284 460 355} type Double resizable modal visible
} {
Fl_Browser template_browser {
@@ -120,7 +120,8 @@ if (img) {
xywh {10 28 180 250} type Hold labelfont 1 align 5 when 3
}
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 {
label {Template Name:}
@@ -134,7 +135,7 @@ if (img) {
label {Instance Name:}
xywh {198 288 252 25} labelfont 1 textfont 4 hide
}
- Fl_Group {} {
+ Fl_Group {} {open
xywh {10 323 440 25}
} {
Fl_Button template_delete {
@@ -217,7 +218,7 @@ strlcat(path, "templates", sizeof(path));
int 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);
strcat(filename, "/FLTK_License.fl");
FILE *f = fopen(filename, "wb");
@@ -233,7 +234,23 @@ if (!sample_templates_generated) {
"er\\n}\\n", 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.flush();
}
@@ -259,6 +276,5 @@ for (i = 0; i < num_files; i ++) {
free(files[i]);
}
-if (num_files > 0) free(files);} {selected
- }
+if (num_files > 0) free(files);} {}
}
diff --git a/fluid/widget_panel.cxx b/fluid/widget_panel.cxx
index da8021a28..0ea114ef6 100644
--- a/fluid/widget_panel.cxx
+++ b/fluid/widget_panel.cxx
@@ -573,7 +573,6 @@ Fl_Double_Window* make_widget_panel() {
o->labelsize(11);
o->callback((Fl_Callback*)propagate_load);
o->when(FL_WHEN_NEVER);
- o->hide();
{ Fl_Group* o = new Fl_Group(95, 40, 309, 20, "Label:");
o->labelfont(1);
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->labelsize(11);
widget_tab_grid->callback((Fl_Callback*)propagate_load);
+ widget_tab_grid->hide();
{ Fl_Group* o = new Fl_Group(95, 60, 315, 20, "Grid Layout:");
o->labelfont(1);
o->labelsize(11);
diff --git a/fluid/widget_panel.fl b/fluid/widget_panel.fl
index cc42315a2..fe74ad327 100644
--- a/fluid/widget_panel.fl
+++ b/fluid/widget_panel.fl
@@ -44,7 +44,7 @@ decl {extern void set_modflag(int mf, int mfc=-1);} {private local
}
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 {} {
comment {Use a Double Window to avoid flickering.} open
@@ -58,8 +58,8 @@ Function {make_widget_panel()} {
} {
Fl_Group {} {
label GUI
- callback propagate_load
- xywh {10 30 400 330} labelsize 11 when 0 hide resizable
+ callback propagate_load selected
+ xywh {10 30 400 330} labelsize 11 when 0 resizable
} {
Fl_Group {} {
label {Label:}
@@ -1053,7 +1053,7 @@ wCallback->do_callback(wCallback, v);} open
Fl_Group widget_tab_grid {
label Grid
callback propagate_load open
- xywh {10 30 400 330} labelsize 11
+ xywh {10 30 400 330} labelsize 11 hide
} {
Fl_Group {} {
label {Grid Layout:}
diff --git a/src/Fl_Input_.cxx b/src/Fl_Input_.cxx
index 4fc429aa3..52fa8cb84 100644
--- a/src/Fl_Input_.cxx
+++ b/src/Fl_Input_.cxx
@@ -1463,6 +1463,54 @@ int Fl_Input_::value(const char* str) {
}
/**
+ 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.
This call updates the text layout so that the cursor is visible.
\param [in] X, Y, W, H new size of the widget