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

Add visibleFrame to Screen api #43

Closed
wants to merge 1 commit into from
Closed

Conversation

shayne
Copy link
Contributor

@shayne shayne commented Oct 28, 2015

In order to correctly position a Modal you need the (potentially) negative x-coordinate given by the Screen's visibleFrame.

In order to correctly position a Modal you need the (potentially)
negative x-coordinate given by the Screen's visibleFrame.
@kasper
Copy link
Owner

kasper commented Oct 29, 2015

Interesting! Would you be able to give an example when you would need this instead of the origin adjusted visibleFrameInRectangle?

@shayne
Copy link
Contributor Author

shayne commented Oct 29, 2015

Sure! I ran into an issue when displaying a modal centered on the current screen. https://github.com/shayne/phonad/blob/master/phoenix.js#L119

@kasper
Copy link
Owner

kasper commented Nov 20, 2015

@shayne Hmm, this shouldn’t be needed.

var frame = Screen.mainScreen().visibleFrameInRectangle();

// Centered modal
var modal = new Modal();
modal.message = 'Message';
modal.origin = { x: (frame.width / 2) - (modal.frame().width / 2),
                 y: (frame.height / 2) - (modal.frame().height / 2) };
modal.show();

Am I missing something? I’m hesitant about merging this to avoid confusion against the origin corrected frames.

@jasonm23
Copy link
Contributor

I think leaving the burden of positioning on the JS side is probably a better idea.

@shayne
Copy link
Contributor Author

shayne commented Nov 23, 2015

It was my experience that this method centered the modal on the primary
screen. Try centering the modal on a secondary screen. I had to use
visibleFrame for this to work.

On Fri, Nov 20, 2015 at 4:17 AM, Kasper Hirvikoski <notifications@github.com

wrote:

@shayne https://github.com/shayne Hmm, this shouldn’t be needed.

var frame = Screen.mainScreen().visibleFrameInRectangle();
// Centered modalvar modal = new Modal();
modal.message = 'Message';
modal.origin = { x: (frame.width / 2) - (modal.frame().width / 2),
y: (frame.height / 2) - (modal.frame().height / 2) };
modal.show();

Am I missing something? I’m hesitant about merging this to avoid confusion
against the origin corrected frames.


Reply to this email directly or view it on GitHub
#43 (comment).

@kasper
Copy link
Owner

kasper commented Nov 23, 2015

@shayne Only the y-coordinate is adjusted. I’m currently abroad, so I do not have access to my secondary screen, but I successfully use and have used this calculation to centre windows on secondary screens: https://gist.github.com/kasper/b7c2a1596a90246c9ccd#file-phoenix-js-L18

As such, this should work:

var frame = Screen.mainScreen().visibleFrameInRectangle();

// Centered modal
var modal = new Modal();
modal.message = 'Message';
modal.origin = { x: frame.x + ((frame.width - modal.frame().width) / 2),
                 y: frame.y + ((frame.height - modal.frame().height) / 2) };
modal.show();

Still looks easier than your way. :) I’m just hesitant about making this API confusing with multiple available frames and agree with @jasonm23 that the burden to calculate correctly (from the API’s perspective) should be on JavaScript’s side.

@shayne
Copy link
Contributor Author

shayne commented Nov 24, 2015

Aha... My secondary screen sits below my primary (MacBook Pro < Thunderbolt
Display)

On Mon, Nov 23, 2015 at 5:12 AM, Kasper Hirvikoski <notifications@github.com

wrote:

@shayne https://github.com/shayne Only the y-coordinate is adjusted.
I’m currently abroad, so I do not have access to my secondary screen, but I
successfully use and have used this calculation to centre windows on
secondary screens:
https://gist.github.com/kasper/b7c2a1596a90246c9ccd#file-phoenix-js-L18

As such, this should work:

var frame = Screen.mainScreen().visibleFrameInRectangle();
// Centered modalvar modal = new Modal();
modal.message = 'Message';
modal.origin = { x: frame.x + ((frame.width - modal.frame().width) / 2),
y: frame.y + ((frame.height - modal.frame().height) / 2) };
modal.show();

Still looks easier than your way. :) I’m just hesitant about making this
API confusing with multiple available frames and agree with @jasonm23
https://github.com/jasonm23 that the burden to calculate correctly
should be on the JavaScript side.


Reply to this email directly or view it on GitHub
#43 (comment).

@shayne
Copy link
Contributor Author

shayne commented Nov 24, 2015

I assumed @jasonm23 was inferring that we keep the frame denormalized and
provide the JS end the the precise frame.

On Mon, Nov 23, 2015 at 6:37 PM, Shayne Sweeney shaynesweeney@me.com
wrote:

Aha... My secondary screen sits below my primary (MacBook Pro <
Thunderbolt Display)

On Mon, Nov 23, 2015 at 5:12 AM, Kasper Hirvikoski <
notifications@github.com> wrote:

@shayne https://github.com/shayne Only the y-coordinate is adjusted.
I’m currently abroad, so I do not have access to my secondary screen, but I
successfully use and have used this calculation to centre windows on
secondary screens:
https://gist.github.com/kasper/b7c2a1596a90246c9ccd#file-phoenix-js-L18

As such, this should work:

var frame = Screen.mainScreen().visibleFrameInRectangle();
// Centered modalvar modal = new Modal();
modal.message = 'Message';
modal.origin = { x: frame.x + ((frame.width - modal.frame().width) / 2),
y: frame.y + ((frame.height - modal.frame().height) / 2) };
modal.show();

Still looks easier than your way. :) I’m just hesitant about making this
API confusing with multiple available frames and agree with @jasonm23
https://github.com/jasonm23 that the burden to calculate correctly
should be on the JavaScript side.


Reply to this email directly or view it on GitHub
#43 (comment).

@kasper
Copy link
Owner

kasper commented Nov 24, 2015

@shayne Ah, perhaps. I haven’t changed this behaviour, it has been this way from the beginning. I was puzzled by the actual reason first, but the reason is to make it easier and more straightforward to count the y-position. At least this is how I understand it. Especially as a secondary screen can be positioned in any corner, lower or higher than the main screen — as you just noticed. So I think it’s reasonable.

@kasper kasper closed this Nov 28, 2015
@kasper
Copy link
Owner

kasper commented Nov 28, 2015

I’ll close this for now, but this is duly noted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants