From 56fb58fc2f0fc5e6c54c445f6399c2d0e31c6545 Mon Sep 17 00:00:00 2001 From: Abendstolz Date: Wed, 26 Dec 2018 14:58:10 +0100 Subject: [PATCH] WIP widget split + 2018 edition --- Cargo.toml | 1 + backends/conrod_example_shared/Cargo.toml | 1 + backends/conrod_example_shared/src/lib.rs | 59 +++++----- conrod_core/Cargo.toml | 5 +- conrod_core/src/border.rs | 2 +- conrod_core/src/color.rs | 2 +- conrod_core/src/cursor.rs | 4 +- conrod_core/src/event.rs | 12 +- conrod_core/src/graph/algo.rs | 8 +- conrod_core/src/graph/depth_order.rs | 2 +- conrod_core/src/graph/mod.rs | 14 ++- conrod_core/src/input/global.rs | 6 +- conrod_core/src/input/mod.rs | 8 +- conrod_core/src/input/state.rs | 21 ++-- conrod_core/src/input/widget.rs | 13 ++- conrod_core/src/label.rs | 7 +- conrod_core/src/lib.rs | 25 ++-- conrod_core/src/position/matrix.rs | 14 ++- conrod_core/src/position/mod.rs | 10 +- conrod_core/src/position/range.rs | 8 +- conrod_core/src/position/rect.rs | 2 +- conrod_core/src/render.rs | 36 +++--- conrod_core/src/tests/global_input.rs | 14 +-- conrod_core/src/tests/ui.rs | 16 +-- conrod_core/src/tests/widget_input.rs | 12 +- conrod_core/src/text.rs | 12 +- conrod_core/src/theme.rs | 18 +-- conrod_core/src/ui.rs | 52 +++++---- conrod_core/src/utils.rs | 10 +- conrod_core/src/widget/bordered_rectangle.rs | 9 +- conrod_core/src/widget/button.rs | 21 +++- .../widget/file_navigator/directory_view.rs | 16 +-- conrod_core/src/widget/file_navigator/mod.rs | 8 +- conrod_core/src/widget/graph/mod.rs | 31 +++-- conrod_core/src/widget/graph/node.rs | 22 +++- conrod_core/src/widget/id.rs | 8 +- conrod_core/src/widget/mod.rs | 85 ++++---------- conrod_core/src/widget/primitive/image.rs | 15 ++- conrod_core/src/widget/primitive/line.rs | 20 +++- conrod_core/src/widget/primitive/mod.rs | 2 +- .../src/widget/primitive/point_path.rs | 21 +++- .../src/widget/primitive/shape/circle.rs | 14 ++- conrod_core/src/widget/primitive/shape/mod.rs | 8 +- .../src/widget/primitive/shape/oval.rs | 18 ++- .../src/widget/primitive/shape/polygon.rs | 20 +++- .../src/widget/primitive/shape/rectangle.rs | 14 ++- .../src/widget/primitive/shape/triangles.rs | 22 ++-- conrod_core/src/widget/primitive/text.rs | 20 ++-- conrod_core/src/widget/rounded_rectangle.rs | 24 ++-- conrod_core/src/widget/scroll.rs | 12 +- conrod_derive/Cargo.toml | 2 + conrod_derive/src/common.rs | 8 +- conrod_derive/src/lib.rs | 2 +- conrod_derive/src/style.rs | 53 +++++++-- conrod_widgets/Cargo.toml | 15 +++ .../widget => conrod_widgets/src}/canvas.rs | 27 +++-- .../src}/collapsible_area.rs | 27 ++++- .../src}/drop_down_list.rs | 45 ++++--- .../src}/envelope_editor.rs | 32 +++-- .../src/widget => conrod_widgets/src}/grid.rs | 18 ++- conrod_widgets/src/lib.rs | 46 ++++++++ .../src/widget => conrod_widgets/src}/list.rs | 47 ++++---- .../src}/list_select.rs | 110 ++++++++++-------- .../widget => conrod_widgets/src}/matrix.rs | 21 +++- .../src}/number_dialer.rs | 28 +++-- .../src}/plot_path.rs | 24 +++- .../src}/range_slider.rs | 33 ++++-- .../src}/scrollbar.rs | 46 +++++--- .../widget => conrod_widgets/src}/slider.rs | 29 +++-- .../src/widget => conrod_widgets/src}/tabs.rs | 45 +++---- .../widget => conrod_widgets/src}/text_box.rs | 30 +++-- .../src}/text_edit.rs | 37 ++++-- .../src}/title_bar.rs | 23 +++- .../widget => conrod_widgets/src}/toggle.rs | 23 +++- .../widget => conrod_widgets/src}/xy_pad.rs | 24 ++-- 75 files changed, 1032 insertions(+), 567 deletions(-) create mode 100644 conrod_widgets/Cargo.toml rename {conrod_core/src/widget => conrod_widgets/src}/canvas.rs (96%) rename {conrod_core/src/widget => conrod_widgets/src}/collapsible_area.rs (96%) rename {conrod_core/src/widget => conrod_widgets/src}/drop_down_list.rs (92%) rename {conrod_core/src/widget => conrod_widgets/src}/envelope_editor.rs (97%) rename {conrod_core/src/widget => conrod_widgets/src}/grid.rs (97%) create mode 100644 conrod_widgets/src/lib.rs rename {conrod_core/src/widget => conrod_widgets/src}/list.rs (96%) rename {conrod_core/src/widget => conrod_widgets/src}/list_select.rs (89%) rename {conrod_core/src/widget => conrod_widgets/src}/matrix.rs (96%) rename {conrod_core/src/widget => conrod_widgets/src}/number_dialer.rs (97%) rename {conrod_core/src/widget => conrod_widgets/src}/plot_path.rs (93%) rename {conrod_core/src/widget => conrod_widgets/src}/range_slider.rs (96%) rename {conrod_core/src/widget => conrod_widgets/src}/scrollbar.rs (94%) rename {conrod_core/src/widget => conrod_widgets/src}/slider.rs (95%) rename {conrod_core/src/widget => conrod_widgets/src}/tabs.rs (92%) rename {conrod_core/src/widget => conrod_widgets/src}/text_box.rs (93%) rename {conrod_core/src/widget => conrod_widgets/src}/text_edit.rs (98%) rename {conrod_core/src/widget => conrod_widgets/src}/title_bar.rs (95%) rename {conrod_core/src/widget => conrod_widgets/src}/toggle.rs (95%) rename {conrod_core/src/widget => conrod_widgets/src}/xy_pad.rs (96%) diff --git a/Cargo.toml b/Cargo.toml index bf624ff20..496975fd5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ members = [ "conrod_core", "conrod_derive", + "conrod_widgets", "backends/conrod_example_shared", "backends/conrod_winit", "backends/conrod_gfx", diff --git a/backends/conrod_example_shared/Cargo.toml b/backends/conrod_example_shared/Cargo.toml index 9ef2ed7b1..5288e8371 100644 --- a/backends/conrod_example_shared/Cargo.toml +++ b/backends/conrod_example_shared/Cargo.toml @@ -6,4 +6,5 @@ description = "A small crate for sharing common code between conrod examples." [dependencies] conrod_core = { path = "../../conrod_core", version = "0.62" } +conrod_widgets = {path = "../../conrod_widgets", version = "0.62"} rand = "0.6" diff --git a/backends/conrod_example_shared/src/lib.rs b/backends/conrod_example_shared/src/lib.rs index cd1a2586e..7f665e7aa 100644 --- a/backends/conrod_example_shared/src/lib.rs +++ b/backends/conrod_example_shared/src/lib.rs @@ -4,13 +4,14 @@ //! //! - `pub struct DemoApp` as a demonstration of some state we want to change. //! - `pub fn gui` as a demonstration of all widgets, some of which mutate our `DemoApp`. -//! - `pub struct Ids` - a set of all `widget::Id`s used in the `gui` fn. +//! - `pub struct Ids` - a set of all `conrod_widgets::Id`s used in the `gui` fn. //! //! By sharing these items between these examples, we can test and ensure that the different events //! and drawing backends behave in the same manner. #![allow(dead_code)] #[macro_use] extern crate conrod_core; +extern crate conrod_widgets; extern crate rand; pub const WIN_W: u32 = 600; @@ -103,7 +104,7 @@ widget_ids! { /// Instantiate a GUI demonstrating every widget available in conrod. pub fn gui(ui: &mut conrod_core::UiCell, ids: &Ids, app: &mut DemoApp) { - use conrod_core::{widget, Colorable, Labelable, Positionable, Sizeable, Widget}; + use conrod_core::{widget as core_widget, Colorable, Labelable, Positionable, Sizeable, Widget}; use std::iter::once; const MARGIN: conrod_core::Scalar = 30.0; @@ -115,7 +116,7 @@ pub fn gui(ui: &mut conrod_core::UiCell, ids: &Ids, app: &mut DemoApp) { // By default, its size is the size of the window. We'll use this as a background for the // following widgets, as well as a scrollable container for the children widgets. const TITLE: &'static str = "All Widgets"; - widget::Canvas::new().pad(MARGIN).scroll_kids_vertically().set(ids.canvas, ui); + conrod_widgets::Canvas::new().pad(MARGIN).scroll_kids_vertically().set(ids.canvas, ui); //////////////// @@ -125,7 +126,7 @@ pub fn gui(ui: &mut conrod_core::UiCell, ids: &Ids, app: &mut DemoApp) { // We'll demonstrate the `Text` primitive widget by using it to draw a title and an // introduction to the example. - widget::Text::new(TITLE).font_size(TITLE_SIZE).mid_top_of(ids.canvas).set(ids.title, ui); + core_widget::Text::new(TITLE).font_size(TITLE_SIZE).mid_top_of(ids.canvas).set(ids.title, ui); const INTRODUCTION: &'static str = "This example aims to demonstrate all widgets that are provided by conrod.\ @@ -134,7 +135,7 @@ pub fn gui(ui: &mut conrod_core::UiCell, ids: &Ids, app: &mut DemoApp) { all other widget types. These types are \"special\" in the sense that conrod knows \ how to render them via `conrod_core::render::Primitive`s.\ \n\nScroll down to see more widgets!"; - widget::Text::new(INTRODUCTION) + core_widget::Text::new(INTRODUCTION) .padded_w_of(ids.canvas, MARGIN) .down(60.0) .align_middle_x_of(ids.canvas) @@ -148,7 +149,7 @@ pub fn gui(ui: &mut conrod_core::UiCell, ids: &Ids, app: &mut DemoApp) { //////////////////////////// - widget::Text::new("Lines and Shapes") + core_widget::Text::new("Lines and Shapes") .down(70.0) .align_middle_x_of(ids.canvas) .font_size(SUBTITLE_SIZE) @@ -158,7 +159,7 @@ pub fn gui(ui: &mut conrod_core::UiCell, ids: &Ids, app: &mut DemoApp) { // // TODO: Have conrod provide an auto-flowing, fluid-list widget that is more adaptive for these // sorts of situations. - widget::Canvas::new() + conrod_widgets::Canvas::new() .down(0.0) .align_middle_x_of(ids.canvas) .kid_area_w_of(ids.canvas) @@ -166,8 +167,8 @@ pub fn gui(ui: &mut conrod_core::UiCell, ids: &Ids, app: &mut DemoApp) { .color(conrod_core::color::TRANSPARENT) .pad(MARGIN) .flow_down(&[ - (ids.shapes_left_col, widget::Canvas::new()), - (ids.shapes_right_col, widget::Canvas::new()), + (ids.shapes_left_col, conrod_widgets::Canvas::new()), + (ids.shapes_right_col, conrod_widgets::Canvas::new()), ]) .set(ids.shapes_canvas, ui); @@ -175,37 +176,37 @@ pub fn gui(ui: &mut conrod_core::UiCell, ids: &Ids, app: &mut DemoApp) { let w = shapes_canvas_rect.w(); let h = shapes_canvas_rect.h() * 5.0 / 6.0; let radius = 10.0; - widget::RoundedRectangle::fill([w, h], radius) + core_widget::RoundedRectangle::fill([w, h], radius) .color(conrod_core::color::CHARCOAL.alpha(0.25)) .middle_of(ids.shapes_canvas) .set(ids.rounded_rectangle, ui); let start = [-40.0, -40.0]; let end = [40.0, 40.0]; - widget::Line::centred(start, end).mid_left_of(ids.shapes_left_col).set(ids.line, ui); + core_widget::Line::centred(start, end).mid_left_of(ids.shapes_left_col).set(ids.line, ui); let left = [-40.0, -40.0]; let top = [0.0, 40.0]; let right = [40.0, -40.0]; let points = once(left).chain(once(top)).chain(once(right)); - widget::PointPath::centred(points).right(SHAPE_GAP).set(ids.point_path, ui); + core_widget::PointPath::centred(points).right(SHAPE_GAP).set(ids.point_path, ui); - widget::Rectangle::fill([80.0, 80.0]).right(SHAPE_GAP).set(ids.rectangle_fill, ui); + core_widget::Rectangle::fill([80.0, 80.0]).right(SHAPE_GAP).set(ids.rectangle_fill, ui); - widget::Rectangle::outline([80.0, 80.0]).right(SHAPE_GAP).set(ids.rectangle_outline, ui); + core_widget::Rectangle::outline([80.0, 80.0]).right(SHAPE_GAP).set(ids.rectangle_outline, ui); let bl = [-40.0, -40.0]; let tl = [-20.0, 40.0]; let tr = [20.0, 40.0]; let br = [40.0, -40.0]; let points = once(bl).chain(once(tl)).chain(once(tr)).chain(once(br)); - widget::Polygon::centred_fill(points).mid_left_of(ids.shapes_right_col).set(ids.trapezoid, ui); + core_widget::Polygon::centred_fill(points).mid_left_of(ids.shapes_right_col).set(ids.trapezoid, ui); - widget::Oval::fill([40.0, 80.0]).right(SHAPE_GAP + 20.0).align_middle_y().set(ids.oval_fill, ui); + core_widget::Oval::fill([40.0, 80.0]).right(SHAPE_GAP + 20.0).align_middle_y().set(ids.oval_fill, ui); - widget::Oval::outline([80.0, 40.0]).right(SHAPE_GAP + 20.0).align_middle_y().set(ids.oval_outline, ui); + core_widget::Oval::outline([80.0, 40.0]).right(SHAPE_GAP + 20.0).align_middle_y().set(ids.oval_outline, ui); - widget::Circle::fill(40.0).right(SHAPE_GAP).align_middle_y().set(ids.circle, ui); + core_widget::Circle::fill(40.0).right(SHAPE_GAP).align_middle_y().set(ids.circle, ui); ///////////////// @@ -213,14 +214,14 @@ pub fn gui(ui: &mut conrod_core::UiCell, ids: &Ids, app: &mut DemoApp) { ///////////////// - widget::Text::new("Image") + core_widget::Text::new("Image") .down_from(ids.shapes_canvas, MARGIN) .align_middle_x_of(ids.canvas) .font_size(SUBTITLE_SIZE) .set(ids.image_title, ui); const LOGO_SIDE: conrod_core::Scalar = 144.0; - widget::Image::new(app.rust_logo) + core_widget::Image::new(app.rust_logo) .w_h(LOGO_SIDE, LOGO_SIDE) .down(60.0) .align_middle_x_of(ids.canvas) @@ -232,7 +233,7 @@ pub fn gui(ui: &mut conrod_core::UiCell, ids: &Ids, app: &mut DemoApp) { ///////////////////////////////// - widget::Text::new("Button, XYPad and Toggle") + core_widget::Text::new("Button, XYPad and Toggle") .down_from(ids.rust_logo, 60.0) .align_middle_x_of(ids.canvas) .font_size(SUBTITLE_SIZE) @@ -246,7 +247,7 @@ pub fn gui(ui: &mut conrod_core::UiCell, ids: &Ids, app: &mut DemoApp) { let max_y = ball_y_range / 3.0; let side = 130.0; - for _press in widget::Button::new() + for _press in core_widget::Button::new() .label("PRESS ME") .mid_left_with_margin_on(ids.canvas, MARGIN) .down_from(ids.button_title, 60.0) @@ -258,7 +259,7 @@ pub fn gui(ui: &mut conrod_core::UiCell, ids: &Ids, app: &mut DemoApp) { app.ball_xy = [x, y]; } - for (x, y) in widget::XYPad::new(app.ball_xy[0], min_x, max_x, + for (x, y) in conrod_widgets::XYPad::new(app.ball_xy[0], min_x, max_x, app.ball_xy[1], min_y, max_y) .label("BALL XY") .wh_of(ids.button) @@ -272,7 +273,7 @@ pub fn gui(ui: &mut conrod_core::UiCell, ids: &Ids, app: &mut DemoApp) { let is_white = app.ball_color == conrod_core::color::WHITE; let label = if is_white { "WHITE" } else { "BLACK" }; - for is_white in widget::Toggle::new(is_white) + for is_white in conrod_widgets::Toggle::new(is_white) .label(label) .label_color(if is_white { conrod_core::color::WHITE } else { conrod_core::color::LIGHT_CHARCOAL }) .mid_right_with_margin_on(ids.canvas, MARGIN) @@ -284,7 +285,7 @@ pub fn gui(ui: &mut conrod_core::UiCell, ids: &Ids, app: &mut DemoApp) { let ball_x = app.ball_xy[0]; let ball_y = app.ball_xy[1] - max_y - side * 0.5 - MARGIN; - widget::Circle::fill(20.0) + core_widget::Circle::fill(20.0) .color(app.ball_color) .x_y_relative_to(ids.xy_pad, ball_x, ball_y) .set(ids.ball, ui); @@ -295,7 +296,7 @@ pub fn gui(ui: &mut conrod_core::UiCell, ids: &Ids, app: &mut DemoApp) { ////////////////////////////////// - widget::Text::new("NumberDialer and PlotPath") + core_widget::Text::new("NumberDialer and PlotPath") .down_from(ids.xy_pad, max_y - min_y + side * 0.5 + MARGIN) .align_middle_x_of(ids.canvas) .font_size(SUBTITLE_SIZE) @@ -305,7 +306,7 @@ pub fn gui(ui: &mut conrod_core::UiCell, ids: &Ids, app: &mut DemoApp) { let min = 0.5; let max = 200.0; let decimal_precision = 1; - for new_freq in widget::NumberDialer::new(app.sine_frequency, min, max, decimal_precision) + for new_freq in conrod_widgets::NumberDialer::new(app.sine_frequency, min, max, decimal_precision) .down(60.0) .align_middle_x_of(ids.canvas) .w_h(160.0, 40.0) @@ -320,7 +321,7 @@ pub fn gui(ui: &mut conrod_core::UiCell, ids: &Ids, app: &mut DemoApp) { let max_x = std::f32::consts::PI * 2.0 * app.sine_frequency; let min_y = -1.0; let max_y = 1.0; - widget::PlotPath::new(min_x, max_x, min_y, max_y, f32::sin) + conrod_widgets::PlotPath::new(min_x, max_x, min_y, max_y, f32::sin) .kid_area_w_of(ids.canvas) .h(240.0) .down(60.0) @@ -333,5 +334,5 @@ pub fn gui(ui: &mut conrod_core::UiCell, ids: &Ids, app: &mut DemoApp) { ///////////////////// - widget::Scrollbar::y_axis(ids.canvas).auto_hide(true).set(ids.canvas_scrollbar, ui); + conrod_widgets::Scrollbar::y_axis(ids.canvas).auto_hide(true).set(ids.canvas_scrollbar, ui); } diff --git a/conrod_core/Cargo.toml b/conrod_core/Cargo.toml index 0476ed324..d40005ae4 100644 --- a/conrod_core/Cargo.toml +++ b/conrod_core/Cargo.toml @@ -14,11 +14,14 @@ homepage = "https://github.com/pistondevelopers/conrod" documentation = "http://docs.piston.rs/conrod/conrod/" categories = ["gui"] +edition = "2018" + [package.metadata.docs.rs] all-features = true [dependencies] -conrod_derive = { path = "../conrod_derive", version = "0.62" } +#conrod_derive = { path = "../conrod_derive", version = "0.62" } +conrod_derive = "0.62" daggy = "0.5" fnv = "1.0" num = "0.2" diff --git a/conrod_core/src/border.rs b/conrod_core/src/border.rs index 6a1f0d96a..9b6baf579 100644 --- a/conrod_core/src/border.rs +++ b/conrod_core/src/border.rs @@ -1,5 +1,5 @@ -use color::{Color, hsl, hsla, rgb, rgba}; +use crate::color::{Color, hsl, hsla, rgb, rgba}; /// To be used as a parameter for defining the aesthetic /// of the widget border. diff --git a/conrod_core/src/color.rs b/conrod_core/src/color.rs index 8030ea5de..db8fd30b3 100644 --- a/conrod_core/src/color.rs +++ b/conrod_core/src/color.rs @@ -12,7 +12,7 @@ //! use std::f32::consts::PI; -use utils::{degrees, fmod, turns}; +use crate::utils::{degrees, fmod, turns}; /// Color supporting RGB and HSL variants. #[derive(PartialEq, Copy, Clone, Debug)] diff --git a/conrod_core/src/cursor.rs b/conrod_core/src/cursor.rs index 65a2a1881..c95a86ac6 100644 --- a/conrod_core/src/cursor.rs +++ b/conrod_core/src/cursor.rs @@ -1,9 +1,9 @@ //! Contains an extendable enum of supported mouse cursor types. //! //! Use this module to map from the conrod's mouse cursor types to the types known to the window -//! backend you are using. A lot of these are already implemented in `conrod::backend`. Unless you +//! backend you are using. A lot of these are already implemented in `conrod_core::backend`. Unless you //! are using custom mouse cursor types not provided here, then using one of the implementations in -//! `conrod::backend` should be sufficient. +//! `conrod_core::backend` should be sufficient. /// This enum specifies cursor types used by internal widgets. For custom widgets using custom /// cursor types, you can still use this enum by specifying a numbered custom variant. diff --git a/conrod_core/src/event.rs b/conrod_core/src/event.rs index 5cd688a76..f293370f4 100644 --- a/conrod_core/src/event.rs +++ b/conrod_core/src/event.rs @@ -35,10 +35,12 @@ //! Because we use the `pistoncore-input` `Event` type, we also re-export its associated data //! types (`Button`, `ControllerAxisArgs`, `Key`, etc). -use input; -use position::{Dimensions, Point}; -use utils::vec2_sub; -use widget; +use crate::{ + input, + position::{Dimensions, Point}, + utils::vec2_sub, + widget +}; /// The event type that is used by conrod to track inputs from the world. Events yielded by polling @@ -63,7 +65,7 @@ pub enum Input { /// A button on some input device was released. Release(input::Button), /// The window was received to the given dimensions. - Resize(f64, f64), + Resize(u32, u32), /// Some motion input was received (e.g. moving mouse or joystick axis). Motion(input::Motion), /// Input from a touch surface/screen. diff --git a/conrod_core/src/graph/algo.rs b/conrod_core/src/graph/algo.rs index 1386bb920..56dd79e1c 100644 --- a/conrod_core/src/graph/algo.rs +++ b/conrod_core/src/graph/algo.rs @@ -6,11 +6,13 @@ use daggy::Walker; -use position::{Point, Rect}; +use crate::{ + position::{Point, Rect}, + theme::Theme, + widget +}; use fnv; use super::{EdgeIndex, Graph}; -use theme::Theme; -use widget; /// A node "walker" that yields all widgets under the given `xy` position in order from top to diff --git a/conrod_core/src/graph/depth_order.rs b/conrod_core/src/graph/depth_order.rs index 083896ed4..10464d48e 100644 --- a/conrod_core/src/graph/depth_order.rs +++ b/conrod_core/src/graph/depth_order.rs @@ -4,7 +4,7 @@ use daggy::Walker; use std; use fnv; use super::{Graph, Node}; -use widget; +use crate::widget; /// Contains Node indices in order of depth, starting with the deepest. diff --git a/conrod_core/src/graph/mod.rs b/conrod_core/src/graph/mod.rs index 3d513b7b1..21cf35ecb 100644 --- a/conrod_core/src/graph/mod.rs +++ b/conrod_core/src/graph/mod.rs @@ -4,11 +4,15 @@ //! The primary type of interest in this module is the [**Graph**](./struct.Graph) type. use daggy; -use position::{Axis, Depth, Rect}; -use std; -use std::any::Any; -use std::ops::{Index, IndexMut}; -use widget::{self, Widget}; +use crate::{ + position::{Axis, Depth, Rect}, + widget::{self, Widget} +}; +use std::{ + self, + any::Any, + ops::{Index, IndexMut} +}; pub use daggy::Walker; pub use self::depth_order::DepthOrder; diff --git a/conrod_core/src/input/global.rs b/conrod_core/src/input/global.rs index 7867f2eb8..d687ccd64 100644 --- a/conrod_core/src/input/global.rs +++ b/conrod_core/src/input/global.rs @@ -2,8 +2,10 @@ //! The core of this module is the `Global` struct. It is responsible for aggregating //! and interpreting raw input events into high-level semantic events. -use event; -use input; +use crate::{ + event, + input +}; use std; /// Global input event handler that also implements `input::Provider`. The `Ui` passes all events diff --git a/conrod_core/src/input/mod.rs b/conrod_core/src/input/mod.rs index 0ab331ead..07bec0559 100644 --- a/conrod_core/src/input/mod.rs +++ b/conrod_core/src/input/mod.rs @@ -19,16 +19,16 @@ pub mod state; pub mod widget; pub mod global; -use Scalar; +use crate::Scalar; pub use self::state::State; pub use self::global::Global; pub use self::touch::Touch; pub use self::widget::Widget; #[doc(inline)] -pub use piston_input::keyboard::ModifierKey; +pub use crate::piston_input::keyboard::ModifierKey; #[doc(inline)] -pub use piston_input::{ +pub use crate::piston_input::{ Button, ControllerButton, ControllerAxisArgs, @@ -71,7 +71,7 @@ pub enum Motion { /// Touch-related items. pub mod touch { - use Point; + use crate::Point; /// A type for uniquely identifying the source of a touch interaction. #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/conrod_core/src/input/state.rs b/conrod_core/src/input/state.rs index 908daa95f..1dc8d2bf2 100644 --- a/conrod_core/src/input/state.rs +++ b/conrod_core/src/input/state.rs @@ -7,12 +7,14 @@ //! //! This module exists mostly to support the `input::Provider` trait. -use position::Point; +use crate::{ + position::Point, + utils, + widget +}; use self::mouse::Mouse; use fnv; use super::keyboard::ModifierKey; -use utils; -use widget; /// Holds the current state of user input. @@ -65,9 +67,11 @@ impl State { /// Touch specific state. pub mod touch { - use position::Point; + use crate::{ + position::Point, + widget + }; use std; - use widget; /// State stored about the start of a `Touch` interaction. #[derive(Copy, Clone, Debug, PartialEq)] @@ -97,10 +101,11 @@ pub mod touch { /// Mouse specific state. pub mod mouse { - use position::Point; + use crate::{ + position::Point, + widget, + }; use std; - use widget; - #[doc(inline)] pub use input::MouseButton as Button; diff --git a/conrod_core/src/input/widget.rs b/conrod_core/src/input/widget.rs index 2cc51d99d..b8ca21431 100644 --- a/conrod_core/src/input/widget.rs +++ b/conrod_core/src/input/widget.rs @@ -3,11 +3,14 @@ //! The core of this module is the `Widget::for_widget` method, which creates an //! `InputProvider` that provides input events for a specific widget. -use {Point, Rect}; -use event; -use input; -use utils; -use widget; +use crate::{ + Point, + Rect, + event, + input, + utils, + widget +}; /// Provides only events and input state that are relevant to a specific widget. diff --git a/conrod_core/src/label.rs b/conrod_core/src/label.rs index b01274cd3..7ead25c01 100644 --- a/conrod_core/src/label.rs +++ b/conrod_core/src/label.rs @@ -1,6 +1,7 @@ - -use color::{Color, hsl, hsla, rgb, rgba}; -use ui::Ui; +use crate::{ + color::{Color, hsl, hsla, rgb, rgba}, + ui::Ui +}; /// Font size used throughout Conrod. pub type FontSize = u32; diff --git a/conrod_core/src/lib.rs b/conrod_core/src/lib.rs index ab382b55a..2589a7b3f 100644 --- a/conrod_core/src/lib.rs +++ b/conrod_core/src/lib.rs @@ -3,7 +3,6 @@ //! An easy-to-use, immediate-mode, 2D GUI library featuring a range of useful widgets. //! //! If you are new to Conrod, we recommend checking out [The Guide](./guide/index.html). - #![deny(unsafe_code)] #![deny(missing_copy_implementations)] #![warn(missing_docs)] @@ -15,30 +14,32 @@ extern crate num; extern crate input as piston_input; extern crate rusttype; -pub use color::{Color, Colorable}; -pub use conrod_derive::*; -pub use border::{Bordering, Borderable}; -pub use label::{FontSize, Labelable}; -pub use position::{Dimensions, Point, Position, Positionable, Range, Rect, Scalar, Sizeable}; -pub use theme::Theme; -pub use ui::{Ui, UiCell, UiBuilder}; -pub use widget::{scroll, Widget}; +pub use crate::{ + color::{Color, Colorable}, + conrod_derive::*, + border::{Bordering, Borderable}, + label::{FontSize, Labelable}, + position::{Dimensions, Point, Position, Positionable, Range, Rect, Scalar, Sizeable}, + theme::Theme, + ui::{Ui, UiCell, UiBuilder}, + widget::{scroll, Widget} +}; -mod border; pub mod color; pub mod event; pub mod graph; pub mod guide; pub mod image; pub mod input; -mod label; pub mod position; pub mod render; pub mod text; pub mod theme; -mod ui; pub mod utils; pub mod widget; pub mod cursor; +pub mod border; +pub mod label; +pub mod ui; #[cfg(test)] mod tests; diff --git a/conrod_core/src/position/matrix.rs b/conrod_core/src/position/matrix.rs index d6a10ab9e..c81369050 100644 --- a/conrod_core/src/position/matrix.rs +++ b/conrod_core/src/position/matrix.rs @@ -1,7 +1,11 @@ -use {Backend, CharacterCache, Ui}; use super::{Depth, Dimension, Dimensions, Point, Position, Positionable, Scalar, Sizeable}; -use ui; -use widget; +use crate::{ + ui, + Backend, + CharacterCache, + Ui, + widget +}; pub type WidgetNum = usize; pub type ColNum = usize; @@ -52,7 +56,7 @@ impl Matrix { C: CharacterCache, F: FnMut(&mut Ui, WidgetNum, ColNum, RowNum, Point, Dimensions), { - use utils::map_range; + use crate::utils::map_range; let x_pos = self.get_x_position(ui); let y_pos = self.get_y_position(ui); @@ -142,7 +146,7 @@ impl Sizeable for Matrix fn get_y_dimension(&self, ui: &Ui) -> Dimension { const DEFAULT_HEIGHT: Dimension = Dimension::Absolute(256.0); self.maybe_y_dimension.or_else(|| { - ui.theme.widget_style::(widget::matrix::KIND) + ui.theme.widget_style::(widget::matrix::KIND) .map(|default| default.common.maybe_y_dimension.unwrap_or(DEFAULT_HEIGHT)) }).unwrap_or(DEFAULT_HEIGHT) } diff --git a/conrod_core/src/position/mod.rs b/conrod_core/src/position/mod.rs index 129f553f0..2330d5a73 100644 --- a/conrod_core/src/position/mod.rs +++ b/conrod_core/src/position/mod.rs @@ -1,7 +1,9 @@ //! Items related to 2D positioning, used throughout conrod. -use Ui; -use widget; +use crate::{ + Ui, + widget +}; pub use self::range::{Edge, Range}; pub use self::rect::{Corner, Rect}; @@ -148,10 +150,10 @@ pub enum Dimension { pub trait Positionable: Sized { /// Build with the given **Position** along the *x* axis. - fn x_position(self, Position) -> Self; + fn x_position(self, _: Position) -> Self; /// Build with the given **Position** along the *y* axis. - fn y_position(self, Position) -> Self; + fn y_position(self, _: Position) -> Self; /// Get the **Position** along the *x* axis. fn get_x_position(&self, ui: &Ui) -> Position; diff --git a/conrod_core/src/position/range.rs b/conrod_core/src/position/range.rs index 24660f9ab..660266806 100644 --- a/conrod_core/src/position/range.rs +++ b/conrod_core/src/position/range.rs @@ -149,7 +149,7 @@ impl Range { /// assert_eq!(a.map_value_to(10.0, &c), -30.0); /// ``` pub fn map_value_to(&self, value: Scalar, other: &Range) -> Scalar { - ::utils::map_range(value, self.start, self.end, other.start, other.end) + crate::utils::map_range(value, self.start, self.end, other.start, other.end) } /// Shift the `Range` start and end points by a given `Scalar`. @@ -253,8 +253,8 @@ impl Range { pub fn overlap(mut self, mut other: Self) -> Option { self = self.undirected(); other = other.undirected(); - let start = ::utils::partial_max(self.start, other.start); - let end = ::utils::partial_min(self.end, other.end); + let start = crate::utils::partial_max(self.start, other.start); + let end = crate::utils::partial_min(self.end, other.end); let magnitude = end - start; if magnitude >= 0.0 { Some(Range::new(start, end)) @@ -403,7 +403,7 @@ impl Range { /// assert_eq!(Range::new(5.0, 10.0).clamp_value(0.0), 5.0); /// ``` pub fn clamp_value(&self, value: Scalar) -> Scalar { - ::utils::clamp(value, self.start, self.end) + crate::utils::clamp(value, self.start, self.end) } /// Stretch the end that is closest to the given value only if it lies outside the Range. diff --git a/conrod_core/src/position/rect.rs b/conrod_core/src/position/rect.rs index b903739b6..5fe4043bc 100644 --- a/conrod_core/src/position/rect.rs +++ b/conrod_core/src/position/rect.rs @@ -114,7 +114,7 @@ impl Rect { /// The length of the longest side of the rectangle. pub fn len(&self) -> Scalar { - ::utils::partial_max(self.w(), self.h()) + crate::utils::partial_max(self.w(), self.h()) } /// The Rect's lowest y value. diff --git a/conrod_core/src/render.rs b/conrod_core/src/render.rs index 6254cfa6a..50449d128 100644 --- a/conrod_core/src/render.rs +++ b/conrod_core/src/render.rs @@ -9,16 +9,22 @@ //! This is the only module in which the src graphics crate will be used directly. -use {Color, FontSize, Point, Rect, Scalar}; -use color; -use graph::{self, Graph}; -use image; -use position::{Align, Dimensions}; +use crate::{ + Color, + FontSize, + Point, + Rect, + Scalar, + color, + graph::{self, Graph}, + image, + position::{Align, Dimensions}, + text, + theme::Theme, + widget::{self, Widget}, + widget::triangles::{ColoredPoint, Triangle} +}; use std; -use text; -use theme::Theme; -use widget::{self, Widget}; -use widget::triangles::{ColoredPoint, Triangle}; /// An iterator-like type that yields a reference to each primitive in order of depth for @@ -140,7 +146,7 @@ pub enum PrimitiveKind<'a> { /// to bottom right. text: Text<'a>, /// The unique identifier for the font, useful for the `glyph_cache.rect_for(id, glyph)` - /// method when using the `conrod::text::GlyphCache` (rusttype's GPU `Cache`). + /// method when using the `conrod_core::text::GlyphCache` (rusttype's GPU `Cache`). font_id: text::font::Id, }, @@ -319,9 +325,9 @@ impl<'a> Primitives<'a> { } = *self; while let Some(widget) = next_widget(depth_order, graph, crop_stack, window_rect) { - use widget::primitive::point_path::{State as PointPathState, Style as PointPathStyle}; - use widget::primitive::shape::polygon::{State as PolygonState}; - use widget::primitive::shape::Style as ShapeStyle; + use crate::widget::primitive::point_path::{State as PointPathState, Style as PointPathStyle}; + use crate::widget::primitive::shape::polygon::{State as PolygonState}; + use crate::widget::primitive::shape::Style as ShapeStyle; type TrianglesSingleColorState = widget::triangles::State>>; @@ -480,7 +486,7 @@ impl<'a> Primitives<'a> { } } else if container.type_id == std::any::TypeId::of::() { - use widget::primitive::shape::Style; + use crate::widget::primitive::shape::Style; if let Some(polygon) = container.state_and_style::() { let graph::UniqueWidgetState { ref state, ref style } = *polygon; triangles.clear(); @@ -608,7 +614,7 @@ impl<'a> Primitives<'a> { } } else if container.type_id == state_type_id::() { - use widget::primitive::image::{State, Style}; + use crate::widget::primitive::image::{State, Style}; if let Some(image) = container.state_and_style::() { let graph::UniqueWidgetState { ref state, ref style } = *image; let color = style.maybe_color(theme); diff --git a/conrod_core/src/tests/global_input.rs b/conrod_core/src/tests/global_input.rs index cf5093273..5b9174e7d 100644 --- a/conrod_core/src/tests/global_input.rs +++ b/conrod_core/src/tests/global_input.rs @@ -1,9 +1,10 @@ -use event::{self, Input}; -use input::{self, Key, Motion, MouseButton}; -use input::Button::Keyboard; -use input::Button::Mouse; -use position::Scalar; - +use crate::{ + event::{self, Input}, + input::{self, Key, Motion, MouseButton}, + input::Button::Keyboard, + input::Button::Mouse, + position::Scalar +}; // Pushes an event onto the given global input with a default drag threshold. fn push_event(input: &mut input::Global, event: event::Event) { @@ -14,7 +15,6 @@ fn mouse_move_event(x: Scalar, y: Scalar) -> event::Event { event::Event::Raw(Input::Motion(Motion::MouseRelative { x: x, y: y })) } - #[test] fn resetting_input_should_set_starting_state_to_current_state() { let mut input = input::Global::new(); diff --git a/conrod_core/src/tests/ui.rs b/conrod_core/src/tests/ui.rs index 1d8c8db4d..6f498ca6b 100644 --- a/conrod_core/src/tests/ui.rs +++ b/conrod_core/src/tests/ui.rs @@ -1,4 +1,4 @@ -use { +use crate::{ Color, Labelable, Positionable, @@ -6,13 +6,13 @@ use { Sizeable, Widget, Ui, - UiBuilder + UiBuilder, + event::{self, Input}, + input::{self, Button, Key, Motion, MouseButton}, + input::keyboard::ModifierKey, + widget, + position::Point }; -use event::{self, Input}; -use input::{self, Button, Key, Motion, MouseButton}; -use input::keyboard::ModifierKey; -use widget; -use position::Point; ///// Test assist code. @@ -112,7 +112,7 @@ fn ui_should_push_input_events_to_aggregator() { test_handling_basic_input_event(ui, Input::Press(input::Button::Keyboard(Key::LCtrl))); test_handling_basic_input_event(ui, Input::Release(input::Button::Keyboard(Key::LCtrl))); test_handling_basic_input_event(ui, Input::Text("my string".to_string())); - test_handling_basic_input_event(ui, Input::Resize(55.0, 99.0)); + test_handling_basic_input_event(ui, Input::Resize(55, 99)); test_handling_basic_input_event(ui, Input::Focus(true)); } diff --git a/conrod_core/src/tests/widget_input.rs b/conrod_core/src/tests/widget_input.rs index a3e9f6b90..bac6273b9 100644 --- a/conrod_core/src/tests/widget_input.rs +++ b/conrod_core/src/tests/widget_input.rs @@ -1,8 +1,10 @@ -use event::{self, Input}; -use input::{self, Button, Motion, MouseButton}; -use input::keyboard::ModifierKey; -use widget; -use position::Rect; +use crate::{ + event::{self, Input}, + input::{self, Button, Motion, MouseButton}, + input::keyboard::ModifierKey, + widget, + position::Rect +}; // Pushes an event onto the given global input with a default drag threshold. fn push_event(input: &mut input::Global, event: event::Event) { diff --git a/conrod_core/src/text.rs b/conrod_core/src/text.rs index f92486e88..ed97b2852 100644 --- a/conrod_core/src/text.rs +++ b/conrod_core/src/text.rs @@ -1,6 +1,6 @@ //! Text layout logic. -use {FontSize, Scalar}; +use crate::{FontSize, Scalar}; use std; // Re-export all relevant rusttype types here. @@ -261,7 +261,7 @@ pub mod font { /// Logic and types specific to individual glyph layout. pub mod glyph { - use {FontSize, Range, Rect, Scalar}; + use crate::{FontSize, Range, Rect, Scalar}; use std; /// Some position along the X axis (used within `CharXs`). @@ -462,8 +462,8 @@ pub mod glyph { /// Logic related to the positioning of the cursor within text. pub mod cursor { - use FontSize; - use position::{Range, Rect, Scalar, Point, Align}; + use crate::FontSize; + use crate::position::{Range, Rect, Scalar, Point, Align}; use std; /// Every possible cursor position within each line of text yielded by the given iterator. @@ -881,8 +881,8 @@ pub mod cursor { /// /// This module is the core of multi-line text handling. pub mod line { - use FontSize; - use position::{Align, Range, Rect, Scalar}; + use crate::FontSize; + use crate::position::{Align, Range, Rect, Scalar}; use std; /// The two types of **Break** indices returned by the **WrapIndicesBy** iterators. diff --git a/conrod_core/src/theme.rs b/conrod_core/src/theme.rs index a94c4355c..40591b513 100644 --- a/conrod_core/src/theme.rs +++ b/conrod_core/src/theme.rs @@ -2,14 +2,18 @@ //! Types a functionality for handling Canvas and Widget theming. //! -use Scalar; -use color::{Color, BLACK, WHITE}; -use position::{Align, Direction, Padding, Position, Relative}; +use crate::{ + Scalar, + color::{Color, BLACK, WHITE}, + position::{Align, Direction, Padding, Position, Relative}, + text, + widget +}; use fnv; -use std; -use std::any::Any; -use text; -use widget; +use std::{ + self, + any::Any +}; /// `std::collections::HashMap` with `fnv::FnvHasher` for unique styling /// of each widget, index-able by the **Widget::kind**. diff --git a/conrod_core/src/ui.rs b/conrod_core/src/ui.rs index d112298e2..fa551cabc 100644 --- a/conrod_core/src/ui.rs +++ b/conrod_core/src/ui.rs @@ -1,17 +1,21 @@ -use color::Color; -use event; -use graph::{self, Graph}; -use input; -use position::{self, Align, Direction, Dimensions, Padding, Point, Position, Range, Rect, Scalar}; -use render; -use std; -use std::sync::atomic::{self, AtomicUsize}; +use crate::{ + color::Color, + event, + graph::{self, Graph}, + input, + position::{self, Align, Direction, Dimensions, Padding, Point, Position, Range, Rect, Scalar}, + render, + text, + theme::Theme, + utils, + widget::{self, Widget}, + cursor +}; +use std::{ + self, + sync::atomic::{self, AtomicUsize} +}; use fnv; -use text; -use theme::Theme; -use utils; -use widget::{self, Widget}; -use cursor; /// A constructor type for building a `Ui` instance with a set of optional parameters. pub struct UiBuilder { @@ -381,13 +385,15 @@ impl Ui { /// The given `event` must implement the **ToRawEvent** trait so that it can be converted to a /// `RawEvent` that can be used by the `Ui`. pub fn handle_event(&mut self, event: event::Input) { - use event::{self, Input}; - use input::{Button, Key, ModifierKey, Motion}; - use input::state::mouse::Button as MouseButton; + use crate::{ + event::{self, Input}, + input::{Button, Key, ModifierKey, Motion}, + input::state::mouse::Button as MouseButton + }; // A function for filtering `ModifierKey`s. fn filter_modifier(key: Key) -> Option { - use input::keyboard::ModifierKey; + use crate::input::keyboard::ModifierKey; match key { Key::LCtrl | Key::RCtrl => Some(ModifierKey::CTRL), Key::LShift | Key::RShift => Some(ModifierKey::SHIFT), @@ -696,7 +702,7 @@ impl Ui { fn offset_is_at_bound(scroll: &widget::scroll::State, additional_offset: Scalar) -> bool { - use utils; + use crate::utils; fn approx_eq(a: Scalar, b: Scalar) -> bool { (a - b).abs() < 0.000001 @@ -945,7 +951,7 @@ impl Ui { dim: Dimensions, place_on_kid_area: bool) -> Point { - use utils::vec2_add; + use crate::utils::vec2_add; // Retrieves the absolute **Scalar** position from the given position for a single axis. // @@ -1066,7 +1072,7 @@ impl Ui { // This widget acts as the parent-most widget and root node for the Ui's `widget_graph`, // upon which all other widgets are placed. { - use {color, Colorable, Borderable, Positionable, Widget}; + use crate::{color, Colorable, Borderable, Positionable, Widget}; type Window = widget::BorderedRectangle; Window::new([ui_cell.win_w, ui_cell.win_h]) .no_parent() @@ -1103,7 +1109,7 @@ impl Ui { /// be a `Rectangle` the size of the window in which conrod is hosted. /// /// This method sets the colour with which this `Rectangle` is drawn (the default being - /// `conrod::color::TRANSPARENT`. + /// `conrod_core::color::TRANSPARENT`. pub fn clear_with(&mut self, color: Color) { self.maybe_background_color = Some(color); } @@ -1315,8 +1321,8 @@ pub fn widget_graph_mut(ui: &mut Ui) -> &mut Graph { /// /// When a different parent may be inferred from either `Position`, the *x* `Position` is favoured. pub fn infer_parent_from_position(ui: &Ui, x: Position, y: Position) -> Option { - use Position::Relative; - use position::Relative::{Align, Direction, Place, Scalar}; + use crate::Position::Relative; + use crate::position::Relative::{Align, Direction, Place, Scalar}; match (x, y) { (Relative(Place(_), maybe_parent_id), _) | (_, Relative(Place(_), maybe_parent_id)) => maybe_parent_id, diff --git a/conrod_core/src/utils.rs b/conrod_core/src/utils.rs index 04656508b..c3a14b91d 100644 --- a/conrod_core/src/utils.rs +++ b/conrod_core/src/utils.rs @@ -4,10 +4,12 @@ use num::{Float, NumCast, PrimInt, ToPrimitive}; -use position::{Point, Range, Rect}; -use std::borrow::Cow; -use std::iter::{Chain, once, Once}; -use std; +use crate::position::{Point, Range, Rect}; +use std::{ + borrow::Cow, + iter::{Chain, once, Once}, + self +}; /// Compare to PartialOrd values and return the min. diff --git a/conrod_core/src/widget/bordered_rectangle.rs b/conrod_core/src/widget/bordered_rectangle.rs index 003b3a789..2f010e205 100644 --- a/conrod_core/src/widget/bordered_rectangle.rs +++ b/conrod_core/src/widget/bordered_rectangle.rs @@ -1,6 +1,6 @@ //! The `BorderedRectangle` widget and related items. -use { +use crate::{ Color, Colorable, Dimensions, @@ -11,10 +11,11 @@ use { Scalar, Sizeable, Widget, + widget::{ + self, + triangles::Triangle, + }, }; -use widget; -use widget::triangles::Triangle; - /// A filled rectangle widget that may or may not have some border. /// diff --git a/conrod_core/src/widget/button.rs b/conrod_core/src/widget/button.rs index 7e68b3bbd..68e856131 100644 --- a/conrod_core/src/widget/button.rs +++ b/conrod_core/src/widget/button.rs @@ -1,11 +1,20 @@ //! The `Button` widget and related items. -use {Color, Colorable, FontSize, Borderable, Labelable, Positionable, Sizeable, UiCell, Widget}; -use image; -use position::{self, Align, Rect, Scalar}; -use text; -use widget; - +use crate::{ + Color, + Colorable, + FontSize, + Borderable, + Labelable, + Positionable, + Sizeable, + UiCell, + Widget, + image, + position::{self, Align, Rect, Scalar}, + text, + widget +}; /// A pressable button widget whose reaction is triggered upon release. #[derive(Clone, WidgetCommon_)] diff --git a/conrod_core/src/widget/file_navigator/directory_view.rs b/conrod_core/src/widget/file_navigator/directory_view.rs index fd6e8d810..483bbbfb9 100644 --- a/conrod_core/src/widget/file_navigator/directory_view.rs +++ b/conrod_core/src/widget/file_navigator/directory_view.rs @@ -3,7 +3,7 @@ //! Reacts to events for selection of one or more files, de-selection, deletion and //! double-clicking. -use { +use crate::{ Borderable, color, Color, @@ -14,11 +14,13 @@ use { Sizeable, Scalar, Widget, + event, + widget +}; +use std::{ + self, + cmp::Ordering }; -use event; -use std; -use widget; -use std::cmp::Ordering; /// For viewing, selecting, double-clicking, etc the contents of a directory. #[derive(WidgetCommon_)] @@ -291,13 +293,13 @@ impl<'a> Widget for DirectoryView<'a> { .collect(); while let Some(event) = list_events.next(ui, |i| state.entries[i].is_selected) { - use widget::list_select; + use crate::widget::list_select; match event { // Instantiate a `Button` for each item. list_select::Event::Item(item) => { - use position::{Place, Relative}; + use crate::position::{Place, Relative}; let entry = &state.entries[item.i]; let is_selected = entry.is_selected; let is_directory = entry.path.is_dir(); diff --git a/conrod_core/src/widget/file_navigator/mod.rs b/conrod_core/src/widget/file_navigator/mod.rs index 7cfaa5d42..62d1c729b 100644 --- a/conrod_core/src/widget/file_navigator/mod.rs +++ b/conrod_core/src/widget/file_navigator/mod.rs @@ -6,7 +6,7 @@ //! of one or more files, de-selection, deletion and double-clicking. //! - `FileView`: Displays some basic information about the file. -use { +use crate::{ color, Color, Colorable, @@ -15,10 +15,10 @@ use { Scalar, Sizeable, Widget, + event, + widget }; -use event; use std; -use widget; pub use self::directory_view::DirectoryView; @@ -339,7 +339,7 @@ impl<'a> Widget for FileNavigator<'a> { // Check for directory navigation. directory_view::Event::Press(press, paths) => { if let Some(key_press) = press.key() { - use input; + use crate::input; match key_press.key { input::Key::Right => if paths.len() == 1 { if paths[0].is_dir() { diff --git a/conrod_core/src/widget/graph/mod.rs b/conrod_core/src/widget/graph/mod.rs index 71c295264..2e85ce798 100644 --- a/conrod_core/src/widget/graph/mod.rs +++ b/conrod_core/src/widget/graph/mod.rs @@ -1,14 +1,27 @@ //! A widget for viewing and controlling graph structures. -use {color, widget, Color, Colorable, Point, Positionable, Scalar, Widget, Ui, UiCell}; -use std::any::{Any, TypeId}; -use std::cell::Cell; -use std::collections::{HashMap, VecDeque}; -use std::hash::Hash; -use std::marker::PhantomData; -use std::ops::{Deref, DerefMut}; -use std::sync::{Arc, Mutex, Weak}; -use utils::{iter_diff, IterDiff}; +use crate::{ + color, + widget, + Color, + Colorable, + Point, + Positionable, + Scalar, + Widget, + Ui, + UiCell, + utils::{iter_diff, IterDiff} +}; +use std::{ + any::{Any, TypeId}, + cell::Cell, + collections::{HashMap, VecDeque}, + hash::Hash, + marker::PhantomData, + ops::{Deref, DerefMut}, + sync::{Arc, Mutex, Weak} +}; pub use self::node::{Node, SocketLayout, SocketSide}; diff --git a/conrod_core/src/widget/graph/node.rs b/conrod_core/src/widget/graph/node.rs index 10ec1733f..afcd0502f 100644 --- a/conrod_core/src/widget/graph/node.rs +++ b/conrod_core/src/widget/graph/node.rs @@ -1,10 +1,22 @@ //! A default container widget to use for nodes that exist within a `Graph` widget. -use {widget, color, Color, Point, Positionable, Scalar, Sizeable, Widget, Ui}; -use graph; -use position::{Axis, Direction, Range, Rect}; -use std::iter::once; -use std::ops::{Deref, DerefMut}; +use crate::{ + widget, + color, + Color, + Point, + Positionable, + Scalar, + Sizeable, + Widget, + Ui, + graph, + position::{Axis, Direction, Range, Rect} +}; +use std::{ + iter::once, + ops::{Deref, DerefMut} +}; /// A widget that acts as a convenience container for some `Node`'s unique widgets. #[derive(Clone, Debug, WidgetCommon_)] diff --git a/conrod_core/src/widget/id.rs b/conrod_core/src/widget/id.rs index 27ac57859..855b3b009 100644 --- a/conrod_core/src/widget/id.rs +++ b/conrod_core/src/widget/id.rs @@ -2,7 +2,7 @@ //! simplify the process of generating them. use daggy; -use graph::Graph; +use crate::graph::Graph; use std; /// Unique widget identifier. @@ -359,8 +359,8 @@ macro_rules! widget_ids { #[test] fn test() { - use ui::UiBuilder; - use widget::{self, Widget}; + use crate::ui::UiBuilder; + use crate::widget::{self, Widget}; widget_ids! { /// Testing generated Ids doc comments. @@ -391,7 +391,7 @@ fn test() { #[test] #[allow(unused_variables)] fn test_invocation_variations() { - use ui::UiBuilder; + use crate::ui::UiBuilder; widget_ids! { struct A { foo, bar } } widget_ids! { pub struct B { foo, bar } } diff --git a/conrod_core/src/widget/mod.rs b/conrod_core/src/widget/mod.rs index 87c80f89b..772ebde3d 100644 --- a/conrod_core/src/widget/mod.rs +++ b/conrod_core/src/widget/mod.rs @@ -3,52 +3,32 @@ //! This module contains items related to the implementation of the `Widget` trait. It also //! re-exports all widgets (and their modules) that are provided by conrod. -use graph::{Container, UniqueWidgetState}; -use position::{Align, Depth, Dimension, Dimensions, Padding, Position, Point, - Positionable, Rect, Relative, Sizeable}; +use crate::{ + graph::{Container, UniqueWidgetState}, + position::{Align, Depth, Dimension, Dimensions, Padding, Position, Point, + Positionable, Rect, Relative, Sizeable}, + text::font, + theme::{self, Theme}, + ui::{self, Ui, UiCell} +}; use std; -use text::font; -use theme::{self, Theme}; -use ui::{self, Ui, UiCell}; - -pub use self::id::Id; - -pub use self::primitive::line::{self, Line}; -pub use self::primitive::image::{self, Image}; -pub use self::primitive::point_path::{self, PointPath}; -pub use self::primitive::shape::circle::{self, Circle}; -pub use self::primitive::shape::oval::{self, Oval}; -pub use self::primitive::shape::polygon::{self, Polygon}; -pub use self::primitive::shape::rectangle::{self, Rectangle}; -pub use self::primitive::shape::triangles::{self, Triangles}; -pub use self::primitive::text::{self, Text}; +pub use self::{ + id::Id, + primitive::line::{self, Line}, + primitive::image::{self, Image}, + primitive::point_path::{self, PointPath}, + primitive::shape::circle::{self, Circle}, + primitive::shape::oval::{self, Oval}, + primitive::shape::polygon::{self, Polygon}, + primitive::shape::rectangle::{self, Rectangle}, + primitive::shape::triangles::{self, Triangles}, + primitive::text::{self, Text} +}; pub use self::bordered_rectangle::BorderedRectangle; pub use self::button::Button; -pub use self::canvas::Canvas; -pub use self::collapsible_area::CollapsibleArea; -pub use self::drop_down_list::DropDownList; -pub use self::envelope_editor::EnvelopeEditor; -pub use self::file_navigator::FileNavigator; -pub use self::grid::Grid; -pub use self::list::List; -pub use self::list_select::ListSelect; -pub use self::matrix::Matrix; -pub use self::graph::Graph; -pub use self::number_dialer::NumberDialer; -pub use self::plot_path::PlotPath; -pub use self::range_slider::RangeSlider; pub use self::rounded_rectangle::RoundedRectangle; -pub use self::scrollbar::Scrollbar; -pub use self::slider::Slider; -pub use self::tabs::Tabs; -pub use self::text_box::TextBox; -pub use self::text_edit::TextEdit; -pub use self::title_bar::TitleBar; -pub use self::toggle::Toggle; -pub use self::xy_pad::XYPad; - // Macro providing modules. #[macro_use] mod builder; @@ -64,28 +44,7 @@ pub mod primitive; pub mod bordered_rectangle; pub mod button; -pub mod canvas; -pub mod collapsible_area; -pub mod drop_down_list; -pub mod envelope_editor; -pub mod file_navigator; -pub mod grid; -pub mod list; -pub mod list_select; -pub mod matrix; -pub mod graph; -pub mod number_dialer; -pub mod plot_path; -pub mod range_slider; pub mod rounded_rectangle; -pub mod scrollbar; -pub mod slider; -pub mod tabs; -pub mod text_box; -pub mod text_edit; -pub mod title_bar; -pub mod toggle; -pub mod xy_pad; /// Arguments for the [**Widget::update**](./trait.Widget#method.update) method in a struct to @@ -560,7 +519,7 @@ pub trait Widget: Common + Sized { /// ``` /// # extern crate conrod_core; /// # #[macro_use] extern crate conrod_derive; - /// # use conrod_core::{Color, FontSize, Scalar}; + /// # use conrod_core::{Color, FontSize, Scalar, Theme}; /// # fn main() {} /// /// Unique styling for a Button widget. /// #[derive(Copy, Clone, Debug, Default, PartialEq, WidgetStyle)] @@ -594,7 +553,7 @@ pub trait Widget: Common + Sized { /// /// The `Ui` will only call this once, immediately prior to the first time that /// **Widget::update** is first called. - fn init_state(&self, id::Generator) -> Self::State; + fn init_state(&self, _: id::Generator) -> Self::State; /// Return the styling of the widget. /// diff --git a/conrod_core/src/widget/primitive/image.rs b/conrod_core/src/widget/primitive/image.rs index 453d99df4..4b9e96513 100644 --- a/conrod_core/src/widget/primitive/image.rs +++ b/conrod_core/src/widget/primitive/image.rs @@ -1,10 +1,13 @@ //! A simple, non-interactive widget for drawing an `Image`. -use {Color, Widget, Ui}; -use image; -use position::{Dimension, Rect}; -use widget; - +use crate::{ + position::{Dimension, Rect}, + image, + Color, + Widget, + Ui, + widget +}; /// A primitive and basic widget for drawing an `Image`. #[derive(Copy, Clone, WidgetCommon_)] @@ -45,7 +48,7 @@ impl Image { /// Construct a new `Image`. /// /// Note that the `Image` widget does not require borrowing or owning any image data directly. - /// Instead, image data is stored within a `conrod::image::Map` where `image::Id`s are mapped + /// Instead, image data is stored within a `conrod_core::image::Map` where `image::Id`s are mapped /// to their associated data. /// /// This is done for a few reasons: diff --git a/conrod_core/src/widget/primitive/line.rs b/conrod_core/src/widget/primitive/line.rs index 0db380ef5..709603325 100644 --- a/conrod_core/src/widget/primitive/line.rs +++ b/conrod_core/src/widget/primitive/line.rs @@ -1,11 +1,19 @@ //! A simple, non-interactive widget for drawing a single straight Line. -use {Color, Colorable, Point, Positionable, Rect, Scalar, Sizeable, Theme}; -use graph; -use utils::{vec2_add, vec2_sub}; -use widget::{self, Widget}; -use widget::triangles::Triangle; - +use crate::{ + Color, + Colorable, + Point, + Positionable, + Rect, + Scalar, + Sizeable, + Theme, + graph, + utils::{vec2_add, vec2_sub}, + widget::{self, Widget}, + widget::triangles::Triangle +}; /// A simple, non-interactive widget for drawing a single straight Line. #[derive(Copy, Clone, Debug, WidgetCommon_)] diff --git a/conrod_core/src/widget/primitive/mod.rs b/conrod_core/src/widget/primitive/mod.rs index 4d9bfcef4..954073e56 100644 --- a/conrod_core/src/widget/primitive/mod.rs +++ b/conrod_core/src/widget/primitive/mod.rs @@ -10,7 +10,7 @@ pub mod point_path; pub mod shape; pub mod text; -use {Point, Range, Rect}; +use crate::{Point, Range, Rect}; /// Find the bounding rect for the given series of points. pub fn bounding_box_for_points(mut points: I) -> Rect diff --git a/conrod_core/src/widget/primitive/point_path.rs b/conrod_core/src/widget/primitive/point_path.rs index 324ef73b7..c26d10170 100644 --- a/conrod_core/src/widget/primitive/point_path.rs +++ b/conrod_core/src/widget/primitive/point_path.rs @@ -1,10 +1,19 @@ //! A simple, non-interactive widget for drawing a series of conjoined lines. -use {Color, Colorable, Point, Positionable, Scalar, Sizeable, Theme, Widget}; -use graph; -use utils::{vec2_add, vec2_sub}; -use widget; -use widget::triangles::Triangle; +use crate::{ + Color, + Colorable, + Point, + Positionable, + Scalar, + Sizeable, + Theme, + Widget, + graph, + utils::{vec2_add, vec2_sub}, + widget, + widget::triangles::Triangle +}; pub use super::line::Pattern; pub use super::line::Style; @@ -165,7 +174,7 @@ impl Widget for PointPath /// Update the state of the Line. fn update(self, args: widget::UpdateArgs) -> Self::Event { - use utils::{iter_diff, IterDiff}; + use crate::utils::{iter_diff, IterDiff}; let widget::UpdateArgs { rect, state, .. } = args; let PointPath { points, maybe_shift_to_centre_from, .. } = self; diff --git a/conrod_core/src/widget/primitive/shape/circle.rs b/conrod_core/src/widget/primitive/shape/circle.rs index 7f3f2093b..4be960485 100644 --- a/conrod_core/src/widget/primitive/shape/circle.rs +++ b/conrod_core/src/widget/primitive/shape/circle.rs @@ -1,9 +1,15 @@ //! An adaptation of the **Oval** type where the width and height are equal. -use {Color, Dimensions, Scalar}; -use super::oval::{Full, Oval}; -use super::Style as Style; -use widget; +use crate::{ + Color, + Dimensions, + Scalar, + widget +}; +use super::{ + oval::{Full, Oval}, + Style as Style +}; /// A tiny wrapper around the **Oval** widget type. #[derive(Copy, Clone, Debug)] diff --git a/conrod_core/src/widget/primitive/shape/mod.rs b/conrod_core/src/widget/primitive/shape/mod.rs index 51a4a12a0..f1cb6b8ff 100644 --- a/conrod_core/src/widget/primitive/shape/mod.rs +++ b/conrod_core/src/widget/primitive/shape/mod.rs @@ -1,8 +1,10 @@ //! A module encompassing the primitive 2D shape widgets. -use color::Color; -use theme::Theme; -use widget; +use crate::{ + color::Color, + theme::Theme, + widget +}; pub mod circle; pub mod oval; diff --git a/conrod_core/src/widget/primitive/shape/oval.rs b/conrod_core/src/widget/primitive/shape/oval.rs index ab38b9373..a21ece72a 100644 --- a/conrod_core/src/widget/primitive/shape/oval.rs +++ b/conrod_core/src/widget/primitive/shape/oval.rs @@ -1,11 +1,21 @@ //! A simple, non-interactive widget for drawing a single **Oval**. -use {Color, Colorable, Dimensions, Point, Rect, Scalar, Sizeable, Theme, Widget}; -use graph; +use crate::{ + Color, + Colorable, + Dimensions, + Point, + Rect, + Scalar, + Sizeable, + Theme, + Widget, + graph, + widget, + widget::triangles::Triangle +}; use std; use super::Style as Style; -use widget; -use widget::triangles::Triangle; /// A simple, non-interactive widget for drawing a single **Oval**. diff --git a/conrod_core/src/widget/primitive/shape/polygon.rs b/conrod_core/src/widget/primitive/shape/polygon.rs index 8d9ecb24f..1c1440825 100644 --- a/conrod_core/src/widget/primitive/shape/polygon.rs +++ b/conrod_core/src/widget/primitive/shape/polygon.rs @@ -1,11 +1,19 @@ //! A simple, non-interactive **Polygon** widget for drawing arbitrary convex shapes. -use {Color, Colorable, Point, Positionable, Sizeable, Theme, Widget}; -use graph; +use crate::{ + Color, + Colorable, + Point, + Positionable, + Sizeable, + Theme, + Widget, + graph, + widget, + widget::triangles::Triangle, + utils::{bounding_box_for_points, vec2_add, vec2_sub} +}; use super::Style; -use widget; -use widget::triangles::Triangle; -use utils::{bounding_box_for_points, vec2_add, vec2_sub}; /// A basic, non-interactive, arbitrary **Polygon** widget. @@ -212,7 +220,7 @@ impl Widget for Polygon /// Update the state of the Polygon. fn update(self, args: widget::UpdateArgs) -> Self::Event { - use utils::{iter_diff, IterDiff}; + use crate::utils::{iter_diff, IterDiff}; let widget::UpdateArgs { rect, state, style, .. } = args; let Polygon { points, maybe_shift_to_centre_from, .. } = self; diff --git a/conrod_core/src/widget/primitive/shape/rectangle.rs b/conrod_core/src/widget/primitive/shape/rectangle.rs index da3244a83..6a1d7ba38 100644 --- a/conrod_core/src/widget/primitive/shape/rectangle.rs +++ b/conrod_core/src/widget/primitive/shape/rectangle.rs @@ -3,10 +3,18 @@ //! Due to the frequency of its use in GUIs, the `Rectangle` gets its own widget to allow backends //! to specialise their rendering implementations. -use {Color, Colorable, Dimensions, Point, Rect, Sizeable, Widget}; +use crate::{ + Color, + Colorable, + Dimensions, + Point, + Rect, + Sizeable, + Widget, + widget, + widget::triangles::Triangle +}; use super::Style as Style; -use widget; -use widget::triangles::Triangle; /// A basic, non-interactive rectangle shape widget. diff --git a/conrod_core/src/widget/primitive/shape/triangles.rs b/conrod_core/src/widget/primitive/shape/triangles.rs index cf68ef18a..50d3fd4a9 100644 --- a/conrod_core/src/widget/primitive/shape/triangles.rs +++ b/conrod_core/src/widget/primitive/shape/triangles.rs @@ -1,11 +1,19 @@ //! A primitive widget that allows for drawing using a list of triangles. -use {Rect, Point, Positionable, Scalar, Sizeable, Theme, Widget}; -use color; -use graph; +use crate::{ + Rect, + Point, + Positionable, + Scalar, + Sizeable, + Theme, + Widget, + color, + graph, + utils::{vec2_add, vec2_sub}, + widget +}; use std; -use utils::{vec2_add, vec2_sub}; -use widget; /// A widget that allows for drawing a list of triangles. #[derive(Copy, Clone, Debug, WidgetCommon_)] @@ -26,7 +34,7 @@ pub trait Vertex: Clone + Copy + PartialEq { /// The x y location of the vertex. fn point(&self) -> Point; /// Add the given vector onto the position of self and return the result. - fn add(self, Point) -> Self; + fn add(self, _: Point) -> Self; } /// Unique styling types for `Triangles`. @@ -325,7 +333,7 @@ impl Widget for Triangles } fn update(self, args: widget::UpdateArgs) -> Self::Event { - use utils::{iter_diff, IterDiff}; + use crate::utils::{iter_diff, IterDiff}; let widget::UpdateArgs { rect, state, .. } = args; let Triangles { triangles, maybe_shift_to_centre_from, .. } = self; diff --git a/conrod_core/src/widget/primitive/text.rs b/conrod_core/src/widget/primitive/text.rs index 83c7513c3..7eed76c85 100644 --- a/conrod_core/src/widget/primitive/text.rs +++ b/conrod_core/src/widget/primitive/text.rs @@ -1,11 +1,17 @@ //! The primitive widget used for displaying text. -use {Color, Colorable, FontSize, Ui, Widget}; -use position::{Dimension, Scalar}; +use crate::{ + Color, + Colorable, + FontSize, + Ui, + Widget, + position::{Dimension, Scalar}, + text, + utils, + widget +}; use std; -use text; -use utils; -use widget; /// Displays some given text centered within a rectangular area. @@ -188,7 +194,7 @@ impl<'a> Widget for Text<'a> { /// The `Font` used by the `Text` is retrieved in order to determine the width of each line. If /// the font used by the `Text` cannot be found, a dimension of `Absolute(0.0)` is returned. fn default_y_dimension(&self, ui: &Ui) -> Dimension { - use position::Sizeable; + use crate::position::Sizeable; let font = match self.style.font_id(&ui.theme) .or(ui.fonts.ids().next()) @@ -256,7 +262,7 @@ impl<'a> Widget for Text<'a> { // Otherwise, we'll check to see if we have to update the line breaks. } else { - use utils::write_if_different; + use crate::utils::write_if_different; use std::borrow::Cow; // Compare the line_infos and only collect the new ones if they are different. diff --git a/conrod_core/src/widget/rounded_rectangle.rs b/conrod_core/src/widget/rounded_rectangle.rs index 99234709a..a19cf9b38 100644 --- a/conrod_core/src/widget/rounded_rectangle.rs +++ b/conrod_core/src/widget/rounded_rectangle.rs @@ -3,14 +3,24 @@ //! The roundedness of the corners is specified with a `radius`. This indicates the radius of the //! circle used to draw the corners. -use {Color, Colorable, Dimensions, Point, Positionable, Range, Rect, Scalar, Sizeable, Theme, - Widget}; -use graph; +use crate::{ + Color, + Colorable, + Dimensions, + Point, + Positionable, + Range, + Rect, + Scalar, + Sizeable, + Theme, + Widget, + graph, + widget, + widget::primitive::shape::Style, + widget::primitive::shape::oval::Circumference +}; use std::f64::consts::PI; -use widget; -use widget::primitive::shape::Style; -use widget::primitive::shape::oval::Circumference; - /// Draws a rectangle with corners rounded via the given radius. #[derive(Copy, Clone, Debug, WidgetCommon_)] diff --git a/conrod_core/src/widget/scroll.rs b/conrod_core/src/widget/scroll.rs index e353349fb..25e5e7d05 100644 --- a/conrod_core/src/widget/scroll.rs +++ b/conrod_core/src/widget/scroll.rs @@ -1,7 +1,9 @@ //! Scroll related types and logic. -use Ui; -use position::{Align, Point, Padding, Range, Rect, Scalar}; +use crate::{ + Ui, + position::{Align, Point, Padding, Range, Rect, Scalar} +}; use std::marker::PhantomData; @@ -37,11 +39,11 @@ pub struct State { /// Methods for distinguishing behaviour between both scroll axes at compile-time. pub trait Axis { /// The range of the given `Rect` that is parallel with this `Axis`. - fn parallel_range(Rect) -> Range; + fn parallel_range(_: Rect) -> Range; /// The range of the given `Rect` that is perpendicular with this `Axis`. - fn perpendicular_range(Rect) -> Range; + fn perpendicular_range(_: Rect) -> Range; /// Given some rectangular `Padding`, return the `Range` that corresponds with this `Axis`. - fn padding_range(Padding) -> Range; + fn padding_range(_: Padding) -> Range; /// The coordinate of the given mouse position that corresponds with this `Axis`. fn mouse_scalar(mouse_xy: Point) -> Scalar; /// A `Scalar` multiplier representing the direction in which positive offset shifts the diff --git a/conrod_derive/Cargo.toml b/conrod_derive/Cargo.toml index 373c349ba..e16eef36c 100644 --- a/conrod_derive/Cargo.toml +++ b/conrod_derive/Cargo.toml @@ -8,6 +8,8 @@ keywords = ["conrod", "gui", "derive", "procedural", "macro"] repository = "https://github.com/pistondevelopers/conrod.git" homepage = "https://github.com/pistondevelopers/conrod" +edition = "2018" + [lib] proc-macro = true diff --git a/conrod_derive/src/common.rs b/conrod_derive/src/common.rs index 5579daf64..7e35443b6 100644 --- a/conrod_derive/src/common.rs +++ b/conrod_derive/src/common.rs @@ -11,11 +11,11 @@ pub fn impl_widget_common(ast: &syn::DeriveInput) -> proc_macro2::TokenStream { let dummy_const = syn::Ident::new(&format!("_IMPL_WIDGET_COMMON_FOR_{}", ident), proc_macro2::Span::call_site()); let impl_item = quote! { - impl #impl_generics _conrod::widget::Common for #ident #ty_generics #where_clause { - fn common(&self) -> &_conrod::widget::CommonBuilder { + impl #impl_generics _conrod_core::widget::Common for #ident #ty_generics #where_clause { + fn common(&self) -> &_conrod_core::widget::CommonBuilder { &self.#common_field } - fn common_mut(&mut self) -> &mut _conrod::widget::CommonBuilder { + fn common_mut(&mut self) -> &mut _conrod_core::widget::CommonBuilder { &mut self.#common_field } } @@ -146,7 +146,7 @@ impl std::error::Error for Error { "Cannot use #[conrod(common_builder)] attribute on unnamed fields", Error::NoCommonBuilderField => "`#[derive(WidgetCommon)]` requires a struct with one field of type \ - `conrod::widget::CommonBuilder` that has the `#[conrod(common_builder)]` \ + `conrod_core::widget::CommonBuilder` that has the `#[conrod(common_builder)]` \ attribute", } } diff --git a/conrod_derive/src/lib.rs b/conrod_derive/src/lib.rs index f0a903e66..1cae77f3b 100644 --- a/conrod_derive/src/lib.rs +++ b/conrod_derive/src/lib.rs @@ -1,6 +1,6 @@ extern crate proc_macro; - extern crate proc_macro2; + #[macro_use] extern crate quote; extern crate syn; diff --git a/conrod_derive/src/style.rs b/conrod_derive/src/style.rs index 3911a670a..3e83ebd10 100644 --- a/conrod_derive/src/style.rs +++ b/conrod_derive/src/style.rs @@ -2,7 +2,7 @@ use std; use proc_macro2; use syn; -use utils; +use crate::utils; // The implementation for `WidgetStyle`. // // This generates an accessor method for every field in the struct @@ -46,10 +46,12 @@ fn impl_tokens(params: &Params, crate_tokens: Option) -> proc_macro2 ref fields, .. } = *params; - let getter_methods = fields - .iter() - .map(|&FieldParams { ref default, ref ty, ref ident }| { - quote! { + match crate_tokens { + Some(_) => { + let getter_methods = fields + .iter() + .map(|&FieldParams { ref default, ref ty, ref ident }| { + quote! { /// Retrieves the value, falling back to a default values in the following order: /// /// 1. If the field is `None`, falls back to the style stored within the `Theme`. @@ -68,11 +70,44 @@ fn impl_tokens(params: &Params, crate_tokens: Option) -> proc_macro2 .unwrap_or_else(|| #default) } } - }); + }); - quote! { - impl #impl_generics #ident #ty_generics #where_clause { - #( #getter_methods )* + quote! { + impl #impl_generics #ident #ty_generics #where_clause { + #( #getter_methods )* + } + } + } + None => { + let getter_methods = fields + .iter() + .map(|&FieldParams { ref default, ref ty, ref ident }| { + quote! { + /// Retrieves the value, falling back to a default values in the following order: + /// + /// 1. If the field is `None`, falls back to the style stored within the `Theme`. + /// 2. If there are no style defaults for the widget in the theme, or if the + /// default field is also `None`, falls back to the expression specified within + /// the field's `#[luchs_core(default = "expr")]` attribute. + /// + /// *This method was generated by the `#[luchs_core(default = "expr")]` attribute + /// associated with the `#[derive(WidgetStyle)]` attribute.* + pub fn #ident(&self, theme: &crate::Theme) -> #ty { + self.#ident + .or_else(|| { + theme.widget_style::() + .and_then(|default| default.style.#ident) + }) + .unwrap_or_else(|| #default) + } + } + }); + + quote! { + impl #impl_generics #ident #ty_generics #where_clause { + #( #getter_methods )* + } + } } } } diff --git a/conrod_widgets/Cargo.toml b/conrod_widgets/Cargo.toml new file mode 100644 index 000000000..0a1e1ca79 --- /dev/null +++ b/conrod_widgets/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "conrod_widgets" +version = "0.62.0" +authors = ["mitchmindtree "] +description = "A crate providing procedural macros for the conrod library" +license = "MIT OR Apache-2.0" +keywords = ["conrod", "gui", "derive", "procedural", "macro"] +repository = "https://github.com/pistondevelopers/conrod.git" +homepage = "https://github.com/pistondevelopers/conrod" + +edition = "2018" + +[dependencies] +conrod_core = {path = "../conrod_core"} +num = "0.2" \ No newline at end of file diff --git a/conrod_core/src/widget/canvas.rs b/conrod_widgets/src/canvas.rs similarity index 96% rename from conrod_core/src/widget/canvas.rs rename to conrod_widgets/src/canvas.rs index a181f7f27..a27e6da47 100644 --- a/conrod_core/src/widget/canvas.rs +++ b/conrod_widgets/src/canvas.rs @@ -1,6 +1,6 @@ //! The `Canvas` widget and related items. -use { +use conrod_core::{ Color, Colorable, FontSize, @@ -12,12 +12,17 @@ use { Ui, UiCell, Widget, + position::{self, Dimensions, Padding, Place, Position, Range, Rect, Scalar}, + position::Direction::{Forwards, Backwards}, + text, + widget, + // Macros + builder_method, + builder_methods, + widget_ids, + WidgetCommon_, + WidgetStyle_, }; -use position::{self, Dimensions, Padding, Place, Position, Range, Rect, Scalar}; -use position::Direction::{Forwards, Backwards}; -use text; -use widget; - /// **Canvas** is designed to be a "container"-like "parent" widget that simplifies placement of /// "children" widgets. @@ -304,7 +309,7 @@ impl<'a> Widget for Canvas<'a> { let justify = style.title_bar_justify(&ui.theme); let line_spacing = style.title_bar_line_spacing(&ui.theme); let maybe_wrap = style.title_bar_maybe_wrap(&ui.theme); - widget::TitleBar::new(label, state.ids.rectangle) + crate::TitleBar::new(label, state.ids.rectangle) .and_mut(|title_bar| { title_bar.style.maybe_wrap = Some(maybe_wrap); title_bar.style.justify = Some(justify); @@ -404,7 +409,7 @@ impl<'a> Widget for Canvas<'a> { /// The height and relative y coordinate of a Canvas' title bar given some canvas height and font /// size for the title bar. fn title_bar_h_rel_y(canvas_h: Scalar, font_size: FontSize) -> (Scalar, Scalar) { - let h = widget::title_bar::calc_height(font_size); + let h = crate::title_bar::calc_height(font_size); let rel_y = canvas_h / 2.0 - h / 2.0; (h, rel_y) } @@ -428,18 +433,18 @@ impl Style { } } -impl<'a> ::color::Colorable for Canvas<'a> { +impl<'a> conrod_core::color::Colorable for Canvas<'a> { builder_method!(color { style.color = Some(Color) }); } -impl<'a> ::border::Borderable for Canvas<'a> { +impl<'a> conrod_core::border::Borderable for Canvas<'a> { builder_methods!{ border { style.border = Some(Scalar) } border_color { style.border_color = Some(Color) } } } -impl<'a> ::label::Labelable<'a> for Canvas<'a> { +impl<'a> conrod_core::label::Labelable<'a> for Canvas<'a> { fn label(self, text: &'a str) -> Self { self.title_bar(text) } diff --git a/conrod_core/src/widget/collapsible_area.rs b/conrod_widgets/src/collapsible_area.rs similarity index 96% rename from conrod_core/src/widget/collapsible_area.rs rename to conrod_widgets/src/collapsible_area.rs index 48995976e..43d28a817 100644 --- a/conrod_core/src/widget/collapsible_area.rs +++ b/conrod_widgets/src/collapsible_area.rs @@ -1,11 +1,26 @@ //! The `CollapsibleArea` widget and related items. -use {Borderable, Colorable, Labelable, Positionable, Sizeable, Widget}; -use {Color, FontSize, Scalar, UiCell}; -use position; -use std; -use text; -use widget; +use conrod_core::{ + Borderable, + Colorable, + Labelable, + Positionable, + Sizeable, + Widget, + Color, + FontSize, + Scalar, + UiCell, + position, + text, + widget, + // Macros + builder_method, + builder_methods, + widget_ids, + WidgetCommon_, + WidgetStyle_, +}; /// A vertically collapsible area. /// diff --git a/conrod_core/src/widget/drop_down_list.rs b/conrod_widgets/src/drop_down_list.rs similarity index 92% rename from conrod_core/src/widget/drop_down_list.rs rename to conrod_widgets/src/drop_down_list.rs index d3e1d55d5..1982c0f56 100644 --- a/conrod_core/src/widget/drop_down_list.rs +++ b/conrod_widgets/src/drop_down_list.rs @@ -1,11 +1,28 @@ //! The `DropDownList` and related items. -use {Color, Colorable, FontSize, Borderable, Labelable, Positionable, Sizeable}; -use position::{self, Align, Scalar}; -use text; -use utils; -use widget::{self, Widget}; - +use conrod_core::{ + Color, + Colorable, + FontSize, + Borderable, + Labelable, + Positionable, + Sizeable, + position::{self, Align, Scalar}, + text, + utils, + widget::{self, Widget}, + // Macros + builder_method, + builder_methods, + widget_ids, + WidgetCommon_, + WidgetStyle_, +}; + +use crate::scrollbar; +use crate::list::{self, List}; +use crate::list_select::ListSelect; /// The index of a selected item. pub type Idx = usize; @@ -58,7 +75,7 @@ pub struct Style { pub maybe_max_visible_height: Option>, /// The position of the scrollbar in the case that the list is scrollable. #[conrod(default = "None")] - pub scrollbar_position: Option>, + pub scrollbar_position: Option>, /// The width of the scrollbar in the case that the list is scrollable. #[conrod(default = "None")] pub scrollbar_width: Option>, @@ -131,14 +148,14 @@ impl<'a, T> DropDownList<'a, T> { /// Specifies that the list should be scrollable and should provide a `Scrollbar` to the right /// of the items. pub fn scrollbar_next_to(mut self) -> Self { - self.style.scrollbar_position = Some(Some(widget::list::ScrollbarPosition::NextTo)); + self.style.scrollbar_position = Some(Some(list::ScrollbarPosition::NextTo)); self } /// Specifies that the list should be scrollable and should provide a `Scrollbar` that hovers /// above the right edge of the items and automatically hides when the user is not scrolling. pub fn scrollbar_on_top(mut self) -> Self { - self.style.scrollbar_position = Some(Some(widget::list::ScrollbarPosition::OnTop)); + self.style.scrollbar_position = Some(Some(list::ScrollbarPosition::OnTop)); self } @@ -275,18 +292,18 @@ impl<'a, T> Widget for DropDownList<'a, T> let scrollbar_position = style.scrollbar_position(&ui.theme); let scrollbar_width = style.scrollbar_width(&ui.theme) .unwrap_or_else(|| { - ui.theme.widget_style::() + ui.theme.widget_style::() .and_then(|style| style.style.thickness) .unwrap_or(10.0) }); - let (mut events, scrollbar) = widget::ListSelect::single(num_items) + let (mut events, scrollbar) = ListSelect::single(num_items) .flow_down() .item_size(item_h) .w_h(w, list_h) .and(|ls| match scrollbar_position { - Some(widget::list::ScrollbarPosition::NextTo) => ls.scrollbar_next_to(), - Some(widget::list::ScrollbarPosition::OnTop) => ls.scrollbar_on_top(), + Some(list::ScrollbarPosition::NextTo) => ls.scrollbar_next_to(), + Some(list::ScrollbarPosition::OnTop) => ls.scrollbar_on_top(), None => ls, }) .scrollbar_color(scrollbar_color) @@ -296,7 +313,7 @@ impl<'a, T> Widget for DropDownList<'a, T> .set(state.ids.list, ui); while let Some(event) = events.next(ui, |i| Some(i) == selected) { - use widget::list_select::Event; + use crate::list_select::Event; match event { // Instantiate a `Button` for each item. diff --git a/conrod_core/src/widget/envelope_editor.rs b/conrod_widgets/src/envelope_editor.rs similarity index 97% rename from conrod_core/src/widget/envelope_editor.rs rename to conrod_widgets/src/envelope_editor.rs index 635b42ee1..cfadc2d56 100644 --- a/conrod_core/src/widget/envelope_editor.rs +++ b/conrod_widgets/src/envelope_editor.rs @@ -1,12 +1,26 @@ //! The `EnvelopeEditor` widget and related items. -use {Color, Colorable, Borderable, FontSize, Labelable, Positionable, Sizeable, Widget}; +use conrod_core::{ + utils::{clamp, map_range, percentage, val_to_string}, + text, + position::{Direction, Edge, Point, Rect, Scalar}, + Color, + Colorable, + Borderable, + FontSize, + Labelable, + Positionable, + Sizeable, + Widget, + widget, + // Macros + builder_method, + builder_methods, + widget_ids, + WidgetCommon_, + WidgetStyle_, +}; use num::Float; -use position::{Direction, Edge, Point, Rect, Scalar}; -use std; -use text; -use utils::{clamp, map_range, percentage, val_to_string}; -use widget; /// Used for editing a series of 2D Points on a cartesian (X, Y) plane within some given range. @@ -319,8 +333,10 @@ impl<'a, E> Widget for EnvelopeEditor<'a, E> // - Dragging points via left `Drag`. let mut events = Vec::new(); 'events: for widget_event in ui.widget_input(id).events() { - use event; - use input::{self, MouseButton}; + use conrod_core::{ + event, + input::{self, MouseButton} + }; match widget_event { diff --git a/conrod_core/src/widget/grid.rs b/conrod_widgets/src/grid.rs similarity index 97% rename from conrod_core/src/widget/grid.rs rename to conrod_widgets/src/grid.rs index 65ee39523..6e0f153b5 100644 --- a/conrod_core/src/widget/grid.rs +++ b/conrod_widgets/src/grid.rs @@ -1,8 +1,20 @@ //! A widget for displaying a grid of lines across two axes. -use {Color, Colorable, Point, Scalar, Widget}; -use widget::{self, CommonBuilder, UpdateArgs}; -use utils::map_range; +use conrod_core::{ + Color, + Colorable, + Point, + Scalar, + Widget, + widget::{self, CommonBuilder, UpdateArgs}, + utils::map_range, + // Macros + builder_method, + builder_methods, + widget_ids, + WidgetCommon_, + WidgetStyle_, +}; /// A widget for displaying a grid of lines across two axes. #[derive(Copy, Clone, Debug, WidgetCommon_)] diff --git a/conrod_widgets/src/lib.rs b/conrod_widgets/src/lib.rs new file mode 100644 index 000000000..6681af2bb --- /dev/null +++ b/conrod_widgets/src/lib.rs @@ -0,0 +1,46 @@ +#![feature(custom_attribute)] + +use conrod_core::widget as widget; +use conrod_core::theme::Theme as Theme; + +pub use crate::{ + canvas::Canvas, + collapsible_area::CollapsibleArea, + drop_down_list::DropDownList, + envelope_editor::EnvelopeEditor, + list::List, + list_select::ListSelect, + grid::Grid, + matrix::Matrix, + number_dialer::NumberDialer, + plot_path::PlotPath, + range_slider::RangeSlider, + scrollbar::Scrollbar, + slider::Slider, + tabs::Tab, + text_box::TextBox, + text_edit::TextEdit, + title_bar::TitleBar, + toggle::Toggle, + xy_pad::XYPad, +}; + +mod canvas; +mod collapsible_area; +mod drop_down_list; +mod envelope_editor; +mod grid; +mod list; +mod list_select; +mod matrix; +mod number_dialer; +mod plot_path; +mod range_slider; +mod scrollbar; +mod slider; +mod tabs; +mod text_box; +mod text_edit; +mod title_bar; +mod toggle; +mod xy_pad; diff --git a/conrod_core/src/widget/list.rs b/conrod_widgets/src/list.rs similarity index 96% rename from conrod_core/src/widget/list.rs rename to conrod_widgets/src/list.rs index 1b19db1a6..d2eb71c7c 100644 --- a/conrod_core/src/widget/list.rs +++ b/conrod_widgets/src/list.rs @@ -1,6 +1,7 @@ //! A helper widget, useful for instantiating a sequence of widgets in a vertical list. -use { +use conrod_core::{ + graph, color, Color, Colorable, @@ -10,11 +11,15 @@ use { Widget, Ui, UiCell, + position::{Range, Rect}, + widget, + // Macros + builder_method, + builder_methods, + widget_ids, + WidgetCommon_, + WidgetStyle_, }; -use graph; -use position::{Range, Rect}; -use std; -use widget; /// A helper widget, useful for instantiating a sequence of widgets in a vertical list. /// @@ -68,13 +73,13 @@ pub struct Dynamic {} /// The direction in which the list is laid out. pub trait Direction { /// The direction along which the `Scrollbar` is laid out. - type Axis: widget::scrollbar::Axis; + type Axis: crate::scrollbar::Axis; /// For some given `Rect`, returns the parallel and perpendicular ranges respectively. - fn ranges(Rect) -> (Range, Range); + fn ranges(_: Rect) -> (Range, Range); /// Begin building the scrollbar for the `List`. - fn scrollbar(widget::Id) -> widget::Scrollbar; + fn scrollbar(_: widget::Id) -> crate::Scrollbar; /// Borrow the scroll state associated with this `Direction`'s axis. fn common_scroll(common: &widget::CommonBuilder) -> Option<&widget::scroll::Scroll>; @@ -108,7 +113,7 @@ pub trait Direction { pub trait ItemSize: Sized + Clone + Copy { /// Update the `List` widget. - fn update_list(List, widget::UpdateArgs>) + fn update_list(_: List, _: widget::UpdateArgs>) -> as Widget>::Event where D: Direction; @@ -185,7 +190,7 @@ pub enum ScrollbarPosition { /// A wrapper around a `List`'s `Scrollbar` and its `widget::Id`. pub struct Scrollbar { - widget: widget::Scrollbar, + widget: crate::Scrollbar, id: widget::Id, } @@ -497,7 +502,7 @@ impl Item { impl Scrollbar - where A: widget::scrollbar::Axis, + where A: crate::scrollbar::Axis, { /// Set the `Scrollbar` within the given `Ui`. pub fn set(self, ui: &mut UiCell) { @@ -538,7 +543,7 @@ impl ItemSize for Fixed { // The width of the scrollbar. let scrollbar_thickness = style.scrollbar_thickness(&ui.theme) .unwrap_or_else(|| { - ui.theme.widget_style::() + ui.theme.widget_style::() .and_then(|style| style.style.thickness) .unwrap_or(10.0) }); @@ -660,7 +665,7 @@ impl ItemSize for Dynamic { // The width of the scrollbar. let scrollbar_thickness = style.scrollbar_thickness(&ui.theme) .unwrap_or_else(|| { - ui.theme.widget_style::() + ui.theme.widget_style::() .and_then(|style| style.style.thickness) .unwrap_or(10.0) }); @@ -720,8 +725,8 @@ impl Direction for Down { (y.invert(), x) } - fn scrollbar(id: widget::Id) -> widget::Scrollbar { - widget::Scrollbar::y_axis(id) + fn scrollbar(id: widget::Id) -> crate::Scrollbar { + crate::Scrollbar::y_axis(id) } fn common_scroll(common: &widget::CommonBuilder) -> Option<&widget::scroll::Scroll> { @@ -775,8 +780,8 @@ impl Direction for Up { (y, x) } - fn scrollbar(id: widget::Id) -> widget::Scrollbar { - widget::Scrollbar::y_axis(id) + fn scrollbar(id: widget::Id) -> crate::Scrollbar { + crate::Scrollbar::y_axis(id) } fn common_scroll(common: &widget::CommonBuilder) -> Option<&widget::scroll::Scroll> { @@ -830,8 +835,8 @@ impl Direction for Left { (x.invert(), y) } - fn scrollbar(id: widget::Id) -> widget::Scrollbar { - widget::Scrollbar::x_axis(id) + fn scrollbar(id: widget::Id) -> crate::Scrollbar { + crate::Scrollbar::x_axis(id) } fn common_scroll(common: &widget::CommonBuilder) -> Option<&widget::scroll::Scroll> { @@ -885,8 +890,8 @@ impl Direction for Right { (x, y) } - fn scrollbar(id: widget::Id) -> widget::Scrollbar { - widget::Scrollbar::x_axis(id) + fn scrollbar(id: widget::Id) -> crate::Scrollbar { + crate::Scrollbar::x_axis(id) } fn common_scroll(common: &widget::CommonBuilder) -> Option<&widget::scroll::Scroll> { diff --git a/conrod_core/src/widget/list_select.rs b/conrod_widgets/src/list_select.rs similarity index 89% rename from conrod_core/src/widget/list_select.rs rename to conrod_widgets/src/list_select.rs index 794aa4658..470e52f5e 100644 --- a/conrod_core/src/widget/list_select.rs +++ b/conrod_widgets/src/list_select.rs @@ -1,10 +1,28 @@ //! A wrapper around the `List` widget providing the ability to select one or more items. -use {Color, Positionable, Scalar, Sizeable, Ui, Widget}; -use {event, graph, input, widget}; -use std; -use input::keyboard::ModifierKey; -use input::state::mouse::Button; +use conrod_core::{ + Color, + Positionable, + Scalar, + Sizeable, + Ui, + Widget, + event, + graph, + input::{ + self, + keyboard::ModifierKey, + state::mouse::Button + }, + widget, + // Macros + builder_method, + builder_methods, + widget_ids, + WidgetCommon_, +}; + +use crate::list::{self, List}; /// A wrapper around the `List` widget that handles single and multiple selection logic. #[derive(Clone, WidgetCommon_)] @@ -16,15 +34,15 @@ pub struct ListSelect { mode: M, direction: std::marker::PhantomData, item_size: S, - style: widget::list::Style, - item_instantiation: widget::list::ItemInstantiation, + style: list::Style, + item_instantiation: list::ItemInstantiation, } /// A trait that extends the `List` `Direction` trait with behaviour necessary for the `ListSelect` /// widget. /// /// Implemented for the `Down`, `Right`, `Up`, `Left` types. -pub trait Direction: widget::list::Direction { +pub trait Direction: list::Direction { /// Maps a given `key` to a direction along the list. fn key_direction(key: input::Key) -> Option; } @@ -47,22 +65,22 @@ pub trait Mode { /// Update the `PendingEvents` in accordance with the given `Click` event. fn click_selection(&self, - event::Click, + _: event::Click, i: usize, num_items: usize, - &State, + _: &State, is_selected: F, - &mut PendingEvents) + _: &mut PendingEvents) where F: Fn(usize) -> bool; /// Update the `PendingEvents` in accordance with the given `KeyPress` event. fn key_selection(&self, - event::KeyPress, + _: event::KeyPress, i: usize, num_items: usize, - &State, + _: &State, is_selected: F, - &mut PendingEvents) + _: &mut PendingEvents) where F: Fn(usize) -> bool, D: Direction; } @@ -89,7 +107,7 @@ pub struct Events where M: Mode, { id: widget::Id, - items: widget::list::Items, + items: list::Items, num_items: usize, mode: M, pending_events: PendingEvents, @@ -100,7 +118,7 @@ pub struct Events #[derive(Clone, Debug)] pub enum Event { /// The next `Item` is ready for instantiation. - Item(widget::list::Item), + Item(list::Item), /// A change in selection has occurred. Selection(Selection), /// A button press occurred while the widget was capturing the mouse. @@ -172,14 +190,14 @@ impl Selection { } -impl ListSelect { +impl ListSelect { /// Construct a new ListSelect, allowing one selected item at a time. pub fn single(num_items: usize) -> Self { Self::new(num_items, Single) } } -impl ListSelect { +impl ListSelect { /// Construct a new ListSelect, allowing multiple selected items. pub fn multiple(num_items: usize) -> Self { Self::new(num_items, Multiple) @@ -189,11 +207,11 @@ impl ListSelect { impl ListSelect where M: Mode, D: Direction, - S: widget::list::ItemSize, + S: list::ItemSize, { /// Flows items from top to bottom. - pub fn flow_down(self) -> ListSelect { + pub fn flow_down(self) -> ListSelect { let ListSelect { common, num_items, mode, item_size, style, item_instantiation, .. } = self; ListSelect { common: common, @@ -207,7 +225,7 @@ impl ListSelect } /// Flows items from left to right. - pub fn flow_right(self) -> ListSelect { + pub fn flow_right(self) -> ListSelect { let ListSelect { common, num_items, mode, item_size, style, item_instantiation, .. } = self; ListSelect { common: common, @@ -221,7 +239,7 @@ impl ListSelect } /// Flows items from right to left. - pub fn flow_left(self) -> ListSelect { + pub fn flow_left(self) -> ListSelect { let ListSelect { common, num_items, mode, item_size, style, item_instantiation, .. } = self; ListSelect { common: common, @@ -235,7 +253,7 @@ impl ListSelect } /// Flows items from bottom to top. - pub fn flow_up(self) -> ListSelect { + pub fn flow_up(self) -> ListSelect { let ListSelect { common, num_items, mode, item_size, style, item_instantiation, .. } = self; ListSelect { common: common, @@ -251,21 +269,21 @@ impl ListSelect /// Specify a fixed item size, where size is a `Scalar` in the direction that the `List` is /// flowing. When a `List` is constructed with this method, all items will have a fixed, equal /// length. - pub fn item_size(self, length: Scalar) -> ListSelect { + pub fn item_size(self, length: Scalar) -> ListSelect { let ListSelect { common, num_items, mode, direction, style, .. } = self; ListSelect { common: common, num_items: num_items, mode: mode, direction: direction, - item_size: widget::list::Fixed { length: length }, + item_size: list::Fixed { length: length }, style: style, - item_instantiation: widget::list::ItemInstantiation::OnlyVisible, + item_instantiation: list::ItemInstantiation::OnlyVisible, } } } -impl ListSelect { +impl ListSelect { /// Begin building a new `ListSelect` with the given mode. /// /// This method is only useful when using a custom `Mode`, otherwise `ListSelect::single` or @@ -275,12 +293,12 @@ impl ListSelect { { ListSelect { common: widget::CommonBuilder::default(), - style: widget::list::Style::default(), + style: list::Style::default(), num_items: num_items, - item_size: widget::list::Dynamic {}, + item_size: list::Dynamic {}, mode: mode, direction: std::marker::PhantomData, - item_instantiation: widget::list::ItemInstantiation::All, + item_instantiation: list::ItemInstantiation::All, } } } @@ -290,14 +308,14 @@ impl ListSelect { /// Specifies that the `List` should be scrollable and should provide a `Scrollbar` to the /// right of the items. pub fn scrollbar_next_to(mut self) -> Self { - self.style.scrollbar_position = Some(Some(widget::list::ScrollbarPosition::NextTo)); + self.style.scrollbar_position = Some(Some(list::ScrollbarPosition::NextTo)); self } /// Specifies that the `List` should be scrollable and should provide a `Scrollbar` that hovers /// above the right edge of the items and automatically hides when the user is not scrolling. pub fn scrollbar_on_top(mut self) -> Self { - self.style.scrollbar_position = Some(Some(widget::list::ScrollbarPosition::OnTop)); + self.style.scrollbar_position = Some(Some(list::ScrollbarPosition::OnTop)); self } @@ -315,7 +333,7 @@ impl ListSelect { } -impl ListSelect { +impl ListSelect { /// Indicates that an `Item` should be instatiated for every element in the list, regardless of /// whether or not the `Item` would be visible. @@ -328,7 +346,7 @@ impl ListSelect { /// We only recommend using this when absolutely necessary as large lists may cause unnecessary /// bloating within the widget graph, and in turn result in greater traversal times. pub fn instantiate_all_items(mut self) -> Self { - self.item_instantiation = widget::list::ItemInstantiation::All; + self.item_instantiation = list::ItemInstantiation::All; self } @@ -338,7 +356,7 @@ impl ListSelect { /// /// This is the default behaviour for `ListSelect`s with fixed item sizes. pub fn instantiate_only_visible_items(mut self) -> Self { - self.item_instantiation = widget::list::ItemInstantiation::OnlyVisible; + self.item_instantiation = list::ItemInstantiation::OnlyVisible; self } @@ -347,11 +365,11 @@ impl ListSelect { impl Widget for ListSelect where M: Mode, D: Direction, - S: widget::list::ItemSize, + S: list::ItemSize, { type State = State; - type Style = widget::list::Style; - type Event = (Events, Option>); + type Style = list::Style; + type Event = (Events, Option>); fn init_state(&self, id_gen: widget::id::Generator) -> Self::State { State { @@ -378,12 +396,12 @@ impl Widget for ListSelect } - let mut list = widget::List::::from_item_size(num_items, item_size); + let mut list = List::::from_item_size(num_items, item_size); let scrollbar_position = style.scrollbar_position(&ui.theme); list = match scrollbar_position { - Some(widget::list::ScrollbarPosition::OnTop) => list.scrollbar_on_top(), - Some(widget::list::ScrollbarPosition::NextTo) => list.scrollbar_next_to(), + Some(list::ScrollbarPosition::OnTop) => list.scrollbar_on_top(), + Some(list::ScrollbarPosition::NextTo) => list.scrollbar_next_to(), None => list, }; @@ -406,7 +424,7 @@ impl Widget for ListSelect impl Events where M: Mode, D: Direction, - S: widget::list::ItemSize, + S: list::ItemSize, { /// Yield the next `Event`. @@ -663,7 +681,7 @@ impl Mode for Multiple { } -impl Direction for widget::list::Down { +impl Direction for list::Down { fn key_direction(key: input::Key) -> Option { match key { input::Key::Down => Some(ListDirection::Forward), @@ -673,7 +691,7 @@ impl Direction for widget::list::Down { } } -impl Direction for widget::list::Up { +impl Direction for list::Up { fn key_direction(key: input::Key) -> Option { match key { input::Key::Up => Some(ListDirection::Forward), @@ -683,7 +701,7 @@ impl Direction for widget::list::Up { } } -impl Direction for widget::list::Right { +impl Direction for list::Right { fn key_direction(key: input::Key) -> Option { match key { input::Key::Right => Some(ListDirection::Forward), @@ -693,7 +711,7 @@ impl Direction for widget::list::Right { } } -impl Direction for widget::list::Left { +impl Direction for list::Left { fn key_direction(key: input::Key) -> Option { match key { input::Key::Left => Some(ListDirection::Forward), diff --git a/conrod_core/src/widget/matrix.rs b/conrod_widgets/src/matrix.rs similarity index 96% rename from conrod_core/src/widget/matrix.rs rename to conrod_widgets/src/matrix.rs index 0e67ae3c5..5c834f213 100644 --- a/conrod_core/src/widget/matrix.rs +++ b/conrod_widgets/src/matrix.rs @@ -1,9 +1,20 @@ //! A helper widget for laying out child widgets in the form of a grid. -use {Scalar, Ui, UiCell, Widget}; -use graph; -use utils; -use widget; +use conrod_core::{ + Scalar, + Ui, + UiCell, + Widget, + graph, + utils, + widget, + // Macros + builder_method, + builder_methods, + widget_ids, + WidgetCommon_, + WidgetStyle_, +}; /// The number of the widget. @@ -249,7 +260,7 @@ impl Element { pub fn set(self, widget: W, ui: &mut UiCell) -> W::Event where W: Widget, { - use {Positionable, Sizeable}; + use conrod_core::{Positionable, Sizeable}; let Element { widget_id, matrix_id, w, h, rel_x, rel_y, .. } = self; widget .w_h(w, h) diff --git a/conrod_core/src/widget/number_dialer.rs b/conrod_widgets/src/number_dialer.rs similarity index 97% rename from conrod_core/src/widget/number_dialer.rs rename to conrod_widgets/src/number_dialer.rs index 4256a9309..c85b0b090 100644 --- a/conrod_core/src/widget/number_dialer.rs +++ b/conrod_widgets/src/number_dialer.rs @@ -1,6 +1,6 @@ //! A widget for precision control over any base-10 digit within a given value. -use { +use conrod_core::{ Color, Colorable, FontSize, @@ -10,13 +10,21 @@ use { Positionable, Scalar, Widget, + text, + utils::clamp, + widget, + // Macros + builder_method, + builder_methods, + widget_ids, + WidgetCommon_, + WidgetStyle_, }; use num::{Float, NumCast}; -use std::cmp::Ordering; -use std::iter::repeat; -use text; -use utils::clamp; -use widget; +use std::{ + cmp::Ordering, + iter::repeat +}; /// A widget for precision control over any digit within a value. @@ -215,7 +223,7 @@ impl<'a, T> Widget for NumberDialer<'a, T> // Returns the index into the `val_string` for retrieving the value. let value_under_rel_xy = |rel_xy: Point| -> Option { if rel_rect.is_over(rel_xy) { - use position::Rect; + use conrod_core::position::Rect; let slot_rect_xy = [label_rel_x + label_dim[0] / 2.0 + slot_w / 2.0, 0.0]; let val_string_xy = [slot_rect_xy[0] - slot_w / 2.0 + val_string_dim[0] / 2.0, 0.0]; let val_string_dim = [val_string_dim[0], slot_h]; @@ -244,8 +252,10 @@ impl<'a, T> Widget for NumberDialer<'a, T> // - `Drag`ging of the mouse while a button is pressed. // - `Scroll`ing of the mouse over a value. 'events: for widget_event in ui.widget_input(id).events() { - use event; - use input::{self, MouseButton}; + use conrod_core::{ + event, + input::{self, MouseButton} + }; match widget_event { diff --git a/conrod_core/src/widget/plot_path.rs b/conrod_widgets/src/plot_path.rs similarity index 93% rename from conrod_core/src/widget/plot_path.rs rename to conrod_widgets/src/plot_path.rs index 3dd264c4f..26fe16c13 100644 --- a/conrod_core/src/widget/plot_path.rs +++ b/conrod_widgets/src/plot_path.rs @@ -1,10 +1,24 @@ //! A widget for plotting a series of lines using the given function *x -> y*. -use {Color, Colorable, Point, Positionable, Scalar, Sizeable, Theme, Widget}; -use graph; -use num; -use utils; -use widget; +use conrod_core::{ + Color, + Colorable, + Point, + Positionable, + Scalar, + Sizeable, + Theme, + Widget, + graph, + utils, + widget, + // Macros + builder_method, + builder_methods, + widget_ids, + WidgetCommon_, + WidgetStyle_, +}; /// A widget that plots a series of lines using the given function *x -> y*. /// diff --git a/conrod_core/src/widget/range_slider.rs b/conrod_widgets/src/range_slider.rs similarity index 96% rename from conrod_core/src/widget/range_slider.rs rename to conrod_widgets/src/range_slider.rs index a33e0090e..242b591ae 100644 --- a/conrod_core/src/widget/range_slider.rs +++ b/conrod_widgets/src/range_slider.rs @@ -1,11 +1,26 @@ //! A widget for specifying start and end values for some linear range. -use {Color, Colorable, FontSize, Borderable, Labelable, Positionable, Widget}; +use conrod_core::{ + utils, + text, + position::{Padding, Range, Rect, Scalar}, + Color, + Colorable, + FontSize, + Borderable, + Labelable, + Positionable, + Widget, + UiCell, + widget, + // Macros + builder_method, + builder_methods, + widget_ids, + WidgetCommon_, + WidgetStyle_, +}; use num::Float; -use position::{Padding, Range, Rect, Scalar}; -use text; -use utils; -use widget; /// Linear range selection. #[derive(WidgetCommon_)] @@ -207,8 +222,10 @@ where let mut new_start = utils::clamp(start, min, max); let mut new_end = utils::clamp(end, start, max); for widget_event in ui.widget_input(id).events() { - use event; - use input; + use conrod_core::{ + event, + input + }; match widget_event { @@ -325,7 +342,7 @@ where } // The **Rectangle** for the border. - let interaction_color = |ui: &::ui::UiCell, color: Color| + let interaction_color = |ui: &UiCell, color: Color| ui.widget_input(id).mouse() .map(|mouse| if mouse.buttons.left().is_down() { color.clicked() diff --git a/conrod_core/src/widget/scrollbar.rs b/conrod_widgets/src/scrollbar.rs similarity index 94% rename from conrod_core/src/widget/scrollbar.rs rename to conrod_widgets/src/scrollbar.rs index 951d0d87a..676616ae4 100644 --- a/conrod_core/src/widget/scrollbar.rs +++ b/conrod_widgets/src/scrollbar.rs @@ -1,13 +1,25 @@ //! A widget that allows for manually scrolling via dragging the mouse. -use {Color, Colorable, Positionable, Ui}; -use graph; -use position::{Dimension, Range, Rect, Scalar}; -use std; -use utils; -use widget::{self, Widget}; -use widget::scroll::{self, X, Y}; - +use conrod_core::{ + position::{Dimension, Range, Rect, Scalar}, + graph, + Color, + Colorable, + Positionable, + Ui, + utils, + widget::{ + self, + Widget, + scroll::{self, X, Y} + }, + // Macros + builder_method, + builder_methods, + widget_ids, + WidgetCommon_, + WidgetStyle_, +}; /// A widget that allows for scrolling via dragging the mouse. #[derive(WidgetCommon_)] @@ -167,9 +179,9 @@ impl Widget for Scrollbar scroll.offset, scroll.scrollable_range_len, scroll.is_scrolling), - None => return, + None => return (), }, - None => return, + None => return (), }; // Calculates the `Rect` for a scroll "handle" sitting on the given `track` with an offset @@ -206,8 +218,10 @@ impl Widget for Scrollbar // Sum all offset yielded by `Press` and `Drag` events. let mut additional_offset = 0.0; for widget_event in ui.widget_input(id).events() { - use event; - use input; + use conrod_core::{ + event, + input + }; match widget_event { @@ -249,17 +263,17 @@ impl Widget for Scrollbar // Scroll the given widget by the accumulated additional offset. if additional_offset != 0.0 { - ui.scroll_widget(widget, A::to_2d(additional_offset)); + ui.scroll_widget(widget, A::to_2d(additional_offset.clone())); } // Don't draw the scrollbar if auto_hide is on and there is no interaction. let auto_hide = style.auto_hide(ui.theme()); let not_scrollable = offset_bounds.magnitude().is_sign_positive(); if auto_hide { - let no_offset = additional_offset == 0.0; + let no_offset = additional_offset.clone() == 0.0; let no_mouse_interaction = ui.widget_input(id).mouse().is_none(); if not_scrollable || (!is_scrolling && no_offset && no_mouse_interaction) { - return; + return (); } } @@ -294,6 +308,8 @@ impl Widget for Scrollbar .graphics_for(id) .parent(id) .set(state.ids.handle, ui); + + () } } diff --git a/conrod_core/src/widget/slider.rs b/conrod_widgets/src/slider.rs similarity index 95% rename from conrod_core/src/widget/slider.rs rename to conrod_widgets/src/slider.rs index 6ddc0bf46..968dbdc83 100644 --- a/conrod_core/src/widget/slider.rs +++ b/conrod_widgets/src/slider.rs @@ -1,11 +1,26 @@ //! A widget for selecting a single value along some linear range. -use {Color, Colorable, FontSize, Borderable, Labelable, Positionable, Widget}; +use conrod_core::{ + widget, + text, + position::{Padding, Range, Rect, Scalar}, + Color, + Colorable, + FontSize, + Borderable, + Labelable, + Positionable, + Widget, + UiCell, + widget::triangles::Triangle, + // Macros + builder_method, + builder_methods, + widget_ids, + WidgetCommon_, + WidgetStyle_, +}; use num::{Float, NumCast, ToPrimitive}; -use position::{Padding, Range, Rect, Scalar}; -use text; -use widget; -use widget::triangles::Triangle; /// Linear value selection. @@ -130,7 +145,7 @@ impl<'a, T> Widget for Slider<'a, T> /// Update the state of the Slider. fn update(self, args: widget::UpdateArgs) -> Self::Event { - use utils::{clamp, map_range, value_from_perc}; + use conrod_core::utils::{clamp, map_range, value_from_perc}; let widget::UpdateArgs { id, state, rect, style, ui, .. } = args; let Slider { value, min, max, skew, maybe_label, .. } = self; @@ -167,7 +182,7 @@ impl<'a, T> Widget for Slider<'a, T> }; // The **Rectangle** for the border. - let interaction_color = |ui: &::ui::UiCell, color: Color| + let interaction_color = |ui: &UiCell, color: Color| ui.widget_input(id).mouse() .map(|mouse| if mouse.buttons.left().is_down() { color.clicked() diff --git a/conrod_core/src/widget/tabs.rs b/conrod_widgets/src/tabs.rs similarity index 92% rename from conrod_core/src/widget/tabs.rs rename to conrod_widgets/src/tabs.rs index fe3f20943..8c401d907 100644 --- a/conrod_core/src/widget/tabs.rs +++ b/conrod_widgets/src/tabs.rs @@ -1,6 +1,6 @@ //! A wrapper around a list of `Canvas`ses that displays them as a list of selectable tabs. -use { +use conrod_core::{ Color, Dimensions, FontSize, @@ -8,11 +8,16 @@ use { Rect, Scalar, Widget, + text, + utils, + widget, + // Macros + builder_method, + builder_methods, + widget_ids, + WidgetCommon_, + WidgetStyle_, }; -use std; -use text; -use utils; -use widget; /// A wrapper around a list of `Canvas`ses that displays them as a list of selectable tabs. @@ -64,8 +69,8 @@ pub struct Style { #[conrod(default = "None")] pub font_id: Option>, /// The styling for each `Canvas`. - #[conrod(default = "widget::canvas::Style::default()")] - pub canvas: Option, + #[conrod(default = "crate::canvas::Style::default()")] + pub canvas: Option, } /// The direction in which the tabs will be laid out. @@ -117,38 +122,38 @@ impl<'a> Tabs<'a> { } /// Build the `Tabs` widget with the given styling for its `Canvas`ses. - pub fn canvas_style(mut self, style: widget::canvas::Style) -> Self { + pub fn canvas_style(mut self, style: crate::canvas::Style) -> Self { self.style.canvas = Some(style); self } - /// Map the `NumberDialer`'s `widget::canvas::Style` to a new `widget::canvas::Style`. + /// Map the `NumberDialer`'s `crate::canvas::Style` to a new `crate::canvas::Style`. fn map_canvas_style(mut self, map: F) -> Self - where F: FnOnce(widget::canvas::Style) -> widget::canvas::Style, + where F: FnOnce(crate::canvas::Style) -> crate::canvas::Style, { self.style.canvas = Some(map({ self.style.canvas.clone() - .unwrap_or_else(widget::canvas::Style::default) + .unwrap_or_else(crate::canvas::Style::default) })); self } - /// If the `Tabs` has some `widget::canvas::Style`, assign the left padding. + /// If the `Tabs` has some `crate::canvas::Style`, assign the left padding. pub fn pad_left(self, pad: Scalar) -> Self { self.map_canvas_style(|mut style| { style.pad_left = Some(pad); style }) } - /// If the `Tabs` has some `widget::canvas::Style`, assign the left padding. + /// If the `Tabs` has some `crate::canvas::Style`, assign the left padding. pub fn pad_right(self, pad: Scalar) -> Self { self.map_canvas_style(|mut style| { style.pad_right = Some(pad); style }) } - /// If the `Tabs` has some `widget::canvas::Style`, assign the left padding. + /// If the `Tabs` has some `crate::canvas::Style`, assign the left padding. pub fn pad_bottom(self, pad: Scalar) -> Self { self.map_canvas_style(|mut style| { style.pad_bottom = Some(pad); style }) } - /// If the `Tabs` has some `widget::canvas::Style`, assign the left padding. + /// If the `Tabs` has some `crate::canvas::Style`, assign the left padding. pub fn pad_top(self, pad: Scalar) -> Self { self.map_canvas_style(|mut style| { style.pad_top = Some(pad); style }) } @@ -272,7 +277,7 @@ impl<'a> Widget for Tabs<'a> { let mut tab_rects = TabRects::new(tabs, layout, rel_tab_bar_rect); let mut i = 0; while let Some((tab_rect, _, label)) = tab_rects.next_with_id_and_label() { - use {Colorable, Borderable, Labelable, Positionable, Sizeable}; + use conrod_core::{Colorable, Borderable, Labelable, Positionable, Sizeable}; let tab = state.tabs[i]; let (xy, dim) = tab_rect.xy_dim(); @@ -303,10 +308,10 @@ impl<'a> Widget for Tabs<'a> { // If we do have some selected tab, we'll draw a Canvas for it. if let Some(selected_idx) = maybe_selected_tab_idx { - use position::{Positionable, Sizeable}; + use conrod_core::position::{Positionable, Sizeable}; let &(child_id, _) = &tabs[selected_idx]; - widget::Canvas::new() + crate::Canvas::new() .with_style(canvas_style) .kid_area_wh_of(id) .middle_of(id) @@ -376,7 +381,7 @@ fn tab_dim(num_tabs: usize, tab_bar_dim: Dimensions, layout: Layout) -> Dimensio } -impl<'a> ::color::Colorable for Tabs<'a> { +impl<'a> conrod_core::color::Colorable for Tabs<'a> { fn color(self, color: Color) -> Self { self.map_canvas_style(|mut style| { style.color = Some(color); @@ -385,7 +390,7 @@ impl<'a> ::color::Colorable for Tabs<'a> { } } -impl<'a> ::border::Borderable for Tabs<'a> { +impl<'a> conrod_core::border::Borderable for Tabs<'a> { fn border(self, width: f64) -> Self { self.map_canvas_style(|mut style| { style.border = Some(width); diff --git a/conrod_core/src/widget/text_box.rs b/conrod_widgets/src/text_box.rs similarity index 93% rename from conrod_core/src/widget/text_box.rs rename to conrod_widgets/src/text_box.rs index e6b4e063f..76b03a49d 100644 --- a/conrod_core/src/widget/text_box.rs +++ b/conrod_widgets/src/text_box.rs @@ -1,11 +1,25 @@ //! A widget for displaying and mutating a one-line field of text. -use {Color, Colorable, FontSize, Borderable, Positionable, Sizeable, Widget}; -use event; -use input; -use position::{Range, Rect, Scalar}; -use text; -use widget; +use conrod_core::{ + Color, + Colorable, + FontSize, + Borderable, + Positionable, + Sizeable, + Widget, + event, + input, + position::{Range, Rect, Scalar}, + text, + widget, + // Macros + builder_method, + builder_methods, + widget_ids, + WidgetCommon_, + WidgetStyle_, +}; /// A widget for displaying and mutating a small, one-line field of text, given by the user in the /// form of a `String`. @@ -161,8 +175,8 @@ impl<'a> Widget for TextBox<'a> { let text_color = style.text_color(ui.theme()); let font_id = style.font_id(&ui.theme).or(ui.fonts.ids().next()); - if let Some(new_string) = widget::TextEdit::new(text) - .and_then(font_id, widget::TextEdit::font_id) + if let Some(new_string) = crate::TextEdit::new(text) + .and_then(font_id, crate::TextEdit::font_id) .wh(text_rect.dim()) .xy(text_rect.xy()) .font_size(font_size) diff --git a/conrod_core/src/widget/text_edit.rs b/conrod_widgets/src/text_edit.rs similarity index 98% rename from conrod_core/src/widget/text_edit.rs rename to conrod_widgets/src/text_edit.rs index 609031857..1a53da87b 100644 --- a/conrod_core/src/widget/text_edit.rs +++ b/conrod_widgets/src/text_edit.rs @@ -1,15 +1,30 @@ //! A widget for displaying and mutating multi-line text, given as a `String`. -use {Color, Colorable, FontSize, Positionable, Sizeable, Widget, Ui}; -use event; -use input; -use position::{Align, Dimension, Point, Range, Rect, Scalar}; -use std; -use text; -use utils; -use widget; -use cursor; -use widget::primitive::text::Wrap; +use conrod_core::{ + position::{Align, Dimension, Point, Range, Rect, Scalar}, + input, + event, + Color, + Colorable, + FontSize, + Positionable, + Sizeable, + Widget, + Ui, + text, + utils, + widget::{ + self, + primitive::text::Wrap + }, + cursor, + // Macros + builder_method, + builder_methods, + widget_ids, + WidgetCommon_, + WidgetStyle_, +}; /// A widget for displaying and mutating multi-line text, given as a `String`. @@ -822,7 +837,7 @@ impl<'a> Widget for TextEdit<'a> { if cursor_has_changed { let cursor_rect = ui.rect_of(state.ids.cursor).unwrap(); if prev_cursor_rect != Some(cursor_rect) { - use graph::Walker; + use conrod_core::graph::Walker; let mut scrollable_parents = ui.widget_graph().scrollable_y_parent_recursion(id); if let Some(parent_id) = scrollable_parents.next_node(ui.widget_graph()) { if let Some(parent_rect) = ui.rect_of(parent_id) { diff --git a/conrod_core/src/widget/title_bar.rs b/conrod_widgets/src/title_bar.rs similarity index 95% rename from conrod_core/src/widget/title_bar.rs rename to conrod_widgets/src/title_bar.rs index 392040984..ab29f67c5 100644 --- a/conrod_core/src/widget/title_bar.rs +++ b/conrod_widgets/src/title_bar.rs @@ -1,9 +1,24 @@ //! A simple title bar widget that automatically sizes itself to the top of some other widget. -use {Color, Colorable, FontSize, Borderable, Labelable, Positionable, Sizeable, Ui}; -use position::{self, Align, Dimension, Scalar}; -use text; -use widget::{self, Widget}; +use conrod_core::{ + Color, + Colorable, + FontSize, + Borderable, + Labelable, + Positionable, + Sizeable, + Ui, + position::{self, Align, Dimension, Scalar}, + text, + widget::{self, Widget}, + // Macros + builder_method, + builder_methods, + widget_ids, + WidgetCommon_, + WidgetStyle_, +}; /// A simple title bar widget that automatically sizes itself to the top of some other widget. diff --git a/conrod_core/src/widget/toggle.rs b/conrod_widgets/src/toggle.rs similarity index 95% rename from conrod_core/src/widget/toggle.rs rename to conrod_widgets/src/toggle.rs index c8df5f738..c06d51ce1 100644 --- a/conrod_core/src/widget/toggle.rs +++ b/conrod_widgets/src/toggle.rs @@ -1,9 +1,24 @@ //! A button that allows for toggling boolean state. -use {Color, Colorable, FontSize, Borderable, Labelable, Positionable, Scalar, Widget}; -use position::{self, Align}; -use text; -use widget; +use conrod_core::{ + Color, + Colorable, + FontSize, + Borderable, + Labelable, + Positionable, + Scalar, + Widget, + position::{self, Align}, + text, + widget, + // Macros + builder_method, + builder_methods, + widget_ids, + WidgetCommon_, + WidgetStyle_, +}; /// A pressable widget for toggling the state of a bool. diff --git a/conrod_core/src/widget/xy_pad.rs b/conrod_widgets/src/xy_pad.rs similarity index 96% rename from conrod_core/src/widget/xy_pad.rs rename to conrod_widgets/src/xy_pad.rs index decc6c538..d947afd59 100644 --- a/conrod_core/src/widget/xy_pad.rs +++ b/conrod_widgets/src/xy_pad.rs @@ -1,6 +1,8 @@ //! Used for displaying and controlling a 2D point on a cartesian plane within a given range. -use { +use num::Float; +use conrod_core::{ + text, Color, Colorable, Borderable, @@ -9,12 +11,17 @@ use { Positionable, Scalar, Widget, + UiCell, + position::{Direction, Edge}, + utils::{map_range, val_to_string}, + widget, + // Macros + builder_method, + builder_methods, + widget_ids, + WidgetCommon_, + WidgetStyle_, }; -use num::Float; -use text; -use utils::{map_range, val_to_string}; -use widget; - /// Used for displaying and controlling a 2D point on a cartesian plane within a given range. /// @@ -125,8 +132,6 @@ impl<'a, X, Y> Widget for XYPad<'a, X, Y> /// Update the XYPad's cached state. fn update(self, args: widget::UpdateArgs) -> Self::Event { - use position::{Direction, Edge}; - let widget::UpdateArgs { id, state, rect, style, ui, .. } = args; let XYPad { x, min_x, max_x, @@ -158,7 +163,7 @@ impl<'a, X, Y> Widget for XYPad<'a, X, Y> None }; - let interaction_color = |ui: &::ui::UiCell, color: Color| + let interaction_color = |ui: &UiCell, color: Color| ui.widget_input(id).mouse() .map(|mouse| if mouse.buttons.left().is_down() { color.clicked() @@ -250,7 +255,6 @@ impl<'a, X, Y> Widget for XYPad<'a, X, Y> event } - }