FLTK logo

Re: [fltk.general] Search widget

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: Search widget Greg Ercolano Sep 09, 2020  
 
> Would it be possible to open the menu from the callbackfunction (choice_cb).
> I want the menu to open automatically when I have a good match.

	Yes; Fl_Input_Choice is a conflation of Fl_Input and Fl_Menu_Button,
	and the class exposes those two classes with the methods:

		input() -- returns the Fl_Input instance
		menubutton() -- returns the Fl_Menu_Button instance

	..and the docs for Fl_Menu_Button indicate you can use popup() to post the menu, e.g.

_________________________________________________________________________________________
Fl_Menu_Button::popup():
https://www.fltk.org/doc-1.4/classFl__Menu__Button.html#a9c4b549c0fad2380153a64aa2d8e7d38


Act exactly as though the user clicked the button or typed the shortcut key.

The menu appears, it waits for the user to pick an item, and if they pick one
it sets value() and does the callback or sets changed() as described above.
The menu item is returned or NULL if the user dismisses the menu.
_________________________________________________________________________________________

	Here's a little demo that automatically posts the menu after the app
	has been running for 3 seconds:

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Input_Choice.H>
void timer_cb(void *data) {
    Fl_Input_Choice *choice = (Fl_Input_Choice*)data;
    choice->menubutton()->popup();        // post the menu
}
int main()
{
    Fl_Window *window = new Fl_Window(320,200);
    Fl_Input_Choice *choice = new Fl_Input_Choice(180,10,140,25, "Choice");
    choice->add("Aaa");
    choice->add("Bbb");
    choice->add("Ccc");
    window->end();
    Fl::add_timeout(3.0, timer_cb, (void*)choice);
    window->show();
    return Fl::run();
}


	Trouble is, as I predicted in my last post, when the menu posts, it steals keyboard
	focus, which would be bad if triggered on keypresses from the user typing into the
	input field.

	So for instance when I run the above app, and start typing into the input field before
	the 3 seconds expire, when the menu suddenly posts, I can no longer keep typing.

	I imagine the popup menu must be doing a 'grab' or something, which can /maybe/ be
	disabled, I'm not sure.. if it can't, that means this might be a tough route to go,
	and a more fully custom widget might have to be crafted.

-- 
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/86ca4414-38c7-e8e8-5ec1-d175e8fe2127%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'.