FLTK logo

[fltk.general] Re: HOWTO = ???->show() in a callback function

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: HOWTO = ???->show() in a callback function "lifeatt... Sep 24, 2022  
  The hack approach: declare cards globally and use it as needed.

Fl_Tabs *cards;
void but1_Callback(...) {
...
cards = new Fl_Tabs(40,40,300,200);
...

void showCards(Fl_Widget *w, void *data) {
      cards->show();
}

The FLTK callback data approach: 

void but1_Callback(...) {
...
  Fl_Tabs *cards = new Fl_Tabs(40,40,300,200);
  menu_items[1].user_data_ = cards;  // provide cards pointer as callback data
  rog->menu(menu_items); // need to use menu_items AFTER modifying it
...

void showCards(Fl_Widget *w, void *data) {
  Fl_Tabs *cards = static_cast<Fl_Tabs *>(data);  // please the compiler by casting void * to cards *
  cards->show();
}

Here is a fully "working" version [working in quotes because showCards() is correctly invoked with cards as the data parameter, but cards->show() has no effect...]

#include <FL/Fl_Window.H>
#include <FL/Fl_Radio_Round_Button.H>
#include <FL/Fl_Menu_.H>
#include <FL/Fl_Menu_Bar.H>
#include <FL/Fl_Tabs.H>

void showCards(Fl_Widget *w, void *data) {
    Fl_Tabs *cards = static_cast<Fl_Tabs *>(data);
    cards->show();
}

Fl_Menu_Item menu_items[] =
{
    {"GeneralJournal", 0, 0, 0,    FL_SUBMENU,                (uchar)FL_NORMAL_LABEL, 0, 10, FL_YELLOW},
        {"Open",   FL_ALT+'o',  showCards,  0, 0, 0, FL_ITALIC,    10, FL_YELLOW},
        {"Save",   FL_ALT+'s',    0,    0,    0, 0, 0, 10, FL_YELLOW},
        {"Cancel", FL_ALT+'a',    0,    0,    FL_MENU_DIVIDER, 0, 0, 10, FL_YELLOW},
        {"Exit",   FL_ALT+'x',    0,    0,    0,  0,  0,    10, FL_YELLOW},
        {0},                                                      
    {0,0,0,0,0,0,0,0,0}
};

void but1_Callback(Fl_Widget *w, void *d) {
  Fl_Window *window2 = new Fl_Window(625, 450);
  Fl_Menu_Bar *rog = new Fl_Menu_Bar(0, 0, 625, 25);
  Fl_Tabs *cards = new Fl_Tabs(40,40,300,200);
  cards->hide();
  menu_items[1].user_data_ = cards;
  rog->menu(menu_items);
  window2->show();
}

int main(int argc, char **argv) {
     Fl_Window *window1 = new Fl_Window(200,200,"Roger's Window");
     int x = 0;
     int y = 0;
     Fl_Radio_Round_Button *but1 = new Fl_Radio_Round_Button(x+15, y+1*20, 70, 15, "SYSTEM");
     but1->callback(but1_Callback);
     window1->show();
     Fl::run();
}

Not sure how the code below comes across but if any one could help I would appreciate it. Just cannot figure out how to do this (not a C++ programmer).
My main() shows window1. A click on a button invokes but1_Callback which creates window2 that has built a menu and some tabs. The tabs are hidden and when you select a menu option it calls ShowCards() where I want to be able to cards->show. I get a "cards was not declared in this scope" error from g++.

--
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/0656b4fd-5883-4079-aec3-1265a911d9ddn%40googlegroups.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'.