Confused about tab-panel usage with mred-designer's code

I'm using mred-designer, and am confused as to how I am supposed to get children under the appropriate tabs. All the areas I have added appear under tabs-panel, but under the first tab only. The generated code looks like this:

  (set! tab-panel-123843
    (new
     (class tab-panel%
       (super-new)
       (define child-panels '())
       (define/public
        (add-child-panel p label)
        (set! child-panels (append child-panels (list p)))
        (send this append label)
        (when (> (length child-panels) 1) (send this delete-child p)))
       (define/public
        (active-child n)
        (send this change-children
          (lambda (children) (list (list-ref child-panels n))))))
     (parent horizontal-pane-123316)
     (choices (list "Market Values" "Market Selections"))
     (callback (λ (tp e) (send tp active-child (send tp get-selection))))
     (style '())
     (enabled #t)
     (vert-margin 0)
     (horiz-margin 0)
     (border 0)
     (spacing 0)
     (alignment (list 'center 'center))
     (min-width 0)
     (min-height 0)
     (stretchable-width #f)
     (stretchable-height #t)))

All areas added with mred appear under the first tab, I can't work out how to get contents under the second tab. I have specified two 'choices', and there appears to be two tabs, but only one with children (trying to set active-child to 1 gives me an error).

Using add-child-panel creates a new tab (with contents), but I can't see how to add/change children under existing tabs? The interface won't let me create an empty tab-panel (i.e. no choices) in order to do add-child-panel from scratch.

I'm obviously missing something, so if someone could please point me in the right direction...

Thanks.

Hi, @shakeshuck.

I remember being confused by them as well, when I tried the first time.

I made a quick application in MrEd, so apologies for the terrible formatting.

Crazy Tab Panels

It's just a button, and, a tab-panel with two tabs which, depending on the selection, adds a text field to either when the button is pressed.

The important bit, though, is the callback for the button, which does the adding:

(the-button-callback
 (lambda (button control-event)
   ;; here I get the child (which is being set by `active-child`)
   (define selected-tab (first (send the-tab-panel get-children)))
   (new text-field%
        [parent selected-tab]
        [label  (format "field #~a" (length (send selected-tab get-children)))])))

I hope that helps!

Edit: missing words


Edit: In case it is unclear (I now realize), the active-child procedure is called when the callback for the-tab-panel is called (in turn when a tab is selected).

In particular, see the tab-panel% docs, where it states:

The callback procedure is called (with the event type 'tab-panel) when the user changes the tab selection.

Thanks for this!
The important bits for me are the class definitions to add panels to the correct tabs at startup - there's no way I would have thought of this, and it's something I can definitely use.

Now I just need to get the population process working, lol.
Thanks again.

Edit: Even after making this comment, it has still taken me some time to realise that the panels listed in child-panels are supposed to be instantiated. I'm getting there slowly...!

1 Like