Sha256: 6ff7ca9243b303a12820b529f468181499fe11105afd0832d6933c37ee7a7150

Contents?: true

Size: 1.04 KB

Versions: 34

Compression:

Stored size: 1.04 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_view = NSImageView.alloc.init
    image_view.image = self.nsimage
    frame = image_view.frame
    frame.size = image_view.intrinsicContentSize
    image_view.frame = frame
    return image_view
  end

end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
sugarcube-4.0.0 lib/osx/sugarcube-ui/nsstring.rb
sugarcube-3.5.0 lib/osx/sugarcube-ui/nsstring.rb
sugarcube-3.4.2 lib/osx/sugarcube-ui/nsstring.rb
sugarcube-3.4.1 lib/osx/sugarcube-ui/nsstring.rb
sugarcube-3.4.0 lib/osx/sugarcube-ui/nsstring.rb
sugarcube-3.3.7 lib/osx/sugarcube-ui/nsstring.rb
sugarcube-3.3.6 lib/osx/sugarcube-ui/nsstring.rb
sugarcube-3.3.5 lib/osx/sugarcube-ui/nsstring.rb
sugarcube-3.3.4 lib/osx/sugarcube-ui/nsstring.rb
sugarcube-3.3.3 lib/osx/sugarcube-ui/nsstring.rb
sugarcube-3.3.2 lib/osx/sugarcube-ui/nsstring.rb
sugarcube-3.3.1 lib/osx/sugarcube-ui/nsstring.rb
sugarcube-3.3.0 lib/osx/sugarcube-ui/nsstring.rb
sugarcube-3.2.0 lib/osx/sugarcube-ui/nsstring.rb
sugarcube-3.1.1 lib/osx/sugarcube-ui/nsstring.rb
sugarcube-3.1.0 lib/osx/sugarcube-ui/nsstring.rb
sugarcube-3.0.8 lib/osx/sugarcube-ui/nsstring.rb
sugarcube-3.0.7 lib/osx/sugarcube-ui/nsstring.rb
sugarcube-3.0.6 lib/osx/sugarcube-ui/nsstring.rb
sugarcube-3.0.5 lib/osx/sugarcube-ui/nsstring.rb