FLTK logo

Re: [fltk.general] cancel event on FL_Text_Editor

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: cancel event on FL_Text_Editor Greg Ercolano Mar 12, 2021  
 


On 3/12/21 1:41 PM, danielc...@gmail.com wrote:
Hi, is it possible to add a cancel event on FL_Text_Editor?
I want on enter key press to do a method instead a new line.
I know how to capture enter key press, I just want to cancel the new line.


    To prevent the Enter key from inserting a new line into the editor,
    just return from your subclass's handle() method when the FL_ENTER
    key goes up and down.

    That will block the event from ever being seen by the Fl_Text_Editor,
    preventing it from being 'typed'.

    And of course you can call your method instead when that happens.

    Just be sure the event doesn't get to the text editor, both the "key up"
    and the "key down" events.

    So basically (code not tested, may contain typos, an exercise for the reader to solve):



void YourSubclass::handle(int e) {
    if ( e == FL_KEYUP || e == FL_KEYDOWN )
        if ( Fl::event_key() == FL_Enter || FL_KP_Enter ) {
            // Enter key was hit or released
            // Do what you want here, but make sure you DONT
            // let the event be seen by Fl_Text_Editor::handle().
            return 1;        // return, indicating the event was handled by you
        }
    }
    // ..possibly other logic here..
    return Fl_Text_Editor::handle(e);  // let all other events be handle()ed by the text editor
}

--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/c96d7420-6757-446e-5b34-cc8bff3f5ee8%40seriss.com.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.