Skip to content

Add initial improved click-to-copy for resources page #2514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 42 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
26f4709
WIP: face name and table generation
pushfoo Jan 15, 2025
023cf78
HIDEOUS code
pushfoo Jan 15, 2025
a23781a
WIP-ish with tiled images
pushfoo Jan 16, 2025
564fb34
Copyables copy but too wide and ugly.
pushfoo Jan 16, 2025
480abd8
Move resources info sections into includes files
pushfoo Jan 19, 2025
4a27cb7
Move ref check to function for it
pushfoo Jan 19, 2025
d1bc7db
Merge remote-tracking branch 'upstream/development' into resources-pa…
pushfoo Jan 20, 2025
30eee6f
Merge remote-tracking branch 'upstream/development' into resources-pa…
pushfoo Jan 21, 2025
3c11275
WIP we have non-huge copy buttons
pushfoo Jan 21, 2025
b6e3db7
WIP commit: seems to render correctly
pushfoo Jan 21, 2025
7e1c060
Clean up table body generation
pushfoo Jan 21, 2025
93d6311
Move image tile to new function
pushfoo Jan 21, 2025
5b3f64d
Add unknown file handling and clean up more
pushfoo Jan 21, 2025
4557a3b
More indents
pushfoo Jan 21, 2025
0def388
Add first draft of inlinable literals for Arcade
pushfoo Jan 21, 2025
dfe3507
Move and comment some things
pushfoo Jan 22, 2025
d741ab2
Quote fix + explain how / why it works
pushfoo Jan 22, 2025
f1150a8
Remove kludges and improve column durability
pushfoo Jan 22, 2025
981eade
Improve clarity and durability for resource paths
pushfoo Jan 22, 2025
471bb74
Fix wrong quoting behavior for copyable embeds
pushfoo Jan 22, 2025
52f09a2
Partly switch over to a clean nested config dict
pushfoo Jan 22, 2025
9a630c9
Remove cruft config storage replaced in last commit
pushfoo Jan 22, 2025
810f8b6
Re-enable resource handle prefix as table caption
pushfoo Jan 22, 2025
74831d7
Clean imports, constants, and commented-out code
pushfoo Jan 22, 2025
86a0e82
Whitespace + more redundancies removed
pushfoo Jan 22, 2025
3b8a903
Encapsulate font data parsing from filenames
pushfoo Jan 22, 2025
28bde0e
Unify media embeds
pushfoo Jan 22, 2025
64d9089
Fix header row generation + move a few things
pushfoo Jan 22, 2025
c2353b9
Fix include behavior + add copy button directions
pushfoo Jan 23, 2025
8620d23
Encapsulate table header + header row behavior
pushfoo Jan 23, 2025
411bf73
Some more consolidation
pushfoo Jan 23, 2025
508f1b7
Separate concerns for table body, header, and conf
pushfoo Jan 23, 2025
9104caa
Add basic file tile thumbing (ty @DigiDuncan)
pushfoo Jan 23, 2025
3af0c4c
Remove old thumbnailing for unknown files
pushfoo Jan 23, 2025
7a7d366
Improve example copy button (almost-correct style)
pushfoo Jan 24, 2025
c481239
Add fall state as a stop-gap for the blue alien
pushfoo Jan 24, 2025
178885d
Remove more cruft
pushfoo Jan 24, 2025
72261c8
Merge remote-tracking branch 'upstream/development' into resources-pa…
pushfoo Jan 24, 2025
f9802d6
Remove unused code + extra whitespace in a regex
pushfoo Jan 24, 2025
acb2d76
Remove linking experiment for now
pushfoo Jan 24, 2025
76f9b5c
Switch glsl shader listing off again
pushfoo Jan 24, 2025
146e82c
Doc cross-ref trick works sorta?
pushfoo Jan 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
3 changes: 3 additions & 0 deletions doc/_includes/resources_Image_Theme_Sets.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Arcade includes an number of themed image sets to help you get started
making specific types of games. Some of these help you complete the tutorials
while others are general-purpose prototyping tools.
9 changes: 9 additions & 0 deletions doc/_includes/resources_Kenney.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.. figure:: images/fonts_blue.png
:align: center
:alt: The bundled Kenney.nl fonts.

