Stupid question about DUIM/widgets 
Author Message
 Stupid question about DUIM/widgets

With DUIM, its been very easy to put widgets into a <frame> and manage
their behavior. What I'm not getting is how I can take a couple of
widgets, group them together, add some behavior, and make a new widget?

Does anyone have a "template" or simple example of creating a widget out
of existing ones?

I think I've got a "can't see the forest past the trees" thing going on
here. Appreciate any help.

Ron Franke-Polz
Pricipal Systems Engineer



Mon, 03 Dec 2001 03:00:00 GMT  
 Stupid question about DUIM/widgets

Quote:
> With DUIM, its been very easy to put widgets into a <frame> and
> manage their behavior. What I'm not getting is how I can take a
> couple of widgets, group them together, add some behavior, and make
> a new widget?

The basic trick is to use the 'define pane' macro, this is just like
'define frame' except that it defines a pane/sheet/gadget (the
terminology is a little redundant). So, if you wanted to define a new
class of collection gadget, you would do something like (untested):

  define pane <option-box-with-label> (<option-box>)
    slot gadget-label :: <string>,
      required-init-keyword: label:;
    slot gadget-items :: <sequence>,
      required-init-keyword: items:;
    pane label-pane (pane)
      make(<label>, label: pane.gadget-label);
    pane option-box-pane (pane)
      make(<option-box>, items: pane.gadget-items);
    layout (pane)
      horizontally (spacing: 2)
        pane.label-pane;
        pane.option-box-pane;
      end;
  end pane <option-box-with-label>;

and then you could make it using:

  make(<option-box-with-label>,
       label: "Choose a color:",
       items: #["Red", "Green", "Blue"]);

Note that this is just a sketch, things get more complicated when you
want to obey all of the getters and setters that an <option-box>
accepts. If you want a more detailed description I can implement a
complete example for you, but the only 'tricky' part is how to get the
setters to do the right thing. For example, here is how I would handle
gadget-items-setter:

  define pane ...
    ...
    slot gadget-items :: <sequence>,
      setter: %items-setter,
      required-init-keyword: items:;
    ...
  end;

  define method gadget-items-setter
      (items :: <sequence>, gadget :: <option-box-with-label>)
   => (items :: <sequence>)
    unless (items = gadget.gadget-items)
      gadget.%items := items;
      gadget-items(gadget.option-box-pane) := items
    end;
    items
  end method gadget-items-setter;

Note that this approach 'wastes' a slot, in that the gadget-items are
stored in both the wrapper and the actual option box. Another approach
which is a little more verbose is to implement both gadget-items and
gadget-items-setter to dispatch to the option box, and to then make
the initialize method on <option-box-with-label> pass on the initial
state to the option box. This approach makes more sense if you end up
implementing more than a few of the gadget protocols.

I've often thought that it would be nice to create a wrapping gadget
class that automatically implemented all of the necessary methods to
dispatch getter and setter methods to the gadget being wrapped
up. I've never gone any further with this idea, though, I'd be
interested to see any suggestions.

Hope this helps,

Andy

----------

Harlequin Inc.



Tue, 04 Dec 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Stupid (very) question about menu Widget

2. Text Widget stupid question ?

3. DUIM focus question

4. A duim menu question

5. DUIM font question

6. DUIM question

7. DUIM question

8. Some questions on elided text in the text widget (and a few other text widget questions)

9. Seemingly Stupid Question

10. Stupid question

11. Stupid Question 101

12. Really stupid question

 

 
Powered by phpBB® Forum Software