Post by matthiasmI'm sorry, My meaning is the content that the controlling part
reveals
You can not right align the text in Fl_Input_ derived stock widgets.
You could write your own derived class though. It should not be too
hard.
And here's one I made earlier, in a very (very) crude fashion... Mostly works, except that selection of text in the widget using the mouse is oddly offset. Selection from the keyboard works OK though, if you need it!
Fixing the mouse selection is left as an exercise for the reader, as I can't be bothered.
-------------------------
#include <string.h>
#include <FL/Fl.H>
#include <FL/fl_draw.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Input.H>
//////////////////////////////////////////////////////////////
class input_R : public Fl_Input
{
public:
input_R(int x, int y, int w, int h, const char *title = 0) : Fl_Input(x, y, w, h, title){};
protected:
void draw(void);
private:
};
void input_R::draw(void)
{
if (input_type() == FL_HIDDEN_INPUT) return;
// Simplest to just redraw the whole box every time...
Fl_Boxtype b = box();
damage(FL_DAMAGE_ALL);
draw_box(b, color());
int xo = x()+Fl::box_dx(b);
int yo = y()+Fl::box_dy(b);
int wo = w()-Fl::box_dw(b);
int ho = h()-Fl::box_dh(b);
int wt, ht;
char buf[128];
// How long is the string to display?
strncpy(buf, value(), 128);
wt = 0; ht = 0;
fl_measure(buf, wt, ht);
// Make the text window be at the right hand end
wt = wt + 5;
xo = xo + wo - wt;
wo = wt;
// Update the text window
Fl_Input_::drawtext(xo, yo, wo, ho);
} // draw
//////////////////////////////////////////////////////////////
static Fl_Double_Window *main_win=(Fl_Double_Window *)0;
static void cb_Quit(Fl_Button*, void*) {
main_win->hide();
}
static input_R *txt_in=(input_R *)0;
int main(int argc, char **argv) {
Fl_Double_Window* w;
{ Fl_Double_Window* o = main_win = new Fl_Double_Window(221, 144, "Input Test");
w = o;
{ Fl_Button* o = new Fl_Button(150, 105, 64, 30, "Quit");
o->callback((Fl_Callback*)cb_Quit);
}
txt_in = new input_R(65, 21, 145, 24, "input:");
o->end();
}
w->show(argc, argv);
return Fl::run();
}
/* End of File */
-------------------------------