Skip to content

Commit

Permalink
Move printer demo and energy-monitor into new top-level demos/ folder
Browse files Browse the repository at this point in the history
These are showing off use-cases for Slint, but they're not examples showing individual Slint features.

Also removed the old printerdemo while at it.
  • Loading branch information
tronical committed Oct 25, 2024
1 parent acafc9c commit a98d470
Show file tree
Hide file tree
Showing 241 changed files with 187 additions and 982 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,9 @@ jobs:
git checkout v${{ matrix.from_version }} --no-overlay -- examples
git checkout v${{ matrix.from_version }} --no-overlay -- tests/cases
git checkout v${{ matrix.from_version }} --no-overlay -- tests/helper_components
# Remove examples from the workspace because they may no longer exist or their Cargo.toml might prevent the build of the updater
# Remove examples and demos from the workspace because they may no longer exist or their Cargo.toml might prevent the build of the updater
sed -i "/examples/d" Cargo.toml
sed -i "/demos/d" Cargo.toml
- name: "Commit old checkout"
run: |
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
Expand Down Expand Up @@ -493,7 +494,6 @@ jobs:
--skip test_interpreter_models_assign_equal_model \
--skip example_carousel \
--skip example_fancy_demo \
--skip example_printerdemo_old \
--skip test_interpreter_elements_path_fit \
--skip test_interpreter_layout_path \
--skip test_interpreter_7guis_booker \
Expand Down Expand Up @@ -544,7 +544,7 @@ jobs:
- uses: Swatinem/rust-cache@v2
- name: Build and Test Printer demo
shell: bash
working-directory: examples/printerdemo_mcu/esp-idf
working-directory: demos/printerdemo_mcu/esp-idf
run: |
. ${IDF_PATH}/export.sh
idf.py build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nightly_snapshot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ jobs:
rm -rf $output_path/demos
mkdir -p $output_path/demos
for demo_subdir in gallery, printerdemo,rust printerdemo_old,rust todo,rust todo-mvc,rust slide_puzzle, memory, imagefilter,rust plotter, opengl_underlay, carousel,rust energy-monitor, weather-demo,; do
for demo_subdir in gallery, printerdemo,rust todo,rust todo-mvc,rust slide_puzzle, memory, imagefilter,rust plotter, opengl_underlay, carousel,rust energy-monitor, weather-demo,; do
IFS=',' read demo subdir <<< "${demo_subdir}"
mkdir -p $output_path/demos/$demo
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/nightly_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- uses: Swatinem/rust-cache@v2
- name: Build and Test Printer demo
shell: bash
working-directory: examples/printerdemo_mcu/esp-idf
working-directory: demos/printerdemo_mcu/esp-idf
run: |
. ${IDF_PATH}/export.sh
idf.py -D SLINT_ESP_LOCAL_EXAMPLE=OFF build
Expand Down Expand Up @@ -123,13 +123,13 @@ jobs:
uses: zephyrproject-rtos/action-zephyr-setup@v1.0.2
with:
app-path: slint
manifest-file-name: examples/printerdemo/zephyr/west.yaml
manifest-file-name: demos/printerdemo/zephyr/west.yaml
sdk-version: 0.16.8
- name: Export the Zephyr CMake package
run: west zephyr-export
- name: Build for ${{matrix.board}}
run: |
west build -b ${{matrix.board}} -p always slint/examples/printerdemo/zephyr -- -DCMAKE_BUILD_TYPE=Release ${{matrix.extra-cmake-args}}
west build -b ${{matrix.board}} -p always slint/demos/printerdemo/zephyr -- -DCMAKE_BUILD_TYPE=Release ${{matrix.extra-cmake-args}}
uefi-demo:
env:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/translations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ jobs:
- name: "printerdemo: Run slint-tr-extractor"
run: find -name \*.slint | xargs cargo run -p slint-tr-extractor -- -d printerdemo -o printerdemo.pot
working-directory: examples/printerdemo
working-directory: demos/printerdemo
- name: "printerdemo: msgmerge and msgfmt"
working-directory: examples/printerdemo
working-directory: demos/printerdemo
run: |
for po in lang/*/LC_MESSAGES
do msgmerge $po/printerdemo.po printerdemo.pot -o $po/printerdemo.po
Expand Down
11 changes: 5 additions & 6 deletions .github/workflows/wasm_demos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
run: |
sed -i "s/#wasm# //" Cargo.toml
wasm-pack build --release --target web
working-directory: examples/printerdemo/rust
working-directory: demos/printerdemo/rust
- name: Gallery WASM build
if: ${{ inputs.build_artifacts }}
run: |
Expand All @@ -46,7 +46,7 @@ jobs:
- name: Remaining wasm demos
if: ${{ inputs.build_artifacts }}
run: |
for demo in examples/printerdemo/rust examples/printerdemo_old/rust examples/todo/rust examples/todo-mvc/rust examples/carousel/rust examples/slide_puzzle examples/memory examples/imagefilter/rust examples/plotter examples/opengl_underlay; do
for demo in demos/printerdemo/rust examples/todo/rust examples/todo-mvc/rust examples/carousel/rust examples/slide_puzzle examples/memory examples/imagefilter/rust examples/plotter examples/opengl_underlay; do
pushd $demo
sed -i "s/#wasm# //" Cargo.toml
wasm-pack build --release --target web
Expand All @@ -57,7 +57,7 @@ jobs:
run: |
sed -i "s/#wasm# //" Cargo.toml
wasm-pack build --release --target web --no-default-features --features slint/default,chrono
working-directory: examples/energy-monitor
working-directory: demos/energy-monitor
- name: Weather Demo example WASM build
run: |
sed -i "s/#wasm# //" Cargo.toml
Expand All @@ -70,8 +70,7 @@ jobs:
name: wasm_demo
path: |
examples/gallery/
examples/printerdemo/rust/
examples/printerdemo_old/rust/
demos/printerdemo/rust/
examples/todo/
examples/todo-mvc/rust/
examples/carousel/rust/
Expand All @@ -80,7 +79,7 @@ jobs:
examples/imagefilter/rust
examples/plotter/
examples/opengl_underlay/
examples/energy-monitor/
demos/energy-monitor/
examples/weather-demo/
!/**/.gitignore
- name: Clean cache # Otherwise the cache is much too big
Expand Down
14 changes: 7 additions & 7 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Files: api/cpp/tests/redpixel.png
Copyright: Copyright © SixtyFPS GmbH <info@slint.dev>
License: MIT

