Skip to content

Commit a3dc83c

Browse files
committed
Add order parameter to Context.new_console.
I've also added the common use of order to the getting started examples.
1 parent 6fd153b commit a3dc83c

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ v2.0.0
88

99
Unreleased
1010
------------------
11+
Added
12+
- Added the important `order` parameter to `Context.new_console`.
1113

1214
11.18.3 - 2020-12-28
1315
--------------------

docs/tcod/getting-started.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Example::
3535
"dejavu10x10_gs_tc.png", 32, 8, tcod.tileset.CHARMAP_TCOD,
3636
)
3737
# Create the main console.
38-
console = tcod.Console(WIDTH, HEIGHT)
38+
console = tcod.Console(WIDTH, HEIGHT, order="F")
3939
# Create a window based on this console and tileset.
4040
with tcod.context.new( # New window for a console of size columns×rows.
4141
columns=console.width, rows=console.height, tileset=tileset,
@@ -97,7 +97,7 @@ Example::
9797
width=WIDTH, height=HEIGHT, sdl_window_flags=FLAGS
9898
) as context:
9999
while True:
100-
console = context.new_console()
100+
console = context.new_console(order="F")
101101
console.print(0, 0, "Hello World")
102102
context.present(console, integer_scaling=True)
103103

tcod/context.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@
4949
""" # noqa: E501
5050
import os
5151
import sys
52-
from typing import Any, Iterable, List, Optional, Tuple
52+
from typing import Any, Iterable, List, Optional, Tuple, Union
53+
54+
from typing_extensions import Literal
5355

5456
import tcod
5557
import tcod.event
@@ -267,6 +269,7 @@ def new_console(
267269
min_columns: int = 1,
268270
min_rows: int = 1,
269271
magnification: float = 1.0,
272+
order: Union[Literal["C"], Literal["F"]] = "C",
270273
) -> tcod.console.Console:
271274
"""Return a new console sized for this context.
272275
@@ -278,6 +281,9 @@ def new_console(
278281
consoles, which will show as larger tiles when presented.
279282
`magnification` must be greater than zero.
280283
284+
`order` is passed to :any:`tcod.console.Console` to determine the
285+
memory order of its NumPy attributes.
286+
281287
The times where it is the most useful to call this method are:
282288
283289
* After the context is created, even if the console was given a
@@ -286,6 +292,12 @@ def new_console(
286292
* After any window resized event, or any manual resizing of the window.
287293
288294
.. versionadded:: 11.18
295+
296+
.. versionchanged:: 11.19
297+
Added `order` parameter.
298+
299+
.. seealso::
300+
:any:`tcod.console.Console`
289301
"""
290302
if magnification < 0:
291303
raise ValueError(
@@ -299,7 +311,7 @@ def new_console(
299311
)
300312
)
301313
width, height = max(min_columns, size[0]), max(min_rows, size[1])
302-
return tcod.console.Console(width, height)
314+
return tcod.console.Console(width, height, order=order)
303315

304316
def recommended_console_size(
305317
self, min_columns: int = 1, min_rows: int = 1

0 commit comments

Comments
 (0)