.. Put the text *after* the CSS, or add <br> via .. raw:: html blocks
.. since the CSS may be broken.

Arcade includes the following fonts from `Kenney.nl's font pack <https://kenney.nl/assets/kenney-fonts>`_
are available using the path and filenames below.
15 changes: 15 additions & 0 deletions doc/_includes/resources_Liberation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.. figure:: images/fonts_liberation.png
:alt: The bundled Liberation font family trio.
:align: center

.. Put the text *after* the CSS, or add <br> via .. raw:: html blocks
.. since the CSS may be broken.

Arcade also includes the Liberation font family. This trio is designed and
licensed specifically to be a portable, drop-in set of substitutes for Times, Arial,
and Courier fonts. It uses the proven, commercial-friendly `SIL Open Font License`_.

To use these fonts, you may use either approach:

* load files for specific variants via :py:func:`arcade.load_font`
* load all variants at once with :py:func:`arcade.resources.load_liberation_fonts`.
8 changes: 8 additions & 0 deletions doc/_includes/resources_Top-Level_Resources.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
This logo of the snake doubles as a quick way to test Arcade's resource handles.

#. Mouse over the copy button (|Example Copy Button|) below
#. It should change color to indicate you've hovered
#. Click to copy

Paste in your favorite text editor!

106 changes: 104 additions & 2 deletions doc/_static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,120 @@ table.dataTable.display tbody tr.even > .sorting_1 {
background-repeat: repeat;
}


/*Test*/
table.resource-table {
empty-cells: hide;
white-space: normal; /* table behavior for CSS styling? maybe dupe of below. */
}

