Schmavery / reprocessing

ReasonML graphics library inspired by Processing
https://schmavery.github.io/reprocessing/
MIT License
682 stars 24 forks source link

Add window dimension accessors #49

Closed jaredly closed 6 years ago

jaredly commented 6 years ago

Need these when on a phone

Schmavery commented 6 years ago

If I'm not missing something, I believe that this is what width and height should be already. However, it's possible that there's an issue in the implementation of resizeable that's causing it to not work because the phone will ignore the requested dimensions (I'm guessing?). As a test, you might be able to just set Env.resizeable to true and check whether the values of width and height are correct (this will depend on your resize callback being set up properly on phone).

To unblock you, I think it would be reasonable to simply replace the implementations of width and height with direct calls to Reasongl.Gl.Window.getWidth for now..

The right fix would probably be to either remove or fix the behaviour of resizeable. What it does now is a little hacky (simply reresize the window on every resize event) and could probably be replaced with bindings to lower level window apis (in reasongl). If we do this, we might be able to remove this record entirely: https://github.com/Schmavery/reprocessing/blob/b078b1e14c1e34d9e3084bad8f59734d92c1401a/src/Reprocessing_Common.re#L61-L65

jaredly commented 6 years ago

So I'm realizing what I actually want is "screen size" or something like unto it. The use case is in native ios, I want to get the current dimensions of the containing GL view, and then set the size of the "window" to be that.

jaredly commented 6 years ago

Or maybe a better explanation of the problem: On native ios, a window has intrinsic size (the size of the GKLView) -- and I want to access that, ~and have the window be set to that size at the start, instead of the default 200x200px

Schmavery commented 6 years ago

On ios, would it make sense to ignore any setting of window size and simply force the size to the size of the device? I can only imagine that a 200x200 window would look strange on ios.

jaredly commented 6 years ago

What happens is I ignore the set size command anyway, but we need to know the size of the view so that internally we calculate things right (so env.window.width etc. are correct)

Schmavery commented 6 years ago

right, so I'm saying to ignore the Env.size and make the Env.width and Env.height functions simply do what you're doing in Env.windowWidth and Env.windowHeight.

jaredly commented 6 years ago

But that would require a change to reprocessing? Are you saying that Env.width would special-case based on the backend? This way we don't have to do that

Schmavery commented 6 years ago

It shouldn't be a breaking change, that's already the value of width etc in non iOS situations (it's just "cached")

Schmavery commented 6 years ago

To clarify: Env.width should always be the value of Reasongl.Gl.Window.Width, regardless of the backend. There should be no need to add a separate Env.windowWidth function that is the same value.

It seems that some of our internal window size logic is messing up on ios because the assumption that the window can actually be resized isn't being respected. This is fine, but will cause Env.width/height to be wrong until it is cleaned up.

jaredly commented 6 years ago

gotcha, cool

jaredly commented 6 years ago

superceeded by #53