summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2024-08-27 15:13:32 +0200
committerMatthias Melcher <github@matthiasm.com>2024-08-27 15:13:32 +0200
commitec05f78d98d8e38ea34eb1bd73647fa5b8b35f81 (patch)
tree64768c2ff44f44200e3d9d8463924fc9450be973 /src
parent5879e7fae7d34c037f2ac02c6c7fca86c42a186d (diff)
Adding horiizonatl and vertical label margin
- sizeof(Fl_Widget) not increased - label positions can be adjusted - try it out in test/label app - full support in FLUD
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Choice.cxx2
-rw-r--r--src/Fl_Menu.cxx4
-rw-r--r--src/Fl_Widget.cxx1
-rw-r--r--src/Fl_Window.cxx2
-rw-r--r--src/fl_labeltype.cxx24
5 files changed, 29 insertions, 4 deletions
diff --git a/src/Fl_Choice.cxx b/src/Fl_Choice.cxx
index 3ba0a2c7d..e5a0276af 100644
--- a/src/Fl_Choice.cxx
+++ b/src/Fl_Choice.cxx
@@ -113,7 +113,7 @@ void Fl_Choice::draw() {
l.font = m.labelsize_ || m.labelfont_ ? m.labelfont_ : textfont();
l.size = m.labelsize_ ? m.labelsize_ : textsize();
l.color= m.labelcolor_ ? m.labelcolor_ : textcolor();
- l.spacing = 0;
+ l.h_margin_ = l.v_margin_ = l.spacing = 0;
if (!m.active()) l.color = fl_inactive((Fl_Color)l.color);
fl_draw_shortcut = 2; // hack value to make '&' disappear
l.draw(xx+3, yy, ww>6 ? ww-6 : 0, hh, FL_ALIGN_LEFT);
diff --git a/src/Fl_Menu.cxx b/src/Fl_Menu.cxx
index 79228de80..a3a1c82e6 100644
--- a/src/Fl_Menu.cxx
+++ b/src/Fl_Menu.cxx
@@ -261,7 +261,7 @@ int Fl_Menu_Item::measure(int* hp, const Fl_Menu_* m) const {
l.font = labelsize_ || labelfont_ ? labelfont_ : (m ? m->textfont() : FL_HELVETICA);
l.size = labelsize_ ? labelsize_ : m ? m->textsize() : FL_NORMAL_SIZE;
l.color = FL_FOREGROUND_COLOR; // this makes no difference?
- l.spacing = 0;
+ l.h_margin_ = l.v_margin_ = l.spacing = 0;
fl_draw_shortcut = 1;
int w = 0; int h = 0;
l.measure(w, hp ? *hp : h);
@@ -281,7 +281,7 @@ void Fl_Menu_Item::draw(int x, int y, int w, int h, const Fl_Menu_* m,
l.font = labelsize_ || labelfont_ ? labelfont_ : (m ? m->textfont() : FL_HELVETICA);
l.size = labelsize_ ? labelsize_ : m ? m->textsize() : FL_NORMAL_SIZE;
l.color = labelcolor_ ? labelcolor_ : m ? m->textcolor() : int(FL_FOREGROUND_COLOR);
- l.spacing = 0;
+ l.h_margin_ = l.v_margin_ = l.spacing = 0;
if (!active()) l.color = fl_inactive((Fl_Color)l.color);
if (selected) {
Fl_Color r = m ? m->selection_color() : FL_SELECTION_COLOR;
diff --git a/src/Fl_Widget.cxx b/src/Fl_Widget.cxx
index d5adb5a08..3a583ca4d 100644
--- a/src/Fl_Widget.cxx
+++ b/src/Fl_Widget.cxx
@@ -118,6 +118,7 @@ Fl_Widget::Fl_Widget(int X, int Y, int W, int H, const char* L) {
label_.size = FL_NORMAL_SIZE;
label_.color = FL_FOREGROUND_COLOR;
label_.align_ = FL_ALIGN_CENTER;
+ label_.h_margin_ = label_.v_margin_ = 0;
label_.spacing = 0;
tooltip_ = 0;
callback_ = default_callback;
diff --git a/src/Fl_Window.cxx b/src/Fl_Window.cxx
index 20a39a68e..6ded79b01 100644
--- a/src/Fl_Window.cxx
+++ b/src/Fl_Window.cxx
@@ -526,7 +526,7 @@ void Fl_Window::draw_backdrop() {
l1.image = image();
if (!active_r() && l1.image && l1.deimage) l1.image = l1.deimage;
l1.type = labeltype();
- l1.spacing = 0;
+ l1.h_margin_ = l1.v_margin_ = l1.spacing = 0;
l1.draw(0,0,w(),h(),align());
}
}
diff --git a/src/fl_labeltype.cxx b/src/fl_labeltype.cxx
index 9f5c5f20e..991bc5e56 100644
--- a/src/fl_labeltype.cxx
+++ b/src/fl_labeltype.cxx
@@ -82,6 +82,29 @@ void Fl::set_labeltype(Fl_Labeltype t,Fl_Label_Draw_F* f,Fl_Label_Measure_F*m)
/** Draws a label with arbitrary alignment in an arbitrary box. */
void Fl_Label::draw(int X, int Y, int W, int H, Fl_Align align) const {
if (!value && !image) return;
+ const Fl_Align FL_ALIGN_CENTER = 0x0000;
+ const Fl_Align FL_ALIGN_TOP = 0x0001;
+ const Fl_Align FL_ALIGN_BOTTOM = 0x0002;
+ const Fl_Align FL_ALIGN_LEFT = 0x0004;
+ const Fl_Align FL_ALIGN_RIGHT = 0x0008;
+ const Fl_Align FL_ALIGN_TOP_LEFT = FL_ALIGN_TOP | FL_ALIGN_LEFT;
+ const Fl_Align FL_ALIGN_TOP_RIGHT = FL_ALIGN_TOP | FL_ALIGN_RIGHT;
+ const Fl_Align FL_ALIGN_BOTTOM_LEFT = FL_ALIGN_BOTTOM | FL_ALIGN_LEFT;
+ const Fl_Align FL_ALIGN_BOTTOM_RIGHT = FL_ALIGN_BOTTOM | FL_ALIGN_RIGHT;
+ const Fl_Align FL_ALIGN_LEFT_TOP = 0x0007;
+ const Fl_Align FL_ALIGN_RIGHT_TOP = 0x000b;
+ const Fl_Align FL_ALIGN_LEFT_BOTTOM = 0x000d;
+ const Fl_Align FL_ALIGN_RIGHT_BOTTOM = 0x000e;
+ switch (align&(FL_ALIGN_TOP|FL_ALIGN_BOTTOM)) {
+ case 0: Y += v_margin_; H -= 2*v_margin_; break;
+ case FL_ALIGN_TOP: Y += v_margin_; H -= v_margin_; break;
+ case FL_ALIGN_BOTTOM: H -= v_margin_; break;
+ }
+ switch (align&(FL_ALIGN_LEFT|FL_ALIGN_RIGHT)) {
+ case 0: X += h_margin_; W -= 2*h_margin_; break;
+ case FL_ALIGN_LEFT: X += h_margin_; W -= h_margin_; break;
+ case FL_ALIGN_RIGHT: W -= h_margin_; break;
+ }
table[type](this, X, Y, W, H, align);
}
/**
@@ -95,6 +118,7 @@ void Fl_Label::measure(int& W, int& H) const {
return;
}
+// if (W > 0) W -= h_margin_;
Fl_Label_Measure_F* f = ::measure[type]; if (!f) f = fl_normal_measure;
f(this, W, H);
}