Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot extend Rectangle? #273

Closed
rcarmo opened this issue Jun 8, 2021 · 5 comments
Closed

Cannot extend Rectangle? #273

rcarmo opened this issue Jun 8, 2021 · 5 comments
Assignees
Labels
Milestone

Comments

@rcarmo
Copy link

rcarmo commented Jun 8, 2021

  • Version: 2.6.7
  • macOS: 11.4

So I'm trying to extend Rectangle:

Rectangle.prototype.pad = () => {
	return new Rectangle(
		this.x + PADDING/2, 
		this.y + PADDING/2,
		this.width - PADDING,
		this.height - PADDING
	);
};

... and I get ReferenceError: Can't find variable: Rectangle (Line:Column)

Since I can hack Screen, shouldn't I be able to do the same for Rectangle, so that I can take a Window.frame and manipulate it directly like this?

@kasper
Copy link
Owner

kasper commented Jun 8, 2021

Rectangle is NSRect (https://developer.apple.com/documentation/foundation/nsrect) under the hood. It’s a struct and not an object, so that’s the reason you get the error. I’m surprised nobody else has noticed this from documentation before. 😄 I’ll fix that.

@kasper kasper added the task label Jun 8, 2021
@rcarmo
Copy link
Author

rcarmo commented Jun 8, 2021

Ah, ok. So I can't override it and do nice things like I do for Window and Screen. Hmmm.

@kasper
Copy link
Owner

kasper commented Jun 8, 2021

@rcarmo You can of course pass it to functions, in a more functional approach.

const pad = (rect) => ({
  ...rect,
  x: rect.x + PADDING,
});

@rcarmo
Copy link
Author

rcarmo commented Jun 8, 2021

Yeah, I wanted to make it smarter. Am now using something called a Frame, which can .displace, .pad and .snap, so I can do neat stuff like foo.snap(screen, WEST).pad()

@kasper kasper self-assigned this Aug 15, 2021
@kasper kasper added this to the 2.6.8 milestone Aug 15, 2021
kasper added a commit that referenced this issue Aug 15, 2021
@kasper
Copy link
Owner

kasper commented Aug 15, 2021

I’ve clarified the documentation in this regard.

@kasper kasper closed this as completed Aug 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants