Scrollbars for Infinite Document?

2019-07-13 07:32发布

Is there a standard Aqua way to handle a practically infinite document?

For example, imagine a level editor for a tile-based game. The level has no preset size (though it's technically limited by NSInteger's size); tiles can be placed anywhere on the grid. Is there a standard interface for scrolling through such a document?

I can't simply limit the scrolling to areas that already have tiles, because the user needs to be able to add tiles outside that boundary. Arbitrarily creating a level size, even if it's easily changeable by the user, doesn't seem ideal either.

Has anyone seen an application that deals with this problem?

2条回答
叼着烟拽天下
2楼-- · 2019-07-13 08:14

One option is to essentially dynamically expand the area as the user scrolls through it - any time the user scrolls within X units of an edge, add another unit in that direction. Essentially, you'll never be able to scroll "all the way" to an edge, because the closer you get the farther it will expand.

If the user scrolls back away from the edge, contract it to back to no more than X units beyond where there is actually content.

查看更多
冷血范
3楼-- · 2019-07-13 08:28

Have you seen what Microsoft Excel does for this problem? It has to represent an unbounded space with scrollbars, as well.

One solution is to define a reasonable space for the original level size, and when the user scrolls to one tile away from its bounds, add another row or column of tiles, and adjust the scrollbar accordingly. This way, the user never reaches the actual bounds.

If the user decides to cut down on the level size, you could also add code that shrinks the "reasonable space" once an unused row consists only of empty tiles. This saves the user from being stuck with a huge level that they scrolled through, with no way to shrink it.

Edit: Same as Dav's answer. :)

查看更多
登录 后发表回答