Move printer demo and energy-monitor into new top-level demos/ folder

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.
This commit is contained in:
Simon Hausmann 2024-10-24 17:02:17 +02:00 committed by Simon Hausmann
parent acafc9c3e6
commit a98d4709be
241 changed files with 187 additions and 982 deletions

View file

@ -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"
@ -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 \
@ -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

View file

@ -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

View file

@ -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
@ -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:

View file

@ -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

View file

@ -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: |
@ -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
@ -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
@ -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/
@ -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

View file

@ -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
@ -35,7 +35,7 @@ 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
@ -43,7 +43,7 @@ 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
@ -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
@ -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

View file

@ -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/)

View file

@ -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',
@ -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',

View file

@ -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
```

View file

@ -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();
}
@ -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}")

View file

@ -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

View file

@ -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
demos/CMakeLists.txt Normal file
View file

@ -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
demos/README.md Normal file
View file

@ -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
```

View file

@ -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"] }

View file

@ -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
```

View file

@ -31,7 +31,6 @@
height: 100vh !important;
}
}
</style>
</head>
@ -45,9 +44,9 @@
</div>
<canvas id="canvas" data-slint-auto-resize-to-preferred="true" unselectable="on"></canvas>
<p class="hide-in-mobile-landscape links">
<a href="https://github.com/slint-ui/slint/blob/master/examples/energy-monitor/ui/desktop_window.slint">
<a href="https://github.com/slint-ui/slint/blob/master/demos/energy-monitor/ui/desktop_window.slint">
View Source Code on GitHub</a> -
<a href="https://slint.dev/editor?load_demo=examples/energy-monitor/ui/desktop_window.slint">
<a href="https://slint.dev/editor?load_demo=demos/energy-monitor/ui/desktop_window.slint">
Open in SlintPad
</a>
</p>

View file

Before

Width:  |  Height:  |  Size: 228 B

After

Width:  |  Height:  |  Size: 228 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 198 B

After

Width:  |  Height:  |  Size: 198 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 225 B

After

Width:  |  Height:  |  Size: 225 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 337 B

After

Width:  |  Height:  |  Size: 337 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Before After
Before After

View file

@ -6,6 +6,6 @@ A fictional user interface for the touch screen of a printer
| `.slint` Design | Rust Source | C++ Source | Node Source | Online wasm Preview | Open in SlintPad |
| --- | --- | --- | --- | --- | --- |
| [`ui.slint`](./ui/printerdemo.slint) | [`main.rs`](./rust/main.rs) | [`main.cpp`](./cpp/main.cpp) | [`main.js`](./node/main.js) | [Online simulation](https://slint.dev/snapshots/master/demos/printerdemo/) | [Preview in Online Code Editor](https://slint.dev/snapshots/master/editor?load_url=https://raw.githubusercontent.com/slint-ui/slint/master/examples/printerdemo/ui/printerdemo.slint) |
| [`ui.slint`](./ui/printerdemo.slint) | [`main.rs`](./rust/main.rs) | [`main.cpp`](./cpp/main.cpp) | [`main.js`](./node/main.js) | [Online simulation](https://slint.dev/snapshots/master/demos/printerdemo/) | [Preview in Online Code Editor](https://slint.dev/snapshots/master/editor?load_url=https://raw.githubusercontent.com/slint-ui/slint/master/demos/printerdemo/ui/printerdemo.slint) |
![Screenshot of the Printer Demo](https://slint.dev/resources/printerdemo_screenshot.png "Printer Demo")
![Screenshot of the Printer Demo](https://slint.dev/resources/printerdemo_screenshot.png "Printer Demo")

View file

@ -31,7 +31,6 @@
height: 100vh !important;
}
}
</style>
</head>
@ -46,9 +45,9 @@
</div>
<canvas id="canvas" unselectable="on"></canvas>
<p class="hide-in-mobile-landscape links">
<a href="https://github.com/slint-ui/slint/blob/master/examples/printerdemo/ui/printerdemo.slint">
<a href="https://github.com/slint-ui/slint/blob/master/demos/printerdemo/ui/printerdemo.slint">
View Source Code on GitHub</a> -
<a href="https://slint.dev/editor?load_demo=examples/printerdemo/ui/printerdemo.slint">
<a href="https://slint.dev/editor?load_demo=demos/printerdemo/ui/printerdemo.slint">
Open in SlintPad
</a>
</p>

Some files were not shown because too many files have changed in this diff Show more