I ported the round transparent sample to a 100% HotCocoa solution: http://github.com/mattetti/hotocoa-roundtransparentwindow/tree/without-nib
As you can see there: http://github.com/mattetti/hotocoa-roundtransparentwindow/blob/9f9717f96e77bfa0b40b2650d71fbbe41f3bd483/lib/application.rb I followed your advise, created 2 modules and extended the mapped instances. I'd like having the option to extend a mapped instance at creation time, that's pretty cool even tho in my example, I would still need to extend an instance manually: http://github.com/mattetti/hotocoa-roundtransparentwindow/blob/9f9717f96e77bfa0b40b2650d71fbbe41f3bd483/lib/application.rb#L29 Thanks for our help. - Matt On Sat, Feb 21, 2009 at 10:29 AM, Richard Kilmer <r...@infoether.com> wrote: > Matt, > You can subclass an NSView on the fly, I don't think a CustomView is > needed: > > v = view :frame => [10,10,100,100] > def v.drawRect(rect) > #custom stuff here > end > > Since you can just redefine methods in ruby this works great. > > Maybe we should add a syntax similar to the rails associations proxies and > enable this: > > module MyCustomBehaviors > def drawRect(rect) > #custom stuff here > end > end > > view :frame => [10,10,100,100], :extend => MyCustomBehaviors > > Thoughts? > > Rich > > On Feb 21, 2009, at 1:36 AM, Matt Aimonetti wrote: > > Oops, I guess the email sent from my iphone never left my 'holy' device. > > Rich, what do you think about adding a new HotCocoa CustomView mapping > since subclassing NSView seems to be pretty common. > > - Matt > > On Tue, Feb 17, 2009 at 10:47 AM, Richard Kilmer <r...@infoether.com>wrote: > >> They do inherit constants, custom methods, etc (see >> lib/hotcocoa/mapper.rb, NOTE: ugly file right now, is a target for refactor) >> >> They are modules and those modules are mixed in. >> Best, >> >> Rich >> >> On Feb 17, 2009, at 12:46 PM, Matt Aimonetti wrote: >> >> 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 <r...@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@lists.macosforge.org >>>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel >>>> >>> >>> _______________________________________________ >>> MacRuby-devel mailing list >>> MacRuby-devel@lists.macosforge.org >>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel >>> >> >> _______________________________________________ >> MacRuby-devel mailing list >> MacRuby-devel@lists.macosforge.org >> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel >> >> >> >> _______________________________________________ >> MacRuby-devel mailing list >> MacRuby-devel@lists.macosforge.org >> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel >> >> > _______________________________________________ > MacRuby-devel mailing list > MacRuby-devel@lists.macosforge.org > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel > > > > _______________________________________________ > MacRuby-devel mailing list > MacRuby-devel@lists.macosforge.org > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel > >
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel