Dynamic UI: can it be done in Cocoa

  • I have a UI library in which UI is dynamically generated by calls in
    code. The result of the calls is a description of the contents,
    position, and sizing of dialogs, and a list of callbacks for
    events. The dialogs are then shown (modal or modeless) and the
    callbacks which were specified are used.

    Ok... this currently exists and uses deprecated Carbon functions. So
    I had been looking for the way forward. I had until just now assumed
    that HIViews (in Carbon) would be the way to achieve this. Now it
    seems that the answer might be Cocoa, something completely unknown
    here.

    So, I have one specific question.

    With Cocoa, can one implement completely dynamic UI (dialogs), with all
    dialogs, elements, sizes and positions specified at runtime through some
    kind of API? (Never mind how, at this point: implementation isn't likely
    to start for some time. It's just whether this is a viable path
    at all).

    Thanks in advance,

    Aandi
  • Am 13.11.2007 um 12:01 schrieb <listreader2...> <listreader2...>
    > :
    > With Cocoa, can one implement completely dynamic UI (dialogs), with
    > all
    > dialogs, elements, sizes and positions specified at runtime through
    > some
    > kind of API? (Never mind how, at this point: implementation isn't
    > likely
    > to start for some time. It's just whether this is a viable path
    > at all).

      In general, yes. UI elements in Cocoa are just regular objects. You
    can simply alloc/initWithFrame: a view and then use addSubView: to put
    it in a window's content view or into another container view.
    Similarly for Windows themselves.

      The only thing where it gets a little hairy is the menu bar. You
    need a basic menu bar stub with an Apple menu etc. in a NIB, IIRC. But
    you can add any additional menus yourself. Another gotcha is that IB
    does some setup work for you right away, i.e. its template objects may
    have some properties set to a non-default value (e.g. pushbuttons by
    default have an old-fashioned NeXT-Style look, and you need to set
    their border to get Aqua buttons), and some objects are actually
    wrapped in other views (e.g. NSTextField and NSTableView are usually
    wrapped in an NSScrollView that draws the border and handles scrolling).

      But in general, it's fairly easy, not more difficult than it was
    with HIView, and compared to the old Control Manager, and just like
    HIView, you can actually take an NSView out of its window and put it
    into another. If you have a list of default controls, you could also
    create NIBs with template objects, and then instantiate them as
    needed. That way you can get the objects set up using IB, and then
    just resize them and change properties as needed in code.

    Cheers,
    -- M. Uli Kusterer
    "The Witnesses of TeachText are everywhere..."
    http://www.zathras.de
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today