Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] widget split + 2018 edition #1241

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
members = [
"conrod_core",
"conrod_derive",
"conrod_widgets",
"backends/conrod_example_shared",
"backends/conrod_winit",
"backends/conrod_gfx",
Expand Down
1 change: 1 addition & 0 deletions backends/conrod_example_shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
59 changes: 30 additions & 29 deletions backends/conrod_example_shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Abendstolz fix me: a replace mistake

//!
//! 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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);


////////////////
Expand All @@ -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.\
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -158,69 +159,69 @@ 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)
.h(360.0)
.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);

let shapes_canvas_rect = ui.rect_of(ids.shapes_canvas).unwrap();
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);


/////////////////
///// Image /////
/////////////////


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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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);
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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);
}
5 changes: 4 additions & 1 deletion conrod_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion conrod_core/src/border.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion conrod_core/src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
4 changes: 2 additions & 2 deletions conrod_core/src/cursor.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
12 changes: 7 additions & 5 deletions conrod_core/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
8 changes: 5 additions & 3 deletions conrod_core/src/graph/algo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion conrod_core/src/graph/depth_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 9 additions & 5 deletions conrod_core/src/graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions conrod_core/src/input/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions conrod_core/src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)]
Expand Down
Loading