Trying to play with Input/Output Widget´s

336 views
Skip to first unread message

Badpit77

unread,
Aug 7, 2014, 2:53:52 PM8/7/14
to fltkg...@googlegroups.com
Hello Community
I am a beginner in C++ and also with FLTK.(and not really good in english 8 i know ;-)  )
and so i play around with my first steps in FLTK.
 in my first programm i have one Fl_Input and one Fl_Output Widget.
now ich wont to write something in the Input Widget,manipulate it, and copy it to the Output Widget.
as reference i use the FLTK page from Robert Arkiletian  (i dont know are links allowed ?)
but my tests are all , misses.
all examples at the side from Robert uses a copy button, i want to copy without a extra button, but i dont know how.
yours sincerly Badpit



Greg Ercolano

unread,
Aug 7, 2014, 4:19:26 PM8/7/14
to fltkg...@googlegroups.com
Show your code, and we can help you fix it.

If you're new to C++ and FLTK, have a look at these videos.
They're somewhat old, but still relevant:
http://seriss.com/people/erco/fltk-videos/

Greg Ercolano

unread,
Aug 7, 2014, 4:25:03 PM8/7/14
to fltkg...@googlegroups.com
On 08/07/14 13:19, Greg Ercolano wrote:
> On 08/07/14 11:53, Badpit77 wrote:
>> in my first programm i have one Fl_Input and one Fl_Output Widget.
>> now [I want] to write something in the Input Widget,manipulate it, and copy it to the Output Widget.
>
> Show your code, and we can help you fix it.

Oh, and just guessing, if you want to manipulate the input widget
from code, you can use the value() method to get and set its value,
e.g. input->value("Hello"); and printf("Input's value is %s\n", input->value());

With Fl_Output would be the same thing; output->value("Hello"); and
printf("Output's value is %s\n", output->value());

If you want it so that if the user types into the Fl_Input widget
and hitting ENTER copies the data to Fl_Output, create a callback()
for the input widget to trigger code that takes input->value()
and sets it to output->value().

But show your code so far, and we can guide you better.


Badpit77

unread,
Aug 9, 2014, 1:41:04 PM8/9/14
to fltkg...@googlegroups.com, erco_...@seriss.com


Hello Greg
this is my Source Code
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Output.H>


using namespace std;

 
static void f_output(Fl_Widget * output,char* text)
{

Fl_Output *outp=(Fl_Output*)output;

outp
->value(text);
};



int main (int argc, char ** argv)
{

double Zahl;
Fl_Window *window;  
 
Fl_Input *input;
 
Fl_Output *output;


  window
= new Fl_Window (600, 400);
  input
= new Fl_Input (100, 200, 260, 20, "Input:");


  output
= new Fl_Output (100,250,260,20,"Output:");

   
const char *text =input->value();


  output
->value(text);

 input
->callback(output,text);
  window
->show();

  window
->end ();
  window
->show (argc, argv);

 
return(Fl::run());
}

 Yes i want to copy the code with the ENTER Key to the Output Widget.
but i have now idea how i write the callback function correctly.


Greg Ercolano

unread,
Aug 9, 2014, 3:30:45 PM8/9/14
to fltkg...@googlegroups.com
On 08/09/14 10:41, Badpit77 wrote:
> Yes i want to copy the code with the ENTER Key to the Output Widget.
> but i have [no] idea how i write the callback function correctly.

Here's your code with the mods to make it work.
I removed some extraneous stuff to keep it simple.

--- snip

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

static void f_output(Fl_Widget *w, void *userdata)
{
Fl_Input *in = (Fl_Input*)w; // get input widget from first argument
Fl_Output *out = (Fl_Output*)userdata; // get output widget from userdata
out->value(in->value()); // set value of output to value of input
}

int main (int argc, char ** argv)
{
Fl_Window *window;
Fl_Input *input;
Fl_Output *output;

window = new Fl_Window(600, 400);
input = new Fl_Input(100, 200, 260, 20, "Input:");
output = new Fl_Output(100, 250, 260, 20, "Output:");

// Set input's callback to invoke 'MyCallback'
// and pass a pointer to the output widget as 'userdata':
//
input->callback(f_output, (void*)output);
// /|\ /|\ //
// | | //
// | 'user data' will be a pointer //
// | to the output widget //
// | //
// The callback function (should not be a widget) //
window->end ();
window->show (argc, argv);
return(Fl::run());
}

--- snip

Badpit77

unread,
Aug 10, 2014, 11:23:25 AM8/10/14
to fltkg...@googlegroups.com, erco_...@seriss.com

Thank you,
now it runs
... ;-)
Reply all
Reply to author
Forward
0 new messages