Skip to content

Commit 5a220f1

Browse files
authored
Add initial improved click-to-copy for resources page (#2514)
* WIP: face name and table generation * HIDEOUS code * WIP-ish with tiled images * Copyables copy but too wide and ugly. * Move resources info sections into includes files * Create doc/_includes * Move links.rst there * Move the resource inclusion there using the include_file feature from the Vfs * Move ref check to function for it * WIP we have non-huge copy buttons * Add custom JS to the force-copy temp fix and clean up header * Add custom JS call to target ezcopy class * Add CSS for buttons * Very ugly code for generating the buttons * WIP commit: seems to render correctly * Clean up table body generation * Move image tile to new function * Add unknown file handling and clean up more * More indents * Add first draft of inlinable literals for Arcade * Wrap the literal and button in a span * Add styling * Remove indent argument from function likely to be removed soon * Move and comment some things * Quote fix + explain how / why it works * Remove kludges and improve column durability * Use iterators instead of non-stop modulo and variable references * Simplify column detection: 1 column when n=1, 3 for fonts, 2 for all else * Add arguments to allow passing in the value to the table generation from outside * Improve clarity and durability for resource paths * fix missing variable name in create_resources_path * rename create_resources_path to path_as_resource_handle: * Fix wrong quoting behavior for copyable embeds * s/quote(/html_quote(/g * use better resource paths * explain a few things better * Partly switch over to a clean nested config dict * Start switching over config reading * Partly decruft the methods * Remove cruft config storage replaced in last commit * Re-enable resource handle prefix as table caption * Use Python's standard library to handle HTML escaping * Remove custom html quote function * Add prefix of handle string as table caption with CSS to make it match the copyables more * Clean imports, constants, and commented-out code * Whitespace + more redundancies removed * Encapsulate font data parsing from filenames * Unify media embeds * Fix header row generation + move a few things * Fix include behavior + add copy button directions * Fix heading generation and start improving the ordering for auto-generation * Fix the include ordering for the resources pages * Add site-wide |Copy Button substitution * Add rough instructions for the copy buttons based on feedback * Encapsulate table header + header row behavior * Some more consolidation * Separate concerns for table body, header, and conf * Add basic file tile thumbing (ty @DigiDuncan) * Remove old thumbnailing for unknown files * Remove code from .rst generation * Remove CSS supporting the .. raw:: html for unknown file types * Improve example copy button (almost-correct style) * Styles almost correctly with hover (inline is breaking) * Add .doc-ui-example-dummy class intended to shut off UI behavior on dummy elements * CSS changes to support the UI elements and on-page instructions * Document some flaws better * Add |Example Copy Button| substitution for Sphinx embeds * Add fall state as a stop-gap for the blue alien * Remove more cruft * Remove unused code + extra whitespace in a regex * Remove linking experiment for now * Switch glsl shader listing off again * Doc cross-ref trick works sorta?
1 parent 4fe91fa commit 5a220f1

16 files changed

+734
-222
lines changed
Loading
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Arcade includes an number of themed image sets to help you get started
2+
making specific types of games. Some of these help you complete the tutorials
3+
while others are general-purpose prototyping tools.

doc/_includes/resources_Kenney.rst

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.. figure:: images/fonts_blue.png
2+
:align: center
3+
:alt: The bundled Kenney.nl fonts.
4+
5+
.. Put the text *after* the CSS, or add <br> via .. raw:: html blocks
6+
.. since the CSS may be broken.
7+
8+
Arcade includes the following fonts from `Kenney.nl's font pack <https://kenney.nl/assets/kenney-fonts>`_
9+
are available using the path and filenames below.
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.. figure:: images/fonts_liberation.png
2+
:alt: The bundled Liberation font family trio.
3+
:align: center
4+
5+
.. Put the text *after* the CSS, or add <br> via .. raw:: html blocks
6+
.. since the CSS may be broken.
7+
8+
Arcade also includes the Liberation font family. This trio is designed and
9+
licensed specifically to be a portable, drop-in set of substitutes for Times, Arial,
10+
and Courier fonts. It uses the proven, commercial-friendly `SIL Open Font License`_.
11+
12+
To use these fonts, you may use either approach:
13+
14+
* load files for specific variants via :py:func:`arcade.load_font`
15+
* load all variants at once with :py:func:`arcade.resources.load_liberation_fonts`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
This logo of the snake doubles as a quick way to test Arcade's resource handles.
2+
3+
#. Mouse over the copy button (|Example Copy Button|) below
4+
#. It should change color to indicate you've hovered
5+
#. Click to copy
6+
7+
Paste in your favorite text editor!
8+

doc/_static/css/custom.css

+104-2
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,120 @@ table.dataTable.display tbody tr.even > .sorting_1 {
214214
background-repeat: repeat;
215215
}
216216

217+
218+
/*Test*/
217219
table.resource-table {
218220
empty-cells: hide;
221+
white-space: normal; /* table behavior for CSS styling? maybe dupe of below. */
219222
}
223+
220224
/* Make the resource page's table cell contents look neat */
221-
table.resource-table td {
225+
226+
/* copy button doesn't need so much margin in here */
227+
.resource-table div.highlight-python {
228+
margin-bottom: 0;
229+
}
230+
231+
/* Only center the contents of tiles which have images in them
232+
* NOTE: The * instead of table alloes for non-table resource tiles
233+
*/
234+
*.resource-table td:has(.resource-thumb) {
222235
text-align: center;
223236
}
224-
table.resource-table td > img {
237+
.resource-table,
238+
.resource-table table
239+
{
240+
width: 100%;
241+
max-width: 100%;
242+
}
243+
.wy-table-responsive table :is(th, td) { white-space: normal; }
244+
/* Prevent huge copyable areas for .. code:: boxes using sphinx-copybutton */
245+
.resource-table div.highlight > pre {
246+
padding: 8px;
247+
}
248+
249+
table.resource-table td > .resource-thumb {
225250
display: inline-block;
251+
}
252+
table.resource-table td > img.resource-thumb {
226253
/* Maximum 20% of the smallest display dimension */
227254
max-width: min(20vw, 20vh);
228255
}
256+
table.resource-table td > .resource-thumb.file-icon {
257+
width: 128px;
258+
height: 128px;
259+
max-width: 128px;
260+
max-height: 128px;
261+
}
262+
263+
264+
.resource-handle {
265+
display: inline-block;
266+
border-radius: 0.4em;
267+
border: 1px solid rgb(0, 0, 0, 0);
268+
width: fit-content !important;
269+
}
270+
.resource-handle:has(button.arcade-ezcopy:hover) {
271+
border-color: #54c079;
272+
color: #54c079;
273+
}
274+
.resource-table .caption-text > .literal,
275+
.resource-handle > .literal {
276+
font-style: normal;
277+
height: 1.5em;
278+
min-height: 1.5em;
279+
border-radius: 0.4em;
280+
border: 1px solid #1b1f2426;
281+
vertical-align: middle;
282+
/* Not clear why this doesn't work for the .caption-text */
283+
font-size: 1em !important;
284+
}
285+
286+
287+
/* Imitate sphinx-copybutton style */
288+
.arcade-ezcopy {
289+
width: 1.5em;
290+
height: 1.5em;
291+
min-width: 1.5em;
292+
min-height: 1.5em;
293+
padding: 0;
294+
295+
/* Imitate sphinx-copybutton minus styling spacing issues */
296+
border-radius: 0.4em 0.4em 0.4em 0.4em;
297+
border: 1px solid #1b1f2426;
298+
299+
border-left: 0;
300+
301+
color: #57606a;
302+
background-color: #f6f8fa;
303+
304+
}
305+
/* Hide left border on items which haven adjacent copy button
306+
307+
CAVEAT: This won't currently work with right-to-left layout modes!
308+
309+
This is because of the following assume left-to-right:
310+
311+
1. The + here assumes the button element's next in the DOM order
312+
2. The right border of the box gets switched off
313+
*/
314+
.resource-table * > .literal:has(+ button.arcade-ezcopy) {
315+
border-radius: 0.4em 0 0 0.4em !important;
316+
}
317+
.resource-table .literal + button.arcade-ezcopy {
318+
border-radius: 0 0.4em 0.4em 0 !important;
319+
}
320+
321+
322+
323+
.arcade-ezcopy > img {
324+
margin: 0;
325+
width: 100%;
326+
height: 100%;
327+
}
328+
.arcade-ezcopy:hover {
329+
background-color: #54c079;
330+
}
229331

230332
table.colorTable {
231333
border-width: 1px;

doc/_static/filetiles/state-error.png

3.06 KB
Loading

doc/_static/filetiles/type-glsl.png

4.33 KB
Loading

doc/_static/filetiles/type-json.png

3.19 KB
Loading
1.95 KB
Loading

doc/_static/js/custom.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,14 @@ function handleSidebarHeaderToggle() {
5555
registerOnScrollEvent(mediaQuery);
5656
}
5757
}
58-
59-
6058
/**
6159
* Load all custom code only once the DOM document has fully loaded.
6260
*
6361
* Notice that jQuery is already available in this file.
6462
*/
6563
$(document).ready(() => {
66-
handleSidebarHeaderToggle()
64+
handleSidebarHeaderToggle();
65+
// Re-use the base ClipboardJS provided by sphinx-copybutton
66+
// .doc-ui-example-dummy marks a button as a training dummy on the resources page and elsewhere
67+
document.ezcopy = new ClipboardJS('.arcade-ezcopy:not(.doc-ui-example-dummy');
6768
});
Loading

doc/conf.py

+39-5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
import sphinx.transforms
1515
import sys
1616

17+
from docutils import nodes
18+
from docutils.nodes import literal
19+
from sphinx.util.docutils import SphinxRole
20+
1721
# As of pyglet==2.1.dev7, this is no longer set in pyglet/__init__.py
1822
# because Jupyter / IPython always load Sphinx into sys.modules. See
1923
# the following for more info:
@@ -166,7 +170,7 @@ def run_util(filename, run_name="__main__", init_globals=None):
166170
# List of patterns, relative to source directory, that match files and
167171
# directories to ignore when looking for source files.
168172
exclude_patterns = [
169-
"links.rst",
173+
"_includes/*",
170174
"substitutions.rst",
171175
"_archive/*",
172176
]
@@ -247,15 +251,22 @@ def run_util(filename, run_name="__main__", init_globals=None):
247251
'pymunk': ('https://www.pymunk.org/en/latest/', None),
248252
}
249253

250-
251254
# These will be joined as one block and prepended to every source file.
252255
# Substitutions for |version| and |release| are predefined by Sphinx.
253256
PROLOG_PARTS = [
254257
#".. include:: /links.rst",
255258
".. |pyglet Player| replace:: pyglet :py:class:`~pyglet.media.player.Player`",
256-
".. _Arcade's License File on GitHub: {FMT_URL_REF_BASE}/license.rst"
259+
".. _Arcade's License File on GitHub: {FMT_URL_REF_BASE}/license.rst",
260+
261+
( # Allows explaining how to copy anywhere in the doc.
262+
'.. |Example Copy Button| raw:: html\n\n'
263+
' <div class="arcade-ezcopy doc-ui-example-dummy" style="display: inline-block;">\n'
264+
' <img src="/_static/copy-button.svg"/>\n\n'
265+
' </div>\n\n'
266+
)
267+
257268
]
258-
with open("links.rst") as f:
269+
with open("_includes/links.rst") as f:
259270
PROLOG_PARTS.extend(f.readlines())
260271

261272
rst_prolog = "\n".join(PROLOG_PARTS)
@@ -409,6 +420,29 @@ class A(NamedTuple):
409420
A('doctreedir'),
410421
)
411422

423+
424+
class ResourceRole(SphinxRole): # pending: 3.1
425+
"""Get resource file and category cross-references sorta working.
426+
427+
This needs improvement.
428+
"""
429+
def run(self) -> tuple[list[nodes.Node], list[nodes.system_message]]:
430+
raw = self.text.removeprefix(":resource:")
431+
page_id = self.text\
432+
.replace(':', '')\
433+
.replace('/', '-')\
434+
.replace('_', '-')\
435+
.replace('.', '-')
436+
437+
filename = f"'{raw.split('/')[-1]}'"
438+
node = nodes.reference(text=filename, refuri=''.join([
439+
'/api_docs/resources.html#', page_id]),
440+
)
441+
442+
print("HALP?", locals())
443+
return [node], []
444+
445+
412446
def setup(app):
413447
print("Diagnostic info since readthedocs doesn't use our make.py:")
414448
for attr, comment in APP_CONFIG_DIRS:
@@ -432,7 +466,7 @@ def setup(app):
432466
app.connect('autodoc-process-signature', strip_init_return_typehint, -1000)
433467
app.connect('autodoc-process-bases', on_autodoc_process_bases)
434468
# app.add_transform(Transform)
435-
469+
app.add_role('resource', ResourceRole())
436470

437471
# ------------------------------------------------------
438472
# Old hacks that breaks the api docs. !!! DO NOT USE !!!

0 commit comments

Comments
 (0)