@@ -3,7 +3,7 @@ use super::Content;
33use crate :: engine:: Spellcheck ;
44use crate :: { Camera , Drawable } ;
55use itertools:: Itertools ;
6- use kurbo:: Shape ;
6+ use kurbo:: { BezPath , Shape } ;
77use p2d:: bounding_volume:: Aabb ;
88use piet:: { RenderContext , TextLayout , TextLayoutBuilder } ;
99use rnote_compose:: ext:: { AabbExt , Affine2Ext , Vector2Ext } ;
@@ -414,8 +414,8 @@ impl TextStyle {
414414 transform : & Transform ,
415415 camera : & Camera ,
416416 ) {
417- const OUTLINE_COLOR : piet:: Color = color:: GNOME_REDS [ 2 ] ;
418- let outline_width = 1.5 / camera. total_zoom ( ) ;
417+ const ERROR_COLOR : piet:: Color = color:: GNOME_REDS [ 2 ] ;
418+ let scale = 1.0 / camera. total_zoom ( ) ;
419419
420420 if let Ok ( selection_rects) =
421421 self . get_rects_for_indices ( text. clone ( ) , start_index, end_index)
@@ -425,24 +425,15 @@ impl TextStyle {
425425
426426 if let Ok ( line_metric) = self . cursor_line_metric ( cx. text ( ) , text, start_index) {
427427 for selection_rect in selection_rects {
428- let bottom_line = transform. to_kurbo ( )
429- * kurbo:: Line :: new (
430- kurbo:: Point :: new (
431- selection_rect. x0 ,
432- selection_rect. y0 + line_metric. baseline + 2.0 ,
433- ) ,
434- kurbo:: Point :: new (
435- selection_rect. x1 ,
436- selection_rect. y0 + line_metric. baseline + 2.0 ,
437- ) ,
428+ let width = selection_rect. width ( ) ;
429+ let origin = transform. to_kurbo ( )
430+ * kurbo:: Point :: new (
431+ selection_rect. x0 ,
432+ selection_rect. y0 + line_metric. baseline + 2.0 ,
438433 ) ;
439434
440- cx. stroke_styled (
441- bottom_line,
442- & OUTLINE_COLOR ,
443- outline_width,
444- & piet:: StrokeStyle :: new ( ) . dash_pattern ( & [ 4.0 , 2.0 ] ) ,
445- ) ;
435+ let path = create_wavy_line ( origin, width, scale) ;
436+ cx. stroke ( path, & ERROR_COLOR , 1.5 * scale) ;
446437 }
447438 }
448439 }
@@ -1228,3 +1219,35 @@ fn remove_intersecting_attrs_in_range(
12281219 . filter ( |attr| !attr. range . is_empty ( ) )
12291220 . collect :: < Vec < RangedTextAttribute > > ( )
12301221}
1222+
1223+ fn create_wavy_line ( origin : kurbo:: Point , max_width : f64 , scale : f64 ) -> BezPath {
1224+ const WIDTH : f64 = 3.5 ;
1225+ const HEIGHT : f64 = 4.0 ;
1226+
1227+ if !max_width. is_finite ( ) {
1228+ return BezPath :: new ( ) ;
1229+ }
1230+
1231+ let width = WIDTH * scale;
1232+ let half_height = ( HEIGHT / 2.0 ) * scale;
1233+
1234+ let mut path = BezPath :: new ( ) ;
1235+ path. move_to ( origin + ( 0.0 , half_height) ) ;
1236+
1237+ let mut x = 0.0 ;
1238+ let mut direction = 1.0 ;
1239+
1240+ while x < max_width {
1241+ let center_point = origin + ( x, half_height) ;
1242+
1243+ let stationary_point = center_point + ( width / 2.0 , half_height * direction) ;
1244+ let next_center_point = center_point + ( width, 0.0 ) ;
1245+
1246+ path. quad_to ( stationary_point, next_center_point) ;
1247+
1248+ x += width;
1249+ direction = -direction;
1250+ }
1251+
1252+ path
1253+ }
0 commit comments