changeset 2113:01c1a5571552

draw the labels when hidden inputs are shown In fltk-1.3, it doesn't draw inside labels for Fl_Inputs, and it wasn't very nice anyway. Here I move them to the left. Johannes took a look at this change: "The only issue I could think of is that the additional draw_outside_label() would cause excessive redraws for some reason. But I didn't see anything like that during short testing here."
author corvid <corvid@lavabit.com>
date Sun, 03 Jul 2011 19:45:26 +0000
parents 842076515462
children 420e8aa657ff
files dw/fltkui.cc dw/fltkui.hh dw/fltkviewbase.cc
diffstat 3 files changed, 28 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/dw/fltkui.cc	Thu Jun 30 13:56:05 2011 -0400
+++ b/dw/fltkui.cc	Sun Jul 03 19:45:26 2011 +0000
@@ -471,6 +471,7 @@
    this->maxLength = maxLength;
    this->password = password;
    this->label = label ? strdup(label) : NULL;
+   this->label_w = 0;
 
    initText = NULL;
    editable = false;
@@ -499,7 +500,7 @@
 
    if (label) {
       input->label(label);
-      input->align(FL_ALIGN_INSIDE);
+      input->align(FL_ALIGN_LEFT);
    }
    if (initText)
       input->value (initText);
@@ -518,6 +519,13 @@
    in->cursor_color(in->textcolor());
    in->textsize(in->labelsize());
    in->textfont(in->labelfont());
+
+   if (label) {
+      int h;
+      label_w = 0;
+      widget->measure_label(label_w, h);
+      label_w += RELIEF_X_THICKNESS;
+   }
 }
 
 void FltkEntryResource::setDisplayed(bool displayed)
@@ -534,7 +542,7 @@
       requisition->width =
          (int)fl_width ('n')
          * (maxLength == UNLIMITED_MAX_LENGTH ? 10 : maxLength)
-         + 2 * RELIEF_X_THICKNESS;
+         + label_w + (2 * RELIEF_X_THICKNESS);
       requisition->ascent = font->ascent + RELIEF_Y_THICKNESS;
       requisition->descent = font->descent + RELIEF_Y_THICKNESS;
    } else {
@@ -544,6 +552,21 @@
    }
 }
 
+void FltkEntryResource::sizeAllocate (core::Allocation *allocation)
+{
+   if (!label) {
+      FltkResource::sizeAllocate(allocation);
+   } else {
+      this->allocation = *allocation;
+
+      /* push the Fl_Input over to the right of the label */
+      core::Allocation a = this->allocation;
+      a.x += this->label_w;
+      a.width -= this->label_w;
+      view->allocateFltkWidget (widget, &a);
+   }
+}
+
 void FltkEntryResource::widgetCallback (Fl_Widget *widget, void *data)
 {
    ((FltkEntryResource*)data)->emitActivate ();
--- a/dw/fltkui.hh	Thu Jun 30 13:56:05 2011 -0400
+++ b/dw/fltkui.hh	Sun Jul 03 19:45:26 2011 +0000
@@ -286,6 +286,7 @@
    bool password;
    const char *initText;
    char *label;
+   int label_w;
    bool editable;
 
    static void widgetCallback (Fl_Widget *widget, void *data);
@@ -301,6 +302,7 @@
    ~FltkEntryResource ();
 
    void sizeRequest (core::Requisition *requisition);
+   void sizeAllocate (core::Allocation *allocation);
 
    const char *getText ();
    void setText (const char *text);
--- a/dw/fltkviewbase.cc	Thu Jun 30 13:56:05 2011 -0400
+++ b/dw/fltkviewbase.cc	Sun Jul 03 19:45:26 2011 +0000
@@ -614,6 +614,7 @@
                                    core::Rectangle *area)
 {
    draw_child (*widget);
+   draw_outside_label(*widget);
 }
 
 } // namespace fltk