diff --git a/LICENSE-APACHE b/LICENSE-APACHE new file mode 100644 index 0000000..16fe87b --- /dev/null +++ b/LICENSE-APACHE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/LICENSE-MIT b/LICENSE-MIT new file mode 100644 index 0000000..31aa793 --- /dev/null +++ b/LICENSE-MIT @@ -0,0 +1,23 @@ +Permission is hereby granted, free of charge, to any +person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the +Software without restriction, including without +limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice +shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index acd76a0..bb44257 100644 --- a/README.md +++ b/README.md @@ -1 +1,20 @@ # Embedded graphics examples + +- [development (`eg-next`)](./eg-next) +- [0.6 (`eg-0.6`)](./eg-0.6) + +## License + +Licensed under either of + +- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or + http://www.apache.org/licenses/LICENSE-2.0) +- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) + +at your option. + +### Contribution + +Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the +work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any +additional terms or conditions. diff --git a/doc/assets/0.6/analog-clock.png b/doc/assets/0.6/analog-clock.png new file mode 100644 index 0000000..b02f133 Binary files /dev/null and b/doc/assets/0.6/analog-clock.png differ diff --git a/doc/assets/0.6/chaining.png b/doc/assets/0.6/chaining.png new file mode 100644 index 0000000..88de7a4 Binary files /dev/null and b/doc/assets/0.6/chaining.png differ diff --git a/doc/assets/0.6/hello-world.png b/doc/assets/0.6/hello-world.png new file mode 100644 index 0000000..88de7a4 Binary files /dev/null and b/doc/assets/0.6/hello-world.png differ diff --git a/doc/assets/0.6/image-bmp.png b/doc/assets/0.6/image-bmp.png new file mode 100644 index 0000000..d276c08 Binary files /dev/null and b/doc/assets/0.6/image-bmp.png differ diff --git a/doc/assets/0.6/image-tga.png b/doc/assets/0.6/image-tga.png new file mode 100644 index 0000000..d276c08 Binary files /dev/null and b/doc/assets/0.6/image-tga.png differ diff --git a/doc/assets/0.6/input-handling.png b/doc/assets/0.6/input-handling.png new file mode 100644 index 0000000..6346a08 Binary files /dev/null and b/doc/assets/0.6/input-handling.png differ diff --git a/doc/assets/0.6/line-thickness.png b/doc/assets/0.6/line-thickness.png new file mode 100644 index 0000000..af32e18 Binary files /dev/null and b/doc/assets/0.6/line-thickness.png differ diff --git a/doc/assets/0.6/primitives-fill-macros.png b/doc/assets/0.6/primitives-fill-macros.png new file mode 100644 index 0000000..ac8fc36 Binary files /dev/null and b/doc/assets/0.6/primitives-fill-macros.png differ diff --git a/doc/assets/0.6/primitives-fill.png b/doc/assets/0.6/primitives-fill.png new file mode 100644 index 0000000..704f2c1 Binary files /dev/null and b/doc/assets/0.6/primitives-fill.png differ diff --git a/doc/assets/0.6/primitives-stroke.png b/doc/assets/0.6/primitives-stroke.png new file mode 100644 index 0000000..16996d0 Binary files /dev/null and b/doc/assets/0.6/primitives-stroke.png differ diff --git a/doc/assets/0.6/primitives-triangles.png b/doc/assets/0.6/primitives-triangles.png new file mode 100644 index 0000000..4fd2b6a Binary files /dev/null and b/doc/assets/0.6/primitives-triangles.png differ diff --git a/doc/assets/0.6/text-custom-font.png b/doc/assets/0.6/text-custom-font.png new file mode 100644 index 0000000..ee36b43 Binary files /dev/null and b/doc/assets/0.6/text-custom-font.png differ diff --git a/doc/assets/0.6/text-fonts-signs.png b/doc/assets/0.6/text-fonts-signs.png new file mode 100644 index 0000000..5286ce7 Binary files /dev/null and b/doc/assets/0.6/text-fonts-signs.png differ diff --git a/doc/assets/0.6/text-fonts.png b/doc/assets/0.6/text-fonts.png new file mode 100644 index 0000000..235196b Binary files /dev/null and b/doc/assets/0.6/text-fonts.png differ diff --git a/doc/assets/0.6/text-multiline.png b/doc/assets/0.6/text-multiline.png new file mode 100644 index 0000000..b6cb504 Binary files /dev/null and b/doc/assets/0.6/text-multiline.png differ diff --git a/doc/assets/0.6/text-transparent.png b/doc/assets/0.6/text-transparent.png new file mode 100644 index 0000000..9ac7fe6 Binary files /dev/null and b/doc/assets/0.6/text-transparent.png differ diff --git a/doc/assets/next/demo-analog-clock.png b/doc/assets/next/demo-analog-clock.png new file mode 100644 index 0000000..df782f8 Binary files /dev/null and b/doc/assets/next/demo-analog-clock.png differ diff --git a/doc/assets/next/demo-pacman.png b/doc/assets/next/demo-pacman.png new file mode 100644 index 0000000..3e6cb1b Binary files /dev/null and b/doc/assets/next/demo-pacman.png differ diff --git a/doc/assets/next/demo-progress.png b/doc/assets/next/demo-progress.png new file mode 100644 index 0000000..245eff9 Binary files /dev/null and b/doc/assets/next/demo-progress.png differ diff --git a/doc/assets/next/hello-world.png b/doc/assets/next/hello-world.png new file mode 100644 index 0000000..ee68a60 Binary files /dev/null and b/doc/assets/next/hello-world.png differ diff --git a/doc/assets/next/image-bmp.png b/doc/assets/next/image-bmp.png new file mode 100644 index 0000000..d276c08 Binary files /dev/null and b/doc/assets/next/image-bmp.png differ diff --git a/doc/assets/next/image-sub-image.png b/doc/assets/next/image-sub-image.png new file mode 100644 index 0000000..c2ab8f4 Binary files /dev/null and b/doc/assets/next/image-sub-image.png differ diff --git a/doc/assets/next/image-tga.png b/doc/assets/next/image-tga.png new file mode 100644 index 0000000..d276c08 Binary files /dev/null and b/doc/assets/next/image-tga.png differ diff --git a/doc/assets/next/primitives-fill.png b/doc/assets/next/primitives-fill.png new file mode 100644 index 0000000..cba3058 Binary files /dev/null and b/doc/assets/next/primitives-fill.png differ diff --git a/doc/assets/next/primitives-polyline.png b/doc/assets/next/primitives-polyline.png new file mode 100644 index 0000000..6243774 Binary files /dev/null and b/doc/assets/next/primitives-polyline.png differ diff --git a/doc/assets/next/primitives-stroke-alignment.png b/doc/assets/next/primitives-stroke-alignment.png new file mode 100644 index 0000000..ae8a9ab Binary files /dev/null and b/doc/assets/next/primitives-stroke-alignment.png differ diff --git a/doc/assets/next/primitives-stroke.png b/doc/assets/next/primitives-stroke.png new file mode 100644 index 0000000..eaa106e Binary files /dev/null and b/doc/assets/next/primitives-stroke.png differ diff --git a/doc/assets/next/primitives-triangles.png b/doc/assets/next/primitives-triangles.png new file mode 100644 index 0000000..3944d87 Binary files /dev/null and b/doc/assets/next/primitives-triangles.png differ diff --git a/doc/assets/next/text-alignment.png b/doc/assets/next/text-alignment.png new file mode 100644 index 0000000..ea84113 Binary files /dev/null and b/doc/assets/next/text-alignment.png differ diff --git a/doc/assets/next/text-custom-font.png b/doc/assets/next/text-custom-font.png new file mode 100644 index 0000000..0a2a8dd Binary files /dev/null and b/doc/assets/next/text-custom-font.png differ diff --git a/doc/assets/next/text-extended-characters.png b/doc/assets/next/text-extended-characters.png new file mode 100644 index 0000000..d31c274 Binary files /dev/null and b/doc/assets/next/text-extended-characters.png differ diff --git a/doc/assets/next/text-fonts.png b/doc/assets/next/text-fonts.png new file mode 100644 index 0000000..000b56b Binary files /dev/null and b/doc/assets/next/text-fonts.png differ diff --git a/doc/assets/next/text-multiline.png b/doc/assets/next/text-multiline.png new file mode 100644 index 0000000..23c8ded Binary files /dev/null and b/doc/assets/next/text-multiline.png differ diff --git a/doc/assets/next/text-styles.png b/doc/assets/next/text-styles.png new file mode 100644 index 0000000..2a8a713 Binary files /dev/null and b/doc/assets/next/text-styles.png differ diff --git a/doc/assets/next/text-transparent.png b/doc/assets/next/text-transparent.png new file mode 100644 index 0000000..87ae281 Binary files /dev/null and b/doc/assets/next/text-transparent.png differ diff --git a/eg-0.6/Cargo.toml b/eg-0.6/Cargo.toml index a18b905..94bd3e9 100644 --- a/eg-0.6/Cargo.toml +++ b/eg-0.6/Cargo.toml @@ -3,6 +3,7 @@ name = "eg-examples-0-6" version = "0.1.0" edition = "2018" publish = false +license = "MIT OR Apache-2.0" [dependencies] chrono = "0.4.19" diff --git a/eg-0.6/README.md b/eg-0.6/README.md new file mode 100644 index 0000000..57a4b09 --- /dev/null +++ b/eg-0.6/README.md @@ -0,0 +1,66 @@ +# Embedded graphics examples and demos for version `0.6` + +## [analog-clock](examples/analog-clock.rs) + +[![A screenshot of the embedded-graphics version 0.6 example called analog-clock](../doc/assets/0.6/analog-clock.png)](examples/analog-clock.rs) + +## [chaining](examples/chaining.rs) + +[![A screenshot of the embedded-graphics version 0.6 example called chaining](../doc/assets/0.6/chaining.png)](examples/chaining.rs) + +## [hello-world](examples/hello-world.rs) + +[![A screenshot of the embedded-graphics version 0.6 example called hello-world](../doc/assets/0.6/hello-world.png)](examples/hello-world.rs) + +## [image-bmp](examples/image-bmp.rs) + +[![A screenshot of the embedded-graphics version 0.6 example called image-bmp](../doc/assets/0.6/image-bmp.png)](examples/image-bmp.rs) + +## [image-tga](examples/image-tga.rs) + +[![A screenshot of the embedded-graphics version 0.6 example called image-tga](../doc/assets/0.6/image-tga.png)](examples/image-tga.rs) + +## [input-handling](examples/input-handling.rs) + +[![A screenshot of the embedded-graphics version 0.6 example called input-handling](../doc/assets/0.6/input-handling.png)](examples/input-handling.rs) + +## [line-thickness](examples/line-thickness.rs) + +[![A screenshot of the embedded-graphics version 0.6 example called line-thickness](../doc/assets/0.6/line-thickness.png)](examples/line-thickness.rs) + +## [primitives-fill-macros](examples/primitives-fill-macros.rs) + +[![A screenshot of the embedded-graphics version 0.6 example called primitives-fill-macros](../doc/assets/0.6/primitives-fill-macros.png)](examples/primitives-fill-macros.rs) + +## [primitives-fill](examples/primitives-fill.rs) + +[![A screenshot of the embedded-graphics version 0.6 example called primitives-fill](../doc/assets/0.6/primitives-fill.png)](examples/primitives-fill.rs) + +## [primitives-stroke](examples/primitives-stroke.rs) + +[![A screenshot of the embedded-graphics version 0.6 example called primitives-stroke](../doc/assets/0.6/primitives-stroke.png)](examples/primitives-stroke.rs) + +## [primitives-triangles](examples/primitives-triangles.rs) + +[![A screenshot of the embedded-graphics version 0.6 example called primitives-triangles](../doc/assets/0.6/primitives-triangles.png)](examples/primitives-triangles.rs) + +## [text-custom-font](examples/text-custom-font.rs) + +[![A screenshot of the embedded-graphics version 0.6 example called text-custom-font](../doc/assets/0.6/text-custom-font.png)](examples/text-custom-font.rs) + +## [text-fonts](examples/text-fonts.rs) + +[![A screenshot of the embedded-graphics version 0.6 example called text-fonts](../doc/assets/0.6/text-fonts.png)](examples/text-fonts.rs) + +## [text-fonts-signs](examples/text-fonts-signs.rs) + +[![A screenshot of the embedded-graphics version 0.6 example called text-fonts-signs](../doc/assets/0.6/text-fonts-signs.png)](examples/text-fonts-signs.rs) + +## [text-multiline](examples/text-multiline.rs) + +[![A screenshot of the embedded-graphics version 0.6 example called text-multiline](../doc/assets/0.6/text-multiline.png)](examples/text-multiline.rs) + +## [text-transparent](examples/text-transparent.rs) + +[![A screenshot of the embedded-graphics version 0.6 example called text-transparent](../doc/assets/0.6/text-transparent.png)](examples/text-transparent.rs) + diff --git a/eg-next/Cargo.toml b/eg-next/Cargo.toml index 5a19a60..4178145 100644 --- a/eg-next/Cargo.toml +++ b/eg-next/Cargo.toml @@ -3,6 +3,7 @@ name = "eg-examples" version = "0.1.0" edition = "2018" publish = false +license = "MIT OR Apache-2.0" [dependencies] chrono = "0.4.19" @@ -16,3 +17,4 @@ embedded-graphics = { git = "https://github.com/embedded-graphics/embedded-graph embedded-graphics-core = { git = "https://github.com/embedded-graphics/embedded-graphics.git" } tinybmp = { git = "https://github.com/embedded-graphics/tinybmp.git" } tinytga = { git = "https://github.com/embedded-graphics/tinytga.git" } + diff --git a/eg-next/README.md b/eg-next/README.md new file mode 100644 index 0000000..a2793b5 --- /dev/null +++ b/eg-next/README.md @@ -0,0 +1,78 @@ +# Embedded graphics examples and demos for version `next` + +## [demo-analog-clock](examples/demo-analog-clock.rs) + +[![A screenshot of the embedded-graphics version next example called demo-analog-clock](../doc/assets/next/demo-analog-clock.png)](examples/demo-analog-clock.rs) + +## [demo-pacman](examples/demo-pacman.rs) + +[![A screenshot of the embedded-graphics version next example called demo-pacman](../doc/assets/next/demo-pacman.png)](examples/demo-pacman.rs) + +## [demo-progress](examples/demo-progress.rs) + +[![A screenshot of the embedded-graphics version next example called demo-progress](../doc/assets/next/demo-progress.png)](examples/demo-progress.rs) + +## [hello-world](examples/hello-world.rs) + +[![A screenshot of the embedded-graphics version next example called hello-world](../doc/assets/next/hello-world.png)](examples/hello-world.rs) + +## [image-bmp](examples/image-bmp.rs) + +[![A screenshot of the embedded-graphics version next example called image-bmp](../doc/assets/next/image-bmp.png)](examples/image-bmp.rs) + +## [image-sub-image](examples/image-sub-image.rs) + +[![A screenshot of the embedded-graphics version next example called image-sub-image](../doc/assets/next/image-sub-image.png)](examples/image-sub-image.rs) + +## [image-tga](examples/image-tga.rs) + +[![A screenshot of the embedded-graphics version next example called image-tga](../doc/assets/next/image-tga.png)](examples/image-tga.rs) + +## [primitives-fill](examples/primitives-fill.rs) + +[![A screenshot of the embedded-graphics version next example called primitives-fill](../doc/assets/next/primitives-fill.png)](examples/primitives-fill.rs) + +## [primitives-polyline](examples/primitives-polyline.rs) + +[![A screenshot of the embedded-graphics version next example called primitives-polyline](../doc/assets/next/primitives-polyline.png)](examples/primitives-polyline.rs) + +## [primitives-stroke-alignment](examples/primitives-stroke-alignment.rs) + +[![A screenshot of the embedded-graphics version next example called primitives-stroke-alignment](../doc/assets/next/primitives-stroke-alignment.png)](examples/primitives-stroke-alignment.rs) + +## [primitives-stroke](examples/primitives-stroke.rs) + +[![A screenshot of the embedded-graphics version next example called primitives-stroke](../doc/assets/next/primitives-stroke.png)](examples/primitives-stroke.rs) + +## [primitives-triangles](examples/primitives-triangles.rs) + +[![A screenshot of the embedded-graphics version next example called primitives-triangles](../doc/assets/next/primitives-triangles.png)](examples/primitives-triangles.rs) + +## [text-alignment](examples/text-alignment.rs) + +[![A screenshot of the embedded-graphics version next example called text-alignment](../doc/assets/next/text-alignment.png)](examples/text-alignment.rs) + +## [text-custom-font](examples/text-custom-font.rs) + +[![A screenshot of the embedded-graphics version next example called text-custom-font](../doc/assets/next/text-custom-font.png)](examples/text-custom-font.rs) + +## [text-extended-characters](examples/text-extended-characters.rs) + +[![A screenshot of the embedded-graphics version next example called text-extended-characters](../doc/assets/next/text-extended-characters.png)](examples/text-extended-characters.rs) + +## [text-fonts](examples/text-fonts.rs) + +[![A screenshot of the embedded-graphics version next example called text-fonts](../doc/assets/next/text-fonts.png)](examples/text-fonts.rs) + +## [text-multiline](examples/text-multiline.rs) + +[![A screenshot of the embedded-graphics version next example called text-multiline](../doc/assets/next/text-multiline.png)](examples/text-multiline.rs) + +## [text-styles](examples/text-styles.rs) + +[![A screenshot of the embedded-graphics version next example called text-styles](../doc/assets/next/text-styles.png)](examples/text-styles.rs) + +## [text-transparent](examples/text-transparent.rs) + +[![A screenshot of the embedded-graphics version next example called text-transparent](../doc/assets/next/text-transparent.png)](examples/text-transparent.rs) + diff --git a/eg-next/examples/analog-clock.rs b/eg-next/examples/demo-analog-clock.rs similarity index 100% rename from eg-next/examples/analog-clock.rs rename to eg-next/examples/demo-analog-clock.rs diff --git a/eg-next/examples/pacman.rs b/eg-next/examples/demo-pacman.rs similarity index 100% rename from eg-next/examples/pacman.rs rename to eg-next/examples/demo-pacman.rs diff --git a/eg-next/examples/progress.rs b/eg-next/examples/demo-progress.rs similarity index 98% rename from eg-next/examples/progress.rs rename to eg-next/examples/demo-progress.rs index ad551a6..0baa5d4 100644 --- a/eg-next/examples/progress.rs +++ b/eg-next/examples/demo-progress.rs @@ -36,7 +36,7 @@ fn main() -> Result<(), std::convert::Infallible> { let mut window = Window::new("Progress", &output_settings); // The current progress percentage - let mut progress = 0; + let mut progress = 78; 'running: loop { display.clear(BinaryColor::Off)?; diff --git a/eg-next/examples/input-handling.rs b/eg-next/examples/input-handling.rs deleted file mode 100644 index 4d5d219..0000000 --- a/eg-next/examples/input-handling.rs +++ /dev/null @@ -1,79 +0,0 @@ -//! # Example: Input Handling -//! -//! This example allows you to move a red circle to the location of a click on the simulator -//! screen, or move the circle using the arrow keys. Although input handling is not a part of the -//! embedded-graphics API, the simulator can be used to emulate input controls in order to -//! represent more complex UI systems such as touch screens. - -extern crate embedded_graphics; -extern crate embedded_graphics_simulator; - -use embedded_graphics::{ - pixelcolor::Rgb888, - prelude::*, - primitives::{Circle, PrimitiveStyle}, -}; -use embedded_graphics_simulator::{ - sdl2::Keycode, OutputSettings, SimulatorDisplay, SimulatorEvent, Window, -}; - -const BACKGROUND_COLOR: Rgb888 = Rgb888::BLACK; -const FOREGROUND_COLOR: Rgb888 = Rgb888::RED; -const KEYBOARD_DELTA: i32 = 20; - -fn move_circle( - display: &mut SimulatorDisplay, - old_center: Point, - new_center: Point, -) -> Result<(), core::convert::Infallible> { - // Clear old circle - Circle::with_center(old_center, 200) - .into_styled(PrimitiveStyle::with_fill(BACKGROUND_COLOR)) - .draw(display)?; - - // Draw circle at new location - Circle::with_center(new_center, 200) - .into_styled(PrimitiveStyle::with_fill(FOREGROUND_COLOR)) - .draw(display)?; - - Ok(()) -} - -fn main() -> Result<(), core::convert::Infallible> { - let mut display: SimulatorDisplay = SimulatorDisplay::new(Size::new(800, 480)); - let mut window = Window::new("Click to move circle", &OutputSettings::default()); - - let mut position = Point::new(200, 200); - Circle::with_center(position, 200) - .into_styled(PrimitiveStyle::with_fill(FOREGROUND_COLOR)) - .draw(&mut display)?; - - 'running: loop { - window.update(&display); - - for event in window.events() { - match event { - SimulatorEvent::Quit => break 'running, - SimulatorEvent::KeyDown { keycode, .. } => { - let delta = match keycode { - Keycode::Left => Point::new(-KEYBOARD_DELTA, 0), - Keycode::Right => Point::new(KEYBOARD_DELTA, 0), - Keycode::Up => Point::new(0, -KEYBOARD_DELTA), - Keycode::Down => Point::new(0, KEYBOARD_DELTA), - _ => Point::zero(), - }; - let new_position = position + delta; - move_circle(&mut display, position, new_position)?; - position = new_position; - } - SimulatorEvent::MouseButtonUp { point, .. } => { - move_circle(&mut display, position, point)?; - position = point; - } - _ => {} - } - } - } - - Ok(()) -} diff --git a/eg-next/examples/line-thickness.rs b/eg-next/examples/line-thickness.rs deleted file mode 100644 index 5be29e7..0000000 --- a/eg-next/examples/line-thickness.rs +++ /dev/null @@ -1,107 +0,0 @@ -//! A debugging tool for thick lines -//! -//! Use the up/down arrow keys to increase or decrease the line thickness. Click and drag to move -//! the end point of the line around. -//! -//! The thickness, DX and DY components of the line are displayed in the top right corner of the -//! window. - -extern crate embedded_graphics; -extern crate embedded_graphics_simulator; - -use embedded_graphics::{ - mono_font::{ascii::FONT_6X9, MonoTextStyle}, - pixelcolor::Rgb888, - prelude::*, - primitives::{Line, PrimitiveStyle}, - text::Text, -}; -use embedded_graphics_simulator::{ - sdl2::Keycode, OutputSettingsBuilder, SimulatorDisplay, SimulatorEvent, Window, -}; - -const BACKGROUND_COLOR: Rgb888 = Rgb888::BLACK; - -fn draw( - display: &mut SimulatorDisplay, - position: Point, - stroke_width: u32, -) -> Result<(), core::convert::Infallible> { - display.clear(BACKGROUND_COLOR)?; - - let start = Point::new( - display.size().width as i32 / 2, - display.size().height as i32 / 2, - ); - - Text::new( - &format!( - "W: {}\nDX {}, DY {}", - stroke_width, - position.x - start.x, - position.y - start.y - ), - Point::new(5, 10), - MonoTextStyle::new(&FONT_6X9, Rgb888::MAGENTA), - ) - .draw(display)?; - - Line::new(start, position) - .into_styled(PrimitiveStyle::with_stroke( - Rgb888::new(0x80, 0xf2, 0x91), - stroke_width, - )) - .draw(display)?; - - Ok(()) -} - -fn main() -> Result<(), core::convert::Infallible> { - let mut display: SimulatorDisplay = SimulatorDisplay::new(Size::new(200, 200)); - let output_settings = OutputSettingsBuilder::new() - .scale(4) - .pixel_spacing(1) - .build(); - let mut window = Window::new("Line thickness debugger", &output_settings); - - let mut position = Point::new(150, 120); - let mut stroke_width = 5; - let mut mouse_down = false; - - draw(&mut display, position, stroke_width)?; - - 'running: loop { - window.update(&display); - - for event in window.events() { - match event { - SimulatorEvent::Quit => break 'running, - SimulatorEvent::KeyDown { keycode, .. } => { - match keycode { - Keycode::Up => stroke_width += 1, - Keycode::Down => stroke_width = (stroke_width as i32 - 1).max(0) as u32, - _ => (), - } - - draw(&mut display, position, stroke_width)?; - } - SimulatorEvent::MouseButtonDown { point, .. } => { - mouse_down = true; - position = point; - - draw(&mut display, position, stroke_width)?; - } - SimulatorEvent::MouseButtonUp { .. } => mouse_down = false, - SimulatorEvent::MouseMove { point, .. } => { - if mouse_down { - position = point; - draw(&mut display, position, stroke_width)?; - } - } - _ => {} - } - } - } - - Ok(()) -} diff --git a/eg-next/examples/primitives-ellipse.rs b/eg-next/examples/primitives-ellipse.rs deleted file mode 100644 index b7d35a2..0000000 --- a/eg-next/examples/primitives-ellipse.rs +++ /dev/null @@ -1,129 +0,0 @@ -//! # Example: `Ellipse` primitive. -//! -//! Click and drag to move the bottom right corner of the ellipse's bounding box around the screen. -//! -//! The stroke size can be increased or decreased using the up and down arrow keys. -//! -//! This example is not particularly useful on it's own, but is helpful when debugging ellipse -//! rendering. - -use embedded_graphics::{ - mono_font::{ascii::FONT_6X9, MonoTextStyle}, - pixelcolor::Rgb888, - prelude::*, - primitives::*, - text::Text, -}; -use embedded_graphics_simulator::{ - sdl2::Keycode, OutputSettingsBuilder, SimulatorDisplay, SimulatorEvent, Window, -}; - -fn draw_ellipse( - top_left: Point, - size: Size, - stroke_width: u32, - display: &mut SimulatorDisplay, -) { - display.clear(Rgb888::BLACK).unwrap(); - - Text::new( - &format!("S: {}\n{:?}", stroke_width, size), - Point::new(5, 10), - MonoTextStyle::new(&FONT_6X9, Rgb888::MAGENTA), - ) - .draw(display) - .unwrap(); - - // Bounding rect - Rectangle::new(top_left, size) - .into_styled(PrimitiveStyle::with_stroke(Rgb888::WHITE, 1)) - .draw(display) - .unwrap(); - - Ellipse::new(top_left, size) - .into_styled( - PrimitiveStyleBuilder::new() - .stroke_width(stroke_width) - .stroke_color(Rgb888::RED) - .fill_color(Rgb888::GREEN) - .build(), - ) - .draw(display) - .unwrap(); -} - -fn main() -> Result<(), core::convert::Infallible> { - let mut display: SimulatorDisplay = SimulatorDisplay::new(Size::new(200, 200)); - let output_settings = OutputSettingsBuilder::new() - .scale(2) - .pixel_spacing(1) - .build(); - let mut window = Window::new("Ellipse debugger", &output_settings); - - let top_left = Point::new(50, 50); - - let mut mouse_down = false; - - let mut bounding_rect = Rectangle::with_corners(top_left, Point::new(100, 100)); - - let mut stroke_width = 5; - - draw_ellipse( - bounding_rect.top_left, - bounding_rect.size, - stroke_width, - &mut display, - ); - - 'running: loop { - window.update(&display); - - for event in window.events() { - match event { - SimulatorEvent::Quit => break 'running, - SimulatorEvent::MouseButtonDown { point, .. } => { - mouse_down = true; - - bounding_rect = Rectangle::with_corners(top_left, point); - - draw_ellipse( - bounding_rect.top_left, - bounding_rect.size, - stroke_width, - &mut display, - ); - } - SimulatorEvent::KeyDown { keycode, .. } => { - match keycode { - Keycode::Up => stroke_width += 1, - Keycode::Down => stroke_width = (stroke_width as i32 - 1).max(0) as u32, - _ => (), - } - - draw_ellipse( - bounding_rect.top_left, - bounding_rect.size, - stroke_width, - &mut display, - ); - } - SimulatorEvent::MouseButtonUp { .. } => mouse_down = false, - SimulatorEvent::MouseMove { point, .. } => { - if mouse_down { - bounding_rect = Rectangle::with_corners(top_left, point); - - draw_ellipse( - bounding_rect.top_left, - bounding_rect.size, - stroke_width, - &mut display, - ); - } - } - _ => {} - } - } - } - - Ok(()) -} diff --git a/eg-next/examples/primitives-fill.rs b/eg-next/examples/primitives-fill.rs index 65da4d1..1d880a6 100644 --- a/eg-next/examples/primitives-fill.rs +++ b/eg-next/examples/primitives-fill.rs @@ -4,7 +4,7 @@ use core::convert::Infallible; use embedded_graphics::{ - pixelcolor::BinaryColor, + pixelcolor::Rgb888, prelude::*, primitives::{ Circle, CornerRadii, Ellipse, PrimitiveStyle, PrimitiveStyleBuilder, Rectangle, @@ -16,24 +16,24 @@ use embedded_graphics_simulator::{OutputSettingsBuilder, SimulatorDisplay, Windo static CIRCLE_SIZE: i32 = 65; static ELLIPSE_SIZE: Size = Size::new(90, 65); -fn draw_shapes(target: &mut T, style: PrimitiveStyle) -> Result<(), T::Error> +fn draw_shapes(target: &mut T, style: PrimitiveStyle) -> Result<(), T::Error> where - T: DrawTarget, + T: DrawTarget, { Circle::new(Point::new(0, 0), CIRCLE_SIZE as u32) .into_styled(style) .draw(target)?; - Rectangle::new(Point::new(96, 0), Size::new(64, 64)) + Rectangle::new(Point::new(105, 0), Size::new(64, 64)) .into_styled(style) .draw(target)?; - Triangle::new(Point::new(32, 0), Point::new(0, 64), Point::new(64, 64)) - .translate(Point::new(96 * 2, 0)) + Triangle::new(Point::new(33, 0), Point::new(0, 64), Point::new(64, 64)) + .translate(Point::new(96 * 2 + 16, 0)) .into_styled(style) .draw(target)?; - Ellipse::new(Point::new(96 * 3, 0), ELLIPSE_SIZE) + Ellipse::new(Point::new(24, 108), ELLIPSE_SIZE) .into_styled(style) .draw(target)?; @@ -41,39 +41,35 @@ where Rectangle::new(Point::new(32, 0), Size::new(64, 64)), CornerRadii::new(Size::new(16, 16)), ) - .translate(Point::new(96 * 4, 0)) + .translate(Point::new(96 + 24, 108)) .into_styled(style) .draw(target) } fn main() -> Result<(), Infallible> { - let mut display: SimulatorDisplay = SimulatorDisplay::new(Size::new(512, 128)); + let mut display: SimulatorDisplay = SimulatorDisplay::new(Size::new(325, 220)); - let stroke = PrimitiveStyle::with_stroke(BinaryColor::On, 1); + let stroke = PrimitiveStyle::with_stroke(Rgb888::MAGENTA, 1); let stroke_off_fill_off = PrimitiveStyleBuilder::new() - .stroke_color(BinaryColor::Off) + .stroke_color(Rgb888::RED) .stroke_width(1) - .fill_color(BinaryColor::Off) + .fill_color(Rgb888::GREEN) .build(); - let stroke_off_fill_on = PrimitiveStyleBuilder::new() - .stroke_color(BinaryColor::Off) - .stroke_width(1) - .fill_color(BinaryColor::On) - .build(); + let stroke_off_fill_on = PrimitiveStyle::with_fill(Rgb888::YELLOW); - draw_shapes(&mut display, stroke)?; + draw_shapes(&mut display.translated(Point::new(8, 8)), stroke)?; draw_shapes( - &mut display.translated(Point::new(16, 16)), + &mut display.translated(Point::new(24, 24)), stroke_off_fill_on, )?; draw_shapes( - &mut display.translated(Point::new(32, 32)), + &mut display.translated(Point::new(40, 40)), stroke_off_fill_off, )?; - let output_settings = OutputSettingsBuilder::new().scale(2).build(); + let output_settings = OutputSettingsBuilder::new().scale(1).build(); Window::new("Filled primitives", &output_settings).show_static(&display); Ok(()) diff --git a/eg-next/examples/primitives-polyline.rs b/eg-next/examples/primitives-polyline.rs index 78669e7..3cb9c6c 100644 --- a/eg-next/examples/primitives-polyline.rs +++ b/eg-next/examples/primitives-polyline.rs @@ -9,15 +9,14 @@ use embedded_graphics::{ }; use embedded_graphics_simulator::{OutputSettings, SimulatorDisplay, Window}; -const PADDING: i32 = 16; +const PADDING: i32 = 8; fn main() -> Result<(), core::convert::Infallible> { - let (w, h) = (320i32, 256i32); + let (w, h) = (176i32, 256i32); - let mut display: SimulatorDisplay = - SimulatorDisplay::new(Size::new(w as u32, h as u32)); + let mut display: SimulatorDisplay = SimulatorDisplay::new(Size::new(w as u32, 170)); - let line_style = PrimitiveStyle::with_stroke(Rgb888::GREEN, 1); + let line_style = PrimitiveStyle::with_stroke(Rgb888::GREEN, 7); let points = [ Point::new(PADDING, h / 2), @@ -29,7 +28,7 @@ fn main() -> Result<(), core::convert::Infallible> { Point::new(100, PADDING), Point::new(110, h / 2 + 20), Point::new(120, h / 2), - Point::new(w - PADDING, h / 2), + Point::new(160, h / 2), ]; Polyline::new(&points) diff --git a/eg-next/examples/primitives-rounded-rectangle.rs b/eg-next/examples/primitives-rounded-rectangle.rs deleted file mode 100644 index 2c41e44..0000000 --- a/eg-next/examples/primitives-rounded-rectangle.rs +++ /dev/null @@ -1,109 +0,0 @@ -//! # Example: Rounded rectangle -//! -//! This example draws a `RoundedRectangle`. Click and drag to move a corner of the rounded -//! rectangle around the screen. The up/down arrow keys adjust stroke width, left/right the corner -//! radius. Space cycles the stroke alignment between center/outside/inside. - -use embedded_graphics::{pixelcolor::Rgb888, prelude::*, primitives::*}; -use embedded_graphics_simulator::{ - sdl2::Keycode, OutputSettingsBuilder, SimulatorDisplay, SimulatorEvent, Window, -}; - -fn draw( - base_rectangle: Rectangle, - radius: Size, - stroke_width: u32, - align: StrokeAlignment, - display: &mut SimulatorDisplay, -) { - display.clear(Rgb888::BLACK).unwrap(); - - RoundedRectangle::with_equal_corners(base_rectangle, radius) - .into_styled( - PrimitiveStyleBuilder::new() - .stroke_width(stroke_width) - .stroke_color(Rgb888::RED) - .stroke_alignment(align) - .fill_color(Rgb888::GREEN) - .build(), - ) - .draw(display) - .unwrap(); -} - -fn main() -> Result<(), core::convert::Infallible> { - let mut display: SimulatorDisplay = SimulatorDisplay::new(Size::new(200, 200)); - let output_settings = OutputSettingsBuilder::new() - .scale(2) - .pixel_spacing(1) - .build(); - let mut window = Window::new("Rounded rectangle debugger", &output_settings); - - let top_left = Point::new(20, 20); - - let mut mouse_down = false; - - let mut base_rectangle = Rectangle::with_corners(top_left, Point::new(100, 100)); - - let mut stroke_width = 5; - - let mut radius = 20; - - let mut align = StrokeAlignment::Center; - - draw( - base_rectangle, - Size::new(radius, radius), - stroke_width, - align, - &mut display, - ); - - 'running: loop { - window.update(&display); - - for event in window.events() { - match event { - SimulatorEvent::Quit => break 'running, - SimulatorEvent::MouseButtonDown { point, .. } => { - mouse_down = true; - - base_rectangle = Rectangle::with_corners(top_left, point); - } - SimulatorEvent::KeyDown { keycode, .. } => match keycode { - Keycode::Up => stroke_width += 1, - Keycode::Down => stroke_width = stroke_width.saturating_sub(1), - - Keycode::Right => radius += 1, - Keycode::Left => radius = radius.saturating_sub(1), - - Keycode::Space => { - align = match align { - StrokeAlignment::Center => StrokeAlignment::Outside, - StrokeAlignment::Outside => StrokeAlignment::Inside, - StrokeAlignment::Inside => StrokeAlignment::Center, - } - } - _ => (), - }, - SimulatorEvent::MouseButtonUp { .. } => mouse_down = false, - SimulatorEvent::MouseMove { point, .. } => { - if mouse_down { - base_rectangle = Rectangle::with_corners(top_left, point); - } - } - _ => {} - } - - draw( - base_rectangle, - Size::new(radius, radius), - stroke_width, - align, - &mut display, - ); - } - } - - Ok(()) -} diff --git a/eg-next/examples/primitives-stroke.rs b/eg-next/examples/primitives-stroke.rs index ea945b9..df352d9 100644 --- a/eg-next/examples/primitives-stroke.rs +++ b/eg-next/examples/primitives-stroke.rs @@ -3,7 +3,7 @@ //! This example demonstrates the different stroke styles available for primitives. use embedded_graphics::{ - pixelcolor::BinaryColor, + pixelcolor::Rgb888, prelude::*, primitives::{ Circle, CornerRadii, Ellipse, Line, PrimitiveStyle, Rectangle, RoundedRectangle, Triangle, @@ -14,27 +14,27 @@ use embedded_graphics_simulator::{OutputSettings, SimulatorDisplay, Window}; const PADDING: i32 = 16; /// Draws all embedded-graphics primitives. -fn draw_primitives(target: &mut D, style: PrimitiveStyle) -> Result<(), D::Error> +fn draw_primitives(target: &mut D, w: u32) -> Result<(), D::Error> where - D: DrawTarget, + D: DrawTarget, { Triangle::new(Point::new(0, 64), Point::new(64, 0), Point::new(64, 64)) - .into_styled(style) + .into_styled(PrimitiveStyle::with_stroke(Rgb888::CSS_ORANGE_RED, w)) .draw(target)?; Rectangle::new(Point::new(0, 0), Size::new(64, 64)) .translate(Point::new(64 + PADDING, 0)) - .into_styled(style) + .into_styled(PrimitiveStyle::with_stroke(Rgb888::CSS_GOLD, w)) .draw(target)?; Line::new(Point::new(0, 0), Point::new(64, 64)) .translate(Point::new((64 + PADDING) * 2, 0)) - .into_styled(style) + .into_styled(PrimitiveStyle::with_stroke(Rgb888::CSS_SEA_GREEN, w)) .draw(target)?; Circle::new(Point::new(0, 0), 64) .translate(Point::new((64 + PADDING) * 3, 0)) - .into_styled(style) + .into_styled(PrimitiveStyle::with_stroke(Rgb888::CSS_TEAL, w)) .draw(target)?; RoundedRectangle::new( @@ -42,21 +42,17 @@ where CornerRadii::new(Size::new(16, 16)), ) .translate(Point::new((64 + PADDING) * 4, 0)) - .into_styled(style) + .into_styled(PrimitiveStyle::with_stroke(Rgb888::CSS_STEEL_BLUE, w)) .draw(target)?; Ellipse::new(Point::new(0, 0), Size::new(96, 64)) .translate(Point::new((64 + PADDING) * 5, 0)) - .into_styled(style) + .into_styled(PrimitiveStyle::with_stroke(Rgb888::CSS_FUCHSIA, w)) .draw(target) } fn main() -> Result<(), core::convert::Infallible> { - let mut display = SimulatorDisplay::::new(Size::new(512, 256)); - - let thin_stroke = PrimitiveStyle::with_stroke(BinaryColor::On, 1); - let medium_stroke = PrimitiveStyle::with_stroke(BinaryColor::On, 3); - let thick_stroke = PrimitiveStyle::with_stroke(BinaryColor::On, 10); + let mut display = SimulatorDisplay::::new(Size::new(512, 256)); // Draw the primitives using a thin stroke. // @@ -64,15 +60,15 @@ fn main() -> Result<(), core::convert::Infallible> { // using `display.translated(position)`. This translates all drawing operations in `draw_shapes` // by 10 pixels in the x and y direction. let mut position = Point::new(10, 10); - draw_primitives(&mut display.translated(position), thin_stroke)?; + draw_primitives(&mut display.translated(position), 1)?; // Draw the primitives using a medium stroke. position.y += 64 + PADDING; - draw_primitives(&mut display.translated(position), medium_stroke)?; + draw_primitives(&mut display.translated(position), 3)?; // Draw the primitives using a thick stroke. position.y += 64 + PADDING; - draw_primitives(&mut display.translated(position), thick_stroke)?; + draw_primitives(&mut display.translated(position), 10)?; Window::new("Strokes", &OutputSettings::default()).show_static(&display); diff --git a/eg-next/examples/primitives-triangles.rs b/eg-next/examples/primitives-triangles.rs index ecb1abc..0f8e723 100644 --- a/eg-next/examples/primitives-triangles.rs +++ b/eg-next/examples/primitives-triangles.rs @@ -1,60 +1,96 @@ //! # Example: Triangles //! -//! Shows multiple triangles with different properties +//! Shows multiple triangles with different styles. use embedded_graphics::{ - pixelcolor::BinaryColor, + pixelcolor::Rgb888, prelude::*, - primitives::{PrimitiveStyle, Triangle}, + primitives::{PrimitiveStyle, PrimitiveStyleBuilder, StrokeAlignment, Triangle}, }; use embedded_graphics_simulator::{OutputSettingsBuilder, SimulatorDisplay, Window}; -const PAD: i32 = 10; - fn main() -> Result<(), core::convert::Infallible> { - let mut display: SimulatorDisplay = SimulatorDisplay::new(Size::new(512, 128)); + let mut display: SimulatorDisplay = SimulatorDisplay::new(Size::new(600, 128)); - let style = PrimitiveStyle::with_stroke(BinaryColor::On, 1); + let padding = Point::new(10, 20); + let size = display.bounding_box().size.height as i32 - (padding.y * 2); + let half_size = size / 2; + let offset = size + 10; - // No straight lines - Triangle::new(Point::new(0, 0), Point::new(64, 10), Point::new(15, 64)) - .translate(Point::new(PAD, 0)) - .into_styled(style) - .draw(&mut display)?; + // Triangle pointing up + let base_triangle = Triangle::new( + Point::new(0, size), + Point::new(half_size, 0), + Point::new(size, size), + ) + .translate(padding); + + // Triangle pointing down + let flipped_triangle = Triangle::new( + Point::new(0, 0), + Point::new(size, 0), + Point::new(half_size, size), + ) + .translate(padding); + + let inside_thick_stroke = PrimitiveStyleBuilder::new() + .stroke_color(Rgb888::CSS_SALMON) + .stroke_width(10) + .stroke_alignment(StrokeAlignment::Inside) + .build(); + + let center_stroke_fill = PrimitiveStyleBuilder::new() + .stroke_color(Rgb888::CSS_AQUAMARINE) + .stroke_width(10) + .fill_color(Rgb888::CSS_CADET_BLUE) + .build(); + + let outside_stroke_fill = PrimitiveStyleBuilder::new() + .stroke_color(Rgb888::CSS_FIRE_BRICK) + .stroke_width(9) + .stroke_alignment(StrokeAlignment::Outside) + .fill_color(Rgb888::CSS_WHITE_SMOKE) + .build(); + + let thick_stroke = PrimitiveStyleBuilder::new() + .stroke_alignment(StrokeAlignment::Inside) + .stroke_width(20) + .stroke_color(Rgb888::CSS_DARK_TURQUOISE) + .build(); - // Flat top - Triangle::new(Point::new(5, 0), Point::new(30, 64), Point::new(64, 0)) - .translate(Point::new(64 + PAD, 0)) - .into_styled(style) + // Inside thick stroke, no fill + base_triangle + .into_styled(inside_thick_stroke) .draw(&mut display)?; - // Flat left - Triangle::new(Point::new(0, 0), Point::new(0, 64), Point::new(64, 30)) - .translate(Point::new((64 + PAD) * 2, 0)) - .into_styled(style) + // Center stroke alignment with fill + flipped_triangle + .translate(Point::new(offset, 0)) + .into_styled(center_stroke_fill) .draw(&mut display)?; - // Flat bottom - Triangle::new(Point::new(22, 0), Point::new(0, 64), Point::new(64, 64)) - .translate(Point::new((64 + PAD) * 3, 0)) - .into_styled(style) + // Outside stroke alignment with fill + base_triangle + .translate(Point::new(offset * 2, 0)) + .into_styled(outside_stroke_fill) .draw(&mut display)?; - // Flat right - Triangle::new(Point::new(0, 22), Point::new(64, 0), Point::new(64, 64)) - .translate(Point::new((64 + PAD) * 4, 0)) - .into_styled(style) + // Fill only + flipped_triangle + .translate(Point::new(offset * 3, 0)) + .into_styled(PrimitiveStyle::with_fill(Rgb888::CSS_CORAL)) .draw(&mut display)?; - // Draw filled above stroke, should not be visible - Triangle::new(Point::new(0, 22), Point::new(64, 0), Point::new(64, 64)) - .translate(Point::new((64 + PAD) * 5, 0)) - .into_styled(style) + // 1px stroke, no fill + base_triangle + .translate(Point::new(offset * 4, 0)) + .into_styled(PrimitiveStyle::with_stroke(Rgb888::WHITE, 1)) .draw(&mut display)?; - Triangle::new(Point::new(0, 22), Point::new(64, 0), Point::new(64, 64)) - .translate(Point::new((64 + PAD) * 5, 0)) - .into_styled(style) + // Really thick stroke with inside alignment + flipped_triangle + .translate(Point::new(offset * 5, 0)) + .into_styled(thick_stroke) .draw(&mut display)?; let output_settings = OutputSettingsBuilder::new().scale(2).build(); diff --git a/eg-next/examples/rectangle-intersection.rs b/eg-next/examples/rectangle-intersection.rs deleted file mode 100644 index 4013290..0000000 --- a/eg-next/examples/rectangle-intersection.rs +++ /dev/null @@ -1,77 +0,0 @@ -//! # Example: Rectangle intersection -//! -//! This example draws the intersection of two base rectangles (red and green) in blue. - -use embedded_graphics::{pixelcolor::Rgb888, prelude::*, primitives::*}; -use embedded_graphics_simulator::{ - OutputSettingsBuilder, SimulatorDisplay, SimulatorEvent, Window, -}; - -fn draw( - base_rectangle: Rectangle, - moving_rectangle: Rectangle, - display: &mut SimulatorDisplay, -) { - display.clear(Rgb888::BLACK).unwrap(); - - base_rectangle - .into_styled(PrimitiveStyle::with_fill(Rgb888::RED)) - .draw(display) - .unwrap(); - - moving_rectangle - .into_styled(PrimitiveStyle::with_fill(Rgb888::GREEN)) - .draw(display) - .unwrap(); - - let intersection = base_rectangle.intersection(&moving_rectangle); - - if intersection.size != Size::zero() { - intersection - .into_styled(PrimitiveStyle::with_fill(Rgb888::BLUE)) - .draw(display) - .unwrap() - } -} - -fn main() -> Result<(), core::convert::Infallible> { - let mut display: SimulatorDisplay = SimulatorDisplay::new(Size::new(200, 200)); - let output_settings = OutputSettingsBuilder::new() - .scale(2) - .pixel_spacing(1) - .build(); - let mut window = Window::new("Intersection", &output_settings); - - let mut mouse_down = false; - - let base_rectangle = Rectangle::with_corners(Point::new(20, 20), Point::new(100, 100)); - let mut moving_rectangle = Rectangle::with_corners(Point::new(80, 80), Point::new(150, 150)); - - draw(base_rectangle, moving_rectangle, &mut display); - - 'running: loop { - window.update(&display); - - for event in window.events() { - match event { - SimulatorEvent::Quit => break 'running, - SimulatorEvent::MouseButtonDown { point, .. } => { - mouse_down = true; - - moving_rectangle = Rectangle::with_corners(point, Point::new(100, 100)); - } - SimulatorEvent::MouseButtonUp { .. } => mouse_down = false, - SimulatorEvent::MouseMove { point, .. } => { - if mouse_down { - moving_rectangle = Rectangle::with_corners(point, Point::new(150, 150)); - } - } - _ => {} - } - - draw(base_rectangle, moving_rectangle, &mut display); - } - } - - Ok(()) -} diff --git a/eg-next/examples/text-alignment.rs b/eg-next/examples/text-alignment.rs new file mode 100644 index 0000000..d5a393c --- /dev/null +++ b/eg-next/examples/text-alignment.rs @@ -0,0 +1,66 @@ +//! # Example: Text alignment +//! +//! Draw left/center/right aligned text in a containing box. + +use embedded_graphics::{ + mono_font::{ascii::FONT_8X13, MonoTextStyleBuilder}, + pixelcolor::Rgb888, + prelude::*, + text::{Alignment, Baseline, Text, TextStyleBuilder}, +}; +use embedded_graphics_simulator::{OutputSettingsBuilder, SimulatorDisplay, Window}; + +fn main() -> Result<(), core::convert::Infallible> { + let mut display: SimulatorDisplay = SimulatorDisplay::new(Size::new(512, 128)); + + let bounding_box = display.bounding_box(); + + let character_style = MonoTextStyleBuilder::new() + .font(&FONT_8X13) + .text_color(Rgb888::CSS_TOMATO) + .build(); + + let left_aligned = TextStyleBuilder::new() + .alignment(Alignment::Left) + .baseline(Baseline::Top) + .build(); + + let center_aligned = TextStyleBuilder::new() + .alignment(Alignment::Center) + .baseline(Baseline::Middle) + .build(); + + let right_aligned = TextStyleBuilder::new() + .alignment(Alignment::Right) + .baseline(Baseline::Bottom) + .build(); + + Text::with_text_style( + "Left aligned text, origin top left", + bounding_box.top_left, + character_style, + left_aligned, + ) + .draw(&mut display)?; + + Text::with_text_style( + "Center aligned text, origin center center", + bounding_box.center(), + character_style, + center_aligned, + ) + .draw(&mut display)?; + + Text::with_text_style( + "Right aligned text, origin bottom right", + bounding_box.bottom_right().unwrap(), + character_style, + right_aligned, + ) + .draw(&mut display)?; + + let output_settings = OutputSettingsBuilder::new().scale(2).build(); + Window::new("Text alignment", &output_settings).show_static(&display); + + Ok(()) +} diff --git a/eg-next/examples/text-custom-font.rs b/eg-next/examples/text-custom-font.rs index 0339441..09152d5 100644 --- a/eg-next/examples/text-custom-font.rs +++ b/eg-next/examples/text-custom-font.rs @@ -1,11 +1,11 @@ //! # Example: Custom font //! -//! Shows how to implement a custom `SevenSegmentFont` font using the `MonoFontBuilder` struct. This -//! font renders numbers only and emulates a classic 7 segment display. +//! Shows how to implement a custom `SevenSegmentFont` font using the `MonoFont` struct. This font +//! renders numbers only and emulates a classic 7 segment display. use embedded_graphics::{ image::ImageRaw, - mono_font::{GlyphIndices, GlyphRange, MonoFont, MonoFontBuilder, MonoTextStyle}, + mono_font::{mapping::StrGlyphMapping, DecorationDimensions, MonoFont, MonoTextStyle}, pixelcolor::BinaryColor, prelude::*, text::{Alignment, Baseline, Text, TextStyleBuilder}, @@ -14,15 +14,15 @@ use embedded_graphics_simulator::{ BinaryColorTheme, OutputSettingsBuilder, SimulatorDisplay, Window, }; -const SEVENT_SEGMENT_FONT: MonoFont = MonoFontBuilder::new() - .image(ImageRaw::new_binary( - include_bytes!("assets/seven-segment-font.raw"), - 224, - )) - .character_size(Size::new(22, 40)) - .character_spacing(4) - .glyph_indices(GlyphIndices::new(&[GlyphRange::new('0', '9', 0)], 0)) - .build(); +const SEVENT_SEGMENT_FONT: MonoFont = MonoFont { + image: ImageRaw::new_binary(include_bytes!("assets/seven-segment-font.raw"), 224), + glyph_mapping: &StrGlyphMapping::new("0123456789", 0), + character_size: Size::new(22, 40), + character_spacing: 4, + baseline: 7, + underline: DecorationDimensions::default_underline(40), + strikethrough: DecorationDimensions::default_strikethrough(40), +}; fn main() -> Result<(), core::convert::Infallible> { let mut display: SimulatorDisplay = SimulatorDisplay::new(Size::new(128, 128)); diff --git a/eg-next/examples/text-fonts-signs.rs b/eg-next/examples/text-extended-characters.rs similarity index 92% rename from eg-next/examples/text-fonts-signs.rs rename to eg-next/examples/text-extended-characters.rs index a9af4e3..5eb9672 100644 --- a/eg-next/examples/text-fonts-signs.rs +++ b/eg-next/examples/text-extended-characters.rs @@ -1,10 +1,10 @@ //! # Example: Extended characters //! -//! Demonstrate ability of most built in fonts to render extended characters. +//! Demonstrate ability of all built in fonts to render extended characters. use embedded_graphics::{ mono_font::{ - latin1::{FONT_10X20, FONT_6X12, FONT_6X9, FONT_8X13}, + iso_8859_1::{FONT_10X20, FONT_6X12, FONT_6X9, FONT_8X13}, MonoTextStyle, }, pixelcolor::BinaryColor, diff --git a/eg-next/examples/text-fonts.rs b/eg-next/examples/text-fonts.rs index 9136111..af2fcf9 100644 --- a/eg-next/examples/text-fonts.rs +++ b/eg-next/examples/text-fonts.rs @@ -1,6 +1,7 @@ //! # Example: Fonts //! -//! Demonstrate the available builtin fonts. +//! Demonstrate some of the available builtin fonts. A full list of fonts can be found in the +//! [embedded-graphics documentation](https://docs.rs/embedded-graphics). use embedded_graphics::{ mono_font::{ diff --git a/eg-next/examples/text-multiline.rs b/eg-next/examples/text-multiline.rs index fe5c732..fab53c5 100644 --- a/eg-next/examples/text-multiline.rs +++ b/eg-next/examples/text-multiline.rs @@ -13,7 +13,6 @@ use embedded_graphics_simulator::{OutputSettingsBuilder, SimulatorDisplay, Windo fn main() -> Result<(), core::convert::Infallible> { let mut display: SimulatorDisplay = SimulatorDisplay::new(Size::new(256, 128)); - // Show multiline text example let style = MonoTextStyleBuilder::new() .font(&FONT_6X9) .text_color(BinaryColor::On) diff --git a/eg-next/examples/text-styles.rs b/eg-next/examples/text-styles.rs new file mode 100644 index 0000000..138e494 --- /dev/null +++ b/eg-next/examples/text-styles.rs @@ -0,0 +1,71 @@ +//! # Example: Text styles +//! +//! Display a sentence of text using different styles, colors an decorations. + +use embedded_graphics::{ + mono_font::{ + ascii::{FONT_8X13, FONT_8X13_BOLD, FONT_8X13_ITALIC}, + MonoTextStyleBuilder, + }, + pixelcolor::Rgb888, + prelude::*, + text::Text, +}; +use embedded_graphics_simulator::{OutputSettingsBuilder, SimulatorDisplay, Window}; + +fn main() -> Result<(), core::convert::Infallible> { + let mut display: SimulatorDisplay = SimulatorDisplay::new(Size::new(512, 128)); + + let normal = MonoTextStyleBuilder::new() + .font(&FONT_8X13) + .text_color(Rgb888::WHITE) + .build(); + + let underline = MonoTextStyleBuilder::from(&normal) + .text_color(Rgb888::CSS_YELLOW) + .underline() + .build(); + + let strikethrough = MonoTextStyleBuilder::from(&normal) + .strikethrough_with_color(Rgb888::RED) + .build(); + + let background = MonoTextStyleBuilder::from(&normal) + .background_color(Rgb888::CSS_WHEAT) + .text_color(Rgb888::CSS_TOMATO) + .build(); + + let bold = MonoTextStyleBuilder::from(&normal) + .font(&FONT_8X13_BOLD) + .build(); + + let italic = MonoTextStyleBuilder::from(&normal) + .font(&FONT_8X13_ITALIC) + .build(); + + // First line + let position = + Text::new("A sentence with normal, ", Point::new(15, 15), normal).draw(&mut display)?; + let position = Text::new("yellow underline", position, underline).draw(&mut display)?; + let position = Text::new(", ", position, normal).draw(&mut display)?; + let position = Text::new("red strikethrough", position, strikethrough).draw(&mut display)?; + Text::new(", ", position, normal).draw(&mut display)?; + + // Second line + let position = Text::new( + "bold", + Point::new(15, 15 + FONT_8X13.character_size.height as i32), + bold, + ) + .draw(&mut display)?; + let position = Text::new(", ", position, normal).draw(&mut display)?; + let position = Text::new("highlighted", position, background).draw(&mut display)?; + let position = Text::new(" and ", position, normal).draw(&mut display)?; + let position = Text::new("italic", position, italic).draw(&mut display)?; + Text::new(" text!", position, normal).draw(&mut display)?; + + let output_settings = OutputSettingsBuilder::new().scale(2).build(); + Window::new("Text styles", &output_settings).show_static(&display); + + Ok(()) +} diff --git a/eg-next/examples/text-transparent.rs b/eg-next/examples/text-transparent.rs index 30c3465..367a6f5 100644 --- a/eg-next/examples/text-transparent.rs +++ b/eg-next/examples/text-transparent.rs @@ -24,14 +24,28 @@ fn main() -> Result<(), core::convert::Infallible> { .draw(&mut display) .unwrap(); + // Can also be written in the shorter form: TextStyle::new(&FONT_6X9, Rgb565::WHITE) + let no_background = MonoTextStyleBuilder::new() + .font(&FONT_6X9) + .text_color(Rgb565::WHITE) + .build(); + + let filled_background = MonoTextStyleBuilder::new() + .font(&FONT_6X9) + .text_color(Rgb565::YELLOW) + .background_color(Rgb565::BLUE) + .build(); + + let inverse_background = MonoTextStyleBuilder::new() + .font(&FONT_6X9) + .text_color(Rgb565::BLUE) + .background_color(Rgb565::YELLOW) + .build(); + Text::new( "Hello world! - no background", Point::new(15, 15), - // Can also be written in the shorter form: TextStyle::new(&FONT_6X9, Rgb565::WHITE) - MonoTextStyleBuilder::new() - .font(&FONT_6X9) - .text_color(Rgb565::WHITE) - .build(), + no_background, ) .draw(&mut display) .unwrap(); @@ -39,11 +53,7 @@ fn main() -> Result<(), core::convert::Infallible> { Text::new( "Hello world! - filled background", Point::new(15, 30), - MonoTextStyleBuilder::new() - .font(&FONT_6X9) - .text_color(Rgb565::YELLOW) - .background_color(Rgb565::BLUE) - .build(), + filled_background, ) .draw(&mut display) .unwrap(); @@ -51,11 +61,7 @@ fn main() -> Result<(), core::convert::Infallible> { Text::new( "Hello world! - inverse background", Point::new(15, 45), - MonoTextStyleBuilder::new() - .font(&FONT_6X9) - .text_color(Rgb565::BLUE) - .background_color(Rgb565::YELLOW) - .build(), + inverse_background, ) .draw(&mut display)?; diff --git a/justfile b/justfile index 0f229b2..4abcb8e 100644 --- a/justfile +++ b/justfile @@ -8,3 +8,79 @@ build-all: (build "next") (build "0.6") # Build the examples for the given version build version: cd "eg-{{version}}" && cargo build --examples --release + +#---------- +# READMEs +#---------- + +# NOTE: Relative to the version sub-directories +# TODO: Use {{justfile_directory()}} when we upgrade to Just ~0.9 +screenshots_dir := "../doc/assets" + +# Generates a screenshot of an example +generate-example-screenshot version example: + #!/usr/bin/env bash + cd "eg-{{version}}" + mkdir -p "{{screenshots_dir}}/{{version}}" + echo "Generating {{example}} screenshot" + EG_SIMULATOR_DUMP="{{screenshots_dir}}/{{version}}/{{example}}.png" \ + cargo run --example {{example}} + +# # Generates screenshots of all examples for a given version +# @generate-example-screenshots-for-version version: +# #!/usr/bin/env bash +# set -e +# for example in eg-{{version}}/examples/*.rs; do +# just generate-example-screenshot {{version}} $(basename "$example" .rs); +# done + +# generate-example-screenshots: (generate-example-screenshots-for-version "0.6") (generate-example-screenshots-for-version "next") + +# Generate a readme with example screenshots and save it into target/ +_build-readme version: + #!/usr/bin/env bash + set -e + cd eg-{{version}} + + out="target/README.md" + + # Empty the README file + echo -n '' > $out + + echo '# Embedded graphics examples and demos for version `{{version}}`' >> $out + echo '' >> $out + + for example in examples/*.rs; do + name=$(basename "$example" .rs) + just generate-example-screenshot {{version}} $name; + + ( + cat <<-EXAMPLE + ## [$name]($example) + + [![A screenshot of the embedded-graphics version {{version}} example called $name](../doc/assets/{{version}}/$name.png)]($example) + + EXAMPLE + ) >> $out + done + +generate-readme version: (_build-readme version) + #!/usr/bin/env bash + set -euo pipefail + cp "eg-{{version}}/target/README.md" "eg-{{version}}/README.md" + +# Generate readmes for all versions +generate-readmes: (generate-readme "next") (generate-readme "0.6") + +# Check a readme to see if it needs to be regenerated +check-readme version: (_build-readme version) + #!/usr/bin/env bash + set -euo pipefail + diff -q "eg-{{version}}/target/README.md" "eg-{{version}}/README.md" || ( \ + echo -e "\033[1;31mError:\033[0m README.md for eg-{{version}} needs to be regenerated."; \ + echo -e " Run 'just generate-readmes' to regenerate.\n"; \ + exit 1 \ + ) + +# Check all readmes +check-readmes: (check-readme "next") (check-readme "0.6")