diff options
| author | Albrecht Schlosser <albrechts.fltk@online.de> | 2017-02-27 17:00:41 +0000 |
|---|---|---|
| committer | Albrecht Schlosser <albrechts.fltk@online.de> | 2017-02-27 17:00:41 +0000 |
| commit | a60f99d4a1a94bd19125dce89555983f2fa4841c (patch) | |
| tree | e726a8933bfb3e6c901aff3fb2d19835f09b4034 /src | |
| parent | 2d18660f5cf06acff7446dd9983e3f76b97cb420 (diff) | |
Improve label alignment docs and border case implementations.
Make clear that some alignment bit combinations are "illegal" and yield
undefined behavior that can be changed without notice.
Fix label alignment in some border cases where illegal bit combinations like
FL_ALIGN_LEFT and FL_ALIGN_RIGHT or FL_ALIGN_TOP and FL_ALIGN_BOTTOM are
both set, respectively.
Todo: There appears to be inconsistent handling WRT these "illegal" cases,
for instance with inside labels as opposed to outside labels, such that
the behavior seems to be unpredictable. See test/label.cxx.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12181 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_Group.cxx | 28 | ||||
| -rw-r--r-- | src/fl_labeltype.cxx | 12 |
2 files changed, 26 insertions, 14 deletions
diff --git a/src/Fl_Group.cxx b/src/Fl_Group.cxx index 7b10dc9f3..b4ef6d91c 100644 --- a/src/Fl_Group.cxx +++ b/src/Fl_Group.cxx @@ -793,36 +793,40 @@ void Fl_Group::draw_outside_label(const Fl_Widget& widget) const { } else { wx = x(); wy = y(); } - if ( (a & 0x0f) == FL_ALIGN_LEFT_TOP ) { - a = (a &~0x0f ) | FL_ALIGN_TOP_RIGHT; + if ( (a & FL_ALIGN_POSITION_MASK) == FL_ALIGN_LEFT_TOP ) { + a = (a &(~FL_ALIGN_POSITION_MASK) ) | FL_ALIGN_TOP_RIGHT; X = wx; W = widget.x()-X-3; - } else if ( (a & 0x0f) == FL_ALIGN_LEFT_BOTTOM ) { - a = (a &~0x0f ) | FL_ALIGN_BOTTOM_RIGHT; + } else if ( (a & FL_ALIGN_POSITION_MASK) == FL_ALIGN_LEFT_BOTTOM ) { + a = (a &(~FL_ALIGN_POSITION_MASK) ) | FL_ALIGN_BOTTOM_RIGHT; X = wx; W = widget.x()-X-3; - } else if ( (a & 0x0f) == FL_ALIGN_RIGHT_TOP ) { - a = (a &~0x0f ) | FL_ALIGN_TOP_LEFT; + } else if ( (a & FL_ALIGN_POSITION_MASK) == FL_ALIGN_RIGHT_TOP ) { + a = (a &(~FL_ALIGN_POSITION_MASK) ) | FL_ALIGN_TOP_LEFT; X = X+W+3; W = wx+this->w()-X; - } else if ( (a & 0x0f) == FL_ALIGN_RIGHT_BOTTOM ) { - a = (a &~0x0f ) | FL_ALIGN_BOTTOM_LEFT; + } else if ( (a & FL_ALIGN_POSITION_MASK) == FL_ALIGN_RIGHT_BOTTOM ) { + a = (a &(~FL_ALIGN_POSITION_MASK) ) | FL_ALIGN_BOTTOM_LEFT; X = X+W+3; W = wx+this->w()-X; } else if (a & FL_ALIGN_TOP) { - a ^= (FL_ALIGN_BOTTOM|FL_ALIGN_TOP); + a ^= FL_ALIGN_TOP; + a |= FL_ALIGN_BOTTOM; Y = wy; H = widget.y()-Y; } else if (a & FL_ALIGN_BOTTOM) { - a ^= (FL_ALIGN_BOTTOM|FL_ALIGN_TOP); + a ^= FL_ALIGN_BOTTOM; + a |= FL_ALIGN_TOP; Y = Y+H; H = wy+h()-Y; } else if (a & FL_ALIGN_LEFT) { - a ^= (FL_ALIGN_LEFT|FL_ALIGN_RIGHT); + a ^= FL_ALIGN_LEFT; + a |= FL_ALIGN_RIGHT; X = wx; W = widget.x()-X-3; } else if (a & FL_ALIGN_RIGHT) { - a ^= (FL_ALIGN_LEFT|FL_ALIGN_RIGHT); + a ^= FL_ALIGN_RIGHT; + a |= FL_ALIGN_LEFT; X = X+W+3; W = wx+this->w()-X; } diff --git a/src/fl_labeltype.cxx b/src/fl_labeltype.cxx index ce86e7f33..b8c84f46e 100644 --- a/src/fl_labeltype.cxx +++ b/src/fl_labeltype.cxx @@ -42,8 +42,16 @@ fl_normal_measure(const Fl_Label* o, int& W, int& H) { fl_font(o->font, o->size); fl_measure(o->value, W, H); if (o->image) { - if (o->image->w() > W) W = o->image->w(); - H += o->image->h(); + int iw = o->image->w(), ih = o->image->h(); + if (o->align_ & FL_ALIGN_IMAGE_BACKDROP) { // backdrop: ignore + // ignore backdrop image for calculation + } else if (o->align_ & FL_ALIGN_IMAGE_NEXT_TO_TEXT) { // text and image side by side + W += iw; + if (ih > H) H = ih; + } else { + if (iw > W) W = iw; + H += ih; + } } } |
