Sha256: 30d05b55aa8ba14422ed5cd73148f7d26cfb2c6aa399b2584f9b2180b6b22348

Contents?: true

Size: 1.13 KB

Versions: 20

Compression:

Stored size: 1.13 KB

Contents

class NSString

  # @return [NSImage]
  def nsimage
    NSImage.imageNamed(self).tap do |retval|
      NSLog("No image named #{self}") unless retval
    end
  end

  # @return [NSFont]
  def nsfont(size=nil)
    size ||= NSFont.systemFontSize
    NSFont.fontWithName(self, size: size)
  end

  # @param font [NSFont] Optional, defaults to NSFont.systemFontOfSize(NSFont.systemFontSize)
  # @return [NSLabel]
  def nslabel(font=nil)
    font ||= :system.nsfont(NSFont.labelFontSize)
    size = self.sizeWithAttributes({ NSFontAttributeName => font })
    label = NSTextField.alloc.initWithFrame([[0, 0], size])
    label.bezeled = false
    label.drawsBackground = false
    label.editable = false
    label.selectable = false
    label.stringValue = self
    label.font = font
    return label
  end

  # @return [NSImageView]
  def nsimageview
    image = NSImage.imageNamed(self)
    unless image
      NSLog("No image named #{self}")
    end
    image_view = NSImageView.alloc.init
    image_view.image = image
    frame = image_view.frame
    frame.size = image_view.intrinsicContentSize
    image_view.frame = frame
    return image_view
  end

end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
sugarcube-2.8.1 lib/osx/sugarcube-appkit/nsstring.rb
sugarcube-2.8.0 lib/osx/sugarcube-appkit/nsstring.rb
sugarcube-2.7.1 lib/osx/sugarcube-appkit/nsstring.rb
sugarcube-2.7.0 lib/osx/sugarcube-appkit/nsstring.rb
sugarcube-2.6.0 lib/osx/sugarcube-appkit/nsstring.rb
sugarcube-2.5.0 lib/osx/sugarcube-appkit/nsstring.rb
sugarcube-2.4.2 lib/osx/sugarcube-appkit/nsstring.rb
sugarcube-2.4.1 lib/osx/sugarcube-appkit/nsstring.rb
sugarcube-2.4.0 lib/osx/sugarcube-appkit/nsstring.rb
sugarcube-2.3.0 lib/osx/sugarcube-appkit/nsstring.rb
sugarcube-2.2.0 lib/osx/sugarcube-appkit/nsstring.rb
sugarcube-2.1.5 lib/osx/sugarcube-appkit/nsstring.rb
sugarcube-2.1.4 lib/osx/sugarcube-appkit/nsstring.rb
sugarcube-2.1.3 lib/osx/sugarcube-appkit/nsstring.rb
sugarcube-2.1.2 lib/osx/sugarcube-appkit/nsstring.rb
sugarcube-2.1.1 lib/osx/sugarcube-appkit/nsstring.rb
sugarcube-2.1.0 lib/osx/sugarcube-appkit/nsstring.rb
sugarcube-2.0.2 lib/osx/sugarcube-appkit/nsstring.rb
sugarcube-2.0.1 lib/osx/sugarcube-appkit/nsstring.rb
sugarcube-2.0.0 lib/osx/sugarcube-appkit/nsstring.rb