Skip to content

Commit

Permalink
Remove the glutin feature in favour of more flexible winit feature
Browse files Browse the repository at this point in the history
The old `glutin` feature was created before the `winit` crate was in a
usable state and only provides an event conversion function for
converting `winit::Event`s to `conrod::event::Input`s. Now that `winit`
is usable (and is the backend for windowing in the most recent `glutin`
and `glium` versions) It makes much more sense to do this under a
`winit` feature.

This should allow users to use conrod in non-opengl `winit`
applications.
  • Loading branch information
mitchmindtree committed Jan 26, 2017
1 parent ec61a59 commit 8e1c948
Show file tree
Hide file tree
Showing 20 changed files with 428 additions and 399 deletions.
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ rusttype = "0.2.0"
# Provides functions for rendering the `conrod::render::Primitives` yielded by `Ui::draw`.
# Enables the `conrod::backend::glium` module.
#
# `glutin`
# Provides a function for converting glutin `Event`s to `conrod::event::Raw`s.
# Enables the `conrod::backend::glutin` module.
# `winit`
# Provides a function for converting winit `Event`s to `conrod::event::Raw`s.
# Enables the `conrod::backend::winit` module.
#
# `piston`
# Provides functions for:
# - Converting piston `GenericEvent` types to `conrod::event::Raw`s.
# - Rendering the `conrod::render::Primitives` yielded by `Ui::draw`.
# Enables the `conrod::backend::piston` module.
glium = { version = "0.16.0", optional = true }
glutin = { version = "0.7.1", optional = true }
winit = { version = "0.5.9", optional = true }
piston2d-graphics = { version = "0.20", optional = true }

[features]
Expand All @@ -57,5 +57,6 @@ rand = "0.3.13"
gfx = "0.14.0"
gfx_core = "0.6.0"
gfx_window_glutin = "0.14.0"
glutin = "0.7.0"
# piston_window.rs example dependencies
piston_window = "0.62.0"
29 changes: 14 additions & 15 deletions examples/all_glutin_gfx.rs → examples/all_winit_gfx.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
//! A demonstration of using glutin to provide events and GFX to draw the UI
//! A demonstration of using `winit` to provide events and GFX to draw the UI.
//!
//! `winit` is used via the `glutin` crate which also provides an OpenGL context for drawing
//! `conrod::render::Primitives` to the screen.

#![allow(unused_variables)]

#[cfg(feature="glutin")]
#[macro_use]
extern crate conrod;
#[cfg(feature="glutin")]
extern crate glutin;
#[macro_use]
extern crate gfx;
#[cfg(feature="winit")] #[macro_use] extern crate conrod;
#[cfg(feature="winit")] extern crate glutin;
#[macro_use] extern crate gfx;
extern crate gfx_core;

#[cfg(feature="glutin")]
#[cfg(feature="winit")]
mod support;


fn main() {
feature::main();
}

