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)
- Enhance dropdown lists for smaller displays HOT 2
- software rotation is not longer available in 9.x HOT 7
- Jaggy Objects HOT 1
- How to modify the coordinates of the partial refresh area? HOT 1
- Lack Of Pre_Process controlls HOT 3
- rotate180_rgb565 code optimization to yield >= 25% increase in speed HOT 14
- Scrolling list of buttons by dragging often stops until touch is released HOT 1
- LV_INDEV_MODE_EVENT is not compatible with scroll momentum HOT 3
- The placeholder text in textarea control cannot be centered! HOT 2
- Parent `height` set to `LV_SIZE_CONTENT` and child `y` position set using `LV_PCT` macro HOT 3
- How can I vertically center the content displayed in a dropdown control after adjusting its height? HOT 4
- After using the Pinyin plugin of the Chinese character library, it will crash when entering specific uppercase letters. HOT 1
- Bug: Compiler error in 9.2.0 when using LV_LIBINPUT_XKB=1 HOT 1
- It gets suck in draw_buf_flush function just like #6391 HOT 6
- Slider Knob Start Position HOT 1
- Squareline Library Mismatch HOT 1
- Behavior about col_act/row_act of pointer/button devices in lv_table.c HOT 2
- Drop-down scrolling menu optimization scheme HOT 2
- Slider Events for Knob HOT 3
- lv_obj_add_style () may crash appl HOT 3
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.