@@ -11,6 +11,8 @@ using namespace Pinetime::Applications::Screens;
1111 return 0 ; \
1212 }
1313
14+ #define PARAMS_OBJ (i ) ((lv_obj_t *) params[i])
15+
1416static void event_handler (lv_obj_t * obj, lv_event_t event) {
1517 AMX* amx = (AMX*) lv_obj_get_user_data (lv_scr_act ());
1618 int handler_index = (int ) lv_obj_get_user_data (obj);
@@ -28,33 +30,33 @@ static cell AMX_NATIVE_CALL F_lv_scr_act(AMX* amx, const cell* params) {
2830static cell AMX_NATIVE_CALL F_lv_label_create (AMX* amx, const cell* params) {
2931 ASSERT_PARAMS (2 );
3032
31- return (cell) lv_label_create (( lv_obj_t *) params[ 1 ] ?: lv_scr_act (), ( lv_obj_t *) params[ 2 ] );
33+ return (cell) lv_label_create (PARAMS_OBJ ( 1 ) ?: lv_scr_act (), PARAMS_OBJ ( 2 ) );
3234}
3335
3436static cell AMX_NATIVE_CALL F_lv_btn_create (AMX* amx, const cell* params) {
3537 ASSERT_PARAMS (2 );
3638
37- return (cell) lv_btn_create (( lv_obj_t *) params[ 1 ] ?: lv_scr_act (), ( lv_obj_t *) params[ 2 ] );
39+ return (cell) lv_btn_create (PARAMS_OBJ ( 1 ) ?: lv_scr_act (), PARAMS_OBJ ( 2 ) );
3840}
3941
4042static cell AMX_NATIVE_CALL F_lv_obj_set_pos (AMX* amx, const cell* params) {
4143 ASSERT_PARAMS (3 );
4244
43- lv_obj_set_pos (( lv_obj_t *) params[ 1 ] , params[2 ], params[3 ]);
45+ lv_obj_set_pos (PARAMS_OBJ ( 1 ) , params[2 ], params[3 ]);
4446 return 0 ;
4547}
4648
4749static cell AMX_NATIVE_CALL F_lv_obj_set_size (AMX* amx, const cell* params) {
4850 ASSERT_PARAMS (3 );
4951
50- lv_obj_set_size (( lv_obj_t *) params[ 1 ] , params[2 ], params[3 ]);
52+ lv_obj_set_size (PARAMS_OBJ ( 1 ) , params[2 ], params[3 ]);
5153 return 0 ;
5254}
5355
5456static cell AMX_NATIVE_CALL F_lv_obj_set_event_cb (AMX* amx, const cell* params) {
5557 ASSERT_PARAMS (2 );
5658
57- lv_obj_t * obj = ( lv_obj_t *) params[ 1 ] ;
59+ lv_obj_t * obj = PARAMS_OBJ ( 1 ) ;
5860
5961 char * name;
6062 amx_StrParam_Type (amx, params[2 ], name, char *);
@@ -72,7 +74,7 @@ static cell AMX_NATIVE_CALL F_lv_obj_set_event_cb(AMX* amx, const cell* params)
7274static cell AMX_NATIVE_CALL F_lv_label_set_text (AMX* amx, const cell* params) {
7375 ASSERT_PARAMS (2 );
7476
75- lv_obj_t * label = ( lv_obj_t *) params[ 1 ] ;
77+ lv_obj_t * label = PARAMS_OBJ ( 1 ) ;
7678
7779 char * text;
7880 amx_StrParam_Type (amx, params[2 ], text, char *);
@@ -87,7 +89,7 @@ static cell AMX_NATIVE_CALL F_lv_label_set_text(AMX* amx, const cell* params) {
8789static cell AMX_NATIVE_CALL F_lv_obj_set_style_local_int (AMX* amx, const cell* params) {
8890 ASSERT_PARAMS (5 );
8991
90- lv_obj_t * obj = ( lv_obj_t *) params[ 1 ] ;
92+ lv_obj_t * obj = PARAMS_OBJ ( 1 ) ;
9193 cell prop = params[2 ];
9294 cell value = params[3 ];
9395 cell part = params[4 ];
@@ -100,7 +102,7 @@ static cell AMX_NATIVE_CALL F_lv_obj_set_style_local_int(AMX* amx, const cell* p
100102static cell AMX_NATIVE_CALL F_lv_obj_set_style_local_color (AMX* amx, const cell* params) {
101103 ASSERT_PARAMS (5 );
102104
103- lv_obj_t * obj = ( lv_obj_t *) params[ 1 ] ;
105+ lv_obj_t * obj = PARAMS_OBJ ( 1 ) ;
104106 cell prop = params[2 ];
105107 cell value = params[3 ];
106108 cell part = params[4 ];
@@ -113,7 +115,7 @@ static cell AMX_NATIVE_CALL F_lv_obj_set_style_local_color(AMX* amx, const cell*
113115static cell AMX_NATIVE_CALL F_lv_obj_set_style_local_opa (AMX* amx, const cell* params) {
114116 ASSERT_PARAMS (5 );
115117
116- lv_obj_t * obj = ( lv_obj_t *) params[ 1 ] ;
118+ lv_obj_t * obj = PARAMS_OBJ ( 1 ) ;
117119 cell prop = params[2 ];
118120 cell value = params[3 ];
119121 cell part = params[4 ];
@@ -123,6 +125,32 @@ static cell AMX_NATIVE_CALL F_lv_obj_set_style_local_opa(AMX* amx, const cell* p
123125 return 0 ;
124126}
125127
128+ static cell AMX_NATIVE_CALL F_lv_obj_set_style_local_ptr (AMX* amx, const cell* params) {
129+ ASSERT_PARAMS (5 );
130+
131+ lv_obj_t * obj = PARAMS_OBJ (1 );
132+ cell prop = params[2 ];
133+ cell* value = amx_Address (amx, params[3 ]);
134+ cell part = params[4 ];
135+ cell state = params[5 ];
136+
137+ _lv_obj_set_style_local_ptr (obj, part, prop | (state << LV_STYLE_STATE_POS), (void *) value);
138+ return 0 ;
139+ }
140+
141+ static cell AMX_NATIVE_CALL F_lv_obj_align (AMX* amx, const cell* params) {
142+ ASSERT_PARAMS (5 )
143+
144+ lv_obj_t * obj = PARAMS_OBJ (1 );
145+ lv_obj_t * base = PARAMS_OBJ (2 );
146+ cell align = params[3 ];
147+ cell x_ofs = params[4 ];
148+ cell y_ofs = params[5 ];
149+
150+ lv_obj_align (obj, base, align, x_ofs, y_ofs);
151+ return 0 ;
152+ }
153+
126154static cell AMX_NATIVE_CALL F_sprintf (AMX* amx, const cell* params) {
127155 // param[0] is the number of total parameter bytes, divide it by cell size and subtract 3 to account for the fixed parameters
128156 int args_count = params[0 ] / sizeof (cell) - 3 ;
@@ -196,7 +224,11 @@ Pawn::Pawn() {
196224
197225 lv_obj_set_user_data (lv_scr_act (), &amx);
198226
199- static AMX_NATIVE_INFO natives[] = {
227+ cell* font;
228+ if (amx_FindPubVar (&amx, " font_jmec" , &font) == AMX_ERR_NONE)
229+ *font = (cell) &jetbrains_mono_extrabold_compressed;
230+
231+ const AMX_NATIVE_INFO natives[] = {
200232 {" sprintf" , F_sprintf},
201233 {" lv_scr_act" , F_lv_scr_act},
202234 {" lv_label_create" , F_lv_label_create},
@@ -208,6 +240,8 @@ Pawn::Pawn() {
208240 {" lv_obj_set_style_local_int" , F_lv_obj_set_style_local_int},
209241 {" lv_obj_set_style_local_color" , F_lv_obj_set_style_local_color},
210242 {" lv_obj_set_style_local_opa" , F_lv_obj_set_style_local_opa},
243+ {" lv_obj_set_style_local_ptr" , F_lv_obj_set_style_local_ptr},
244+ {" lv_obj_align" , F_lv_obj_align},
211245 {0 , 0 } /* terminator */
212246 };
213247 amx_Register (&amx, natives, -1 );
0 commit comments