/* Make the resource page's table cell contents look neat */
table.resource-table td {

/* copy button doesn't need so much margin in here */
.resource-table div.highlight-python {
margin-bottom: 0;
}

/* Only center the contents of tiles which have images in them
* NOTE: The * instead of table alloes for non-table resource tiles
*/
*.resource-table td:has(.resource-thumb) {
text-align: center;
}
table.resource-table td > img {
.resource-table,
.resource-table table
{
width: 100%;
max-width: 100%;
}
.wy-table-responsive table :is(th, td) { white-space: normal; }
/* Prevent huge copyable areas for .. code:: boxes using sphinx-copybutton */
.resource-table div.highlight > pre {
padding: 8px;
}

table.resource-table td > .resource-thumb {
display: inline-block;
}
table.resource-table td > img.resource-thumb {
/* Maximum 20% of the smallest display dimension */
max-width: min(20vw, 20vh);
}
table.resource-table td > .resource-thumb.file-icon {
width: 128px;
height: 128px;
max-width: 128px;
max-height: 128px;
}


.resource-handle {
display: inline-block;
border-radius: 0.4em;
border: 1px solid rgb(0, 0, 0, 0);
width: fit-content !important;
}
.resource-handle:has(button.arcade-ezcopy:hover) {
border-color: #54c079;
color: #54c079;
}
.resource-table .caption-text > .literal,
.resource-handle > .literal {
font-style: normal;
height: 1.5em;
min-height: 1.5em;
border-radius: 0.4em;
border: 1px solid #1b1f2426;
vertical-align: middle;
/* Not clear why this doesn't work for the .caption-text */
font-size: 1em !important;
}


/* Imitate sphinx-copybutton style */
.arcade-ezcopy {
width: 1.5em;
height: 1.5em;
min-width: 1.5em;
min-height: 1.5em;
padding: 0;

/* Imitate sphinx-copybutton minus styling spacing issues */
border-radius: 0.4em 0.4em 0.4em 0.4em;
border: 1px solid #1b1f2426;

border-left: 0;

color: #57606a;
background-color: #f6f8fa;

}
/* Hide left border on items which haven adjacent copy button

CAVEAT: This won't currently work with right-to-left layout modes!

This is because of the following assume left-to-right:

1. The + here assumes the button element's next in the DOM order
2. The right border of the box gets switched off
*/
.resource-table * > .literal:has(+ button.arcade-ezcopy) {
border-radius: 0.4em 0 0 0.4em !important;
}
.resource-table .literal + button.arcade-ezcopy {
border-radius: 0 0.4em 0.4em 0 !important;
}



.arcade-ezcopy > img {
margin: 0;
width: 100%;
height: 100%;
}
.arcade-ezcopy:hover {
background-color: #54c079;
}

table.colorTable {
border-width: 1px;
Expand Down
Binary file added doc/_static/filetiles/state-error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/_static/filetiles/type-glsl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/_static/filetiles/type-json.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/_static/filetiles/type-unknown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions doc/_static/js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ function handleSidebarHeaderToggle() {
registerOnScrollEvent(mediaQuery);
}
}


/**
* Load all custom code only once the DOM document has fully loaded.
*
* Notice that jQuery is already available in this file.
*/
$(document).ready(() => {
handleSidebarHeaderToggle()
handleSidebarHeaderToggle();
// Re-use the base ClipboardJS provided by sphinx-copybutton
// .doc-ui-example-dummy marks a button as a training dummy on the resources page and elsewhere
document.ezcopy = new ClipboardJS('.arcade-ezcopy:not(.doc-ui-example-dummy');
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 39 additions & 5 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
import sphinx.transforms
import sys

from docutils import nodes
from docutils.nodes import literal
from sphinx.util.docutils import SphinxRole

# As of pyglet==2.1.dev7, this is no longer set in pyglet/__init__.py
# because Jupyter / IPython always load Sphinx into sys.modules. See
# the following for more info:
Expand Down Expand Up @@ -166,7 +170,7 @@ def run_util(filename, run_name="__main__", init_globals=None):
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = [
"links.rst",
"_includes/*",
"substitutions.rst",
"_archive/*",
]
Expand Down Expand Up @@ -247,15 +251,22 @@ def run_util(filename, run_name="__main__", init_globals=None):
'pymunk': ('https://www.pymunk.org/en/latest/', None),
}


# These will be joined as one block and prepended to every source file.
# Substitutions for |version| and |release| are predefined by Sphinx.
PROLOG_PARTS = [
#".. include:: /links.rst",
".. |pyglet Player| replace:: pyglet :py:class:`~pyglet.media.player.Player`",
".. _Arcade's License File on GitHub: {FMT_URL_REF_BASE}/license.rst"
".. _Arcade's License File on GitHub: {FMT_URL_REF_BASE}/license.rst",

( # Allows explaining how to copy anywhere in the doc.
'.. |Example Copy Button| raw:: html\n\n'
' <div class="arcade-ezcopy doc-ui-example-dummy" style="display: inline-block;">\n'
' <img src="/_static/copy-button.svg"/>\n\n'
' </div>\n\n'
)

]
with open("links.rst") as f:
with open("_includes/links.rst") as f:
PROLOG_PARTS.extend(f.readlines())

rst_prolog = "\n".join(PROLOG_PARTS)
Expand Down Expand Up @@ -409,6 +420,29 @@ class A(NamedTuple):
A('doctreedir'),
)


class ResourceRole(SphinxRole): # pending: 3.1
"""Get resource file and category cross-references sorta working.

This needs improvement.
"""
def run(self) -> tuple[list[nodes.Node], list[nodes.system_message]]:
raw = self.text.removeprefix(":resource:")
page_id = self.text\
.replace(':', '')\
.replace('/', '-')\
.replace('_', '-')\
.replace('.', '-')

filename = f"'{raw.split('/')[-1]}'"
node = nodes.reference(text=filename, refuri=''.join([
'/api_docs/resources.html#', page_id]),
)

print("HALP?", locals())
return [node], []


def setup(app):
print("Diagnostic info since readthedocs doesn't use our make.py:")
for attr, comment in APP_CONFIG_DIRS:
Expand All @@ -432,7 +466,7 @@ def setup(app):
app.connect('autodoc-process-signature', strip_init_return_typehint, -1000)
app.connect('autodoc-process-bases', on_autodoc_process_bases)
# app.add_transform(Transform)

app.add_role('resource', ResourceRole())

# ------------------------------------------------------
# Old hacks that breaks the api docs. !!! DO NOT USE !!!
Expand Down
Loading
Loading