Re: GUI programming vs encapsulation



Hi,

So how do you guys deal with this problem? I guess there is no real
way  out of having all the callbacks spread out in this "flat" fashion
because from the C program's point of view there's no telling in what 
order they might be called. Is writing unwieldy spaghetti code a 
necessary part of GUI programming, or have I missed some important
point?

I'm not sure whether this is also applicable to your problem, but my
general advice would be to keep the program core (whatever your program
really does) 100% distinct from the GUI functions.

Now as your particular question is concerned, I have implemented a
hashed symbol table that holds pointers to all widgets that influence
the core (e.g. all parameters that determine the way your program is
run). Then I have several helper functions that access this table.

An example of a symbol table:

typedef struct symbol
  {
  char   *name;
  double *val; /* change with struct if you need more */
  GtkWidget *widget;
  struct symbol *next;
  } symbol;

symbol *symbol_table[97];

Now when you start your application, hash your parameters, fill up your
global symbol table and you're ready to access your GUI from whatever
source file.

Hope this helps,

Andrej



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]