Author: matt
Date: 2010-10-30 14:32:15 -0700 (Sat, 30 Oct 2010)
New Revision: 7782
Log:
Fixed label alignment (STR #2436)

Modified:
   branches/branch-1.3/CHANGES
   branches/branch-1.3/src/Fl.cxx
   branches/branch-1.3/src/Fl_Group.cxx
   branches/branch-1.3/src/fl_draw.cxx
   branches/branch-1.3/test/label.cxx

Modified: branches/branch-1.3/CHANGES
===================================================================
--- branches/branch-1.3/CHANGES 2010-10-30 20:16:43 UTC (rev 7781)
+++ branches/branch-1.3/CHANGES 2010-10-30 21:32:15 UTC (rev 7782)
@@ -1,5 +1,6 @@
 CHANGES IN FLTK 1.3.0
 
+       - Fixed label alignment (STR #2436)
        - Added interface to set color chooser mode (STR #2407)
        - Fixed compile errors when HAVE_LIBJPEG was not defined 
          (STR #2382)

Modified: branches/branch-1.3/src/Fl.cxx
===================================================================
--- branches/branch-1.3/src/Fl.cxx      2010-10-30 20:16:43 UTC (rev 7781)
+++ branches/branch-1.3/src/Fl.cxx      2010-10-30 21:32:15 UTC (rev 7782)
@@ -1414,6 +1414,7 @@
       W += 5; // Add a little to the size of the label to cover overflow
       H += 5;
 
+      // FIXME: this does not take all outside label positions into account!
       if (align() & FL_ALIGN_BOTTOM) {
        window()->damage(FL_DAMAGE_EXPOSE, x(), y() + h(), w(), H);
       } else if (align() & FL_ALIGN_TOP) {

Modified: branches/branch-1.3/src/Fl_Group.cxx
===================================================================
--- branches/branch-1.3/src/Fl_Group.cxx        2010-10-30 20:16:43 UTC (rev 
7781)
+++ branches/branch-1.3/src/Fl_Group.cxx        2010-10-30 21:32:15 UTC (rev 
7782)
@@ -789,38 +789,44 @@
   int Y = widget.y();
   int W = widget.w();
   int H = widget.h();
+  int wx, wy;
+  if (const_cast<Fl_Group*>(this)->as_window()) {
+    wx = wy = 0;
+  } else {
+    wx = x(); wy = y();
+  }
   if ( (a & 0x0f) == FL_ALIGN_LEFT_TOP ) {
     a = (a &~0x0f ) | FL_ALIGN_TOP_RIGHT;
-    X = x();
+    X = wx;
     W = widget.x()-X-3;
   } else if ( (a & 0x0f) == FL_ALIGN_LEFT_BOTTOM ) {
     a = (a &~0x0f ) | FL_ALIGN_BOTTOM_RIGHT; 
-    X = x();
+    X = wx;
     W = widget.x()-X-3;
   } else if ( (a & 0x0f) == FL_ALIGN_RIGHT_TOP ) {
     a = (a &~0x0f ) | FL_ALIGN_TOP_LEFT; 
     X = X+W+3;
-    W = x()+this->w()-X;
+    W = wx+this->w()-X;
   } else if ( (a & 0x0f) == FL_ALIGN_RIGHT_BOTTOM ) {
     a = (a &~0x0f ) | FL_ALIGN_BOTTOM_LEFT; 
     X = X+W+3;
-    W = x()+this->w()-X;
+    W = wx+this->w()-X;
   } else if (a & FL_ALIGN_TOP) {
     a ^= (FL_ALIGN_BOTTOM|FL_ALIGN_TOP);
-    Y = y();
+    Y = wy;
     H = widget.y()-Y;
   } else if (a & FL_ALIGN_BOTTOM) {
     a ^= (FL_ALIGN_BOTTOM|FL_ALIGN_TOP);
     Y = Y+H;
-    H = y()+h()-Y;
+    H = wy+h()-Y;
   } else if (a & FL_ALIGN_LEFT) {
     a ^= (FL_ALIGN_LEFT|FL_ALIGN_RIGHT);
-    X = x();
+    X = wx;
     W = widget.x()-X-3;
   } else if (a & FL_ALIGN_RIGHT) {
     a ^= (FL_ALIGN_LEFT|FL_ALIGN_RIGHT);
     X = X+W+3;
-    W = x()+this->w()-X;
+    W = wx+this->w()-X;
   }
   widget.draw_label(X,Y,W,H,(Fl_Align)a);
 }

Modified: branches/branch-1.3/src/fl_draw.cxx
===================================================================
--- branches/branch-1.3/src/fl_draw.cxx 2010-10-30 20:16:43 UTC (rev 7781)
+++ branches/branch-1.3/src/fl_draw.cxx 2010-10-30 21:32:15 UTC (rev 7782)
@@ -193,7 +193,7 @@
   char buf[MAXBUF];
   int buflen;
   char symbol[2][255], *symptr;
-  int symwidth[2], symoffset, symtotal;
+  int symwidth[2], symoffset, symtotal, imgtotal;
 
   // count how many lines and put the last one into the buffer:
   int lines;
@@ -226,13 +226,14 @@
   }
 
   symtotal = symwidth[0] + symwidth[1];
+  imgtotal = (img && (align&FL_ALIGN_IMAGE_NEXT_TO_TEXT)) ? img->w() : 0;
   
   int strw = 0;
   int strh;
 
   if (str) {
     for (p = str, lines=0; p;) {
-      e = fl_expand_text(p, buf, MAXBUF, w - symtotal, buflen, width, 
+      e = fl_expand_text(p, buf, MAXBUF, w - symtotal - imgtotal, buflen, 
width, 
                          align&FL_ALIGN_WRAP, draw_symbols);
       if (strw<width) strw = (int)width;
       lines++;
@@ -299,7 +300,7 @@
   if (str) {
     int desc = fl_descent();
     for (p=str; ; ypos += height) {
-      if (lines>1) e = fl_expand_text(p, buf, MAXBUF, w - symtotal, buflen, 
+      if (lines>1) e = fl_expand_text(p, buf, MAXBUF, w - symtotal - imgtotal, 
buflen, 
                                width, align&FL_ALIGN_WRAP, draw_symbols);
       else e = "";
 

Modified: branches/branch-1.3/test/label.cxx
===================================================================
--- branches/branch-1.3/test/label.cxx  2010-10-30 20:16:43 UTC (rev 7781)
+++ branches/branch-1.3/test/label.cxx  2010-10-30 21:32:15 UTC (rev 7782)
@@ -56,7 +56,7 @@
   if (clipb->value()) i |= FL_ALIGN_CLIP;
   if (wrapb->value()) i |= FL_ALIGN_WRAP;
   if (imageovertextb->value()) i |= FL_ALIGN_TEXT_OVER_IMAGE;
-  if (imagenexttotextb->value()) i |= FL_ALIGN_TEXT_NEXT_TO_IMAGE;
+  if (imagenexttotextb->value()) i |= FL_ALIGN_IMAGE_NEXT_TO_TEXT;
   if (imagebackdropb->value()) i |= FL_ALIGN_IMAGE_BACKDROP;
   text->align(i);
   window->redraw();

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to