@@ -106,7 +106,6 @@ pub struct Expr<T: EvalexprFloat> {
106106 pub text : String ,
107107 pub display_rational : bool ,
108108 pub node : Option < FlatNode < T > > ,
109- pub inlined_node : Option < FlatNode < T > > ,
110109 pub expr_function : Option < ExpressionFunction < T > > ,
111110 pub args : Vec < IStr > ,
112111 pub equation_type : EquationType ,
@@ -118,7 +117,6 @@ impl<T: EvalexprFloat> Default for Expr<T> {
118117 text : Default :: default ( ) ,
119118 display_rational : false ,
120119 node : Default :: default ( ) ,
121- inlined_node : Default :: default ( ) ,
122120 args : Default :: default ( ) ,
123121 expr_function : Default :: default ( ) ,
124122 equation_type : Default :: default ( ) ,
@@ -132,21 +130,14 @@ impl<T: EvalexprFloat> Expr<T> {
132130 // if unoptimized node is constant, no need to display it
133131 return None ;
134132 }
135- if let Some ( func) = & self . expr_function {
136- func. as_constant ( )
137- } else if let Some ( inlined_node) = & self . inlined_node {
138- inlined_node. as_constant ( )
139- } else {
140- None
141- }
133+ if let Some ( func) = & self . expr_function { func. as_constant ( ) } else { None }
142134 }
143135 fn from_text ( text : & str ) -> Self {
144136 // TODO preprocess here too
145137 Self {
146138 node : evalexpr:: build_flat_node :: < T > ( text) . ok ( ) ,
147139 equation_type : EquationType :: None ,
148140 display_rational : false ,
149- inlined_node : None ,
150141 expr_function : None ,
151142 text : text. to_string ( ) ,
152143 args : Vec :: new ( ) ,
@@ -176,7 +167,6 @@ pub enum FunctionType {
176167pub enum EntryType < T : EvalexprFloat > {
177168 Function {
178169 can_be_drawn : bool ,
179- selectable : bool ,
180170 identifier : IStr ,
181171 func : Expr < T > ,
182172 style : LineStyleConfig ,
@@ -204,36 +194,30 @@ pub enum EntryType<T: EvalexprFloat> {
204194 Points {
205195 identifier : IStr ,
206196 points : Vec < PointEntry < T > > ,
207- style : PointStyle ,
208- } ,
209- Label {
210- x : Expr < T > ,
211- y : Expr < T > ,
212- size : Expr < T > ,
213- underline : bool ,
197+ style : PointStyle < T > ,
214198 } ,
215199 Folder {
216200 entries : Vec < Entry < T > > ,
217201 } ,
218202}
219203
220- #[ derive( Clone , Default , PartialEq , Debug , Serialize , Deserialize ) ]
204+ #[ derive( Clone , Copy , Default , PartialEq , Debug , Serialize , Deserialize ) ]
221205pub enum LabelSize {
222206 #[ default]
223207 Small ,
224208 Medium ,
225209 Large ,
226210}
227211impl LabelSize {
228- pub fn size ( & self ) -> f32 {
212+ pub fn size ( self ) -> f32 {
229213 match self {
230214 LabelSize :: Small => 10.0 ,
231215 LabelSize :: Medium => 16.0 ,
232216 LabelSize :: Large => 20.0 ,
233217 }
234218 }
235219}
236- #[ derive( Clone , Default , PartialEq , Debug , Serialize , Deserialize ) ]
220+ #[ derive( Clone , Copy , Default , PartialEq , Debug , Serialize , Deserialize ) ]
237221pub enum LabelPosition {
238222 #[ default]
239223 Bottom ,
@@ -244,9 +228,10 @@ pub enum LabelPosition {
244228 TRight ,
245229 BLeft ,
246230 BRight ,
231+ Center ,
247232}
248233impl LabelPosition {
249- fn symbol ( & self ) -> & ' static str {
234+ fn symbol ( self ) -> & ' static str {
250235 match self {
251236 LabelPosition :: Top => "⮉" ,
252237 LabelPosition :: Bottom => "⮋" ,
@@ -256,9 +241,10 @@ impl LabelPosition {
256241 LabelPosition :: TRight => "⬈" ,
257242 LabelPosition :: BLeft => "⬋" ,
258243 LabelPosition :: BRight => "⬊" ,
244+ LabelPosition :: Center => "o" ,
259245 }
260246 }
261- fn dir ( & self ) -> egui:: Vec2 {
247+ fn dir ( self ) -> egui:: Vec2 {
262248 match self {
263249 LabelPosition :: Top => egui:: Vec2 :: new ( 0.0 , 1.0 ) ,
264250 LabelPosition :: Bottom => egui:: Vec2 :: new ( 0.0 , -1.0 ) ,
@@ -268,45 +254,51 @@ impl LabelPosition {
268254 LabelPosition :: TRight => egui:: Vec2 :: new ( 0.71 , 0.71 ) ,
269255 LabelPosition :: BLeft => egui:: Vec2 :: new ( -0.71 , -0.71 ) ,
270256 LabelPosition :: BRight => egui:: Vec2 :: new ( 0.71 , -0.71 ) ,
257+ LabelPosition :: Center => egui:: Vec2 :: new ( 0.0 , 0.0 ) ,
271258 }
272259 }
273260}
274261
275- #[ derive( Clone , Default , PartialEq , Debug , Serialize , Deserialize ) ]
276- pub struct LabelConfig {
277- #[ serde( default ) ]
278- size : LabelSize ,
279- #[ serde( default ) ]
280- pos : LabelPosition ,
281- #[ serde( default ) ]
282- italic : bool ,
262+ #[ derive( Clone , Debug ) ]
263+ pub struct LabelConfig < T : EvalexprFloat > {
264+ pub text : String ,
265+ pub size : LabelSize ,
266+ pub pos : LabelPosition ,
267+ pub italic : bool ,
268+ pub angle : Expr < T > ,
269+ }
270+ impl < T : EvalexprFloat > Default for LabelConfig < T > {
271+ fn default ( ) -> Self {
272+ Self {
273+ text : String :: new ( ) ,
274+ size : LabelSize :: Small ,
275+ pos : LabelPosition :: Bottom ,
276+ italic : false ,
277+ angle : Expr :: default ( ) ,
278+ }
279+ }
283280}
284281
285- #[ derive( Clone , PartialEq , Debug , Serialize , Deserialize ) ]
286- pub struct PointStyle {
287- show_lines : bool ,
288- #[ serde( default ) ]
289- show_arrows : bool ,
290- show_points : bool ,
291- line_style : LineStyleConfig ,
292- #[ serde( default ) ]
293- label_config : Option < LabelConfig > ,
294- #[ serde( default ) ]
295- fill : bool ,
296- #[ serde( default ) ]
297- fill_rule : FillRule ,
298- #[ serde( default ) ]
299- connect_first_and_last : bool ,
282+ #[ derive( Clone , Debug ) ]
283+ pub struct PointStyle < T : EvalexprFloat > {
284+ pub show_lines : bool ,
285+ pub show_arrows : bool ,
286+ pub show_points : bool ,
287+ pub line_style : LineStyleConfig ,
288+ pub label_config : Option < LabelConfig < T > > ,
289+ pub fill : bool ,
290+ pub fill_rule : FillRule ,
291+ pub connect_first_and_last : bool ,
300292}
301293
302- impl Default for PointStyle {
294+ impl < T : EvalexprFloat > Default for PointStyle < T > {
303295 fn default ( ) -> Self {
304296 Self {
305297 show_lines : true ,
306298 show_points : true ,
307299 show_arrows : false ,
308- label_config : Some ( LabelConfig :: default ( ) ) ,
309- line_style : LineStyleConfig :: default ( ) ,
300+ label_config : None ,
301+ line_style : LineStyleConfig :: new ( false ) ,
310302 fill : false ,
311303 connect_first_and_last : false ,
312304 fill_rule : FillRule :: default ( ) ,
@@ -323,13 +315,27 @@ pub enum LineStyleType {
323315}
324316#[ derive( Clone , PartialEq , Debug , Serialize , Deserialize ) ]
325317pub struct LineStyleConfig {
318+ #[ serde( default ) ]
319+ selectable : bool ,
326320 line_width : f32 ,
327321 #[ serde( default ) ]
328322 line_style : LineStyleType ,
329323 line_style_size : f32 ,
330324}
331325impl Default for LineStyleConfig {
332- fn default ( ) -> Self { Self { line_width : 1.5 , line_style : LineStyleType :: Solid , line_style_size : 5.5 } }
326+ fn default ( ) -> Self {
327+ Self {
328+ selectable : false ,
329+ line_width : 1.5 ,
330+ line_style : LineStyleType :: Solid ,
331+ line_style_size : 5.5 ,
332+ }
333+ }
334+ }
335+ impl LineStyleConfig {
336+ fn new ( selectable : bool ) -> Self {
337+ Self { selectable, ..Self :: default ( ) }
338+ }
333339}
334340impl LineStyleConfig {
335341 fn egui_line_style ( & self ) -> egui_plot:: LineStyle {
@@ -353,7 +359,6 @@ impl<T: EvalexprFloat> Entry<T> {
353359 }
354360 } ,
355361 EntryType :: Points { .. } => "◊" ,
356- EntryType :: Label { .. } => "📃" ,
357362 EntryType :: Folder { .. } => {
358363 if self . active {
359364 "📂"
@@ -368,7 +373,6 @@ impl<T: EvalexprFloat> Entry<T> {
368373 EntryType :: Function { .. } => "λ Function" ,
369374 EntryType :: Constant { .. } => "⏵ Constant" ,
370375 EntryType :: Points { .. } => "◊ Points" ,
371- EntryType :: Label { .. } => "📃 Label" ,
372376 EntryType :: Folder { .. } => "📂 Folder" ,
373377 }
374378 }
@@ -377,7 +381,6 @@ impl<T: EvalexprFloat> Entry<T> {
377381 EntryType :: Function { .. } => "Function" ,
378382 EntryType :: Constant { .. } => "Constant" ,
379383 EntryType :: Points { .. } => "Points" ,
380- EntryType :: Label { .. } => "Label" ,
381384 EntryType :: Folder { .. } => "Folder" ,
382385 }
383386 }
@@ -391,7 +394,6 @@ impl<T: EvalexprFloat> Entry<T> {
391394 draw_buffer_scheduler : DrawBufferScheduler :: new ( ) ,
392395 ty : EntryType :: Function {
393396 identifier : istr_empty ( ) ,
394- selectable : true ,
395397 can_be_drawn : true ,
396398
397399 func : Expr :: from_text ( text) ,
@@ -401,7 +403,7 @@ impl<T: EvalexprFloat> Entry<T> {
401403 range_end : Expr :: from_text ( "2" ) ,
402404 ty : FunctionType :: Expression ,
403405 fill_rule : FillRule :: default ( ) ,
404- style : LineStyleConfig :: default ( ) ,
406+ style : LineStyleConfig :: new ( true ) ,
405407 implicit_resolution : DEFAULT_IMPLICIT_RESOLUTION ,
406408 } ,
407409 }
@@ -437,21 +439,6 @@ impl<T: EvalexprFloat> Entry<T> {
437439 } ,
438440 }
439441 }
440- pub fn new_label ( id : u64 ) -> Self {
441- Self {
442- id,
443- color : id as usize % NUM_COLORS ,
444- active : true ,
445- name : String :: new ( ) ,
446- draw_buffer_scheduler : DrawBufferScheduler :: new ( ) ,
447- ty : EntryType :: Label {
448- x : Expr :: default ( ) ,
449- y : Expr :: default ( ) ,
450- size : Expr :: default ( ) ,
451- underline : false ,
452- } ,
453- }
454- }
455442 pub fn new_folder ( id : u64 ) -> Self {
456443 Self {
457444 id,
0 commit comments