Skip to content

[Breaking Change] Refactor Event system and update Widgets accordingly. Add new multi-line TextEdit widget. Remove multiple crate deps, and more. #703

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

Merged
merged 100 commits into from
Jun 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
6c9dd5a
Refactor GlobalInput - take drag_threshold as a push_event argument t…
mitchmindtree Mar 1, 2016
7985889
Have relative_to builder methods take self by value instead of by ref…
mitchmindtree Mar 1, 2016
1ca2768
Fix some comment formatting. Chage mouse_position field name to mouse…
mitchmindtree Mar 2, 2016
cb2c3e3
Finish updating widget_under_mouse logic in button press event and re…
mitchmindtree Mar 2, 2016
c27dc5e
Refactor mouse specific state in InputState into its own module. Vari…
mitchmindtree Mar 2, 2016
758519e
Change field and method name current_state to current
mitchmindtree Mar 3, 2016
08a5d97
Change global_input start_state field name to start
mitchmindtree Mar 3, 2016
014a141
Reformat iterator code so that they follow conventions of rest of crate
mitchmindtree Mar 3, 2016
97829be
Change all_events to events
mitchmindtree Mar 4, 2016
2906a90
Inline event interpretation and state updating logic from
mitchmindtree Mar 4, 2016
a56c9db
Add a conversion trait backend::ToEvent to allow users to pass custom…
mitchmindtree Apr 7, 2016
a41529d
Update to new event backend (Ui::handle_event now takes events by val…
mitchmindtree Apr 8, 2016
b0c9c56
Remove debug printlns
mitchmindtree Apr 8, 2016
be31840
Remove now unnecessary tests. Refactor tests to have helper types, im…
mitchmindtree Apr 8, 2016
2a61bb9
Improve module level documentation. Re-export types from pistoncore-i…
mitchmindtree Apr 9, 2016
2053061
Change module structure to improve name-spacing.
mitchmindtree Apr 9, 2016
841049b
Track the widget that was clicked in MouseClick events. Track the wid…
mitchmindtree Apr 9, 2016
ff43049
Rename event::MouseClick to event::Click and event::MouseDrag to even…
mitchmindtree Apr 9, 2016
094567b
- Refactored `UiEvent` into `Event { Raw, Ui } ` and `event::Ui`.
mitchmindtree Apr 12, 2016
b68eac2
Remove graph::algo::{pick_widget, pick_scrollable_widget} functions i…
mitchmindtree Apr 13, 2016
bc6b01a
WIP Begin update of drag logic in widget::set_widget
mitchmindtree Apr 16, 2016
0f664cb
Remove the now unnecessary drag module, along with the drag::State ty…
mitchmindtree Apr 16, 2016
33b75a1
Make widget Drag and Click event coordinates relative to the widget.
mitchmindtree Apr 16, 2016
21a7be2
Move piston crates below other extern crates
mitchmindtree Apr 16, 2016
f2e6279
Make default drag threshold 0.0
mitchmindtree Apr 16, 2016
4ba785e
Update EnvelopeEditor to use new event system rather than custom inte…
mitchmindtree Apr 16, 2016
766242b
Ignore enabled flag in envelope_editor - will add a field to widget::…
mitchmindtree Apr 16, 2016
bfc9a16
Remove time crate in favour of using std::time::Instant
mitchmindtree Apr 16, 2016
9ed582b
Remove dependency on vecmath crate in favour of moving the two functi…
mitchmindtree Apr 16, 2016
09a3030
Remove unnecessary rand crate.
mitchmindtree Apr 16, 2016
fabfd0d
Add support for DoubleClick events
mitchmindtree Apr 16, 2016
2075717
Fix cargo.toml description and keywords
mitchmindtree Apr 16, 2016
0e58192
Update Toggle to latest event system
mitchmindtree Apr 16, 2016
34f2906
Add Rect::relative_to methods for producing a Rect with the same dime…
mitchmindtree Apr 17, 2016
b5ee35c
Use local binding to track pressed_point to avoid calling state.updat…
mitchmindtree Apr 17, 2016
6dd9dde
Update NumberDialer widget to the addition of the event system.
mitchmindtree Apr 17, 2016
06f8301
Update Slider widget to latest event input system changes
mitchmindtree Apr 17, 2016
2cc94fe
Remove unnecessary interaction logic from TitleBar widget, now that u…
mitchmindtree Apr 17, 2016
765fb76
Update XYPad widget to take advantage of latest event system updates
mitchmindtree Apr 17, 2016
114d125
Fix XYPad logic so that dragging outside of the Rect still drags the …
mitchmindtree Apr 17, 2016
6e08063
Improve Ui::handle_event docs slightly
mitchmindtree Apr 17, 2016
1a02a26
Fix issue with new dragging where dragged widget would keep snapping …
mitchmindtree Apr 17, 2016
1a51e71
Expose and handle controller related events from backend
mitchmindtree Apr 18, 2016
f854987
Flatten the Widget event enum by removing the Raw variant in favour o…
mitchmindtree Apr 18, 2016
1df9919
Move text layout logic and types from glyph_cache module into a uniqu…
mitchmindtree Apr 21, 2016
348e215
Move text layout logic from glyph_cache module into new text module. …
mitchmindtree May 4, 2016
d9ef6ea
Remove unnecessary is_over_rect function that duplicates Rect::is_ove…
mitchmindtree May 6, 2016
5888d1f
Add missing match branch
mitchmindtree May 6, 2016
1895a44
Have fn lines take a Range<usize> iterator. Add Break::End variant. A…
mitchmindtree May 6, 2016
b544ce0
Remove unnecessary tracking of capturing in widget::Events::next
mitchmindtree May 6, 2016
24149e1
Simplify lines iterator in graphics backend for text drawing
mitchmindtree May 6, 2016
08bbfe1
Remove unnecessary newline
mitchmindtree May 6, 2016
192857e
Remove unnecessary Button import
mitchmindtree May 6, 2016
c8f3c47
Remove Range and Rect imports
mitchmindtree May 6, 2016
a66b37e
WIP updating TextBox to new event system.
mitchmindtree May 6, 2016
efcc21c
Add align_to methods for aligning Range and Rects by the Align enum
mitchmindtree May 10, 2016
3e7ff6a
Add alignment, line spacing and line wrapping widget style arguments.
mitchmindtree May 10, 2016
b6d4688
Remove unnecessary newline
mitchmindtree May 20, 2016
77914be
Remove dead and unused code from primitive Text widget
mitchmindtree May 20, 2016
d98fc31
Distinguish between byte and char ranges in Break iterators and relat…
mitchmindtree May 20, 2016
e1562cb
Add Left and Right key cursor movement. Draw Rectangle widgets for se…
mitchmindtree May 20, 2016
5049a16
Rename TextBox to TextEdit. Remove unnecssary fields from TextEdit St…
mitchmindtree May 20, 2016
b57c736
Change TextBox to TextEdit in all_widgets example
mitchmindtree May 21, 2016
1a4cd14
Fix Break docs. Fix Infos::next algo
mitchmindtree May 21, 2016
568c595
Add builder methods for wrapping, aligning and restricting the height…
mitchmindtree May 21, 2016
ebe4df5
Import utils module
mitchmindtree May 21, 2016
dc00d2b
Add align_text_to method for aligning text via an Align variant. Move…
mitchmindtree May 22, 2016
1d8dcda
Set dimensions for the TextEdit\'s internal Text widget. Calculate th…
mitchmindtree May 22, 2016
45cc4e3
Remove old unused UserInput type, along with related fields in the Ui…
mitchmindtree May 22, 2016
357d3b0
Update the custom_widget example to both the widget_style macro as we…
mitchmindtree May 22, 2016
bf7ff23
Change PickWidgets walker structs so that they do not borrow the dept…
mitchmindtree May 24, 2016
2e2f8e3
Remove scrollbar related stuff from the scroll module (will re-implem…
mitchmindtree May 24, 2016
fe4f858
Invert y axis of scroll events to match conrod y axis inversion
mitchmindtree May 24, 2016
e7f819c
Clarify documenation for Scroll event in events module
mitchmindtree May 24, 2016
ffca46d
Remove unnecessary import syntax from drop_down_list
mitchmindtree May 24, 2016
8ae8d7f
Remove binding to maybe_react field of TextEdit as it is currently un…
mitchmindtree May 24, 2016
d27b78a
Fix alignment of title text
mitchmindtree May 24, 2016
6362092
Update scroll offset to occur when the event is recived rather than d…
mitchmindtree May 24, 2016
2e1c30b
Remove redundant whitespace
mitchmindtree May 24, 2016
49c3ffc
Remove redundant whitespace in range module
mitchmindtree May 24, 2016
02a046a
Add methods for aligning TextEdit text along the y axis
mitchmindtree May 24, 2016
82f8c5f
Re-add the TextBox widget, using the TextEdit widget internally. Repl…
mitchmindtree May 24, 2016
2004ce7
Remove unnecessary path syntax
mitchmindtree May 24, 2016
ca3572f
Remove redundant whitespace and path specifiers
mitchmindtree May 28, 2016
83eaebf
Add method to Ui that allows for the user to manually offst the scrol…
mitchmindtree May 28, 2016
a4b4ec0
Add Scrollbar widget to allow for manual scrolling of scrollable widg…
mitchmindtree May 28, 2016
55872d3
Remove whitespace
mitchmindtree May 28, 2016
fe0e346
Added `auto_hide` method to `Scrollbar` for hiding the scrollbar when…
mitchmindtree Jun 1, 2016
845b91b
Remove old unused scrollbar.rs module
mitchmindtree Jun 1, 2016
90319c8
Remove `Visitable` type from the graph/depth_order.rs module. This is no
mitchmindtree Jun 1, 2016
582a384
Use G2dTexture instead of GfxGraphics associated Texture type in exam…
mitchmindtree Jun 1, 2016
d2db8d0
Tidy TextBox in all_widgets example. Currently getting an ICE when co…
mitchmindtree Jun 2, 2016
260c3ac
Make widget::State automatically deref to the unique widget state tha…
mitchmindtree Jun 2, 2016
d6790d7
Remove unused lifetime param from set_widget function in widget module.
mitchmindtree Jun 6, 2016
9446a1e
Add an example for the TextEdit widget.
mitchmindtree Jun 6, 2016
3f14177
Fix ICE by removing the type declaration from the closure scope. Use …
mitchmindtree Jun 7, 2016
fbcd42b
Tweak text_edit example so that it looks a little nicer.
mitchmindtree Jun 7, 2016
e4c28ba
Make the types within Widget::set a little clearer by breaking the on…
mitchmindtree Jun 7, 2016
1c0cabd
Update guide with latest widget additions.
mitchmindtree Jun 7, 2016
250228c
Bump crates.io minor version for breaking change.
mitchmindtree Jun 7, 2016
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
10 changes: 4 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "conrod"
version = "0.35.0"
version = "0.36.0"
authors = [
"Mitchell Nordine <[email protected]>",
"Sven Nilsen <[email protected]>"
]
keywords = ["ui", "widgets", "immediate-mode", "piston"]
description = "An easy-to-use, immediate-mode, 2D GUI library"
keywords = ["ui", "widgets", "gui", "piston", "graphics"]
description = "An easy-to-use, extensible 2D GUI library"
license = "MIT OR Apache-2.0"
readme = "README.md"
repository = "https://github.com/pistondevelopers/conrod.git"
Expand All @@ -22,10 +22,8 @@ daggy = "0.4.0"
pistoncore-input = "0.12.0"
piston2d-graphics = "0.16.0"
num = "0.1.30"
rand = "0.3.13"
time = "0.1.34"
vecmath = "0.2.0"

[dev-dependencies]
find_folder = "0.3.0"
rand = "0.3.13"
piston_window = "0.45.0"
37 changes: 22 additions & 15 deletions examples/all_widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#[macro_use] extern crate conrod;
extern crate find_folder;
extern crate piston_window;
extern crate rand; // for making a random color.

use conrod::{
color,
Expand All @@ -25,6 +26,7 @@ use conrod::{
NumberDialer,
Point,
Positionable,
Scrollbar,
Slider,
Sizeable,
Text,
Expand All @@ -35,12 +37,12 @@ use conrod::{
WidgetMatrix,
XYPad,
};
use piston_window::{EventLoop, Glyphs, OpenGL, PistonWindow, UpdateEvent, WindowSettings};
use piston_window::{EventLoop, PistonWindow, UpdateEvent, WindowSettings};
use std::sync::mpsc;


/// Conrod is backend agnostic. Here, we define the `piston_window` backend to use for our `Ui`.
type Backend = (<piston_window::G2d<'static> as conrod::Graphics>::Texture, Glyphs);
type Backend = (piston_window::G2dTexture<'static>, piston_window::Glyphs);
type Ui = conrod::Ui<Backend>;
type UiCell<'a> = conrod::UiCell<'a, Backend>;

Expand Down Expand Up @@ -131,7 +133,7 @@ impl DemoApp {
fn main() {

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

// Construct the window.
let mut window: PistonWindow =
Expand All @@ -143,9 +145,9 @@ fn main() {
let assets = find_folder::Search::KidsThenParents(3, 5)
.for_folder("assets").unwrap();
let font_path = assets.join("fonts/NotoSans/NotoSans-Regular.ttf");
let glyph_cache = piston_window::Glyphs::new(&font_path, window.factory.clone()).unwrap();
let theme = Theme::default();
let glyph_cache = Glyphs::new(&font_path, window.factory.clone());
Ui::new(glyph_cache.unwrap(), theme)
Ui::new(glyph_cache, theme)
};

// Our dmonstration app that we'll control with our GUI.
Expand All @@ -155,7 +157,7 @@ fn main() {

// Poll events from the window.
while let Some(event) = window.next() {
ui.handle_event(&event);
ui.handle_event(event.clone());

// We'll set all our widgets in a single function called `set_widgets`.
// At the moment conrod requires that we set our widgets in the Render loop,
Expand Down Expand Up @@ -190,6 +192,8 @@ fn set_widgets(ui: &mut UiCell, app: &mut DemoApp) {
.color(app.bg_color)
.scroll_kids()
.set(CANVAS, ui);
Scrollbar::x_axis(CANVAS).auto_hide(true).set(CANVAS_Y_SCROLLBAR, ui);
Scrollbar::y_axis(CANVAS).auto_hide(true).set(CANVAS_X_SCROLLBAR, ui);

// Text example.
Text::new("Widget Demonstration")
Expand All @@ -208,7 +212,7 @@ fn set_widgets(ui: &mut UiCell, app: &mut DemoApp) {
.rgb(0.4, 0.75, 0.6)
.frame(app.frame_width)
.label("PRESS")
.react(|| app.bg_color = color::random())
.react(|| app.bg_color = color::rgb(rand::random(), rand::random(), rand::random()))
.set(BUTTON, ui)

}
Expand All @@ -226,7 +230,7 @@ fn set_widgets(ui: &mut UiCell, app: &mut DemoApp) {
};

// Slider widget example slider(value, min, max).
Slider::new(pad as f32, 30.0, 700.0)
Slider::new(pad as f32, 0.0, 670.0)
.w_h(200.0, 50.0)
.mid_left_of(CANVAS)
.down_from(TITLE, 45.0)
Expand Down Expand Up @@ -407,25 +411,26 @@ fn set_widgets(ui: &mut UiCell, app: &mut DemoApp) {
.set(CIRCLE, ui);

// Draw two TextBox and EnvelopeEditor pairs to the right of the DropDownList flowing downward.
for i in 0..2 {
for i in 0..2usize {

let &mut (ref mut env, ref mut text) = &mut app.envelopes[i];

// Draw a TextBox. text_box(&mut String, FontSize)
// A text box in which we can mutate a single line of text, and trigger reactions via the
// `Enter`/`Return` key.
TextBox::new(text)
.and_if(i == 0, |text| text.right_from(COLOR_SELECT, 30.0))
.font_size(20)
.w_h(320.0, 40.0)
.frame(app.frame_width)
.frame_color(app.bg_color.invert().plain_contrast())
.color(app.bg_color.invert())
.react(|_string: &mut String|{})
.set(ENVELOPE_EDITOR + (i * 2), ui);
.react(|string: &mut String| println!("TextBox {}: {:?}", i, string))
.set(ENVELOPE_EDITOR + i * 2, ui);

let env_y_max = match i { 0 => 20_000.0, _ => 1.0 };
let env_skew_y = match i { 0 => 3.0, _ => 1.0 };
let env_y_max = if i == 0 { 20_000.0 } else { 1.0 };
let env_skew_y = if i == 0 { 3.0 } else { 1.0 };

// Draw an EnvelopeEditor. (Vec<Point>, x_min, x_max, y_min, y_max).
// Draw an EnvelopeEditor. (&mut Vec<Point>, x_min, x_max, y_min, y_max).
EnvelopeEditor::new(env, 0.0, 1.0, 0.0, env_y_max)
.down(10.0)
.w_h(320.0, 150.0)
Expand Down Expand Up @@ -453,6 +458,8 @@ fn set_widgets(ui: &mut UiCell, app: &mut DemoApp) {
// the use of `WidgetMatrix` as above).
widget_ids! {
CANVAS,
CANVAS_X_SCROLLBAR,
CANVAS_Y_SCROLLBAR,
TITLE,
BUTTON,
TITLE_PAD_SLIDER,
Expand Down
14 changes: 9 additions & 5 deletions examples/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ extern crate piston_window;


use conrod::{Canvas, Theme, Widget, color};
use piston_window::{EventLoop, Glyphs, OpenGL, PistonWindow, UpdateEvent, WindowSettings};
use piston_window::{EventLoop, OpenGL, PistonWindow, UpdateEvent, WindowSettings};


/// Conrod is backend agnostic. Here, we define the `piston_window` backend to use for our `Ui`.
type Backend = (<piston_window::G2d<'static> as conrod::Graphics>::Texture, Glyphs);
type Backend = (piston_window::G2dTexture<'static>, piston_window::Glyphs);
type Ui = conrod::Ui<Backend>;
type UiCell<'a> = conrod::UiCell<'a, Backend>;

Expand All @@ -34,15 +34,15 @@ fn main() {
.for_folder("assets").unwrap();
let font_path = assets.join("fonts/NotoSans/NotoSans-Regular.ttf");
let theme = Theme::default();
let glyph_cache = Glyphs::new(&font_path, window.factory.clone());
Ui::new(glyph_cache.unwrap(), theme)
let glyph_cache = piston_window::Glyphs::new(&font_path, window.factory.clone()).unwrap();
Ui::new(glyph_cache, theme)
};

window.set_ups(60);

// Poll events from the window.
while let Some(event) = window.next() {
ui.handle_event(&event);
ui.handle_event(event.clone());
event.update(|_| ui.set_widgets(set_widgets));
window.draw_2d(&event, |c, g| ui.draw_if_changed(c, g));
}
Expand All @@ -65,6 +65,9 @@ fn set_widgets(ref mut ui: UiCell) {
(FOOTER, Canvas::new().color(color::BLUE).scroll_kids_vertically()),
]).set(MASTER, ui);

// A scrollbar for the `FOOTER` canvas.
conrod::Scrollbar::y_axis(FOOTER).auto_hide(true).set(FOOTER_SCROLLBAR, ui);

// Now we'll make a couple floating `Canvas`ses.
let floating = Canvas::new().floating(true).w_h(110.0, 150.0).label_color(color::WHITE);
floating.middle_of(LEFT_COLUMN).title_bar("Blue").color(color::BLUE).set(FLOATING_A, ui);
Expand Down Expand Up @@ -131,6 +134,7 @@ widget_ids! {
MIDDLE_COLUMN,
RIGHT_COLUMN,
FOOTER,
FOOTER_SCROLLBAR,
FLOATING_A,
FLOATING_B,
TABS,
Expand Down
10 changes: 5 additions & 5 deletions examples/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ extern crate piston_window;

fn main() {
use conrod::{Labelable, Positionable, Sizeable, Theme, Widget};
use piston_window::{EventLoop, Glyphs, OpenGL, PistonWindow, UpdateEvent, WindowSettings};
use piston_window::{EventLoop, OpenGL, PistonWindow, UpdateEvent, WindowSettings};

// Conrod is backend agnostic. Here, we define the `piston_window` backend to use for our `Ui`.
type Backend = (<piston_window::G2d<'static> as conrod::Graphics>::Texture, Glyphs);
type Backend = (piston_window::G2dTexture<'static>, piston_window::Glyphs);
type Ui = conrod::Ui<Backend>;

// Change this to OpenGL::V2_1 if not working.
Expand All @@ -24,8 +24,8 @@ fn main() {
.for_folder("assets").unwrap();
let font_path = assets.join("fonts/NotoSans/NotoSans-Regular.ttf");
let theme = Theme::default();
let glyph_cache = Glyphs::new(&font_path, window.factory.clone());
Ui::new(glyph_cache.unwrap(), theme)
let glyph_cache = piston_window::Glyphs::new(&font_path, window.factory.clone()).unwrap();
Ui::new(glyph_cache, theme)
};

let mut count = 0;
Expand All @@ -34,7 +34,7 @@ fn main() {

// Poll events from the window.
while let Some(event) = window.next() {
ui.handle_event(&event);
ui.handle_event(event.clone());
event.update(|_| ui.set_widgets(|ref mut ui| {

// Generate the ID for the Button COUNTER.
Expand Down
Loading