mliebelt / pgn-viewer

Simple PGN viewer with the necessary features to display chess games
GNU General Public License v3.0
156 stars 44 forks source link

boardSize does not allow CSS units other than pixels #186

Open martinhinrichs opened 3 years ago

martinhinrichs commented 3 years ago

Hi,

in the API documentation, it says:

boardSize: Size of the board (in CSS terms like '300px')

However, no units other than px seem to be currently supported - '200em', '200%', '200vh' etc are all interpreted as '200px'. Until and unless support for other units is added, the documentation should be changed to reflect this.

Thank you for this library and keep up the good work!

mliebelt commented 3 years ago

Thanks a lot for bringing that to my attention. The reason could be twofold (and I will check that later):

So I will check if it is possible to have the unit used differently, without destroying the layout algorithm.


Digging a little deeper, I found 3 parts in the code (at least) that expect the boardSize to be in pixel. 2 have in common (did that functionality twice), that I had / have problems if the board is not a multiple of 8pixels in some browsers. I will just comment that out during development, and see if that brings a kind of solution.

There is of course something not thought about before. When you set boardSize e.g. to 80vh, and later set width to be the same, then you have a problem. So yes, the code is here not the best, and your demand brings that to light :-).


Additional remark: the board is currently not able to be resized. When you base the board on the size of the window (80%, 80vh), changing the window size is directly changing the board size, but the pieces are not adjusted. So no, there will no easy way to allow this. This will take some time, but is a valuable goal (which I would like to achieve).

mliebelt commented 3 years ago

I did some more experimentation. Here is the (not final) result. This helps a little bit to understand how much has to be done, when doing the implementation. I will push my results on a branch, so @martinhinrichs should be able to reproduce it.

See the branch ticket-186 for the current state.