1616//!
1717//! // Set up link management
1818//! let mut links = LinkManager::new(tracker.cache());
19+ //!
20+ //! // Add a link with default line width (2.0)
1921//! links.add(SimpleLink::new(1, output_pin, input_pin, Color::from_rgb_u8(100, 180, 255)));
2022//!
23+ //! // Or add a link with custom line width
24+ //! links.add(SimpleLink::with_line_width(2, output_pin, input_pin, Color::from_rgb_u8(255, 100, 100), 4.0));
25+ //!
2126//! // Connect to Slint
2227//! window.set_link_paths(links.paths());
2328//!
@@ -46,12 +51,12 @@ struct ConcreteModelSyncer<P, F> {
4651impl < P , F > ModelSyncer for ConcreteModelSyncer < P , F >
4752where
4853 P : Clone + ' static ,
49- F : Fn ( i32 , SharedString , slint:: Color ) -> P ,
54+ F : Fn ( i32 , SharedString , slint:: Color , f32 ) -> P ,
5055{
5156 fn sync ( & self , paths : & [ LinkPathData ] ) {
5257 // Update existing rows or add new ones
5358 for ( i, path) in paths. iter ( ) . enumerate ( ) {
54- let item = ( self . constructor ) ( path. id , path. path_commands . clone ( ) . into ( ) , path. color ) ;
59+ let item = ( self . constructor ) ( path. id , SharedString :: from ( path. path_commands . as_str ( ) ) , path. color , path . line_width ) ;
5560 if i < self . model . row_count ( ) {
5661 self . model . set_row_data ( i, item) ;
5762 } else {
@@ -114,6 +119,7 @@ struct LinkPathData {
114119 id : i32 ,
115120 path_commands : String ,
116121 color : slint:: Color ,
122+ line_width : f32 ,
117123}
118124
119125impl < L , N > LinkManager < L , N >
@@ -145,11 +151,11 @@ where
145151 /// # Arguments
146152 ///
147153 /// * `model` - The VecModel to sync to
148- /// * `constructor` - Function to create path items from (id, path_commands, color)
154+ /// * `constructor` - Function to create path items from (id, path_commands, color, line_width )
149155 pub fn bind_model < P , F > ( & mut self , model : Rc < VecModel < P > > , constructor : F )
150156 where
151157 P : Clone + ' static ,
152- F : Fn ( i32 , SharedString , slint:: Color ) -> P + ' static ,
158+ F : Fn ( i32 , SharedString , slint:: Color , f32 ) -> P + ' static ,
153159 {
154160 self . syncer = Some ( Box :: new ( ConcreteModelSyncer { model, constructor } ) ) ;
155161 }
@@ -230,6 +236,7 @@ where
230236 id : link. id ( ) ,
231237 path_commands : path,
232238 color : link. color ( ) ,
239+ line_width : link. line_width ( ) ,
233240 } ) ;
234241 }
235242 }
@@ -270,19 +277,19 @@ pub trait LinkPathProvider {
270277 /// Create a Slint-compatible model of link paths.
271278 ///
272279 /// The returned closure takes a constructor function that creates
273- /// the Slint LinkPath type from (id, path_commands, color).
280+ /// the Slint LinkPath type from (id, path_commands, color, line_width ).
274281 fn create_paths_model < P , F > ( & self , constructor : F ) -> ModelRc < P >
275282 where
276283 P : Clone + ' static ,
277- F : Fn ( i32 , slint:: SharedString , slint:: Color ) -> P + ' static ;
284+ F : Fn ( i32 , slint:: SharedString , slint:: Color , f32 ) -> P + ' static ;
278285
279286 /// Update an existing paths model in place.
280287 ///
281288 /// This is more efficient than creating a new model each time.
282289 fn update_paths_model < P , F > ( & self , model : & VecModel < P > , constructor : F )
283290 where
284291 P : Clone + ' static ,
285- F : Fn ( i32 , slint:: SharedString , slint:: Color ) -> P ;
292+ F : Fn ( i32 , slint:: SharedString , slint:: Color , f32 ) -> P ;
286293}
287294
288295impl < L , N > LinkPathProvider for LinkManager < L , N >
@@ -293,26 +300,26 @@ where
293300 fn create_paths_model < P , F > ( & self , constructor : F ) -> ModelRc < P >
294301 where
295302 P : Clone + ' static ,
296- F : Fn ( i32 , slint:: SharedString , slint:: Color ) -> P + ' static ,
303+ F : Fn ( i32 , slint:: SharedString , slint:: Color , f32 ) -> P + ' static ,
297304 {
298305 let paths = self . paths . borrow ( ) ;
299306 let items: Vec < P > = paths
300307 . iter ( )
301- . map ( |p| constructor ( p. id , p. path_commands . clone ( ) . into ( ) , p. color ) )
308+ . map ( |p| constructor ( p. id , SharedString :: from ( p. path_commands . as_str ( ) ) , p. color , p . line_width ) )
302309 . collect ( ) ;
303310 ModelRc :: from ( Rc :: new ( VecModel :: from ( items) ) )
304311 }
305312
306313 fn update_paths_model < P , F > ( & self , model : & VecModel < P > , constructor : F )
307314 where
308315 P : Clone + ' static ,
309- F : Fn ( i32 , slint:: SharedString , slint:: Color ) -> P ,
316+ F : Fn ( i32 , slint:: SharedString , slint:: Color , f32 ) -> P ,
310317 {
311318 let paths = self . paths . borrow ( ) ;
312319
313320 // Update existing rows or add new ones
314321 for ( i, path) in paths. iter ( ) . enumerate ( ) {
315- let item = constructor ( path. id , path. path_commands . clone ( ) . into ( ) , path. color ) ;
322+ let item = constructor ( path. id , SharedString :: from ( path. path_commands . as_str ( ) ) , path. color , path . line_width ) ;
316323 if i < model. row_count ( ) {
317324 model. set_row_data ( i, item) ;
318325 } else {
0 commit comments