diff options
| -rw-r--r-- | FL/Fl.H | 3 | ||||
| -rw-r--r-- | src/Fl.cxx | 20 | ||||
| -rw-r--r-- | src/Fl_Menu.cxx | 16 | ||||
| -rw-r--r-- | test/menubar.cxx | 21 |
4 files changed, 50 insertions, 10 deletions
@@ -294,6 +294,7 @@ public: static int e_original_keysym; // late addition static int scrollbar_size_; + static int menu_linespacing_; // STR #2927 #endif @@ -407,6 +408,8 @@ public: static int reload_scheme(); // platform dependent static int scrollbar_size(); static void scrollbar_size(int W); + static int menu_linespacing(); + static void menu_linespacing(int H); // execution: static int wait(); diff --git a/src/Fl.cxx b/src/Fl.cxx index 011e978e0..8695add93 100644 --- a/src/Fl.cxx +++ b/src/Fl.cxx @@ -136,7 +136,8 @@ int Fl::damage_, Fl::e_is_click, Fl::e_keysym, Fl::e_original_keysym, - Fl::scrollbar_size_ = 16; + Fl::scrollbar_size_ = 16, + Fl::menu_linespacing_ = 4; // 4: was a local macro in Fl_Menu.cxx called "LEADING" char *Fl::e_text = (char *)""; int Fl::e_length; @@ -232,6 +233,23 @@ void Fl::scrollbar_size(int W) { scrollbar_size_ = W; } +/** + Gets the default line spacing used by menus. + \returns The default line spacing, in pixels. +*/ +int Fl::menu_linespacing() { + return menu_linespacing_; +} + +/** + Sets the default line spacing used by menus. + Default is 4. + \param[in] H The new default line spacing between menu items, in pixels. +*/ +void Fl::menu_linespacing(int H) { + menu_linespacing_ = H; +} + /** Returns whether or not the mouse event is inside the given rectangle. diff --git a/src/Fl_Menu.cxx b/src/Fl_Menu.cxx index 1d56a1ebd..a943a6b33 100644 --- a/src/Fl_Menu.cxx +++ b/src/Fl_Menu.cxx @@ -143,8 +143,6 @@ public: int is_inside(int x, int y); }; -#define LEADING 4 // extra vertical leading - extern char fl_draw_shortcut; /** @@ -200,7 +198,7 @@ void Fl_Menu_Item::draw(int x, int y, int w, int h, const Fl_Menu_* m, x += 3; w -= 8; } else { - fl_draw_box(b, x+1, y-(LEADING-2)/2, w-2, h+(LEADING-2), r); + fl_draw_box(b, x+1, y-(Fl::menu_linespacing()-2)/2, w-2, h+(Fl::menu_linespacing()-2), r); } } @@ -344,7 +342,7 @@ menuwindow::menuwindow(const Fl_Menu_Item* m, int X, int Y, int Wp, int Hp, if (m) for (; m->text; m = m->next()) { int hh; int w1 = m->measure(&hh, button); - if (hh+LEADING>itemheight) itemheight = hh+LEADING; + if (hh+Fl::menu_linespacing()>itemheight) itemheight = hh+Fl::menu_linespacing(); if (m->flags&(FL_SUBMENU|FL_SUBMENU_POINTER)) w1 += FL_NORMAL_SIZE; if (w1 > W) W = w1; @@ -382,7 +380,7 @@ menuwindow::menuwindow(const Fl_Menu_Item* m, int X, int Y, int Wp, int Hp, //if (X > scr_x+scr_w-W) X = right_edge-W; if (X > scr_x+scr_w-W) X = scr_x+scr_w-W; x(X); w(W); - h((numitems ? itemheight*numitems-LEADING : 0)+2*BW+3); + h((numitems ? itemheight*numitems-Fl::menu_linespacing() : 0)+2*BW+3); if (selected >= 0) { Y = Y+(Hp-itemheight)/2-selected*itemheight-BW; } else { @@ -459,10 +457,10 @@ void menuwindow::drawentry(const Fl_Menu_Item* m, int n, int eraseit) { int W = w(); int ww = W-2*BW-1; int yy = BW+1+n*itemheight; - int hh = itemheight - LEADING; + int hh = itemheight - Fl::menu_linespacing(); if (eraseit && n != selected) { - fl_push_clip(xx+1, yy-(LEADING-2)/2, ww-2, hh+(LEADING-2)); + fl_push_clip(xx+1, yy-(Fl::menu_linespacing()-2)/2, ww-2, hh+(Fl::menu_linespacing()-2)); draw_box(box(), 0, 0, w(), h(), button ? button->color() : color()); fl_pop_clip(); } @@ -496,9 +494,9 @@ void menuwindow::drawentry(const Fl_Menu_Item* m, int n, int eraseit) { if (m->flags & FL_MENU_DIVIDER) { fl_color(FL_DARK3); - fl_xyline(BW-1, yy+hh+(LEADING-2)/2, W-2*BW+2); + fl_xyline(BW-1, yy+hh+(Fl::menu_linespacing()-2)/2, W-2*BW+2); fl_color(FL_LIGHT3); - fl_xyline(BW-1, yy+hh+((LEADING-2)/2+1), W-2*BW+2); + fl_xyline(BW-1, yy+hh+((Fl::menu_linespacing()-2)/2+1), W-2*BW+2); } } diff --git a/test/menubar.cxx b/test/menubar.cxx index b54336a9e..03c301ada 100644 --- a/test/menubar.cxx +++ b/test/menubar.cxx @@ -26,6 +26,7 @@ #include <FL/Fl_Toggle_Button.H> #include <FL/Fl_Menu_Button.H> #include <FL/Fl_Choice.H> +#include <FL/Fl_Value_Slider.H> #include <stdio.h> #include <stdlib.h> #include "../src/flstring.h" @@ -207,6 +208,12 @@ void menu_location_cb(Fl_Widget* w, void* data) } #endif // __APPLE__ +void menu_linespacing_cb(Fl_Widget* w, void*) { + Fl_Value_Slider *fvs = (Fl_Value_Slider*)w; + int val = (int)fvs->value(); + Fl::menu_linespacing(val); // takes effect when someone opens a new menu.. +} + #define WIDTH 700 Fl_Menu_* menus[4]; @@ -250,6 +257,20 @@ int main(int argc, char **argv) { ch2.value(1); menu_location_cb(&ch2, &menubar); #endif + + Fl_Value_Slider menu_linespacing_slider(500,150,150,20,"Fl::menu_linespacing()"); + menu_linespacing_slider.tooltip("Changes the line spacing between all menu items"); + menu_linespacing_slider.type(1); + //menu_linespacing_slider.labelsize(14); + menu_linespacing_slider.value(Fl::menu_linespacing()); + menu_linespacing_slider.color((Fl_Color)46); + menu_linespacing_slider.selection_color((Fl_Color)1); + //menu_linespacing_slider.textsize(10); + menu_linespacing_slider.align(Fl_Align(FL_ALIGN_LEFT)); + menu_linespacing_slider.range(0.1, 50.0); + menu_linespacing_slider.step(1.0); + menu_linespacing_slider.callback(menu_linespacing_cb); + window.end(); #ifdef __APPLE__ |
