11use alloc:: sync:: Arc ;
2- use core:: cell:: Cell ;
2+ use core:: cell:: { Cell , RefCell } ;
33use core:: mem;
44use core:: ops:: RangeInclusive ;
55use regex:: Regex ;
@@ -711,10 +711,20 @@ pub fn edit_entry_ui<T: EvalexprNumericTypes>(
711711 DragPoint :: BothCoordConstants ( x, y) => {
712712 format ! ( "{}({}, {})" , point. drag_type. symbol( ) , x, y, )
713713 } ,
714+ DragPoint :: SameConstantBothCoords ( x) => {
715+ format ! ( "{}({})" , point. drag_type. symbol( ) , x)
716+ } ,
714717 } ,
715718 None => point. drag_type . symbol ( ) . to_string ( ) ,
716719 } ;
717720 ui. menu_button ( drag_menu_text, |ui| {
721+ drag_type_changed |= ui
722+ . selectable_value (
723+ & mut point. drag_type ,
724+ PointDragType :: NoDrag ,
725+ PointDragType :: NoDrag . name ( ) ,
726+ )
727+ . changed ( ) ;
718728 if point. both_drag_dirs_available {
719729 drag_type_changed |= ui
720730 . selectable_value (
@@ -766,6 +776,12 @@ pub fn edit_entry_ui<T: EvalexprNumericTypes>(
766776 let range = ty. range ( ) ;
767777 let start = * range. start ( ) ;
768778 let end = * range. end ( ) ;
779+
780+ if v > end {
781+ v -= end - start;
782+ } else if v < start {
783+ v += end - start;
784+ }
769785 v = v. clamp ( start, end) ;
770786
771787 ui. vertical ( |ui| {
@@ -945,14 +961,24 @@ pub fn recompile_entry<T: EvalexprNumericTypes>(
945961 if x_state. is_literal {
946962 point. drag_point = Some ( DragPoint :: XLiteral ) ;
947963 } else if let Some ( x_const) = x_state. constants . first ( ) {
948- point. drag_point = Some ( DragPoint :: XConstant ( x_const. to_string ( ) ) ) ;
964+ if y_state. constants . iter ( ) . any ( |c| c == x_const) {
965+ point. drag_point =
966+ Some ( DragPoint :: SameConstantBothCoords ( x_const. to_string ( ) ) ) ;
967+ } else {
968+ point. drag_point = Some ( DragPoint :: XConstant ( x_const. to_string ( ) ) ) ;
969+ }
949970 }
950971 } ,
951972 PointDragType :: Y => {
952973 if y_state. is_literal {
953974 point. drag_point = Some ( DragPoint :: YLiteral ) ;
954975 } else if let Some ( y_const) = y_state. constants . first ( ) {
955- point. drag_point = Some ( DragPoint :: YConstant ( y_const. to_string ( ) ) ) ;
976+ if x_state. constants . iter ( ) . any ( |c| c == y_const) {
977+ point. drag_point =
978+ Some ( DragPoint :: SameConstantBothCoords ( y_const. to_string ( ) ) ) ;
979+ } else {
980+ point. drag_point = Some ( DragPoint :: YConstant ( y_const. to_string ( ) ) ) ;
981+ }
956982 }
957983 } ,
958984 }
@@ -1081,7 +1107,7 @@ pub struct PlotParams {
10811107#[ allow( clippy:: too_many_arguments) ]
10821108pub fn create_entry_plot_elements < T : EvalexprNumericTypes > (
10831109 entry : & mut Entry < T > , id : Id , selected_id : Option < Id > , ctx : & evalexpr:: HashMapContext < T > ,
1084- plot_params : & PlotParams , draw_buffer : & mut DrawBuffer ,
1110+ plot_params : & PlotParams , draw_buffer : & RefCell < DrawBuffer > ,
10851111) -> Result < ( ) , String > {
10861112 let visible = entry. visible ;
10871113 if !visible && !matches ! ( entry. ty, EntryType :: Integral { .. } ) {
@@ -1092,6 +1118,7 @@ pub fn create_entry_plot_elements<T: EvalexprNumericTypes>(
10921118 match & mut entry. ty {
10931119 EntryType :: Constant { .. } => { } ,
10941120 EntryType :: Integral { func, lower, upper, calculated, resolution, .. } => {
1121+ let mut draw_buffer = draw_buffer. borrow_mut ( ) ;
10951122 let ( Some ( lower_node) , Some ( upper_node) , Some ( func_node) ) = ( & lower. node , & upper. node , & func. node )
10961123 else {
10971124 return Ok ( ( ) ) ;
@@ -1266,6 +1293,8 @@ pub fn create_entry_plot_elements<T: EvalexprNumericTypes>(
12661293 * calculated = Some ( result) ;
12671294 } ,
12681295 EntryType :: Label { x, y, size, underline, .. } => {
1296+ let mut draw_buffer = draw_buffer. borrow_mut ( ) ;
1297+
12691298 match eval_point ( ctx, x. node . as_ref ( ) , y. node . as_ref ( ) ) {
12701299 Ok ( Some ( ( x, y) ) ) => {
12711300 let size = if let Some ( size) = & size. node {
@@ -1294,6 +1323,7 @@ pub fn create_entry_plot_elements<T: EvalexprNumericTypes>(
12941323 }
12951324 } ,
12961325 EntryType :: Points ( ps) => {
1326+ let mut draw_buffer = draw_buffer. borrow_mut ( ) ;
12971327 // main_context
12981328 // .write()
12991329 // .unwrap()
@@ -1374,7 +1404,8 @@ pub fn create_entry_plot_elements<T: EvalexprNumericTypes>(
13741404 // .entry(text.clone())
13751405 // .or_insert_with(|| AHashMap::with_capacity(ui_state.conf.resolution))
13761406 // });
1377- let mut add_line = |line : Vec < PlotPoint > | {
1407+ let add_line = |line : Vec < PlotPoint > | {
1408+ let mut draw_buffer = draw_buffer. borrow_mut ( ) ;
13781409 draw_buffer. lines . push ( FunctionLine {
13791410 width,
13801411 id,
@@ -1671,6 +1702,7 @@ pub enum DragPoint {
16711702 XLiteralYConstant ( String ) ,
16721703 YLiteralXConstant ( String ) ,
16731704 BothCoordConstants ( String , String ) ,
1705+ SameConstantBothCoords ( String ) ,
16741706}
16751707
16761708pub struct NodeAnalysis < ' a > {
0 commit comments