Skip to content

Commit 2efded8

Browse files
Merge pull request #855 from mitchmindtree/remove_raw_event
Remove `event::Raw` in favour of using `event::Input`
2 parents 6c11ba6 + 9f0bca5 commit 2efded8

26 files changed

+468
-528
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pistoncore-event_loop = { version = "0.26.0", optional = true }
6060
piston2d-gfx_graphics = { version = "0.31.1", optional = true }
6161
piston-texture = { version = "0.5.0", optional = true }
6262
shader_version = { version = "0.2.0", optional = true }
63-
pistoncore-glutin_window = { version = "0.31.0", optional = true }
63+
pistoncore-glutin_window = { version = "0.32.0", optional = true }
6464

6565
[features]
6666
default = ["piston"]

examples/all_widgets.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ fn main() {
3131
let mut app = support::DemoApp::new();
3232

3333
// construct our `Ui`.
34-
let mut ui = conrod::UiBuilder::new().theme(support::theme()).build();
34+
let mut ui = conrod::UiBuilder::new([WIDTH as f64, HEIGHT as f64])
35+
.theme(support::theme())
36+
.build();
3537

3638
// Add a `Font` to the `Ui`'s `font::Map` from file.
3739
let assets = find_folder::Search::KidsThenParents(3, 5).for_folder("assets").unwrap();

examples/canvas.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn main() {
2222
let mut events = WindowEvents::new();
2323

2424
// construct our `Ui`.
25-
let mut ui = conrod::UiBuilder::new().build();
25+
let mut ui = conrod::UiBuilder::new([WIDTH as f64, HEIGHT as f64]).build();
2626

2727
// Add a `Font` to the `Ui`'s `font::Map` from file.
2828
let assets = find_folder::Search::KidsThenParents(3, 5).for_folder("assets").unwrap();

examples/counter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn main() {
2121
let mut events = WindowEvents::new();
2222

2323
// construct our `Ui`.
24-
let mut ui = conrod::UiBuilder::new().build();
24+
let mut ui = conrod::UiBuilder::new([WIDTH as f64, HEIGHT as f64]).build();
2525

2626
// Generate the widget identifiers.
2727
widget_ids!(struct Ids { canvas, counter });

examples/custom_widget.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ pub fn main() {
247247
let mut events = WindowEvents::new();
248248

249249
// construct our `Ui`.
250-
let mut ui = conrod::UiBuilder::new().build();
250+
let mut ui = conrod::UiBuilder::new([WIDTH as f64, HEIGHT as f64]).build();
251251

252252
// The `widget_ids` macro is a easy, safe way of generating a type for producing `widget::Id`s.
253253
widget_ids! {

examples/file_navigator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn main() {
2222
let mut events = WindowEvents::new();
2323

2424
// Construct our `Ui`.
25-
let mut ui = conrod::UiBuilder::new().build();
25+
let mut ui = conrod::UiBuilder::new([WIDTH as f64, HEIGHT as f64]).build();
2626

2727
// A unique identifier for each widget.
2828
widget_ids!(struct Ids { canvas, file_navigator });

examples/glutin_gfx.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ mod feature {
168168
let mut app = support::DemoApp::new();
169169

170170
// Create Ui and Ids of widgets to instantiate
171-
let mut ui = conrod::UiBuilder::new().theme(support::theme()).build();
171+
let mut ui = conrod::UiBuilder::new([WIN_W as f64, WIN_H as f64]).theme(support::theme()).build();
172172
let ids = support::Ids::new(ui.widget_id_generator());
173173

174174
// Load font from file
@@ -209,9 +209,6 @@ mod feature {
209209

210210
let dpi_factor = window.hidpi_factor();
211211

212-
let dt_secs = 0.0;
213-
ui.handle_event(conrod::event::render(dt_secs, win_w, win_h, dpi_factor as conrod::Scalar));
214-
215212
if let Some(mut primitives) = ui.draw_if_changed() {
216213
let (screen_width, screen_height) = (win_w as f32 * dpi_factor, win_h as f32 * dpi_factor);
217214
let mut vertices = Vec::new();

examples/glutin_glium.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ mod feature {
3939
let mut app = support::DemoApp::new();
4040

4141
// Construct our `Ui`.
42-
let mut ui = conrod::UiBuilder::new().theme(support::theme()).build();
42+
let mut ui = conrod::UiBuilder::new([WIN_W as f64, WIN_H as f64]).theme(support::theme()).build();
4343

4444
// The `widget::Id` of each widget instantiated in `support::gui`.
4545
let ids = support::Ids::new(ui.widget_id_generator());
@@ -81,12 +81,6 @@ mod feature {
8181
// - Repeat.
8282
'main: loop {
8383

84-
// Construct a render event for conrod at the beginning of rendering.
85-
// NOTE: This will be removed in a future version of conrod as Render events shouldn't
86-
// be necessary.
87-
let window = display.get_window().unwrap();
88-
ui.handle_event(conrod::backend::glutin::render_event(window).unwrap());
89-
9084
// Poll for events.
9185
for event in display.poll_events() {
9286

@@ -115,7 +109,7 @@ mod feature {
115109
let (win_w, win_h) = (win_rect.w() as u32, win_rect.h() as u32);
116110
let (w, h) = display.get_window().unwrap().get_inner_size_points().unwrap();
117111
if w != win_w || h != win_h {
118-
let event: conrod::event::Raw = conrod::event::Input::Resize(w, h).into();
112+
let event = conrod::event::Input::Resize(w, h);
119113
ui.handle_event(event);
120114
}
121115
}

examples/image.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn main() {
2727
let mut events = WindowEvents::new();
2828

2929
// construct our `Ui`.
30-
let mut ui = conrod::UiBuilder::new().build();
30+
let mut ui = conrod::UiBuilder::new([WIDTH as f64, HEIGHT as f64]).build();
3131

3232
// Create an empty texture to pass for the text cache as we're not drawing any text.
3333
let mut text_texture_cache = piston::window::GlyphCache::new(&mut window, 0, 0);
@@ -47,7 +47,11 @@ fn main() {
4747

4848
// Poll events from the window.
4949
while let Some(event) = window.next_event(&mut events) {
50-
ui.handle_event(event.clone());
50+
51+
// Convert the piston event to a conrod input event.
52+
if let Some(e) = piston::window::convert_event(event.clone(), &window) {
53+
ui.handle_event(e);
54+
}
5155

5256
window.draw_2d(&event, |c, g| {
5357
if let Some(primitives) = ui.draw_if_changed() {

examples/image_button.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn main() {
3232
let mut events = WindowEvents::new();
3333

3434
// construct our `Ui`.
35-
let mut ui = conrod::UiBuilder::new().build();
35+
let mut ui = conrod::UiBuilder::new([WIDTH as f64, HEIGHT as f64]).build();
3636

3737
// Add a `Font` to the `Ui`'s `font::Map` from file.
3838
let assets = find_folder::Search::KidsThenParents(3, 5).for_folder("assets").unwrap();

examples/list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn main() {
2323
let mut events = WindowEvents::new();
2424

2525
// Construct our `Ui`.
26-
let mut ui = conrod::UiBuilder::new().build();
26+
let mut ui = conrod::UiBuilder::new([WIDTH as f64, HEIGHT as f64]).build();
2727

2828
// Unique identifier for each widget.
2929
let ids = Ids::new(ui.widget_id_generator());

examples/list_select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn main() {
2727
let mut events = WindowEvents::new();
2828

2929
// Construct our `Ui`.
30-
let mut ui = conrod::UiBuilder::new().build();
30+
let mut ui = conrod::UiBuilder::new([WIDTH as f64, HEIGHT as f64]).build();
3131

3232
// A unique identifier for each widget.
3333
let ids = Ids::new(ui.widget_id_generator());

examples/old_demo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ fn main() {
108108
let mut events = WindowEvents::new();
109109

110110
// construct our `Ui`.
111-
let mut ui = conrod::UiBuilder::new().build();
111+
let mut ui = conrod::UiBuilder::new([WIDTH as f64, HEIGHT as f64]).build();
112112

113113
// Identifiers used for instantiating our widgets.
114114
let mut ids = Ids::new(ui.widget_id_generator());

examples/plot_path.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ widget_ids! {
99
}
1010

1111
fn main() {
12+
const WIDTH: u32 = 720;
13+
const HEIGHT: u32 = 360;
1214

1315
// Construct the window.
1416
let mut window: Window =
15-
piston::window::WindowSettings::new("PlotPath Demo", [720, 360])
17+
piston::window::WindowSettings::new("PlotPath Demo", [WIDTH, HEIGHT])
1618
.opengl(OpenGL::V3_2)
1719
.samples(4)
1820
.exit_on_esc(true)
@@ -23,7 +25,7 @@ fn main() {
2325
let mut events = WindowEvents::new();
2426

2527
// Construct our `Ui`.
26-
let mut ui = conrod::UiBuilder::new().build();
28+
let mut ui = conrod::UiBuilder::new([WIDTH as f64, HEIGHT as f64]).build();
2729

2830
// A unique identifier for each widget.
2931
let ids = Ids::new(ui.widget_id_generator());

examples/primitives.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,22 @@ widget_ids! {
2121

2222

2323
fn main() {
24+
const WIDTH: u32 = 400;
25+
const HEIGHT: u32 = 720;
2426

2527
// Change this to OpenGL::V2_1 if not working.
2628
let opengl = OpenGL::V3_2;
2729

2830
// Construct the window.
2931
let mut window: Window =
30-
piston::window::WindowSettings::new("Primitives Demo", [400, 720])
32+
piston::window::WindowSettings::new("Primitives Demo", [WIDTH, HEIGHT])
3133
.opengl(opengl).samples(4).exit_on_esc(true).build().unwrap();
3234

3335
// Create the event loop.
3436
let mut events = WindowEvents::new();
3537

3638
// construct our `Ui`.
37-
let mut ui = conrod::UiBuilder::new().build();
39+
let mut ui = conrod::UiBuilder::new([WIDTH as f64, HEIGHT as f64]).build();
3840

3941
// A unique identifier for each widget.
4042
let ids = Ids::new(ui.widget_id_generator());

examples/range_slider.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn main() {
2525
let mut events = WindowEvents::new();
2626

2727
// Construct our `Ui`.
28-
let mut ui = conrod::UiBuilder::new().build();
28+
let mut ui = conrod::UiBuilder::new([WIDTH as f64, HEIGHT as f64]).build();
2929

3030
// A unique identifier for each widget.
3131
let ids = Ids::new(ui.widget_id_generator());

examples/text.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn main() {
2020
let mut events = WindowEvents::new();
2121

2222
// Construct our `Ui`.
23-
let mut ui = conrod::UiBuilder::new().build();
23+
let mut ui = conrod::UiBuilder::new([WIDTH as f64, HEIGHT as f64]).build();
2424

2525
// A unique identifier for each widget.
2626
let ids = Ids::new(ui.widget_id_generator());

examples/text_edit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn main() {
2121
let mut events = WindowEvents::new();
2222

2323
// Construct our `Ui`.
24-
let mut ui = conrod::UiBuilder::new().build();
24+
let mut ui = conrod::UiBuilder::new([WIDTH as f64, HEIGHT as f64]).build();
2525

2626
// A unique identifier for each widget.
2727
let ids = Ids::new(ui.widget_id_generator());

src/backend/glutin.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
//! A function for converting a `glutin::Event` to a `conrod::event::Raw`.
1+
//! A function for converting a `glutin::Event` to a `conrod::event::Input`.
22
//!
33
//! The following is adapted from the piston `glutin_window` crate.
44
55
extern crate glutin;
66

77
use Scalar;
8-
use event::{self, Input, Motion};
8+
use event::{Input, Motion};
99
use input;
1010
use std;
1111

12-
/// A function for converting a `glutin::Event` to a `conrod::event::Raw`.
13-
pub fn convert<W>(e: glutin::Event, window: W) -> Option<event::Raw>
12+
/// A function for converting a `glutin::Event` to a `conrod::event::Input`.
13+
pub fn convert<W>(e: glutin::Event, window: W) -> Option<Input>
1414
where W: std::ops::Deref<Target=glutin::Window>,
1515
{
1616

@@ -96,21 +96,6 @@ pub fn convert<W>(e: glutin::Event, window: W) -> Option<event::Raw>
9696
}
9797
}
9898

99-
/// Creates a `event::Raw::Render`.
100-
///
101-
/// Returns `None` if the window is no longer open.
102-
///
103-
/// NOTE: This will be removed in a future version of conrod as Render events shouldn't be
104-
/// necessary.
105-
pub fn render_event<W>(window: W) -> Option<event::Raw>
106-
where W: std::ops::Deref<Target=glutin::Window>,
107-
{
108-
window.get_inner_size_pixels().map(|(win_w, win_h)| {
109-
let dpi_factor = window.hidpi_factor();
110-
event::render(0.0, win_w, win_h, dpi_factor as Scalar)
111-
})
112-
}
113-
11499
/// Maps Glutin's key to a conrod `Key`.
115100
pub fn map_key(keycode: glutin::VirtualKeyCode) -> input::keyboard::Key {
116101
use input::keyboard::Key;

src/backend/piston/event.rs

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,60 @@
1-
//! A backend for converting piston events to conrod's `event::Raw` type.
2-
//!
3-
//! The module also allows provides an `EventWindow` impl for the default piston game event loop
4-
//! from pistoncore-event_loop, allowing compatibility with conrod's custom piston `Window`.
1+
//! A backend for converting piston events to conrod's `Input` type.
52
63
use {Point, Scalar};
7-
use event::{self, Input, Motion, RawEvent};
8-
4+
use event::{Input, Motion};
95
pub use piston_input::{GenericEvent, UpdateEvent};
106

11-
12-
/// Converts any `GenericEvent` to a `Raw` conrod event.
13-
pub fn convert<E>(event: E, win_w: Scalar, win_h: Scalar) -> Option<event::Raw>
7+
/// Converts any `GenericEvent` to an `Input` event for conrod.
8+
///
9+
/// The given `width` and `height` must be `Scalar` (DPI agnostic) values.
10+
pub fn convert<E>(event: E, win_w: Scalar, win_h: Scalar) -> Option<Input>
1411
where E: GenericEvent,
1512
{
1613
// Translate the coordinates from top-left-origin-with-y-down to centre-origin-with-y-up.
1714
let translate_coords = |xy: Point| (xy[0] - win_w / 2.0, -(xy[1] - win_h / 2.0));
1815

19-
if let Some(args) = event.render_args() {
20-
return Some(RawEvent::Render(args));
21-
}
22-
2316
if let Some(xy) = event.mouse_cursor_args() {
2417
let (x, y) = translate_coords(xy);
25-
return Some(Input::Move(Motion::MouseCursor(x, y)).into());
18+
return Some(Input::Move(Motion::MouseCursor(x, y)));
2619
}
2720

2821
if let Some(rel_xy) = event.mouse_relative_args() {
2922
let (rel_x, rel_y) = translate_coords(rel_xy);
30-
return Some(Input::Move(Motion::MouseRelative(rel_x, rel_y)).into());
23+
return Some(Input::Move(Motion::MouseRelative(rel_x, rel_y)));
3124
}
3225

3326
if let Some(xy) = event.mouse_scroll_args() {
3427
// Invert the scrolling of the *y* axis as *y* is up in conrod.
3528
let (x, y) = (xy[0], -xy[1]);
36-
return Some(Input::Move(Motion::MouseScroll(x, y)).into());
29+
return Some(Input::Move(Motion::MouseScroll(x, y)));
3730
}
3831

3932
if let Some(args) = event.controller_axis_args() {
40-
return Some(Input::Move(Motion::ControllerAxis(args)).into());
33+
return Some(Input::Move(Motion::ControllerAxis(args)));
4134
}
4235

4336
if let Some(button) = event.press_args() {
44-
return Some(Input::Press(button).into());
37+
return Some(Input::Press(button));
4538
}
4639

4740
if let Some(button) = event.release_args() {
48-
return Some(Input::Release(button).into());
41+
return Some(Input::Release(button));
4942
}
5043

5144
if let Some(text) = event.text_args() {
52-
return Some(Input::Text(text).into());
45+
return Some(Input::Text(text));
5346
}
5447

5548
if let Some(dim) = event.resize_args() {
56-
return Some(Input::Resize(dim[0], dim[1]).into());
49+
return Some(Input::Resize(dim[0], dim[1]));
5750
}
5851

5952
if let Some(b) = event.focus_args() {
60-
return Some(Input::Focus(b).into());
53+
return Some(Input::Focus(b));
6154
}
6255

6356
if let Some(b) = event.cursor_args() {
64-
return Some(Input::Cursor(b).into());
57+
return Some(Input::Cursor(b));
6558
}
6659

6760
None

src/backend/piston/window.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl EventWindow<WindowEvents> for Window {
228228
}
229229

230230
/// Converts any `GenericEvent` to a `Raw` conrod event.
231-
pub fn convert_event<E, B>(event: E, window: &Window<B>) -> Option<event::Raw>
231+
pub fn convert_event<E, B>(event: E, window: &Window<B>) -> Option<event::Input>
232232
where E: GenericEvent,
233233
B: BasicWindow,
234234
{

0 commit comments

Comments
 (0)