1- use crate :: data:: { NodeProperty , Store } ;
1+ use crate :: data:: node:: measure_line_height;
2+ use crate :: data:: { NodeProperty , Store , FONT_SIZE , TEXT_PADDING } ;
23use dioxus:: prelude:: * ;
34use std:: rc:: Rc ;
45use uuid:: Uuid ;
@@ -9,10 +10,7 @@ const SELECTED_PADDING: f32 = 5.0;
910pub fn DraggedNode ( id : Uuid , coords : ( f32 , f32 ) ) -> Element {
1011 rsx ! {
1112 g { transform: format!( "translate({}, {})" , coords. 0 , coords. 1 ) ,
12- r#use {
13- href: format!( "#{id}" ) ,
14- style: "transform: scale(0.5); opacity: 0.3;" ,
15- }
13+ r#use { href: format!( "#{id}" ) }
1614 }
1715 }
1816}
@@ -61,6 +59,22 @@ fn RawRootNode(width: f32, height: f32, color: String) -> Element {
6159 }
6260}
6361
62+ #[ component]
63+ fn NodeLabel ( label : String ) -> Element {
64+ rsx ! {
65+ for ( index , line) in label. lines( ) . enumerate( ) {
66+ text {
67+ y: index as f32 * measure_line_height( ) + TEXT_PADDING ,
68+ x: TEXT_PADDING ,
69+ text_anchor: "start" ,
70+ dominant_baseline: "text-before-edge" ,
71+ font_size: FONT_SIZE ,
72+ "{line}"
73+ }
74+ }
75+ }
76+ }
77+
6478#[ component]
6579fn RawNode ( node : crate :: data:: RenderedNode ) -> Element {
6680 let width = node. width ( ) ;
@@ -184,14 +198,13 @@ pub fn Node(id: Uuid, store: Store) -> Element {
184198 }
185199 }
186200
187- foreignObject {
188- x : format! ( "{}" , -width / 2.0 ) ,
189- y : format!( "{}" , -height / 2.0 ) ,
190- width : format!( "{}" , width ) ,
191- height : format!( "{}" , height ) ,
192- if * store . pane . editing . read ( ) == Some ( node . id ) {
201+ if * store . pane . editing . read ( ) == Some ( node . id ) {
202+ foreignObject {
203+ x : format!( "{}" , -width / 2.0 ) ,
204+ y : format!( "{}" , -height / 2.0 ) ,
205+ width : format!( "{}" , width ) ,
206+ height : format! ( "{}" , height ) ,
193207 textarea {
194- style: if store. pane. dragging_node. read( ) . is_some( ) { "pointer-events: none;" } else { "" } ,
195208 key: "{id}-textarea" ,
196209 onmounted: move |element| input_element. set( Some ( element. data( ) ) ) ,
197210 value: "{node.text}" ,
@@ -202,51 +215,31 @@ pub fn Node(id: Uuid, store: Store) -> Element {
202215 tabindex: -1 ,
203216 style: "
204217 user-select: none;
205- margin: 0px 10px ;
206- padding: 9px 0px ;
218+ margin: 0px;
219+ padding: {TEXT_PADDING}px {TEXT_PADDING}px ;
207220 font-family: inherit;
208- width: 100% ;
209- height: 100% ;
221+ width: {width}px ;
222+ height: {height}px ;
210223 outline:none;
211224 background: transparent;
212225 border: none;
213226 resize:none;
214227 overflow:hidden;
215228 font-size: {font_size}px;
216229 display: block;
217- line-height: 1.2 " ,
230+ line-height: {measure_line_height() + 0.3}px " ,
218231 oninput: move |evt| {
219232 store. graph. update_node( id, NodeProperty :: Text ( evt. value( ) . clone( ) ) ) ;
220233 } ,
221234 }
222- } else {
223- div {
224- style: "
225- vertical-align: top;
226- line-height: 1.2;
227- padding-left: 2px;
228- display: flex;
229- justify-content: center;
230- align-items: center;
231- width: 100%;
232- height: 100%;
233- overflow: hidden;
234- white-space: pre-wrap;
235- word-wrap: break-word;
236- text-align: center;
237- font-size: {font_size}px;
238- background: transparent;
239- color: black;
240- pointer-events: none;
241- -webkit-user-select: none;
242- -moz-user-select: none;
243- -ms-user-select: none;
244- user-select: none;
245- font-family: inherit;" ,
246- { node. text}
247- }
235+ }
236+ } else {
237+ g { transform: format!( "translate({},{})" , -width / 2.0 , -height / 2.0 ) ,
238+
239+ NodeLabel { label: node. text }
248240 }
249241 }
242+
250243 }
251244 }
252245 }
0 commit comments