#[cfg(feature="glutin")]
#[cfg(feature="winit")]
mod feature {
extern crate gfx_window_glutin;
extern crate find_folder;
Expand Down Expand Up @@ -342,8 +341,8 @@ mod feature {
let (w, h) = (win_w as conrod::Scalar, win_h as conrod::Scalar);
let dpi_factor = dpi_factor as conrod::Scalar;

// Convert glutin event to conrod event, requires conrod to be built with the `glutin` feature
if let Some(event) = conrod::backend::glutin::convert(event.clone(), &window) {
// Convert winit event to conrod event, requires conrod to be built with the `winit` feature
if let Some(event) = conrod::backend::winit::convert(event.clone(), window.as_winit_window()) {
ui.handle_event(event);
}

Expand All @@ -366,10 +365,10 @@ mod feature {
}
}

#[cfg(not(feature="glutin"))]
#[cfg(not(feature="winit"))]
mod feature {
pub fn main() {
println!("This example requires the `glutin` feature. \
Try running `cargo run --release --no-default-features --features=\"glutin\" --example <example_name>`");
println!("This example requires the `winit` feature. \
Try running `cargo run --release --no-default-features --features=\"winit\" --example <example_name>`");
}
}
19 changes: 9 additions & 10 deletions examples/all_glutin_glium.rs → examples/all_winit_glium.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//! A demonstration using glutin to provide events and glium for drawing the Ui.
//! A demonstration using winit to provide events and glium for drawing the Ui.
//!
//! Note that the `glium` crate is re-exported via the `conrod::backend::glium` module.

#[cfg(all(feature="glutin", feature="glium"))] #[macro_use] extern crate conrod;
#[cfg(all(feature="winit", feature="glium"))] #[macro_use] extern crate conrod;

#[cfg(all(feature="glutin", feature="glium"))] mod support;
#[cfg(all(feature="winit", feature="glium"))] mod support;

fn main() {
feature::main();
}

#[cfg(all(feature="glutin", feature="glium"))]
#[cfg(all(feature="winit", feature="glium"))]
mod feature {
extern crate find_folder;
extern crate image;
Expand Down Expand Up @@ -84,9 +84,8 @@ mod feature {
// Handle all events.
for event in event_loop.next(&display) {

// Use the `glutin` backend feature to convert the glutin event to a conrod one.
let window = display.get_window().unwrap();
if let Some(event) = conrod::backend::glutin::convert(event.clone(), window) {
// Use the `winit` backend feature to convert the winit event to a conrod one.
if let Some(event) = conrod::backend::winit::convert(event.clone(), &display) {
ui.handle_event(event);
event_loop.needs_update();
}
Expand Down Expand Up @@ -116,10 +115,10 @@ mod feature {

}

#[cfg(not(all(feature="glutin", feature="glium")))]
#[cfg(not(all(feature="winit", feature="glium")))]
mod feature {
pub fn main() {
println!("This example requires the `glutin` and `glium` features. \
Try running `cargo run --release --features=\"glutin glium\" --example <example_name>`");
println!("This example requires the `winit` and `glium` features. \
Try running `cargo run --release --features=\"winit glium\" --example <example_name>`");
}
}
17 changes: 8 additions & 9 deletions examples/canvas.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! A simple demonstration of how to construct and use Canvasses by splitting up the window.

#[cfg(all(feature="glutin", feature="glium"))] #[macro_use] extern crate conrod;
#[cfg(all(feature="glutin", feature="glium"))] mod support;
#[cfg(all(feature="winit", feature="glium"))] #[macro_use] extern crate conrod;
#[cfg(all(feature="winit", feature="glium"))] mod support;

fn main() {
feature::main();
}

#[cfg(all(feature="glutin", feature="glium"))]
#[cfg(all(feature="winit", feature="glium"))]
mod feature {
extern crate find_folder;
use conrod;
Expand Down Expand Up @@ -52,9 +52,8 @@ mod feature {
// Handle all events.
for event in event_loop.next(&display) {

// Use the `glutin` backend feature to convert the glutin event to a conrod one.
let window = display.get_window().unwrap();
if let Some(event) = conrod::backend::glutin::convert(event.clone(), window) {
// Use the `winit` backend feature to convert the winit event to a conrod one.
if let Some(event) = conrod::backend::winit::convert(event.clone(), &display) {
ui.handle_event(event);
event_loop.needs_update();
}
Expand Down Expand Up @@ -199,10 +198,10 @@ mod feature {
}
}

#[cfg(not(all(feature="glutin", feature="glium")))]
#[cfg(not(all(feature="winit", feature="glium")))]
mod feature {
pub fn main() {
println!("This example requires the `glutin` and `glium` features. \
Try running `cargo run --release --features=\"glutin glium\" --example <example_name>`");
println!("This example requires the `winit` and `glium` features. \
Try running `cargo run --release --features=\"winit glium\" --example <example_name>`");
}
}
17 changes: 8 additions & 9 deletions examples/counter.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#[cfg(all(feature="glutin", feature="glium"))] #[macro_use] extern crate conrod;
#[cfg(all(feature="glutin", feature="glium"))] mod support;
#[cfg(all(feature="winit", feature="glium"))] #[macro_use] extern crate conrod;
#[cfg(all(feature="winit", feature="glium"))] mod support;
extern crate find_folder;

fn main() {
feature::main();
}

#[cfg(all(feature="glutin", feature="glium"))]
#[cfg(all(feature="winit", feature="glium"))]
mod feature {
extern crate find_folder;
use conrod::{self, widget, Labelable, Positionable, Sizeable, Widget};
Expand Down Expand Up @@ -54,9 +54,8 @@ mod feature {
// Handle all events.
for event in event_loop.next(&display) {

// Use the `glutin` backend feature to convert the glutin event to a conrod one.
let window = display.get_window().unwrap();
if let Some(event) = conrod::backend::glutin::convert(event.clone(), window) {
// Use the `winit` backend feature to convert the winit event to a conrod one.
if let Some(event) = conrod::backend::winit::convert(event.clone(), &display) {
ui.handle_event(event);
event_loop.needs_update();
}
Expand Down Expand Up @@ -100,10 +99,10 @@ mod feature {
}
}

#[cfg(not(all(feature="glutin", feature="glium")))]
#[cfg(not(all(feature="winit", feature="glium")))]
mod feature {
pub fn main() {
println!("This example requires the `glutin` and `glium` features. \
Try running `cargo run --release --features=\"glutin glium\" --example <example_name>`");
println!("This example requires the `winit` and `glium` features. \
Try running `cargo run --release --features=\"winit glium\" --example <example_name>`");
}
}
16 changes: 8 additions & 8 deletions examples/custom_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@

#[macro_use] extern crate conrod;
extern crate find_folder;
#[cfg(all(feature="glutin", feature="glium"))] mod support;
#[cfg(all(feature="winit", feature="glium"))] mod support;


/// The module in which we'll implement our own custom circular button.
#[cfg(all(feature="winit", feature="glium"))]
mod circular_button {
use conrod::{self, widget, Colorable, Dimensions, Labelable, Point, Positionable, Widget};

Expand Down Expand Up @@ -234,7 +235,7 @@ mod circular_button {
}


#[cfg(all(feature="glutin", feature="glium"))]
#[cfg(all(feature="winit", feature="glium"))]
fn main() {
use conrod::{self, widget, Colorable, Labelable, Positionable, Sizeable, Widget};
use conrod::backend::glium::glium;
Expand Down Expand Up @@ -286,9 +287,8 @@ fn main() {
// Handle all events.
for event in event_loop.next(&display) {

// Use the `glutin` backend feature to convert the glutin event to a conrod one.
let window = display.get_window().unwrap();
if let Some(event) = conrod::backend::glutin::convert(event.clone(), window) {
// Use the `winit` backend feature to convert the winit event to a conrod one.
if let Some(event) = conrod::backend::winit::convert(event.clone(), &display) {
ui.handle_event(event);
event_loop.needs_update();
}
Expand Down Expand Up @@ -336,8 +336,8 @@ fn main() {
}
}

#[cfg(not(all(feature="glutin", feature="glium")))]
#[cfg(not(all(feature="winit", feature="glium")))]
fn main() {
println!("This example requires the `glutin` and `glium` features. \
Try running `cargo run --release --features=\"glutin glium\" --example <example_name>`");
println!("This example requires the `winit` and `glium` features. \
Try running `cargo run --release --features=\"winit glium\" --example <example_name>`");
}
17 changes: 8 additions & 9 deletions examples/file_navigator.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
extern crate find_folder;
#[cfg(all(feature="glutin", feature="glium"))] #[macro_use] extern crate conrod;
#[cfg(all(feature="glutin", feature="glium"))] mod support;
#[cfg(all(feature="winit", feature="glium"))] #[macro_use] extern crate conrod;
#[cfg(all(feature="winit", feature="glium"))] mod support;


#[cfg(all(feature="glutin", feature="glium"))]
#[cfg(all(feature="winit", feature="glium"))]
fn main() {
use conrod::backend::glium::glium;
use conrod::backend::glium::glium::{DisplayBuild, Surface};
Expand Down Expand Up @@ -47,9 +47,8 @@ fn main() {
// Handle all events.
for event in event_loop.next(&display) {

// Use the `glutin` backend feature to convert the glutin event to a conrod one.
let window = display.get_window().unwrap();
if let Some(event) = conrod::backend::glutin::convert(event.clone(), window) {
// Use the `winit` backend feature to convert the winit event to a conrod one.
if let Some(event) = conrod::backend::winit::convert(event.clone(), &display) {
ui.handle_event(event);
event_loop.needs_update();
}
Expand Down Expand Up @@ -94,8 +93,8 @@ fn main() {
}
}

#[cfg(not(all(feature="glutin", feature="glium")))]
#[cfg(not(all(feature="winit", feature="glium")))]
fn main() {
println!("This example requires the `glutin` and `glium` features. \
Try running `cargo run --release --features=\"glutin glium\" --example <example_name>`");
println!("This example requires the `winit` and `glium` features. \
Try running `cargo run --release --features=\"winit glium\" --example <example_name>`");
}
17 changes: 8 additions & 9 deletions examples/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
//! A simple demonstration of how to instantiate an `Image` widget.
//!

#[cfg(all(feature="glutin", feature="glium"))] #[macro_use] extern crate conrod;
#[cfg(all(feature="glutin", feature="glium"))] mod support;
#[cfg(all(feature="winit", feature="glium"))] #[macro_use] extern crate conrod;
#[cfg(all(feature="winit", feature="glium"))] mod support;

fn main() {
feature::main();
}

#[cfg(all(feature="glutin", feature="glium"))]
#[cfg(all(feature="winit", feature="glium"))]
mod feature {
extern crate find_folder;
extern crate image;
Expand Down Expand Up @@ -57,9 +57,8 @@ mod feature {
// Handle all events.
for event in event_loop.next(&display) {

// Use the `glutin` backend feature to convert the glutin event to a conrod one.
let window = display.get_window().unwrap();
if let Some(event) = conrod::backend::glutin::convert(event.clone(), window) {
// Use the `winit` backend feature to convert the winit event to a conrod one.
if let Some(event) = conrod::backend::winit::convert(event.clone(), &display) {
ui.handle_event(event);
}

Expand Down Expand Up @@ -104,10 +103,10 @@ mod feature {
}
}

#[cfg(not(all(feature="glutin", feature="glium")))]
#[cfg(not(all(feature="winit", feature="glium")))]
mod feature {
pub fn main() {
println!("This example requires the `glutin` and `glium` features. \
Try running `cargo run --release --features=\"glutin glium\" --example <example_name>`");
println!("This example requires the `winit` and `glium` features. \
Try running `cargo run --release --features=\"winit glium\" --example <example_name>`");
}
}
17 changes: 8 additions & 9 deletions examples/image_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
//! check the current `Theme` within the `Ui` and retrieve defaults from there.
//!

#[cfg(all(feature="glutin", feature="glium"))] #[macro_use] extern crate conrod;
#[cfg(all(feature="glutin", feature="glium"))] mod support;
#[cfg(all(feature="winit", feature="glium"))] #[macro_use] extern crate conrod;
#[cfg(all(feature="winit", feature="glium"))] mod support;

fn main() {
feature::main();
}

#[cfg(all(feature="glutin", feature="glium"))]
#[cfg(all(feature="winit", feature="glium"))]
mod feature {
extern crate find_folder;
extern crate image;
Expand Down Expand Up @@ -71,9 +71,8 @@ mod feature {
// Handle all events.
for event in event_loop.next(&display) {

// Use the `glutin` backend feature to convert the glutin event to a conrod one.
let window = display.get_window().unwrap();
if let Some(event) = conrod::backend::glutin::convert(event.clone(), window) {
// Use the `winit` backend feature to convert the winit event to a conrod one.
if let Some(event) = conrod::backend::winit::convert(event.clone(), &display) {
ui.handle_event(event);
event_loop.needs_update();
}
Expand Down Expand Up @@ -133,10 +132,10 @@ mod feature {
}
}

#[cfg(not(all(feature="glutin", feature="glium")))]
#[cfg(not(all(feature="winit", feature="glium")))]
mod feature {
pub fn main() {
println!("This example requires the `glutin` and `glium` features. \
Try running `cargo run --release --features=\"glutin glium\" --example <example_name>`");
println!("This example requires the `winit` and `glium` features. \
Try running `cargo run --release --features=\"winit glium\" --example <example_name>`");
}
}
Loading

0 comments on commit 8e1c948

Please sign in to comment.