Modernize fl_symbol hashing to C++11 code (#1417) (#1418)
Build and Test / build-linux (push) Has been cancelled
Build and Test / build-wayland (push) Has been cancelled
Build and Test / build-macos (push) Has been cancelled
Build and Test / build-windows (push) Has been cancelled

* Replace hand rolles symbol hashing with C++11 code
* Update symbol drawing functions, add fl_remove_symbol()
* Refactored some of fl_draw_symbol.
* Using clang format for symbol code and test
* Circumvent Doxygen bug https://github.com/doxygen/doxygen/issues/11190

Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Albrecht Schlosser <albrechts.fltk@online.de>
This commit is contained in:
Matthias Melcher
2026-05-17 21:40:22 +02:00
committed by GitHub
parent cf87ae9c3b
commit 33c2248959
5 changed files with 894 additions and 456 deletions
+19 -3
View File
@@ -1,7 +1,7 @@
# #
# clang-format control file for the FLTK project. # clang-format control file for the FLTK project.
# #
# Copyright 2017-2022 by Bill Spitzak and others. # Copyright 2017-2026 by Bill Spitzak and others.
# #
# This library is free software. Distribution and use rights are outlined in # This library is free software. Distribution and use rights are outlined in
# the file "COPYING" which should have been included with this file. If this # the file "COPYING" which should have been included with this file. If this
@@ -112,7 +112,9 @@ SortIncludes: false
# Multiple constructor initializers must be on consecutive lines. # Multiple constructor initializers must be on consecutive lines.
# Note: this is NOT (always) true in current FLTK code! # Note: this is NOT (always) true in current FLTK code!
BreakConstructorInitializersBeforeComma: true BreakConstructorInitializers: BeforeColon
# or: BeforeColon, BeforeComma, AfterColon, AfterComma
# was: BreakConstructorInitializersBeforeComma: true
# Constructor initializers will be indented by 2 spaces. # Constructor initializers will be indented by 2 spaces.
# LLVM default: 4 # LLVM default: 4
@@ -125,6 +127,20 @@ ConstructorInitializerIndentWidth: 2
# LLVM default: 4 # LLVM default: 4
# ContinuationIndentWidth: 2 # ContinuationIndentWidth: 2
# If a control statement (if-clause, etc.) spans multiple lines, the opening
# brace can get visibly lost and it is hard to see when the condition ends and
# the statements start. MultiLine puts the brace on the next line in this case.
#
# AfterFunction: true would be a change in style and is up for debate.
# I like it because it separates the declaration from the body. I wish there
# was a MultiLine option here as well.
BreakBeforeBraces: Custom
BraceWrapping:
AfterControlStatement: MultiLine
AfterFunction: true
SplitEmptyFunction: false
# Most of FLTK's code uses 'void *p' as opposed to 'void* p'. # Most of FLTK's code uses 'void *p' as opposed to 'void* p'.
# This is particularly useful in combined declarations like: # This is particularly useful in combined declarations like:
# int var, var2, *pv, **pp; # int var, var2, *pv, **pp;
@@ -136,4 +152,4 @@ ConstructorInitializerIndentWidth: 2
# in function parameter lists. # in function parameter lists.
DerivePointerAlignment: false DerivePointerAlignment: false
PointerAlignment: Right PointerAlignment: Left
+5 -3
View File
@@ -1,7 +1,7 @@
// //
// Portable drawing function header file for the Fast Light Tool Kit (FLTK). // Portable drawing function header file for the Fast Light Tool Kit (FLTK).
// //
// Copyright 1998-2025 by Bill Spitzak and others. // Copyright 1998-2026 by Bill Spitzak and others.
// //
// This library is free software. Distribution and use rights are outlined in // This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this // the file "COPYING" which should have been included with this file. If this
@@ -1251,9 +1251,11 @@ FL_EXPORT void fl_set_spot(int font, int size, int X, int Y, int W, int H, Fl_Wi
FL_EXPORT void fl_reset_spot(void); FL_EXPORT void fl_reset_spot(void);
// XForms symbols: // Symbols (originally from XForms):
FL_EXPORT int fl_draw_symbol(const char *label, int x, int y, int w, int h, Fl_Color); FL_EXPORT int fl_draw_symbol(const char *label, int x, int y, int w, int h, Fl_Color);
FL_EXPORT int fl_add_symbol(const char *name, void (*drawit)(Fl_Color), int scalable); FL_EXPORT int fl_add_symbol(const char *name, void (*drawit)(Fl_Color c), int scalable);
FL_EXPORT int fl_add_symbol(const char *name, void (*draw_in_rect)(int x, int y, int w, int h, Fl_Color c), int scalable);
FL_EXPORT int fl_remove_symbol(const char *name);
/** @} */ /** @} */
#endif #endif
Submodule fluid/.claude/worktrees/naughty-blackburn-008169 added at d2ed9a50cc
+785 -375
View File
File diff suppressed because it is too large Load Diff
+84 -75
View File
@@ -30,29 +30,38 @@ int N = 0;
#define ROWS 6 #define ROWS 6
#define COLS 7 #define COLS 7
Fl_Double_Window *window; Fl_Double_Window* window;
Fl_Value_Slider *orientation; Fl_Value_Slider* orientation;
Fl_Value_Slider *size; Fl_Value_Slider* size;
void slider_cb(Fl_Widget *, void *) { void slider_cb(Fl_Widget*, void*)
{
static char buf[80]; static char buf[80];
int val = (int)orientation->value(); int val = (int)orientation->value();
int sze = (int)size->value(); int sze = (int)size->value();
for (int i = window->children(); i--; ) { // all window children for (int i = window->children(); i--;) { // all window children
Fl_Widget *wc = window->child(i); Fl_Widget* wc = window->child(i);
const char *l = (const char *)(wc->user_data()); const char* l = (const char*)(wc->user_data());
if ( l && *l == '@' ) { // all children with '@' if (l && *l == '@') { // all children with '@'
l ++; l++;
if ( wc->box() == FL_NO_BOX ) { // ascii legend? if (wc->box() == FL_NO_BOX) { // ascii legend?
if (val&&sze) snprintf(buf, sizeof(buf), "@@%+d%d%s", sze, val, l); if (val && sze)
else if (val) snprintf(buf, sizeof(buf), "@@%d%s", val, l); snprintf(buf, sizeof(buf), "@@%+d%d%s", sze, val, l);
else if (sze) snprintf(buf, sizeof(buf), "@@%+d%s", sze, l); else if (val)
else snprintf(buf, sizeof(buf), "@@%s", l); snprintf(buf, sizeof(buf), "@@%d%s", val, l);
} else { // box with symbol else if (sze)
if (val&&sze) snprintf(buf, sizeof(buf), "@%+d%d%s", sze, val, l); snprintf(buf, sizeof(buf), "@@%+d%s", sze, l);
else if (val) snprintf(buf, sizeof(buf), "@%d%s", val, l); else
else if (sze) snprintf(buf, sizeof(buf), "@%+d%s", sze, l); snprintf(buf, sizeof(buf), "@@%s", l);
else snprintf(buf, sizeof(buf), "@%s", l); } else { // box with symbol
if (val && sze)
snprintf(buf, sizeof(buf), "@%+d%d%s", sze, val, l);
else if (val)
snprintf(buf, sizeof(buf), "@%d%s", val, l);
else if (sze)
snprintf(buf, sizeof(buf), "@%+d%s", sze, l);
else
snprintf(buf, sizeof(buf), "@%s", l);
} }
wc->copy_label(buf); wc->copy_label(buf);
} }
@@ -60,80 +69,80 @@ void slider_cb(Fl_Widget *, void *) {
window->redraw(); window->redraw();
} }
void bt(const char *name) { void bt(const char* name)
int x = N%COLS; {
int y = N/COLS; int x = N % COLS;
int y = N / COLS;
char buf[255]; char buf[255];
N++; N++;
x = x*W+10; x = x * W + 10;
y = y*H+10; y = y * H + 10;
snprintf(buf, sizeof(buf), "@%s", name); snprintf(buf, sizeof(buf), "@%s", name);
Fl_Box *a = new Fl_Box(x,y,W-20,H-20); Fl_Box* a = new Fl_Box(x, y, W - 20, H - 20);
a->box(FL_NO_BOX); a->box(FL_NO_BOX);
a->copy_label(buf); a->copy_label(buf);
a->align(FL_ALIGN_BOTTOM); a->align(FL_ALIGN_BOTTOM);
a->labelsize(11); a->labelsize(11);
a->user_data((void *)name); a->user_data((void*)name);
Fl_Box *b = new Fl_Box(x,y,W-20,H-20); Fl_Box* b = new Fl_Box(x, y, W - 20, H - 20);
b->box(FL_UP_BOX); b->box(FL_UP_BOX);
b->copy_label(name); b->copy_label(name);
b->labelcolor(FL_DARK3); b->labelcolor(FL_DARK3);
b->user_data((void *)name); b->user_data((void*)name);
} }
int main(int argc, char ** argv) { int main(int argc, char** argv)
window = new Fl_Double_Window(COLS*W,ROWS*H+60); {
bt("@->"); window = new Fl_Double_Window(COLS * W, ROWS * H + 60);
bt("@>"); bt("@->");
bt("@>>"); bt("@>");
bt("@>|"); bt("@>>");
bt("@>[]"); bt("@>|");
bt("@|>"); bt("@>[]");
bt("@<-"); bt("@|>");
bt("@<"); bt("@<-");
bt("@<<"); bt("@<");
bt("@|<"); bt("@<<");
bt("@[]<"); bt("@|<");
bt("@<|"); bt("@[]<");
bt("@<->"); bt("@<|");
bt("@-->"); bt("@<->");
bt("@+"); bt("@-->");
bt("@->|"); bt("@+");
bt("@||"); bt("@->|");
bt("@arrow"); bt("@||");
bt("@returnarrow"); bt("@arrow");
bt("@square"); bt("@returnarrow");
bt("@circle"); bt("@square");
bt("@line"); bt("@circle");
bt("@menu"); bt("@line");
bt("@UpArrow"); bt("@menu");
bt("@DnArrow"); bt("@UpArrow");
bt("@search"); bt("@DnArrow");
bt("@FLTK"); bt("@search");
bt("@filenew"); bt("@FLTK");
bt("@fileopen"); bt("@filenew");
bt("@filesave"); bt("@fileopen");
bt("@filesaveas"); bt("@filesave");
bt("@fileprint"); bt("@filesaveas");
bt("@refresh"); bt("@fileprint");
bt("@reload"); bt("@refresh");
bt("@undo"); bt("@reload");
bt("@redo"); bt("@undo");
bt("@import"); bt("@redo");
bt("@export"); bt("@import");
bt("@export");
orientation = new Fl_Value_Slider( orientation = new Fl_Value_Slider((int)(window->w() * .05 + .5), window->h() - 40,
(int)(window->w()*.05+.5), window->h()-40, (int)(window->w() * .42 + .5), 16, "Orientation");
(int)(window->w()*.42+.5), 16, "Orientation");
orientation->type(FL_HORIZONTAL); orientation->type(FL_HORIZONTAL);
orientation->range(0.0, 9.0); orientation->range(0.0, 9.0);
orientation->value(0.0); orientation->value(0.0);
orientation->step(1); orientation->step(1);
orientation->callback(slider_cb, 0); orientation->callback(slider_cb, 0);
size = new Fl_Value_Slider( size = new Fl_Value_Slider((int)(window->w() * .53 + .5), window->h() - 40,
(int)(window->w()*.53+.5), window->h()-40, (int)(window->w() * .42 + .5), 16, "Size");
(int)(window->w()*.42+.5), 16, "Size");
size->type(FL_HORIZONTAL); size->type(FL_HORIZONTAL);
size->range(-3.0, 9.0); size->range(-3.0, 9.0);
size->value(0.0); size->value(0.0);
@@ -141,6 +150,6 @@ bt("@export");
size->callback(slider_cb, 0); size->callback(slider_cb, 0);
window->resizable(window); window->resizable(window);
window->show(argc,argv); window->show(argc, argv);
return Fl::run(); return Fl::run();
} }