Skip to content

Commit

Permalink
Merge pull request nannou-org#7 from mitchmindtree/ci
Browse files Browse the repository at this point in the history
Add some basic free CI testing using github actions
  • Loading branch information
mitchmindtree authored Jul 14, 2021
2 parents efe8d26 + 97d005a commit e59b892
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 39 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/nannou_egui.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: nannou_egui
on: [push, pull_request]
jobs:
cargo-fmt-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install stable
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt
- name: cargo fmt check
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

cargo-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Update apt
run: sudo apt update
- name: Install alsa dev tools
run: sudo apt-get install libasound2-dev
- name: Install libxcb dev tools
run: sudo apt-get install libxcb-composite0-dev
- name: Install stable
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: cargo test
uses: actions-rs/cargo@v1
with:
command: test
args: --all --verbose

cargo-doc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Update apt
run: sudo apt update
- name: Install stable
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: cargo doc
uses: actions-rs/cargo@v1
with:
command: doc
args: --all --verbose
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# nannou_egui
[![Latest version](https://img.shields.io/crates/v/nannou_egui.svg)](https://crates.io/crates/nannou_egui)

[![Actions Status](https://github.com/alexene/nannou_egui/workflows/nannou_egui/badge.svg)](https://github.com/alexene/nannou_egui/actions) [![Crates.io](https://img.shields.io/crates/v/nannou_egui.svg)](https://crates.io/crates/nannou_egui) [![Crates.io](https://img.shields.io/crates/l/nannou_egui.svg)](https://github.com/alexene/nannou_egui/blob/master/LICENSE-MIT) [![docs.rs](https://docs.rs/nannou_egui/badge.svg)](https://docs.rs/nannou_egui/)

This is my [egui] integration for nannou. The purpose of this is to allow you to tune values for your generative art creations without requiring a compilation cycle.

There are a bunch of rough edges as this is really early in dev (and I am not familiar with webgpu).
Most notably, right now you need to have MSAA = 1 in your window settings and scaling doesn't work at the moment.
Most notably, right now you need to have MSAA = 1 in your window settings and scaling doesn't work at the moment.
For inspiration on how to expose UI widgets, please check the [egui] repo as it has a lot of examples. You have sliders, color pickers, checkboxes, dropdownlists and many more widgets available.

For information on how to integrate it to your nannou creations, there's an [example] in this repo.

To run the circle packing example: `cargo run --example circle_packing`:
To run the circle packing example: `cargo run --example circle_packing`:

![](https://github.com/AlexEne/nannou_egui/blob/main/nannou_egui/media/circle_packing.gif)

Expand Down
33 changes: 16 additions & 17 deletions nannou_egui/examples/circle_packing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,22 @@ fn update(_app: &App, model: &mut Model, update: Update) {

egui.set_elapsed_time(update.since_start);
let ctx = egui.begin_frame();
egui::Window::new("Workshop window")
.show(&ctx, |ui| {
let mut changed = false;
changed |= ui
.add(egui::Slider::new(&mut settings.min_radius, 0.0..=20.0).text("min radius"))
.changed();
changed |= ui
.add(egui::Slider::new(&mut settings.max_radius, 0.0..=200.0).text("max radius"))
.changed();
changed |= ui
.add(egui::Slider::new(&mut settings.circle_count, 0..=2000).text("circle count"))
.changed();
changed |= ui.button("Generate").clicked();
if changed {
*circles = generate_circles(settings);
}
});
egui::Window::new("Workshop window").show(&ctx, |ui| {
let mut changed = false;
changed |= ui
.add(egui::Slider::new(&mut settings.min_radius, 0.0..=20.0).text("min radius"))
.changed();
changed |= ui
.add(egui::Slider::new(&mut settings.max_radius, 0.0..=200.0).text("max radius"))
.changed();
changed |= ui
.add(egui::Slider::new(&mut settings.circle_count, 0..=2000).text("circle count"))
.changed();
changed |= ui.button("Generate").clicked();
if changed {
*circles = generate_circles(settings);
}
});
}

fn raw_window_event(_app: &App, model: &mut Model, event: &nannou::winit::event::WindowEvent) {
Expand Down
33 changes: 15 additions & 18 deletions nannou_egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ pub use egui_wgpu_backend;

use egui::{pos2, ClippedMesh, CtxRef};
use egui_wgpu_backend::{epi, ScreenDescriptor};
use nannou::{
wgpu,
winit::event::VirtualKeyCode,
winit::event::WindowEvent::*,
};
use nannou::{wgpu, winit::event::VirtualKeyCode, winit::event::WindowEvent::*};
use std::{
cell::RefCell,
ops::Deref,
Expand Down Expand Up @@ -75,7 +71,11 @@ impl Egui {
let renderer = RefCell::new(Renderer::new(device, target_format, target_msaa_samples));
let input = Input::new(window_scale_factor, window_size_pixels);
let context = Default::default();
Self { renderer, input, context }
Self {
renderer,
input,
context,
}
}

/// Construct a `Egui` associated with the given window.
Expand Down Expand Up @@ -251,7 +251,7 @@ impl Input {
}
ModifiersChanged(input) => {
self.raw.modifiers = winit_to_egui_modifiers(*input);
},
}
KeyboardInput { input, .. } => {
if let Some(virtual_keycode) = input.virtual_keycode {
if let Some(key) = winit_to_egui_key_code(virtual_keycode) {
Expand All @@ -265,8 +265,7 @@ impl Input {
}
}
ReceivedCharacter(ch) => {
if ch.is_alphanumeric() && !self.raw.modifiers.ctrl && !self.raw.modifiers.command
{
if ch.is_alphanumeric() && !self.raw.modifiers.ctrl && !self.raw.modifiers.command {
self.raw.events.push(egui::Event::Text(ch.to_string()));
}
}
Expand Down Expand Up @@ -342,13 +341,7 @@ impl Renderer {
render_pass.update_texture(device, queue, &context.texture());
render_pass.update_user_textures(&device, &queue);
render_pass.update_buffers(device, queue, &paint_jobs, &screen_descriptor);
render_pass.execute(
encoder,
dst_texture,
&paint_jobs,
&screen_descriptor,
None,
);
render_pass.execute(encoder, dst_texture, &paint_jobs, &screen_descriptor, None);
}

/// Encodes a render pass for drawing the given context's texture to the given frame.
Expand Down Expand Up @@ -506,8 +499,12 @@ pub fn edit_color(ui: &mut egui::Ui, color: &mut nannou::color::Hsv) {
1.0,
);

if egui::color_picker::color_edit_button_hsva(ui, &mut egui_hsv, egui::color_picker::Alpha::Opaque)
.changed()
if egui::color_picker::color_edit_button_hsva(
ui,
&mut egui_hsv,
egui::color_picker::Alpha::Opaque,
)
.changed()
{
*color = nannou::color::hsv(egui_hsv.h, egui_hsv.s, egui_hsv.v);
}
Expand Down

0 comments on commit e59b892

Please sign in to comment.