fltk gui question - how to auto scroll down?

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Post Reply
blue21
Posts: 7
Joined: Oct 11, 2021 8:59

fltk gui question - how to auto scroll down?

Post by blue21 »

hi

sorry for a silly question but I trying to dev a gui app with fltk library in freebasic - how do I make the fl_text_editor widget auto scroll down to the end of the last text - I've been searching on the documentation and manuals and in the forum and just couldn't wrap my brain on that...

here is the code I have so far:

Code: Select all

#INCLUDE "fltk-c.bi"

'Window and widgets:
DIM SHARED AS Fl_Window PTR Window_Main
DIM SHARED AS Fl_Input PTR Input_text
DIM SHARED AS Fl_Text_Editor PTR Editor_text
DIM SHARED AS Fl_Text_Buffer PTR Buffer_text
'dim shared as Fl_Text_Display ptr pTextDisplay
DIM SHARED AS Fl_Button PTR Button_Copy


SUB Create_Window_Main ()
'Window with widgets:

    Window_Main = Fl_WindowNew (800, 600, "test gui")
    Input_text = Fl_InputNew (100 ,580 ,580, 20, "Text Input")
    Editor_text = Fl_Text_EditorNew (10, 10, 500, 500)
    Button_Copy = Fl_Return_ButtonNew (700, 580, 100, 20, "Copy")
    Fl_Input_SetValue (Input_text, "Edit me!")
    
    'Text editor with an editable text:
    Buffer_text = Fl_Text_BufferNew ()
    Fl_Text_DisplaySetBuffer (Editor_text, Buffer_text)
    Fl_Text_BufferSetText (Buffer_text, "Always look at the right side of life! Be happy, don't worry!")
  
	
END SUB

'

SUB Button_Copy_Event CDECL (widget AS FL_Widget PTR)
'Callback function for Button

  DIM text AS STRING 


  text = *Fl_Input_GetValue (Input_text)
  Fl_Text_BufferAppend (buffer_text, !"\n" & text & !"\n")

  text = ""

END SUB


'Main program:
Create_Window_Main ()
'Fl_WidgetSetCallback0 (Button_Copy, @Button_Copy_Event())
Fl_WidgetSetCallback0 (Button_Copy, @Button_Copy_Event)
Fl_WindowShow (Window_Main)
Fl_Run

END
Imortis
Moderator
Posts: 1923
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: fltk gui question - how to auto scroll down?

Post by Imortis »

You probably one one of these two functions:

Code: Select all

declare function kf_page_down (byval c as long, byval te as Fl_Text_Editor ptr) as long
declare function kf_down      (byval c as long, byval te as Fl_Text_Editor ptr) as long
The "C" parameter in both of those is unused.

Code: Select all

'Moves down one page in the editor
kf_page_down(0, *TextEditor)

'Moves down one line in the editor
kf_down(0, *TextEditor)
Edit:
Found exactly what you are looking for:

Code: Select all

declare function kf_move      (byval c as long, byval te as Fl_Text_Editor ptr) as long

Code: Select all

'Moves to the end of the document.
kf_move(FL_End, *TextEditor)
blue21
Posts: 7
Joined: Oct 11, 2021 8:59

Re: fltk gui question - how to auto scroll down?

Post by blue21 »

hi imortis...

thank you for your help... as well as to the answer how to make only a vertical scroll bar (word wrapper) to the text editor

Code: Select all

Fl_Text_DisplayWrapMode(*Text_Display, WRAP_AT_BOUNDS, 0)
Post Reply