[MacRuby-devel] HotCocoa subclassing NSView

Matt Aimonetti mattaimonetti at gmail.com
Tue Feb 17 09:46:48 PST 2009


Thanks Rich, but if I do what you recommended, I guess I would not be able
to use all the NSView extra stuff defined by the existing NSView mapping
(constants, custom methods etc..).

Wouldn't be better to make each mapping a mixin? That would allow us to
reuse some default settings and subclassing a mapped class would give us all
the mapping goodies.

- Matt



On Tue, Feb 17, 2009 at 4:33 AM, Richard Kilmer <rich at infoether.com> wrote:

> This is how I would do it:
>
> class MyNewView < NSView
>
>  def drawRect(rect)
>  end
>
> end
>
> HotCocoa::Mappings.map :my_new_view => :"MyNewView" do
>  defaults :frame => DefaultEmptyRect, :layout => {}
>
>  def init_with_options(view, options)
>    view.initWithFrame options.delete(:frame)
>  end
> end
>
> Then in your code you can just use it like any HotCocoa mapped class:
>
> my_new_view :frame => [0,0,10,10]
>
> etc.
>
> -rich
>
>
>
> On Feb 17, 2009, at 4:15 AM, Matt Aimonetti wrote:
>
>  I'm working on a new HotCocoa sample and I need to subclass NSView to
>> override drawRect and add few more methods.
>> I would like to be able to reuse all the goodies from HotCocoa and the
>> view helper, what's the best way to do that?
>>
>> -Matt
>> _______________________________________________
>> MacRuby-devel mailing list
>> MacRuby-devel at lists.macosforge.org
>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>>
>
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20090217/f31ecbbd/attachment.html>


More information about the MacRuby-devel mailing list