@@ -17,7 +17,9 @@ use crate::{
1717 layer:: LayerId ,
1818 popup:: PopupId ,
1919 util:: convert:: { FromApi , TryFromApi } ,
20- widget:: { MouseAreaEvent , TextInputEvent , ViewFn , WidgetEvent , WidgetId } ,
20+ widget:: {
21+ MouseAreaEvent , TextInputEvent , TouchAreaEvent , ViewFn , WidgetEvent , WidgetId , touch_area,
22+ } ,
2123} ;
2224
2325#[ tonic:: async_trait]
@@ -67,6 +69,9 @@ impl widget_service_server::WidgetService for super::WidgetService {
6769 WidgetEvent :: TextInput ( evt) => {
6870 widget_event:: Event :: TextInput ( evt. into ( ) )
6971 }
72+ WidgetEvent :: TouchArea ( evt) => {
73+ widget_event:: Event :: TouchArea ( evt. into ( ) )
74+ }
7075 } ) ,
7176 } )
7277 . collect ( ) ,
@@ -994,6 +999,89 @@ pub fn widget_def_to_fn(def: WidgetDef) -> Option<ViewFn> {
994999 text_input. into ( )
9951000 } ) ;
9961001
1002+ Some ( f)
1003+ }
1004+ widget_def:: Widget :: TouchArea ( touch_area) => {
1005+ let widget:: v1:: TouchArea {
1006+ child,
1007+ widget_id,
1008+ on_down,
1009+ on_up,
1010+ on_enter,
1011+ on_move,
1012+ on_exit,
1013+ on_cancel,
1014+ } = * touch_area;
1015+
1016+ let child_widget_fn = child. and_then ( |def| widget_def_to_fn ( * def) ) ;
1017+
1018+ let f: ViewFn = Box :: new ( move || {
1019+ let mut touch_area = touch_area:: TouchArea :: new (
1020+ child_widget_fn
1021+ . as_ref ( )
1022+ . map ( |child| child ( ) )
1023+ . unwrap_or_else ( || iced:: widget:: Text :: new ( "NULL" ) . into ( ) ) ,
1024+ ) ;
1025+
1026+ if let Some ( widget_id) = widget_id {
1027+ if on_down {
1028+ touch_area = touch_area. on_down ( move |id, pos| {
1029+ crate :: widget:: SnowcapMessage :: WidgetEvent (
1030+ WidgetId ( widget_id) ,
1031+ WidgetEvent :: TouchArea ( TouchAreaEvent :: Down ( id, pos) ) ,
1032+ )
1033+ } ) ;
1034+ }
1035+
1036+ if on_up {
1037+ touch_area = touch_area. on_up ( move |id| {
1038+ crate :: widget:: SnowcapMessage :: WidgetEvent (
1039+ WidgetId ( widget_id) ,
1040+ WidgetEvent :: TouchArea ( TouchAreaEvent :: Up ( id) ) ,
1041+ )
1042+ } ) ;
1043+ }
1044+
1045+ if on_enter {
1046+ touch_area = touch_area. on_enter ( move |id| {
1047+ crate :: widget:: SnowcapMessage :: WidgetEvent (
1048+ WidgetId ( widget_id) ,
1049+ WidgetEvent :: TouchArea ( TouchAreaEvent :: Enter ( id) ) ,
1050+ )
1051+ } ) ;
1052+ }
1053+
1054+ if on_move {
1055+ touch_area = touch_area. on_move ( move |id, pos| {
1056+ crate :: widget:: SnowcapMessage :: WidgetEvent (
1057+ WidgetId ( widget_id) ,
1058+ WidgetEvent :: TouchArea ( TouchAreaEvent :: Move ( id, pos) ) ,
1059+ )
1060+ } ) ;
1061+ }
1062+
1063+ if on_exit {
1064+ touch_area = touch_area. on_exit ( move |id| {
1065+ crate :: widget:: SnowcapMessage :: WidgetEvent (
1066+ WidgetId ( widget_id) ,
1067+ WidgetEvent :: TouchArea ( TouchAreaEvent :: Exit ( id) ) ,
1068+ )
1069+ } ) ;
1070+ }
1071+
1072+ if on_cancel {
1073+ touch_area = touch_area. on_cancel ( move |id| {
1074+ crate :: widget:: SnowcapMessage :: WidgetEvent (
1075+ WidgetId ( widget_id) ,
1076+ WidgetEvent :: TouchArea ( TouchAreaEvent :: Cancel ( id) ) ,
1077+ )
1078+ } ) ;
1079+ }
1080+ }
1081+
1082+ touch_area. into ( )
1083+ } ) ;
1084+
9971085 Some ( f)
9981086 }
9991087 }
@@ -1469,3 +1557,50 @@ impl FromApi<widget::v1::text_input::Style> for crate::widget::text_input::Style
14691557 }
14701558 }
14711559}
1560+
1561+ impl From < TouchAreaEvent > for snowcap_api_defs:: snowcap:: widget:: v1:: touch_area:: Event {
1562+ fn from ( value : TouchAreaEvent ) -> Self {
1563+ use snowcap_api_defs:: snowcap:: widget:: v1:: touch_area:: { self , event:: Data } ;
1564+
1565+ let data = match value {
1566+ TouchAreaEvent :: Down ( finger, point) => {
1567+ let down_evt = touch_area:: DownEvent {
1568+ finger : Some ( touch_area:: Finger :: from_api ( finger) ) ,
1569+ point : Some ( touch_area:: Point :: from_api ( point) ) ,
1570+ } ;
1571+
1572+ Data :: Down ( down_evt)
1573+ }
1574+ TouchAreaEvent :: Up ( finger) => Data :: Up ( touch_area:: Finger :: from_api ( finger) ) ,
1575+ TouchAreaEvent :: Enter ( finger) => Data :: Enter ( touch_area:: Finger :: from_api ( finger) ) ,
1576+ TouchAreaEvent :: Move ( finger, point) => {
1577+ let down_evt = touch_area:: MoveEvent {
1578+ finger : Some ( touch_area:: Finger :: from_api ( finger) ) ,
1579+ point : Some ( touch_area:: Point :: from_api ( point) ) ,
1580+ } ;
1581+
1582+ Data :: Move ( down_evt)
1583+ }
1584+ TouchAreaEvent :: Exit ( finger) => Data :: Exit ( touch_area:: Finger :: from_api ( finger) ) ,
1585+ TouchAreaEvent :: Cancel ( finger) => Data :: Cancel ( touch_area:: Finger :: from_api ( finger) ) ,
1586+ } ;
1587+
1588+ Self { data : Some ( data) }
1589+ }
1590+ }
1591+
1592+ impl FromApi < iced:: touch:: Finger > for snowcap_api_defs:: snowcap:: widget:: v1:: touch_area:: Finger {
1593+ fn from_api ( api_type : iced:: touch:: Finger ) -> Self {
1594+ Self {
1595+ id : api_type. 0 as u32 ,
1596+ }
1597+ }
1598+ }
1599+
1600+ impl FromApi < iced:: Point > for snowcap_api_defs:: snowcap:: widget:: v1:: touch_area:: Point {
1601+ fn from_api ( api_type : iced:: Point ) -> Self {
1602+ let iced:: Point { x, y } = api_type;
1603+
1604+ Self { x, y }
1605+ }
1606+ }
0 commit comments