Files: examples/*/LC_MESSAGES/*.mo examples/*/sdkconfig*
Files: examples/*/LC_MESSAGES/*.mo examples/*/sdkconfig* demos/*/LC_MESSAGES/*.mo demos/*/sdkconfig*
Copyright: Copyright © SixtyFPS GmbH <info@slint.dev>
License: MIT

Expand All @@ -35,15 +35,15 @@ Files: api/*/*.json
Copyright: Copyright © SixtyFPS GmbH <info@slint.dev>
License: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

Files: examples/*.json examples/*/README examples/*/README.txt examples/cpp/qt_viewer/interface.ui
Files: examples/*.json examples/*/README examples/*/README.txt examples/cpp/qt_viewer/interface.ui demos/*.json demos/*/README
Copyright: Copyright © SixtyFPS GmbH <info@slint.dev>
License: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

Files: examples/memory/icons/*.svg examples/memory/icons/*.png
Copyright: Fontawesome project <https://fontawesome.com/license/free>
License: CC-BY-4.0

Files: examples/printerdemo/ui/images/*.svg examples/printerdemo_old/ui/images/*.svg
Files: demos/printerdemo/ui/images/*.svg
Copyright: CoreyGinnivan <https://github.com/CoreyGinnivan/system-uicons>
License: Unlicense

Expand Down Expand Up @@ -83,7 +83,7 @@ Files: examples/carousel/fonts/*.ttf
Copyright: Roboto <https://fonts.google.com/specimen/Roboto/about>
License: Apache-2.0

Files: examples/*/esp-idf/*/partitions.csv examples/*/esp-idf/partitions.csv
Files: examples/*/esp-idf/*/partitions.csv examples/*/esp-idf/partitions.csv demos/*/esp-idf/partitions.csv
Copyright: Copyright © SixtyFPS GmbH <info@slint.dev>
License: MIT

Expand Down Expand Up @@ -115,15 +115,15 @@ Files: internal/backends/linuxkms/mouse-pointer.svg examples/virtual_keyboard/ui
Copyright: Copyright © 2018 Dave Gandy & Fork Awesome
License: MIT

Files: examples/energy-monitor/ui/assets/sunny.svg examples/energy-monitor/ui/assets/settings.svg examples/energy-monitor/ui/assets/information.svg examples/energy-monitor/ui/assets/cloudy.svg examples/energy-monitor/ui/assets/cloud.svg examples/energy-monitor/ui/assets/check.svg examples/energy-monitor/ui/assets/arrow-right.svg examples/energy-monitor/ui/assets/arrow-left.svg examples/energy-monitor/ui/assets/dashboard.svg
Files: demos/energy-monitor/ui/assets/sunny.svg demos/energy-monitor/ui/assets/settings.svg demos/energy-monitor/ui/assets/information.svg demos/energy-monitor/ui/assets/cloudy.svg demos/energy-monitor/ui/assets/cloud.svg demos/energy-monitor/ui/assets/check.svg demos/energy-monitor/ui/assets/arrow-right.svg demos/energy-monitor/ui/assets/arrow-left.svg demos/energy-monitor/ui/assets/dashboard.svg
Copyright: Copyright © SixtyFPS GmbH <info@slint.dev>
License: MIT

