Skip to content

Commit 9c75360

Browse files
committed
Remove the now unnecessary drag module, along with the drag::State type. Logic has been replaced with use of new event system.
1 parent 9234cdd commit 9c75360

File tree

5 files changed

+29
-173
lines changed

5 files changed

+29
-173
lines changed

src/graph/mod.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ pub struct Container {
8181
pub rect: Rect,
8282
/// The depth at which the widget will be rendered comparatively to its siblings.
8383
pub depth: Depth,
84-
/// The drag state of the Widget.
85-
pub drag_state: widget::drag::State,
8684
/// The area in which child widgets are placed.
8785
pub kid_area: widget::KidArea,
8886
/// Whether or not the widget is a "Floating" widget.
@@ -205,7 +203,6 @@ impl Container {
205203
style: style,
206204
rect: self.rect,
207205
depth: self.depth,
208-
drag_state: self.drag_state,
209206
kid_area: self.kid_area,
210207
maybe_floating: self.maybe_floating,
211208
maybe_x_scroll_state: self.maybe_x_scroll_state,
@@ -701,7 +698,7 @@ impl Graph {
701698
{
702699
let widget::PreUpdateCache {
703700
kind, idx, maybe_parent_idx, maybe_x_positioned_relatively_idx,
704-
maybe_y_positioned_relatively_idx, rect, depth, kid_area, drag_state, maybe_floating,
701+
maybe_y_positioned_relatively_idx, rect, depth, kid_area, maybe_floating,
705702
maybe_x_scroll_state, maybe_y_scroll_state, maybe_graphics_for,
706703
} = widget;
707704

@@ -711,7 +708,6 @@ impl Graph {
711708
kind: kind,
712709
rect: rect,
713710
depth: depth,
714-
drag_state: drag_state,
715711
kid_area: kid_area,
716712
maybe_floating: maybe_floating,
717713
maybe_x_scroll_state: maybe_x_scroll_state,
@@ -777,7 +773,6 @@ impl Graph {
777773
container.kind = kind;
778774
container.rect = rect;
779775
container.depth = depth;
780-
container.drag_state = drag_state;
781776
container.kid_area = kid_area;
782777
container.maybe_floating = maybe_floating;
783778
container.maybe_x_scroll_state = maybe_x_scroll_state;

src/input/widget.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<'a> Widget<'a> {
125125
/// events. If the widget captures the keyboard it *will* receive all keyboard events.
126126
///
127127
/// All mouse events will have their coordinates relative to the middle of the widget's `Rect`.
128-
pub fn events(&self) -> Events {
128+
pub fn events(&self) -> Events<'a> {
129129
Events {
130130
global_events: self.global.events(),
131131
capturing_keyboard: self.global.start.widget_capturing_keyboard,
@@ -139,23 +139,23 @@ impl<'a> Widget<'a> {
139139
///
140140
/// A _click_ is determined to have occured if a pointing device button was both pressed and
141141
/// released over the widget.
142-
pub fn clicks(&self) -> Clicks {
142+
pub fn clicks(&self) -> Clicks<'a> {
143143
Clicks { events: self.events() }
144144
}
145145

146146
/// Produces an iterator that yields all `event::Drag` events yielded by the `Events` iterator.
147147
///
148148
/// Only events that occurred while the widget was capturing the device that did the dragging
149149
/// will be yielded.
150-
pub fn drags(&self) -> Drags {
150+
pub fn drags(&self) -> Drags<'a> {
151151
Drags { events: self.events() }
152152
}
153153

154154
/// Produces an iterator that yields all `Input::Text` events that have occurred as `&str`s
155155
/// since the last time `Ui::set_widgets` was called.
156156
///
157157
/// Only events that occurred while the widget was capturing the keyboard will be yielded.
158-
pub fn text(&self) -> Texts {
158+
pub fn text(&self) -> Texts<'a> {
159159
Texts { events: self.events() }
160160
}
161161

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub use position::{Align, Axis, Corner, Depth, Direction, Dimension, Dimensions,
7878
pub use theme::Theme;
7979
pub use ui::{Ui, UiCell, UserInput};
8080
pub use widget::{default_x_dimension, default_y_dimension};
81-
pub use widget::{drag, scroll};
81+
pub use widget::scroll;
8282
pub use widget::{CommonBuilder, CommonState, CommonStyle, Floating, IndexSlot, MaybeParent,
8383
UpdateArgs, Widget};
8484
pub use widget::{KidArea, KidAreaArgs};

src/widget/drag.rs

Lines changed: 0 additions & 53 deletions
This file was deleted.

src/widget/mod.rs

Lines changed: 23 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ pub use self::index::Index;
1515
#[macro_use] mod style;
1616

1717
// Widget functionality modules.
18-
pub mod drag;
1918
mod id;
2019
mod index;
2120
pub mod scroll;
@@ -240,8 +239,6 @@ pub struct CommonState {
240239
pub rect: Rect,
241240
/// The rendering depth for the Widget (the default is 0.0).
242241
pub depth: Depth,
243-
/// The current state of the dragged widget, if it is draggable.
244-
pub drag_state: drag::State,
245242
/// Floating state for the widget if it is floating.
246243
pub maybe_floating: Option<Floating>,
247244
/// The area of the widget upon which kid widgets are placed.
@@ -260,8 +257,6 @@ pub struct Cached<W>
260257
pub rect: Rect,
261258
/// Previous rendering depth of the Widget.
262259
pub depth: Depth,
263-
/// The current state of the dragged widget, if it is draggable.
264-
pub drag_state: drag::State,
265260
/// The area in which child widgets are placed.
266261
pub kid_area: KidArea,
267262
/// Whether or not the Widget is a "floating" Widget.
@@ -303,8 +298,6 @@ pub struct PreUpdateCache {
303298
pub depth: Depth,
304299
/// The area upon which the **Widget**'s children widgets will be placed.
305300
pub kid_area: KidArea,
306-
/// The current state of the dragged **Widget**, if it is draggable.
307-
pub drag_state: drag::State,
308301
/// Floating data for the **Widget** if there is some.
309302
pub maybe_floating: Option<Floating>,
310303
/// Scrolling data for the **Widget**'s *x* axis if there is some.
@@ -828,7 +821,6 @@ fn set_widget<'a, B, W>(widget: W, idx: Index, ui: &mut Ui<B>)
828821
style,
829822
rect,
830823
depth,
831-
drag_state,
832824
maybe_floating,
833825
maybe_x_scroll_state,
834826
maybe_y_scroll_state,
@@ -840,7 +832,6 @@ fn set_widget<'a, B, W>(widget: W, idx: Index, ui: &mut Ui<B>)
840832
let prev_common = CommonState {
841833
rect: rect,
842834
depth: depth,
843-
drag_state: drag_state,
844835
maybe_floating: maybe_floating,
845836
kid_area: kid_area,
846837
};
@@ -868,111 +859,36 @@ fn set_widget<'a, B, W>(widget: W, idx: Index, ui: &mut Ui<B>)
868859
// check the positioning to retrieve the Id from there.
869860
let maybe_parent_idx = widget.common().maybe_parent_idx.get(idx, ui, x_pos, y_pos);
870861

871-
let xy = {
872-
// A function for generating the xy coords from the given alignment and Position.
873-
let calc_xy = || ui.calc_xy(Some(idx), x_pos, y_pos, dim, place_on_kid_area);
874-
875-
// Check to see if the widget is currently being dragged and return the new xy / drag.
876-
maybe_prev_common
877-
.as_ref()
878-
.and_then(|prev| {
879-
let maybe_drag_area = widget.drag_area(dim, &new_style, &ui.theme);
880-
maybe_drag_area.and_then(|drag_area| {
881-
let mut left_mouse_drags = ui.widget_input(idx).drags().left();
882-
let maybe_first_drag = left_mouse_drags.next();
883-
maybe_first_drag.and_then(|first_drag| {
884-
if drag_area.is_over(first_drag.from) {
885-
let total_drag_xy = left_mouse_drags
886-
.fold(first_drag.delta_xy, |total, drag| {
887-
[total[0] + drag[0], total[1] + drag[1]]
888-
});
889-
let prev_xy = prev.rect.xy();
890-
Some([prev_xy[0] + total_drag_xy[0], prev_xy[1] + total_drag_xy[1]])
891-
} else {
892-
None
893-
}
894-
})
862+
// Calculate the `xy` location of the widget, considering drag.
863+
let xy = maybe_prev_common
864+
.as_ref()
865+
.and_then(|prev| {
866+
let maybe_drag_area = widget.drag_area(dim, &new_style, &ui.theme);
867+
maybe_drag_area.and_then(|drag_area| {
868+
let mut left_mouse_drags = ui.widget_input(idx).drags().left();
869+
let maybe_first_drag = left_mouse_drags.next();
870+
maybe_first_drag.and_then(|first_drag| {
871+
if drag_area.is_over(first_drag.from) {
872+
let total_drag_xy = left_mouse_drags
873+
.fold(first_drag.delta_xy, |total, drag| {
874+
[total[0] + drag.delta_xy[0], total[1] + drag.delta_xy[1]]
875+
});
876+
let prev_xy = prev.rect.xy();
877+
Some([prev_xy[0] + total_drag_xy[0], prev_xy[1] + total_drag_xy[1]])
878+
} else {
879+
None
880+
}
895881
})
896882
})
897-
// If there is no previous state to compare for dragging, return an initial state.
898-
.unwrap_or_else(calc_xy)
899-
900-
// // Check to see if the widget is currently being dragged and return the new xy / drag.
901-
// match maybe_prev_common {
902-
// // If there is no previous state to compare for dragging, return an initial state.
903-
// None => calc_xy(),
904-
// Some(ref prev) => {
905-
// let input = ui.widget_input(idx);
906-
// let maybe_drag_area = widget.drag_area(dim, &new_style, &ui.theme);
907-
// match maybe_drag_area {
908-
// None => calc_xy(),
909-
// Some(drag_area) => {
910-
// let mut left_mouse_drags = input.drags().left();
911-
// match left_mouse_drags.next() {
912-
// None => calc_xy(),
913-
// Some(first_drag) => {
914-
// if drag_area.is_over(first_drag.from) {
915-
// let total_drag_xy = left_mouse_drags
916-
// .fold(first_drag.delta_xy, |total, drag| {
917-
// [total[0] + drag[0], total[1] + drag[1]]
918-
// });
919-
// let prev_xy = prev.rect.xy();
920-
// [prev_xy[0] + total_drag_xy[0], prev_xy[1] + total_drag_xy[1]]
921-
// } else {
922-
// calc_xy()
923-
// }
924-
// },
925-
// }
926-
// },
927-
// }
928-
// },
929-
// }
930-
931-
// NOTE: Old drag logic that shouldn't be necessary now we have event::Drag.
883+
})
884+
// If there is no previous state to compare for dragging, return an initial state.
932885
//
933-
// let maybe_mouse = ui::get_mouse_state(ui, idx);
934-
// let maybe_drag_area = widget.drag_area(dim, &new_style, &ui.theme);
935-
// match maybe_drag_area {
936-
// // If the widget isn't draggable, generate its position the normal way.
937-
// // FIXME: This may cause issues in the case that a widget's draggable area
938-
// // is dynamic (i.e. sometimes its Some, other times its None).
939-
// // Specifically, if a widget is dragged somewhere and then it returns None,
940-
// // it will snap back to the position produced by calc_xy. We should keep
941-
// // track of whether or not a widget `has_been_dragged` to see if we should
942-
// // leave it at its previous xy or use calc_xy.
943-
// None => (calc_xy(), drag::State::Normal),
944-
// Some(drag_area) => match maybe_mouse {
945-
// // If there is some draggable area and mouse, drag the xy.
946-
// Some(mouse) => {
947-
// let drag_state = prev.drag_state;
948-
949-
// // Drag the xy of the widget and return the new xy.
950-
// drag::drag_widget(prev.rect.xy(), drag_area, drag_state, mouse)
951-
// },
952-
// // Otherwise just return the regular xy and drag state.
953-
// None => (prev.rect.xy(), drag::State::Normal),
954-
// },
955-
// }
956-
// },
957-
// }
958-
};
886+
// A function for generating the xy coords from the given alignment and Position.
887+
.unwrap_or_else(|| ui.calc_xy(Some(idx), x_pos, y_pos, dim, place_on_kid_area));
959888

960889
// Construct the rectangle describing our Widget's area.
961890
let rect = Rect::from_xy_dim(xy, dim);
962891

963-
// Check whether we have stopped / started dragging the widget and in turn whether or not
964-
// we need to capture the mouse.
965-
match (maybe_prev_common.as_ref().map(|prev| prev.drag_state), drag_state) {
966-
(Some(drag::State::Highlighted), drag::State::Clicked(_)) => {
967-
ui::mouse_captured_by(ui, idx);
968-
},
969-
(Some(drag::State::Clicked(_)), drag::State::Highlighted) |
970-
(Some(drag::State::Clicked(_)), drag::State::Normal) => {
971-
ui::mouse_uncaptured_by(ui, idx);
972-
},
973-
_ => (),
974-
}
975-
976892
// Check whether or not the widget is a "floating" (hovering / pop-up style) widget.
977893
let maybe_floating = if widget.common().is_floating {
978894

@@ -1056,7 +972,6 @@ fn set_widget<'a, B, W>(widget: W, idx: Index, ui: &mut Ui<B>)
1056972
maybe_y_positioned_relatively_idx: maybe_y_positioned_relatively_idx,
1057973
rect: rect,
1058974
depth: depth,
1059-
drag_state: drag_state,
1060975
kid_area: kid_area,
1061976
maybe_floating: maybe_floating,
1062977
maybe_y_scroll_state: maybe_y_scroll_state,
@@ -1070,7 +985,6 @@ fn set_widget<'a, B, W>(widget: W, idx: Index, ui: &mut Ui<B>)
1070985
let prev_common = maybe_prev_common.unwrap_or_else(|| CommonState {
1071986
rect: rect,
1072987
depth: depth,
1073-
drag_state: drag_state,
1074988
maybe_floating: maybe_floating,
1075989
kid_area: kid_area,
1076990
});

0 commit comments

Comments
 (0)