scroller test
jbcooper
c_cpp
08/15/2026 2:08 AM
3.6 KB
17
Indexable
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Input.H>
#include <FL/x.H>
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <FL/Fl_Scrollbar.H>
using namespace std;
Fl_Window* window;
Fl_Input* inpseq;
Fl_Scrollbar* scroller;
int cursor_pos;
void cb_scroller(Fl_Widget* o, void* v);
void set_scrollbar(Fl_Widget* o, void* v);
// Set up a class for the input widget with a scroll bar.
class InPaste : public Fl_Input {
static void Paste_CB(Fl_Widget*, void *userdata) {
// printf("*** PASTE ***\n");
InPaste *in = (InPaste*)userdata;
Fl::paste(*in,1);
}
public:
int handle(int e) {
switch (e) {
case FL_KEYBOARD:
// Keyboard left or right arrow keys presses need to update scrollbar
cursor_pos=inpseq->insert_position();
if ( Fl::event_key() == FL_Left ) {
cursor_pos-=1;
inpseq->insert_position(cursor_pos);
scroller->value(cursor_pos);
//cout<<"Cursor position "<<cursor_pos<<"\n";
return(1);} // (tells caller we handled this event)
if ( Fl::event_key() == FL_Right) {
cursor_pos+=1;
inpseq->insert_position(cursor_pos);
scroller->value(cursor_pos);
//cout<<"Cursor position "<<cursor_pos<<"\n";
return(1); } // (tells caller we handled this event)
break;
}
return(Fl_Input::handle(e)); // let Fl_Input handle all other events
}
InPaste(int X,int Y,int W,int H,const char*L=0):Fl_Input(X,Y,W,H,L) {
}
};
// End of paste method.
int main (int argc, char **argv){
window = new Fl_Window(600,200," test");
inpseq = new InPaste(170,50,400,30,"Paste in text here");
inpseq->when(FL_WHEN_CHANGED);
inpseq->callback(set_scrollbar);
scroller=new Fl_Scrollbar (170, 100, 400, 20);
scroller->type(FL_HORIZONTAL);
scroller->slider_size(.25); // the fractional size of the scrollbar's tab, 1/4 scollbar's size
scroller->linesize(10);
scroller->callback(cb_scroller);
window->end();
window->resizable();
window->show();
return Fl::run();
}
void cb_scroller(Fl_Widget* o, void* v){ // Scroller callback function
int scroller_value=scroller->value();
//cout<<"Scroller value "<<scroller_value<<"\n";
inpseq->insert_position(scroller_value);
}
// Callback function to get text length, set scroller limits.
void set_scrollbar(Fl_Widget* o, void* z){
int sequence_length = inpseq->size();
//cout<<"Sequence length "<<sequence_length<<"\n";
scroller->bounds(0,sequence_length);
cursor_pos=inpseq->insert_position();
//cout<<"Cursor position "<<cursor_pos<<"\n";
scroller->value(cursor_pos);
}
Editor is loading...
Leave a Comment