zng/examples
Samuel e4afb24484
Implement custom cursors. (#178)
2024-05-01 17:09:29 -03:00
..
res Implement debug crash handler dialog (#139) 2024-04-25 16:55:44 -03:00
util Add app-process crash handler (#129) 2024-04-24 16:39:06 -03:00
Cargo.toml Implement zng-view window extension API (#156) 2024-04-30 17:42:57 -03:00
README.md Add examples tip. 2024-04-27 00:09:28 -03:00
animation.rs Implement debug crash handler dialog (#139) 2024-04-25 16:55:44 -03:00
border.rs Implement debug crash handler dialog (#139) 2024-04-25 16:55:44 -03:00
button.rs Fix when/assign expansion (#154) 2024-04-28 11:43:33 -03:00
calculator.rs Add `enabled_buttons`. (#152) 2024-04-27 19:59:55 -03:00
config.rs Implement debug crash handler dialog (#139) 2024-04-25 16:55:44 -03:00
countdown.rs Add `enabled_buttons`. (#152) 2024-04-27 19:59:55 -03:00
cursor.rs Implement custom cursors. (#178) 2024-05-01 17:09:29 -03:00
extend_view.rs Implement zng-view window extension API (#156) 2024-04-30 17:42:57 -03:00
focus.rs Implement debug crash handler dialog (#139) 2024-04-25 16:55:44 -03:00
gradient.rs Implement debug crash handler dialog (#139) 2024-04-25 16:55:44 -03:00
headless.rs Implement examples README generation (#105) 2024-04-16 17:10:58 -03:00
icon.rs Add footer to icon example (#169) 2024-04-29 20:22:29 -03:00
image.rs Implement debug crash handler dialog (#139) 2024-04-25 16:55:44 -03:00
layer.rs Implement debug crash handler dialog (#139) 2024-04-25 16:55:44 -03:00
localize.rs Implement debug crash handler dialog (#139) 2024-04-25 16:55:44 -03:00
markdown.rs Implement debug crash handler dialog (#139) 2024-04-25 16:55:44 -03:00
respawn.rs Implement zng-view window extension API (#156) 2024-04-30 17:42:57 -03:00
scroll.rs Implement debug crash handler dialog (#139) 2024-04-25 16:55:44 -03:00
shortcut.rs Add `enabled_buttons`. (#152) 2024-04-27 19:59:55 -03:00
text.rs Implement debug crash handler dialog (#139) 2024-04-25 16:55:44 -03:00
transform.rs Implement debug crash handler dialog (#139) 2024-04-25 16:55:44 -03:00
window.rs Implement custom cursors. (#178) 2024-05-01 17:09:29 -03:00

README.md

animation

headless screenshot

Source: animation.rs

cargo do run animation

Demonstrates animation, easing functions.

border

headless screenshot

Source: border.rs

cargo do run border

Demonstrates borders, corner radius, multiple borders per widget and clip-to-bounds.

button

headless screenshot

Source: button.rs

cargo do run button

Demonstrates the button widget.

calculator

headless screenshot

Source: calculator.rs

cargo do run calculator

Simple calculator, demonstrates Grid layout, data context.

config

headless screenshot

Source: config.rs

cargo do run config

Demonstrates the CONFIG service, live updating config between processes.

countdown

Source: countdown.rs

cargo do run countdown

Demonstrates the TIMERS service, variable mapping.

cursor

headless screenshot

Source: cursor.rs

cargo do run cursor

Demonstrates each CursorIcon, tooltip anchored to cursor.

extend_view

Source: extend_view.rs

cargo do run extend_view

Demonstrates the zng-view extension API and render extensions API.

focus

headless screenshot

Source: focus.rs

cargo do run focus

Demonstrates the focus service, logical and directional navigation.

gradient

headless screenshot

Source: gradient.rs

cargo do run gradient

Demonstrates gradient rendering.

headless

headless screenshot

Source: headless.rs

cargo do run headless

Demonstrates headless apps, image and video rendering.

icon

headless screenshot

Source: icon.rs

cargo do run icon

Search and copy Material Icons constants.

image

headless screenshot

Source: image.rs

cargo do run image

Demonstrates image loading, displaying, animated sprites, rendering, pasting.

layer

headless screenshot

Source: layer.rs

cargo do run layer

Demonstrates the LAYERS service.

localize

headless screenshot

Source: localize.rs

cargo do run localize

Demonstrates localization.

markdown

headless screenshot

Source: markdown.rs

cargo do run markdown

Demonstrates the Markdown! widget.

respawn

headless screenshot

Source: respawn.rs

cargo do run respawn

Demonstrates app-process crash handler and view-process respawn.

scroll

headless screenshot

Source: scroll.rs

cargo do run scroll

Demonstrates the Scroll! widget and scroll commands.

shortcut

headless screenshot

Source: shortcut.rs

cargo do run shortcut

Small utility that displays the pressed key gestures.

text

headless screenshot

Source: text.rs

cargo do run text

Demonstrates the Text! and TextInput! widgets. Text rendering, text editor.

transform

headless screenshot

Source: transform.rs

cargo do run transform

Demonstrates 2D and 3D transforms, touch transforms.

window

headless screenshot

Source: window.rs

cargo do run window

Demonstrates the window widget, service, state and commands.

Adding an Example

Add the new example in examples/<example-name>.rs:

//! Demonstrates foo, bar.

#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use zng::prelude::*;

use zng::view_process::prebuilt as view_process;

fn main() {
    examples_util::print_info();
    // view_process::run_same_process(app_main);

    view_process::init();
    app_main();
}

fn app_main() {
    APP.defaults().run_window(async {
        Window! {
            title = "Foo Example";
            child = Text!("Bar");
        }
    })
}

Register it in examples/Cargo.toml:

[[example]]
name = "<example-name>"
path = "<example-name>.rs"

Run the example and test it.

cargo do run <example-name>

Optionally, take a screenshot and save it to examples/res/screenshots/<example-name>.png. You can take a screenshot using the inspector window, press Ctrl+Shift+I then click the "Save Screenshot" menu.

Run oxipng or another minifier on the screenshot before committing.

oxipng -o max --strip safe --alpha "examples/res/screenshots/<example-name>.png"

Update the auto generated README:

cargo do doc --readme-examples

Done. You can run the new example using:

cargo do run <example-name>

Local Example

You can create local examples for manual testing in /examples/examples/<test>.rs. These files are git-ignored and can be run using cargo do run <test> without needing to register.