Discussion:
position about Fl_Input' text
Robert Chan
2006-07-11 01:59:31 UTC
Permalink
Hi,
I have a question about Fl_Input.
It's text always at top left.Can I set the text to right top.

--


Best Regards,
Robert
Jim Wilson
2006-07-11 13:17:30 UTC
Permalink
Post by Robert Chan
It's text always at top left.Can I set the text to right top.
Do you mean the widget label, the ubiquitous adornment that typically
serves as a prompt for the data to be entered into the Fl_Input's interior?

http://fltk.org/doc-1.1/Fl_Widget.html#Fl_Widget.align

Jim Wilson
Gainesville, FL
Robert Chan
2006-07-12 00:29:47 UTC
Permalink
I'm sorry,My meaning is the content that the controlling part reveals,not
the label.
--


Best Regards,
Robert
MacArthur, Ian (SELEX) (UK)
2006-07-12 09:21:44 UTC
Permalink
If I follow this thread correctly, you are asking whether it is possible
to right-justify the text in a Fl_Input field, rather than the default
left-justified layout?

I don't think there is a way of doing that with fltk-1 (although I could
very well be wrong) as I looked for such a method before, but could not
find it.

I was writing a simple "pocket calculator" style app at the time, and
wanted the "display" to be right-justified, as that seems to be the norm
in such devices.
Anyway, I ended up writing as simple subclass of the Fl widget that did
the "right thing" in its draw method.
Perhaps there is an even easier way, but I did not find it, and this way
was pretty easy anyway!
--
Ian

********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************
Albrecht Schlosser
2006-07-19 07:47:15 UTC
Permalink
Post by MacArthur, Ian (SELEX) (UK)
If I follow this thread correctly, you are asking whether it is possible
to right-justify the text in a Fl_Input field, rather than the default
left-justified layout?
I don't think there is a way of doing that with fltk-1 (although I could
very well be wrong) as I looked for such a method before, but could not
find it.
I was writing a simple "pocket calculator" style app at the time, and
wanted the "display" to be right-justified, as that seems to be the norm
in such devices.
Anyway, I ended up writing as simple subclass of the Fl widget that did
the "right thing" in its draw method.
If I would do this, I would

(a) use a fixed font (FL_HELVETICA ?)
(b) format the string to have enough leading spaces
(c) use the handle method to catch FL_KEYBOARD events, modify the string
accordingly, setting the new value() and (maybe) call redraw() after this.

I did similar things, checking each key entered, and maybe converting characters
to upper case, and then calling Fl_Input::insert(), IIRC.

Just a thought ...

Albrecht

matthiasm
2006-07-12 09:22:08 UTC
Permalink
Post by Robert Chan
I'm sorry,My meaning is the content that the controlling part
reveals,not
the label.
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.

----
http://robowerk.com/
Ian MacArthur
2006-07-12 16:45:44 UTC
Permalink
Post by matthiasm
I'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 */
-------------------------------
Robert Chan
2006-07-13 02:43:52 UTC
Permalink
thanks ,all
Loading...