Page 1 of 2
onScreenWidthChange function
Posted: 17 October 2019, 22:17
by hersh
I noticed an empty function called onScreenWidthChange() in gameui. Can we use it or is reserved for other reasons? I can't find any documentation regarding it.
It appears better to use than onresize since it triggers when the playing area size changes even though the window has not. For example switching between log_mode = normal to 2cols
thanks
Re: onScreenWidthChange function
Posted: 18 October 2019, 09:07
by Een
Well, then it's something missing in the documentation

You can use it, it's meant to be the way to react to a resizing of the game area.
Re: onScreenWidthChange function
Posted: 29 June 2020, 21:54
by Brainchild
This is a nice callback. I have a couple of questions:
1. Is it safe to assume this will always be called before setup()?
2. Is it possible to add the width as a callback parameter?
If not, what is the recommended way to get the width? I am using
Code: Select all
let topbarCoords = dojo.position("topbar");
as I've seen you mention this technique in another thread.
Re: onScreenWidthChange function
Posted: 30 June 2020, 08:03
by tchobello
you can get width with topbarCoords.w
for instance, Dungeon Twister board adapts its size to window's width.
Re: onScreenWidthChange function
Posted: 30 June 2020, 09:10
by Brainchild
tchobello wrote: ↑30 June 2020, 08:03you can get width with topbarCoords.w
for instance, Dungeon Twister board adapts its size to window's width.
I know, I'm wondering if this is the best way, and ideally if onScreenWidthChange can include the width value in the callback.
e.g. onScreenWidthChange(newWidth)
Re: onScreenWidthChange function
Posted: 30 June 2020, 09:50
by JumpMaybe
The problem with using the topbar's width is there are 1 or 2 columns of player info + logs on the right (in desktop mode anyway) whose width you would have to subtract.
If you use
you get the actual width of the playing area. I'm using it since last week, so there might still be some trickyness with it I haven't run into.
Re: onScreenWidthChange function
Posted: 06 July 2020, 23:33
by Brainchild
JumpMaybe wrote: ↑30 June 2020, 09:50
The problem with using the topbar's width is there are 1 or 2 columns of player info + logs on the right (in desktop mode anyway) whose width you would have to subtract.
If you use
you get the actual width of the playing area. I'm using it since last week, so there might still be some trickyness with it I haven't run into.
I switched to page-title but I'm unfortunately getting the same width value regardless of whether the player has "game log in second column" enabled. I'm pretty sure it's because that option hasn't been applied yet at the moment I check the width of page-title (in setup()).
It would be nice to have a BGA Studio official way of getting the width of the play area, accounting for any player layout options.
Re: onScreenWidthChange function
Posted: 07 July 2020, 00:06
by Tisaac
Re: onScreenWidthChange function
Posted: 07 July 2020, 00:09
by Brainchild
Tisaac wrote: ↑07 July 2020, 00:06
What about
?
I tried that but it doesn't exist yet in setup().
Re: onScreenWidthChange function
Posted: 07 July 2020, 00:13
by Tisaac
Then just use a conditional and call the function again in the onScreenWidthChange :
Code: Select all
updateSize: function(){
if($('game_play_area')){
var w = dojo.position('game_play_area')['w'];
...
},
onScreenWidthChange: function(){
this.updateSize();
}