Files: examples/energy-monitor/ui/assets/spyrosoft-logo.svg
Files: demos/energy-monitor/ui/assets/spyrosoft-logo.svg
Copyright: Copyright © Spyrosoft Solutions GmbH <office@spyro-soft.com>
License: CC-BY-4.0

Files: examples/printerdemo/zephyr/VERSION
Files: demos/printerdemo/zephyr/VERSION
Copyright: Copyright © SixtyFPS GmbH <info@slint.dev>
License: MIT

Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ endif()
add_subdirectory(api/cpp/)

option(SLINT_BUILD_EXAMPLES "Build Slint Examples" OFF)
add_feature_info(SLINT_BUILD_EXAMPLES SLINT_BUILD_EXAMPLES "configure whether to build the examples")
add_feature_info(SLINT_BUILD_EXAMPLES SLINT_BUILD_EXAMPLES "configure whether to build the examples and demos")

if(SLINT_BUILD_EXAMPLES)
add_subdirectory(examples)
add_subdirectory(demos)
endif()
if(SLINT_BUILD_TESTING AND (SLINT_FEATURE_COMPILER OR SLINT_COMPILER))
add_subdirectory(docs/reference/src/quickstart/)
Expand Down
12 changes: 5 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ members = [
'examples/ffmpeg',
'examples/gstreamer-player',
'examples/plotter',
'examples/printerdemo_old/rust',
'examples/printerdemo/rust',
'examples/printerdemo_mcu',
'demos/printerdemo/rust',
'demos/printerdemo_mcu',
'examples/slide_puzzle',
'examples/todo/rust',
'examples/todo-mvc/rust',
'examples/virtual_keyboard/rust',
'examples/carousel/rust',
'examples/energy-monitor',
'demos/energy-monitor',
'examples/mcu-board-support',
'examples/uefi-demo',
'examples/weather-demo',
Expand Down Expand Up @@ -72,13 +71,12 @@ default-members = [
'api/rs/slint',
'examples/gallery',
'examples/memory',
'examples/printerdemo_old/rust',
'examples/printerdemo/rust',
'demos/printerdemo/rust',
'examples/slide_puzzle',
'examples/todo/rust',
'examples/virtual_keyboard/rust',
'examples/carousel/rust',
'examples/energy-monitor',
'demos/energy-monitor',
'internal/backends/winit',
'internal/backends/qt',
'internal/backends/selector',
Expand Down
4 changes: 2 additions & 2 deletions api/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ The installation will use binaries provided vi macOS, Windows, and Linux for var

## Try it out

If you want to just play with this, you can try running our Python port of the [printer demo](../../examples/printerdemo/python/README.md):
If you want to just play with this, you can try running our Python port of the [printer demo](../../demos/printerdemo/python/README.md):

```bash
cd examples/printerdemo/python
cd demos/printerdemo/python
pipenv update
pipenv run python main.py
```
Expand Down
4 changes: 2 additions & 2 deletions api/python/tests/test_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_property_access():
finished: true,
dash-prop: true,
};
in property <image> imageprop: @image-url("../../../examples/printerdemo/ui/images/cat.jpg");
in property <image> imageprop: @image-url("../../../demos/printerdemo/ui/images/cat.jpg");
callback test-callback();
}
Expand Down Expand Up @@ -177,7 +177,7 @@ def test_callbacks():
if __name__ == "__main__":
import slint
module = slint.load_file(
"../../examples/printerdemo/ui/printerdemo.slint")
"../../demos/printerdemo/ui/printerdemo.slint")
instance = module.MainWindow()
instance.PrinterQueue.start_job = lambda title: print(
f"new print job {title}")
Expand Down
2 changes: 1 addition & 1 deletion api/python/tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_magic_import_path():
try:
sys.path.append(os.path.join(os.path.dirname(__file__),
"..", "..", ".."))
instance = loader.examples.printerdemo.ui.printerdemo.MainWindow()
instance = loader.demos.printerdemo.ui.printerdemo.MainWindow()
del instance
finally:
sys.path = oldsyspath
2 changes: 1 addition & 1 deletion api/rs/slint/mcu.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,4 +422,4 @@ in your `Cargo.toml`.

