FLTK logo

Re: [fltk.general] Right-justify value in Fl_Value_Output

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: Right-justify value in Fl_Value_Output Greg Ercolano Jun 01, 2021  
 

On 5/31/21 7:04 AM, Fady Megally wrote:

I apologize if I am missing something obvious here but does Fl_Value_Output allow for changing the justification of the value out of the box ? trying to right justify the 7-seg oil temp number here. will have other value below and want the decimals to be aligned.

    If you use an Fl_Output with a fixed width font like FL_COURIER, you can use sprintf()
    to pad the floating point value to a fixed number of digits so that it right justifies, e.g.:

        sprintf(s, "%6.1f", float_val);
        output->value(s);

    ..and make sure the Fl_Value_Output is large enough to show that many digits.
    Complete example below:



#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Output.H>

Fl_Window *G_win = 0;
Fl_Output *G_out = 0;

void Timer_CB(void*)
{
    // Running floating point number that changes each timer tick
    static float f = 0;
    f += 10.3;
    if ( f > 500 ) f = 0;

    // Right padded 6 digit
    char s[80]; sprintf(s, "%6.1f", f);
    G_out->value(s);

    Fl::repeat_timeout(0.5, Timer_CB);
}

int main()
{
    // Window
    G_win = new Fl_Window(640,480);
    G_win->color(0xa0a0a000);   // bg

    // Digit Display
    G_out = new Fl_Output(10,10,120,40,"Oil Temp");
    G_out->align(FL_ALIGN_CENTER|FL_ALIGN_BOTTOM);
    G_out->labelcolor(FL_WHITE);
    G_out->color(FL_BLACK);
    G_out->textcolor(FL_GREEN);
    G_out->textfont(FL_COURIER);
    G_out->textsize(24);

    G_win->show();                 // ADDED
    Fl::add_timeout(0.5, Timer_CB);
    return Fl::run();           // ADDED
}

--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/46285c2b-2845-3f05-be45-db7adf640344%40seriss.com.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.