Comments (6)
pct_to_px method is my friend, thank you both for your help!
from lvgl.
Ah you're right, it's always correct for pixel values.
@leidto you can do this
print('btn x value:', lv.pct_to_px(
btn.get_x_aligned(), # value
btn.get_parent().get_width() # base
))
btn x value: 42
42 is 10% of 420, the screen width.
from lvgl.
get_x_aligned
grabs the style property for x position of the object while get_x
does a bit more to give you the real pixel value. The reason get_x_aligned
reports 536870922 is because percent values are represented as special large numbers.
I was able to get 192 with
btn.update_layout()
print('btn x value:', btn.get_x())
The update_layout
is needed to calculate the real pixel location.
The docstring for get_x_aligned
(lv_obj_get_x_aligned
) is:
/**
* Get the actually set x coordinate of object, i.e. the offset form the set alignment
* @param obj pointer to an object
* @return the set x coordinate
*/
int32_t lv_obj_get_x_aligned(const lv_obj_t * obj);
And the docstring for get_x
(lv_obj_get_x
) is:
/**
* Get the x coordinate of object.
* @param obj pointer to an object
* @return distance of `obj` from the left side of its parent plus the parent's left padding
* @note The position of the object is recalculated only on the next redraw. To force coordinate recalculation
* call `lv_obj_update_layout(obj)`.
* @note Zero return value means the object is on the left padding of the parent, and not on the left edge.
* @note Scrolling of the parent doesn't change the returned value.
* @note The returned value is always the distance from the parent even if `obj` is positioned by a layout.
*/
int32_t lv_obj_get_x(const lv_obj_t * obj);
from lvgl.
Interesting. The get_x_aligned method doesn't make much sense in this form. I'm looking for a method to get the aligned coordinates. In this case the 192 is incorrect, because is relative to the top left but I work with a centered button in this case. I'd like to get the aligned coordinates.
from lvgl.
Fair enough! In fact, get_x_aligned
doesn't do what that docstring says.
@kisvegabor should this be fixed? If so, should it call get_x
internally and then calculate the offset based on the currently set align
?
from lvgl.
The docstring says
Get the actually set x coordinate of object, i.e. the offset form the set alignment
So if you set the x offset in pixels, it will return it. If you set %, it would return that. In fact, update_layout
is not required as get_x_aligned
reads the data from the styles directly.
int32_t lv_obj_get_x_aligned(const lv_obj_t * obj)
{
return lv_obj_get_style_x(obj, LV_PART_MAIN);
}
from lvgl.
Related Issues (20)
- About the Release Date of New Versions HOT 2
- Slider Indicator Bigger Image Replacement on Press Event HOT 1
- "Does the lv_fs_dir_open function support opening directories with Chinese paths?" HOT 1
- ESP32 SPIFFS HOT 4
- animation LV_ANIM_REPEAT_INFINITE not works? HOT 1
- Overflow focus not handled correctly on full_refresh=0 HOT 1
- FPS and Fragmentation HOT 1
- How to use evdev in v9? HOT 7
- Adding border to different sides HOT 2
- Lottile on web pages https://docs.lvgl.io/master/widgets/lottie.html ,there is no button to view the C code
- Slider only changes value when moved HOT 2
- Tiny TTF lib: lv_tiny_ttf_set_size() should be removed or clear the cache HOT 14
- Input device driver callback is not working HOT 1
- X11 driver not correctly working (or I am doing it wrong) HOT 4
- Funky code in the indev pointer driver for handling rotation HOT 7
- Online Font Converter fonts not displaying correctly HOT 14
- simple container of radius one shows mixed color HOT 2
- Can lvgl support copying and pasting text using the mouse on Windows? HOT 1
- Possible bug in font-converter (or rendering text) HOT 5
- Demos widget 'Monthly Target' crashes on Elecrow ESP32 S3 Terminal HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lvgl.