Get current value from Fl_Value_Slider

6 views
Skip to first unread message

Dave Branson

unread,
Oct 16, 2020, 12:39:41 PM10/16/20
to fltk.general
I am new to the use of FLTK, and am having a problem with my initial test use of the Value Slider widget.  I am attempting to use this slider to extract values for a controls project, but cannot seem to grab the current value as the slider is exercised.  A sample of my test code is below.  Any advise would be welcomed.
valsu slider test.JPG

imm

unread,
Oct 16, 2020, 12:46:38 PM10/16/20
to general fltk
On Fri, 16 Oct 2020 at 17:39, Dave Branson wrote:
>
> I am new to the use of FLTK, and am having a problem with my initial test use of the Value Slider widget. I am attempting to use this slider to extract values for a controls project, but cannot seem to grab the current value as the slider is exercised. A sample of my test code is below. Any advise would be welcomed.


Umm... Where to start...

I think your best bet might be to look in the test folder, in
particular at the valuators demo, and see how that does this - in
essence, any GUI will typically be event driven, so you cannot just
read it in main().

In fltk, the event handling is done via callbacks (though other
toolkits may take different approaches, this method is fairly common)
so you will need to create callbacks for the events that come from
your widgets.

As I say, the test and example folders in the fltk checkout show some
basics, and it worth having a look at Greg's examples too:
http://seriss.com/people/erco/fltk/

Beyond that, there are some tutorial videos around the web you can
refer too also.

Albrecht Schlosser

unread,
Oct 16, 2020, 12:56:14 PM10/16/20
to fltkg...@googlegroups.com
Hi Dave,

it's great that you posted your code, but an image is not very helpful.
You can attach your source file (.cxx, .cpp, whatever) here w/o issues.
If we had the source code we could easily (test and) modify it to show
you how to proceed.

Another important info would be the OS and compiler/toolchain you're
using. If it's Windows (maybe VS ?), then printf doesn't work as you may
assume.

That said, your code does only print the value right at the beginning of
the program (what does it print, BTW?) but not during runtime when the
slider is moved.

(See also Ian's post which I saw while writing this.)

I understand that the latter is what you want. If you want to access the
value during runtime you need either a callback or another means like a
button or timer to access the value whenever you need. The most direct
way would likely be a callback with an appropriate when() condition that
gets triggered when the slider is moved, something like (untested!):

void slider_cb(Fl_Widget *w, void *v) {

Fl_Value_Slider *sl = (Fl_Value_Slider *)w;
printf("Slider value = %d\n", sl->value());

}

But note, this is not going to output anything if you're using Windows.
Please ask again if you need further advice.
Reply all
Reply to author
Forward
0 new messages