For an entire template, check out our [Slint Bare Metal Microcontroller Rust Template](https://github.com/slint-ui/slint-mcu-rust-template).

We also have a version of our printer demo that we've adapted to small screens, the [MCU Printer Demo](https://github.com/slint-ui/slint/tree/master/examples/printerdemo_mcu).
We also have a version of our printer demo that we've adapted to small screens, the [MCU Printer Demo](https://github.com/slint-ui/slint/tree/master/demos/printerdemo_mcu).
19 changes: 19 additions & 0 deletions demos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright © SixtyFPS GmbH <info@slint.dev>
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.21)
project(SlintDemos LANGUAGES CXX)

list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")

if (NOT TARGET Slint::Slint)
find_package(Slint REQUIRED)
include(FetchContent)
endif()

if (TARGET Slint::slint-compiler)
add_subdirectory(printerdemo/cpp/)
endif()
if (SLINT_FEATURE_INTERPRETER)
add_subdirectory(printerdemo/cpp_interpreted/)
endif()

73 changes: 73 additions & 0 deletions demos/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<!-- Copyright © SixtyFPS GmbH <info@slint.dev> ; SPDX-License-Identifier: MIT -->

# Demos

These demos showcase different complex use-cases for building UIs with Slint.



| Thumbnail | Description | Demo |
| --- | --- | --- |
| [Printer UI ![Printer Demo image](https://github.com/user-attachments/assets/7e7400ad-283a-4404-b04a-8620ba4df452)](./printerdemo) | A fictional user interface for the touch screen of a printer. <br/> [Project...](./printerdemo) | [Wasm Demo](https://slint.dev/snapshots/master/demos/printerdemo/) |
| [Energy Meter![Energy meter demo image](https://github.com/user-attachments/assets/abfe03e3-ded6-4ddc-82b7-8303ee45515c "Energy meter demo image")](./energy-monitor/) | A fictional user interface of a device that monitors energy consumption in a building. <br/> [Project...](./energy-monitor) | [Wasm Demo](https://slint.dev/snapshots/master/demos/energy-monitor/) |

---
### Running the Rust Demos

You can run the examples either by going into folder or into the rust sub-folder and use `cargo run`, for example:

```sh
cd demos/printerdemo/rust
cargo run --release
```

or you can run them from anywhere in the Cargo workspace by name:

```sh
cargo run --release --bin printerdemo
```

---
### Wasm builds

In order to make the wasm build of the example, you first need to edit the Cargo.toml
files to uncomment the line starting with `#wasm#` (or use the `sed` line bellow)
You can then use wasm-pack (which you may need to obtain with `cargo install wasm-pack`).
This will generate the wasm in the `./pkg` directory, which the `index.html` file will open.
Since wasm files cannot be served from `file://` URL, you need to open a wab server to serve
the content

```sh
cd demos/printerdemo/rust
sed -i "s/^#wasm# //" Cargo.toml
wasm-pack build --release --target web
python3 -m http.server
```

---
### Running the C++ Examples

* **When compiling Slint from sources:** If you follow the [C++ build instructions](/docs/building.md#c-build), this will build the C++
examples as well by default
* **From [installed binary packages](/api/cpp/README.md#binary-packages):** Simply run cmake in one of the example directory containing a CMakeLists.txt

```sh
mkdir build && cd build
cmake -GNinja -DCMAKE_PREFIX_PATH="<path to installed>" ..
cmake --build .
```

---
### Running the Node Examples

You can run the examples by going into the node sub-folder and use `npm`, for example:

```sh
pushd api/node
npm install
npm run compile
popd
cd demos/printerdemo/node
npm install
npm start
```
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ crate-type = ["cdylib", "lib"]

[dependencies]
slint = { path = "../../api/rs/slint", default-features = false, features = ["compat-1-2"] }
mcu-board-support = { path = "../mcu-board-support", optional = true }
mcu-board-support = { path = "../../examples/mcu-board-support", optional = true }
chrono = { version = "0.4.34", optional = true, default-features = false, features = ["clock", "std", "wasmbind"] }
weer_api = { version = "0.1", optional = true }
tokio = { version = "1.25", optional = true, features = ["full"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ cargo apk run -p energy-monitor --target aarch64-linux-android --lib

```sh
cargo install wasm-pack
cd examples/energy-monitor/
cd demos/energy-monitor/
wasm-pack build --release --target web --no-default-features --features slint/default,chrono
python3 -m http.server
```
File renamed without changes.
Loading

0 comments on commit a98d470

Please sign in to comment.