summaryrefslogtreecommitdiff
path: root/fluid
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2023-09-03 00:09:32 +0200
committerMatthias Melcher <github@matthiasm.com>2023-09-03 00:09:40 +0200
commit5e8adebac2899d60fffc53d4692bc4972abcf795 (patch)
treeb79581c85dc80c4d132390de42c15faee8f3d4c9 /fluid
parent502fa72eb472382cc47964874893085fb88116f5 (diff)
Adds compact buttons feature to create keypads.
See test/buttons for an example.
Diffstat (limited to 'fluid')
-rw-r--r--fluid/Fl_Button_Type.cxx28
-rw-r--r--fluid/Fl_Button_Type.h4
-rw-r--r--fluid/Fl_Widget_Type.cxx34
-rw-r--r--fluid/alignment_panel.cxx3
-rw-r--r--fluid/alignment_panel.fl10
-rw-r--r--fluid/widget_panel.cxx8
-rw-r--r--fluid/widget_panel.fl7
-rw-r--r--fluid/widget_panel.h1
8 files changed, 88 insertions, 7 deletions
diff --git a/fluid/Fl_Button_Type.cxx b/fluid/Fl_Button_Type.cxx
index 53355b7c3..ee12c731a 100644
--- a/fluid/Fl_Button_Type.cxx
+++ b/fluid/Fl_Button_Type.cxx
@@ -25,6 +25,7 @@
#include "Fl_Button_Type.h"
#include "Fd_Snap_Action.h"
+#include "file.h"
#include <FL/Fl.H>
#include <FL/Fl_Button.H>
@@ -34,6 +35,9 @@
#include <FL/Fl_Repeat_Button.H>
#include <FL/Fl_Round_Button.H>
+#include <stdlib.h>
+
+
// ---- Button Types --------------------------------------------------- MARK: -
@@ -61,6 +65,30 @@ Fl_Widget *Fl_Button_Type::widget(int x, int y, int w, int h) {
return new Fl_Button(x, y, w, h, "Button");
}
+void Fl_Button_Type::write_properties(Fd_Project_Writer &f) {
+ Fl_Widget_Type::write_properties(f);
+ Fl_Button *btn = (Fl_Button*)o;
+ if (btn->compact()) {
+ f.write_string("compact");
+ f.write_string("%d", btn->compact());
+ }
+}
+
+void Fl_Button_Type::read_property(Fd_Project_Reader &f, const char *c) {
+ Fl_Button *btn = (Fl_Button*)o;
+ if (!strcmp(c, "compact")) {
+ btn->compact((uchar)atol(f.read_word()));
+ } else {
+ Fl_Widget_Type::read_property(f, c);
+ }
+}
+
+void Fl_Button_Type::copy_properties() {
+ Fl_Widget_Type::copy_properties();
+ Fl_Button *s = (Fl_Button*)o, *d = (Fl_Button*)live_widget;
+ d->compact(s->compact());
+}
+
Fl_Button_Type Fl_Button_type;
diff --git a/fluid/Fl_Button_Type.h b/fluid/Fl_Button_Type.h
index 743c1fdd5..c731ce7e7 100644
--- a/fluid/Fl_Button_Type.h
+++ b/fluid/Fl_Button_Type.h
@@ -35,6 +35,10 @@ public:
int is_button() const FL_OVERRIDE { return 1; }
ID id() const FL_OVERRIDE { return ID_Button; }
bool is_a(ID inID) const FL_OVERRIDE { return (inID==ID_Button) ? true : super::is_a(inID); }
+ void write_properties(Fd_Project_Writer &f) FL_OVERRIDE;
+ void read_property(Fd_Project_Reader &f, const char *) FL_OVERRIDE;
+ void copy_properties() FL_OVERRIDE;
+
};
extern Fl_Button_Type Fl_Button_type;
diff --git a/fluid/Fl_Widget_Type.cxx b/fluid/Fl_Widget_Type.cxx
index 7418e65e1..3eddc890f 100644
--- a/fluid/Fl_Widget_Type.cxx
+++ b/fluid/Fl_Widget_Type.cxx
@@ -1081,6 +1081,39 @@ void down_box_cb(Fl_Choice* i, void *v) {
}
}
+void compact_cb(Fl_Light_Button* i, void* v) {
+ if (v == LOAD) {
+ uchar n;
+ if (current_widget->is_a(Fl_Type::ID_Button)) {
+ n = ((Fl_Button*)(current_widget->o))->compact();
+ i->value(n);
+ i->show();
+ } else {
+ i->hide();
+ }
+ } else {
+ int mod = 0;
+ uchar n = (uchar)i->value();
+ for (Fl_Type *o = Fl_Type::first; o; o = o->next) {
+ if (o->selected && o->is_a(Fl_Type::ID_Button)) {
+ Fl_Widget_Type* q = (Fl_Widget_Type*)o;
+ uchar v = ((Fl_Button*)(q->o))->compact();
+ if (n != v) {
+ if (!mod) {
+ mod = 1;
+ undo_checkpoint();
+ }
+ ((Fl_Button*)(q->o))->compact(n);
+ q->redraw();
+ }
+ }
+ }
+ if (mod) set_modflag(1);
+ }
+}
+
+
+
////////////////////////////////////////////////////////////////
Fl_Menu_Item whenmenu[] = {
@@ -3039,6 +3072,7 @@ void Fl_Widget_Type::write_widget_code(Fd_Code_Writer& f) {
if (b->down_box()) f.write_c("%s%s->down_box(FL_%s);\n", f.indent(), var,
boxname(b->down_box()));
if (b->value()) f.write_c("%s%s->value(1);\n", f.indent(), var);
+ if (b->compact()) f.write_c("%s%s->compact(%d);\n", f.indent(), var, b->compact());
} else if (is_a(Fl_Type::ID_Input_Choice)) {
Fl_Input_Choice* b = (Fl_Input_Choice*)o;
if (b->down_box()) f.write_c("%s%s->down_box(FL_%s);\n", f.indent(), var,
diff --git a/fluid/alignment_panel.cxx b/fluid/alignment_panel.cxx
index b3df61cfe..29f21fd4c 100644
--- a/fluid/alignment_panel.cxx
+++ b/fluid/alignment_panel.cxx
@@ -1239,18 +1239,21 @@ ped using octal notation `\\0123`. If this option is checked, Fluid will write\
{ preset_choice[0] = new Fl_Button(85, 107, 78, 20, "Application");
preset_choice[0]->type(102);
preset_choice[0]->value(1);
+ preset_choice[0]->compact(1);
preset_choice[0]->selection_color(FL_DARK2);
preset_choice[0]->labelsize(11);
preset_choice[0]->callback((Fl_Callback*)edit_layout_preset_cb, (void*)(0));
} // Fl_Button* preset_choice[0]
{ preset_choice[1] = new Fl_Button(163, 107, 79, 20, "Dialog");
preset_choice[1]->type(102);
+ preset_choice[1]->compact(1);
preset_choice[1]->selection_color(FL_DARK2);
preset_choice[1]->labelsize(11);
preset_choice[1]->callback((Fl_Callback*)edit_layout_preset_cb, (void*)(1));
} // Fl_Button* preset_choice[1]
{ preset_choice[2] = new Fl_Button(242, 107, 78, 20, "Toolbox");
preset_choice[2]->type(102);
+ preset_choice[2]->compact(1);
preset_choice[2]->selection_color(FL_DARK2);
preset_choice[2]->labelsize(11);
preset_choice[2]->callback((Fl_Callback*)edit_layout_preset_cb, (void*)(2));
diff --git a/fluid/alignment_panel.fl b/fluid/alignment_panel.fl
index d6b9325b4..845d7b7f6 100644
--- a/fluid/alignment_panel.fl
+++ b/fluid/alignment_panel.fl
@@ -107,7 +107,7 @@ decl {void scheme_cb(Fl_Scheme_Choice *, void *);} {public local
Function {make_settings_window()} {open
} {
Fl_Window settings_window {
- label {FLUID Settings} open selected
+ label {FLUID Settings} open
xywh {423 204 340 580} type Double align 80 non_modal visible
} {
Fl_Tabs w_settings_tabs {
@@ -115,7 +115,7 @@ Function {make_settings_window()} {open
xywh {10 10 320 530} selection_color 12 labelsize 11 labelcolor 255
} {
Fl_Group {} {
- label General open
+ label General open selected
image {icons/general_64.png} compress_image 1 xywh {10 60 320 480} labelsize 11
code0 {o->image()->scale(36, 24);}
} {
@@ -471,19 +471,19 @@ g_layout_list.update_dialogs();}
label Application
user_data 0 user_data_type long
callback edit_layout_preset_cb
- xywh {85 107 78 20} type Radio value 1 selection_color 45 labelsize 11
+ xywh {85 107 78 20} type Radio value 1 selection_color 45 labelsize 11 compact 1
}
Fl_Button {preset_choice[1]} {
label Dialog
user_data 1 user_data_type long
callback edit_layout_preset_cb
- xywh {163 107 79 20} type Radio selection_color 45 labelsize 11
+ xywh {163 107 79 20} type Radio selection_color 45 labelsize 11 compact 1
}
Fl_Button {preset_choice[2]} {
label Toolbox
user_data 2 user_data_type long
callback edit_layout_preset_cb
- xywh {242 107 78 20} type Radio selection_color 45 labelsize 11
+ xywh {242 107 78 20} type Radio selection_color 45 labelsize 11 compact 1
}
}
Fl_Box {} {
diff --git a/fluid/widget_panel.cxx b/fluid/widget_panel.cxx
index 4bb22b797..12976268b 100644
--- a/fluid/widget_panel.cxx
+++ b/fluid/widget_panel.cxx
@@ -803,10 +803,16 @@ sized to fit the container.");
} // Fl_Menu_Button* o
o->end();
} // Fl_Group* o
- { Fl_Box* o = new Fl_Box(95, 140, 300, 40);
+ { Fl_Box* o = new Fl_Box(95, 165, 300, 40);
o->labelsize(11);
Fl_Group::current()->resizable(o);
} // Fl_Box* o
+ { Fl_Light_Button* o = new Fl_Light_Button(95, 140, 90, 20, "Compact");
+ o->tooltip("use compact box types for closely set buttons");
+ o->selection_color((Fl_Color)1);
+ o->labelsize(11);
+ o->callback((Fl_Callback*)compact_cb);
+ } // Fl_Light_Button* o
o->end();
} // Fl_Group* o
{ Fl_Group* o = new Fl_Group(10, 30, 400, 330, "C++");
diff --git a/fluid/widget_panel.fl b/fluid/widget_panel.fl
index 1ebbaa7d6..139dbe716 100644
--- a/fluid/widget_panel.fl
+++ b/fluid/widget_panel.fl
@@ -655,7 +655,12 @@ Use Ctrl-J for newlines.} xywh {95 285 310 20} labelfont 1 labelsize 11 textsize
} {}
}
Fl_Box {} {
- xywh {95 140 300 40} labelsize 11 resizable
+ xywh {95 165 300 40} labelsize 11 resizable
+ }
+ Fl_Light_Button {} {
+ label Compact
+ callback compact_cb
+ tooltip {use compact box types for closely set buttons} xywh {95 140 90 20} selection_color 1 labelsize 11
}
}
Fl_Group {} {
diff --git a/fluid/widget_panel.h b/fluid/widget_panel.h
index ae15583b0..196e10632 100644
--- a/fluid/widget_panel.h
+++ b/fluid/widget_panel.h
@@ -113,6 +113,7 @@ extern void textsize_cb(Fl_Value_Input*, void*);
extern void textcolor_cb(Fl_Button*, void*);
extern Fl_Button *w_textcolor;
extern void textcolor_menu_cb(Fl_Menu_Button*, void*);
+extern void compact_cb(Fl_Light_Button*, void*);
extern void subclass_cb(Fl_Input*, void*);
extern void subtype_cb(Fl_Choice*, void*);
extern void name_cb(Fl_Input*, void*);