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 ;
@@ -11,7 +12,6 @@ pub fn DraggedNode(id: Uuid, coords: (f32, f32)) -> Element {
1112 g { transform: format!( "translate({}, {})" , coords. 0 , coords. 1 ) ,
1213 r#use {
1314 href: format!( "#{id}" ) ,
14- style: "transform: scale(0.5); opacity: 0.3;" ,
1515 }
1616 }
1717 }
@@ -61,6 +61,22 @@ fn RawRootNode(width: f32, height: f32, color: String) -> Element {
6161 }
6262}
6363
64+ #[ component]
65+ fn NodeLabel ( label : String ) -> Element {
66+ rsx ! {
67+ for ( index, line) in label. lines( ) . enumerate( ) {
68+ text {
69+ y: index as f32 * measure_line_height( ) + TEXT_PADDING ,
70+ x: TEXT_PADDING ,
71+ text_anchor: "start" ,
72+ dominant_baseline: "text-before-edge" ,
73+ font_size: FONT_SIZE ,
74+ "{line}"
75+ }
76+ }
77+ }
78+ }
79+
6480#[ component]
6581fn RawNode ( node : crate :: data:: RenderedNode ) -> Element {
6682 let width = node. width ( ) ;
@@ -184,14 +200,13 @@ pub fn Node(id: Uuid, store: Store) -> Element {
184200 }
185201 }
186202
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 ) {
203+ if * store . pane . editing . read ( ) == Some ( node . id ) {
204+ foreignObject {
205+ x : format!( "{}" , -width / 2.0 ) ,
206+ y : format!( "{}" , -height / 2.0 ) ,
207+ width : format!( "{}" , width ) ,
208+ height : format! ( "{}" , height ) ,
193209 textarea {
194- style: if store. pane. dragging_node. read( ) . is_some( ) { "pointer-events: none;" } else { "" } ,
195210 key: "{id}-textarea" ,
196211 onmounted: move |element| input_element. set( Some ( element. data( ) ) ) ,
197212 value: "{node.text}" ,
@@ -202,51 +217,32 @@ pub fn Node(id: Uuid, store: Store) -> Element {
202217 tabindex: -1 ,
203218 style: "
204219 user-select: none;
205- margin: 0px 10px ;
206- padding: 9px 0px ;
220+ margin: 0px;
221+ padding: {TEXT_PADDING}px {TEXT_PADDING}px ;
207222 font-family: inherit;
208- width: 100% ;
209- height: 100% ;
223+ width: {width}px ;
224+ height: {height}px ;
210225 outline:none;
211226 background: transparent;
212227 border: none;
213228 resize:none;
214229 overflow:hidden;
215230 font-size: {font_size}px;
216231 display: block;
217- line-height: 1.2 " ,
232+ line-height: {measure_line_height() + 0.3}px " ,
218233 oninput: move |evt| {
219234 store. graph. update_node( id, NodeProperty :: Text ( evt. value( ) . clone( ) ) ) ;
220235 } ,
221236 }
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- }
248237 }
238+ } else {
239+ g {
240+ transform: format!( "translate({},{})" , -width / 2.0 , -height / 2.0 ) ,
241+
242+ NodeLabel { label: node. text }
243+ }
249244 }
245+
250246 }
251247 }
252248 }
0 commit comments