The keyboard plug-in for lvgl moves in any position on the screen

What do you want to achieve?

I want to ask, what is the way to move the lvgl’s keyboard in the screen?

What have you tried so far?

I used the following method, but I can’t use the keyboard plug-in on the squareline. Once I move the keyboard, I don’t know where to go.

static void drag_event_handler(lv_event_t* e)
{
lv_obj_t* obj = lv_event_get_target(e);
lv_indev_t* indev = lv_indev_get_act();
lv_point_t vect;
lv_indev_get_vect(indev, &vect);
lv_coord_t x = lv_obj_get_x(obj) + vect.x;
lv_coord_t y = lv_obj_get_y(obj) + vect.y;
lv_obj_set_pos(obj, x, y);
}

Others

  • **SquareLine Studio version:1.4.1
  • **Operating system:rt-thread
  • **Target hardware:stm32f407zgt6

It’s not quite clear from the description what your exact problem is, but I think it’s better to use absolute coordinates instead of movement vectors for this, so possible accumulated misalignments can be prevented. At least it’s worth a try with lv_indev_get_point() function if it serves your purpose better.

As soon as I touch the keyboard and prepare to move the keyboard, the keyboard disappears in the picture, and I can’t see the keyboard.Use the same function result as you provide (lv_indev_get_point(indev, &vect)).
The picture becomes the following appearance:

It should work, but you still need to calculate the middle of the keyboard from its size, and subtract it from the indev-coordinates before applying them to the keyboard (if you want to move with its middle, but a surrounding inactive button-less area would be better for clean grabbing).
With a printf() you can check if the coordinates from the indev are coming correctly at all. Also you can reprocess the received coordinate-values by LV_CLAMP function to always stay in the screen, even if the indev coordinates are negative or out of screen…

"LV _ CLAMP " This function “lvgl V8.3” seems to have no.

But it’s just a convenience macro, you can still limit your coordinates to the screen-resolution by a custom simple code or function.

Well, thanks for your guidance!

1 Like