Browse Source

Various fixes:

o pre-selection of first cell
	o simplified input selection
	o Enabled ESC to quit app (original app did not handle it)
	o Ignore Fl_Tab to make tab navigation operate as expected



git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7750 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
pull/49/head
Greg Ercolano 15 years ago
parent
commit
347007964e
  1. 11
      examples/table-with-keyboard-nav.cxx

11
examples/table-with-keyboard-nav.cxx

@ -248,8 +248,11 @@ void SingleInput::event_callback2() {
//FALLTHROUGH //FALLTHROUGH
case FL_KEYBOARD: case FL_KEYBOARD:
if (Fl::event() == FL_KEYBOARD && Fl::e_length == 0) { if ( Fl::event_key() == FL_Escape )
return; exit(0); // ESC closes app
if (Fl::event() == FL_KEYBOARD &&
( Fl::e_length == 0 || Fl::event_key() == FL_Tab) ) {
return; // ignore eg. keyboard nav keys
} }
if (C == cols()-1 || R == rows()-1) return; if (C == cols()-1 || R == rows()-1) return;
if (input->visible()) input->do_callback(); if (input->visible()) input->do_callback();
@ -262,8 +265,7 @@ void SingleInput::event_callback2() {
char s[30]; char s[30];
sprintf(s, "%d", values[R][C]); sprintf(s, "%d", values[R][C]);
input->value(s); input->value(s);
input->position(strlen(s)); // position cursor at end of string input->position(0,strlen(s)); // pre-highlight (so typing replaces contents)
input->mark(0); // pre-highlight (so typing replaces contents)
input->show(); input->show();
input->take_focus(); input->take_focus();
if (Fl::event() == FL_KEYBOARD && Fl::e_text[0] != '\r') { if (Fl::event() == FL_KEYBOARD && Fl::e_text[0] != '\r') {
@ -324,6 +326,7 @@ int main() {
table->col_resize(1); table->col_resize(1);
table->cols(11); table->cols(11);
table->col_width_all(70); table->col_width_all(70);
table->set_selection(0,0,0,0); // select top/left cell
// Add children to window // Add children to window
win.begin(); win.begin();

Loading…
Cancel
Save