@@ -15,7 +15,6 @@ pub use self::index::Index;
15
15
#[ macro_use] mod style;
16
16
17
17
// Widget functionality modules.
18
- pub mod drag;
19
18
mod id;
20
19
mod index;
21
20
pub mod scroll;
@@ -240,8 +239,6 @@ pub struct CommonState {
240
239
pub rect : Rect ,
241
240
/// The rendering depth for the Widget (the default is 0.0).
242
241
pub depth : Depth ,
243
- /// The current state of the dragged widget, if it is draggable.
244
- pub drag_state : drag:: State ,
245
242
/// Floating state for the widget if it is floating.
246
243
pub maybe_floating : Option < Floating > ,
247
244
/// The area of the widget upon which kid widgets are placed.
@@ -260,8 +257,6 @@ pub struct Cached<W>
260
257
pub rect : Rect ,
261
258
/// Previous rendering depth of the Widget.
262
259
pub depth : Depth ,
263
- /// The current state of the dragged widget, if it is draggable.
264
- pub drag_state : drag:: State ,
265
260
/// The area in which child widgets are placed.
266
261
pub kid_area : KidArea ,
267
262
/// Whether or not the Widget is a "floating" Widget.
@@ -303,8 +298,6 @@ pub struct PreUpdateCache {
303
298
pub depth : Depth ,
304
299
/// The area upon which the **Widget**'s children widgets will be placed.
305
300
pub kid_area : KidArea ,
306
- /// The current state of the dragged **Widget**, if it is draggable.
307
- pub drag_state : drag:: State ,
308
301
/// Floating data for the **Widget** if there is some.
309
302
pub maybe_floating : Option < Floating > ,
310
303
/// 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>)
828
821
style,
829
822
rect,
830
823
depth,
831
- drag_state,
832
824
maybe_floating,
833
825
maybe_x_scroll_state,
834
826
maybe_y_scroll_state,
@@ -840,7 +832,6 @@ fn set_widget<'a, B, W>(widget: W, idx: Index, ui: &mut Ui<B>)
840
832
let prev_common = CommonState {
841
833
rect : rect,
842
834
depth : depth,
843
- drag_state : drag_state,
844
835
maybe_floating : maybe_floating,
845
836
kid_area : kid_area,
846
837
} ;
@@ -868,111 +859,36 @@ fn set_widget<'a, B, W>(widget: W, idx: Index, ui: &mut Ui<B>)
868
859
// check the positioning to retrieve the Id from there.
869
860
let maybe_parent_idx = widget. common ( ) . maybe_parent_idx . get ( idx, ui, x_pos, y_pos) ;
870
861
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
+ }
895
881
} )
896
882
} )
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.
932
885
//
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) ) ;
959
888
960
889
// Construct the rectangle describing our Widget's area.
961
890
let rect = Rect :: from_xy_dim ( xy, dim) ;
962
891
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
-
976
892
// Check whether or not the widget is a "floating" (hovering / pop-up style) widget.
977
893
let maybe_floating = if widget. common ( ) . is_floating {
978
894
@@ -1056,7 +972,6 @@ fn set_widget<'a, B, W>(widget: W, idx: Index, ui: &mut Ui<B>)
1056
972
maybe_y_positioned_relatively_idx : maybe_y_positioned_relatively_idx,
1057
973
rect : rect,
1058
974
depth : depth,
1059
- drag_state : drag_state,
1060
975
kid_area : kid_area,
1061
976
maybe_floating : maybe_floating,
1062
977
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>)
1070
985
let prev_common = maybe_prev_common. unwrap_or_else ( || CommonState {
1071
986
rect : rect,
1072
987
depth : depth,
1073
- drag_state : drag_state,
1074
988
maybe_floating : maybe_floating,
1075
989
kid_area : kid_area,
1076
990
} ) ;
0 commit comments