@@ -9,6 +9,7 @@ use azul_desktop::{
9
9
Dom , NodeDataInlineCssProperty , NodeDataInlineCssPropertyVec ,
10
10
NodeDataInlineCssProperty :: { Normal , Hover , Focus }
11
11
} ,
12
+ task:: OptionTimerId ,
12
13
callbacks:: { RefAny , Callback , CallbackInfo , Update } ,
13
14
} ;
14
15
use azul_core:: { callbacks:: { Animation , AnimationRepeatCount } , task:: SystemTimeDiff , window:: { KeyboardState , VirtualKeyCode } } ;
@@ -43,6 +44,7 @@ pub struct TextInputStateWrapper {
43
44
pub on_focus_lost : OptionTextInputOnFocusLost ,
44
45
pub update_text_input_before_calling_focus_lost_fn : bool ,
45
46
pub update_text_input_before_calling_vk_down_fn : bool ,
47
+ pub cursor_animation : OptionTimerId ,
46
48
}
47
49
48
50
#[ derive( Debug , Copy , Clone , PartialEq ) ]
@@ -285,6 +287,8 @@ static TEXT_INPUT_CONTAINER_PROPS: &[NodeDataInlineCssProperty] = &[
285
287
286
288
#[ cfg( target_os = "windows" ) ]
287
289
static TEXT_INPUT_LABEL_PROPS : & [ NodeDataInlineCssProperty ] = & [
290
+ Normal ( CssProperty :: const_display ( LayoutDisplay :: InlineBlock ) ) ,
291
+ Normal ( CssProperty :: const_flex_grow ( LayoutFlexGrow :: const_new ( 0 ) ) ) ,
288
292
Normal ( CssProperty :: const_position ( LayoutPosition :: Relative ) ) ,
289
293
Normal ( CssProperty :: const_font_size ( StyleFontSize :: const_px ( 13 ) ) ) ,
290
294
Normal ( CssProperty :: const_text_color ( StyleTextColor { inner : COLOR_4C4C4C } ) ) ,
@@ -293,15 +297,19 @@ static TEXT_INPUT_LABEL_PROPS: &[NodeDataInlineCssProperty] = &[
293
297
294
298
#[ cfg( target_os = "linux" ) ]
295
299
static TEXT_INPUT_LABEL_PROPS : & [ NodeDataInlineCssProperty ] = & [
296
- Normal ( CssProperty :: const_position ( LayoutPosition :: Relative ) ) ,
300
+ Normal ( CssProperty :: const_display ( LayoutDisplay :: InlineBlock ) ) ,
301
+ Normal ( CssProperty :: const_flex_grow ( LayoutFlexGrow :: const_new ( 0 ) ) ) ,
302
+ Normal ( CssProperty :: const_position ( LayoutPosition :: Relative ) ) ,
297
303
Normal ( CssProperty :: const_font_size ( StyleFontSize :: const_px ( 13 ) ) ) ,
298
304
Normal ( CssProperty :: const_text_color ( StyleTextColor { inner : COLOR_4C4C4C } ) ) ,
299
305
Normal ( CssProperty :: const_font_family ( SANS_SERIF_FAMILY ) ) ,
300
306
] ;
301
307
302
308
#[ cfg( target_os = "macos" ) ]
303
309
static TEXT_INPUT_LABEL_PROPS : & [ NodeDataInlineCssProperty ] = & [
304
- Normal ( CssProperty :: const_position ( LayoutPosition :: Relative ) ) ,
310
+ Normal ( CssProperty :: const_display ( LayoutDisplay :: InlineBlock ) ) ,
311
+ Normal ( CssProperty :: const_flex_grow ( LayoutFlexGrow :: const_new ( 0 ) ) ) ,
312
+ Normal ( CssProperty :: const_position ( LayoutPosition :: Relative ) ) ,
305
313
Normal ( CssProperty :: const_font_size ( StyleFontSize :: const_px ( 13 ) ) ) ,
306
314
Normal ( CssProperty :: const_text_color ( StyleTextColor { inner : COLOR_4C4C4C } ) ) ,
307
315
Normal ( CssProperty :: const_font_family ( SANS_SERIF_FAMILY ) ) ,
@@ -339,6 +347,7 @@ impl Default for TextInputStateWrapper {
339
347
on_focus_lost : None . into ( ) ,
340
348
update_text_input_before_calling_focus_lost_fn : true ,
341
349
update_text_input_before_calling_vk_down_fn : true ,
350
+ cursor_animation : None . into ( ) ,
342
351
}
343
352
}
344
353
}
@@ -452,6 +461,13 @@ impl TextInput {
452
461
] . into ( ) )
453
462
. with_children ( vec ! [
454
463
Dom :: text( label_text)
464
+ . with_callbacks( vec![
465
+ CallbackData {
466
+ event: EventFilter :: Hover ( HoverEventFilter :: LeftMouseDown ) ,
467
+ data: state_ref. clone( ) ,
468
+ callback: Callback { cb: default_on_label_click }
469
+ } ,
470
+ ] . into( ) )
455
471
. with_ids_and_classes( vec![ Class ( "__azul-native-text-input-label" . into( ) ) ] . into( ) )
456
472
. with_inline_css_props( self . label_style)
457
473
. with_children( vec![
@@ -740,6 +756,9 @@ extern "C" fn default_on_container_click(text_input: &mut RefAny, info: &mut Cal
740
756
Some ( s) => s,
741
757
None => return Update :: DoNothing ,
742
758
} ;
759
+
760
+ println ! ( "container clicked at position {:?}" , info. get_cursor_relative_to_node( ) ) ;
761
+
743
762
// TODO: clear selection, set cursor to text hit
744
763
Update :: DoNothing
745
764
}
@@ -749,6 +768,11 @@ extern "C" fn default_on_label_click(text_input: &mut RefAny, info: &mut Callbac
749
768
Some ( s) => s,
750
769
None => return Update :: DoNothing ,
751
770
} ;
771
+
772
+ println ! ( "label clicked at position {:?}" , info. get_cursor_relative_to_node( ) ) ;
773
+
774
+ info. stop_propagation ( ) ;
775
+
752
776
// TODO: set cursor to end or start
753
777
Update :: DoNothing
754
778
}
@@ -768,15 +792,20 @@ extern "C" fn default_on_focus_received(text_input: &mut RefAny, info: &mut Call
768
792
None => return Update :: DoNothing ,
769
793
} ;
770
794
771
- let timer_id = info. start_animation ( cursor_node_id, Animation {
772
- from : CssProperty :: const_opacity ( StyleOpacity :: const_new ( 100 ) ) ,
773
- to : CssProperty :: const_opacity ( StyleOpacity :: const_new ( 0 ) ) ,
774
- duration : Duration :: System ( SystemTimeDiff :: from_millis ( 500 ) ) ,
775
- repeat : AnimationRepeat :: PingPong ,
776
- repeat_times : AnimationRepeatCount :: Infinite ,
777
- easing : AnimationInterpolationFunction :: EaseInOut ,
778
- relayout_on_finish : false ,
779
- } ) ;
795
+ if text_input. cursor_animation . is_none ( ) {
796
+ let timer_id = info. start_animation ( cursor_node_id, Animation {
797
+ from : CssProperty :: const_opacity ( StyleOpacity :: const_new ( 100 ) ) ,
798
+ to : CssProperty :: const_opacity ( StyleOpacity :: const_new ( 0 ) ) ,
799
+ duration : Duration :: System ( SystemTimeDiff :: from_millis ( 500 ) ) ,
800
+ repeat : AnimationRepeat :: PingPong ,
801
+ repeat_times : AnimationRepeatCount :: Infinite ,
802
+ easing : AnimationInterpolationFunction :: EaseInOut ,
803
+ relayout_on_finish : false ,
804
+ } ) ;
805
+ if let Some ( timer_id) = timer_id {
806
+ text_input. cursor_animation = Some ( timer_id) . into ( ) ;
807
+ }
808
+ }
780
809
781
810
// TODO: start text cursor blinking
782
811
Update :: DoNothing
@@ -795,6 +824,11 @@ extern "C" fn default_on_focus_lost(text_input: &mut RefAny, info: &mut Callback
795
824
let onfocuslost = & mut text_input. on_focus_lost ;
796
825
let inner = & text_input. inner ;
797
826
827
+ if let Some ( timer_id) = text_input. cursor_animation . clone ( ) . into_option ( ) {
828
+ info. stop_timer ( timer_id) ;
829
+ text_input. cursor_animation = None . into ( ) ;
830
+ }
831
+
798
832
match onfocuslost. as_mut ( ) {
799
833
Some ( TextInputOnFocusLost { callback, data } ) => ( callback. cb ) ( data, info, & inner) ,
800
834
None => Update :: DoNothing ,
0 commit comments