diff --git a/docs/overview/coords.md b/docs/overview/coords.md index 4fd541ec7..7ff1df19a 100644 --- a/docs/overview/coords.md +++ b/docs/overview/coords.md @@ -5,47 +5,310 @@ # Positions, sizes, and layouts ## Overview -Inspired by CSS. -Stored in style +Similarly to many other parts of LVGL, the concept of setting the coordinates were inspired by CSS. It doesn't mean a perfect copy of the standard but parts that are reasonable were adopted in LVGL. +It shorts it means: +- the set corrdintates (size, position, layouts, etc) are stored in styles +- support min-width, max-width, min-height, max-height +- have pixel, percentage, and "content" units +- a subset of felxbox and grid layouts are supported by default + +### Units +- pixel: Simply a position in pixels. A simple integer always mean pixel. E.g. `lv_obj_set_x(btn, 10)` +- percentage: The percentage of the size of the obejct or its parent (dependeing on the property). The `lv_pct(value)` converts a value to percentage. E.g. `lv_obj_set_width(btn, lv_pct(50))` +- `LV_SIZE_CONTENT`: Specai lvalue to set the width/height of an object to involve all the children. Its similar to `auto` in CSS. E.g. `lv_obj_set_width(btn, LV_SIZE_CONTENT)`. -## Units -pixel -LV_PCT -LV_SIZE_CONTENT +### Boxing model +An object's "box" is built from the following parts: +- bounding box: the width/height of the elements. +- padding: space between the sides of the object and its children. +- content: the content area which size if the bounding box reduced by the size of the paddings. -## Boxing model -Border, padding, content +The border is drawn inside the bounding box and doesn't take an extra space. (It's different from CSS in which increasing the border width makes the object larger.) +The outline is drawn outside of the bounding box. ## Position ### Simple way -`lv_obj_set_pos/x/y` +To simple set the x and y coordinates of an object use +```c +lv_obj_set_x(obj, 10); +lv_obj_set_y(obj, 20); +lv_obj_set_pos(obj, 10, 20); //Or in one function +``` + +By default the the x and y coordinates are measured from the top left corner of the parent's content area. +For example if the parent has 5 pixel padding on every side, the above code will place `obj` to (15, 25) becasue the content area starts after the padding. + +If percentage values are calculated from the parents content area size. +```c +lv_obj_set_x(btn, lv_pct(10)); //x = 10 % of parant content area width +``` ### Align -`lv_obj_align` -`lv_obj_align_to` -`lv_obj_center` +In some cases it's convinient to change the origin of the positioning from the the default top left. If the the orogin is changed e.g. to bottom-right, the (0,0) positon means: align to the bottom-right corner. +To change the origin use: +```c +lv_obj_set_align(obj, align); +``` -### Translate positon +To change the alignment and set new coordiantes: +```c +lv_obj_align(obj, align, x, y); +``` + +The following alignment options can be used: +- `LV_ALIGN_TOP_LEFT` +- `LV_ALIGN_TOP_MID` +- `LV_ALIGN_TOP_RIGHT` +- `LV_ALIGN_BOTTOM_LEFT` +- `LV_ALIGN_BOTTOM_MID` +- `LV_ALIGN_BOTTOM_RIGHT` +- `LV_ALIGN_LEFT_MID` +- `LV_ALIGN_RIGHT_MID` +- `LV_ALIGN_CENTER` + +It quite common to align a children to the center of its parent, tehre fore is a dedicated function for it: +```c +lv_obj_center(obj); + +//Has the same effect +lv_obj_align(obj, LV_ALIGN_CENTER, 0, 0); +``` + +If the parent's size changes the set alignment and position of the children is applied again automatically. + +The functions introduced above aligns the obejct to its parent. However it's also possible to align an obejct to an arbitrary object. +```c +lv_obj_align_to(obj_to_align, reference_obj, align, x, y); +``` + +Besides the alignments optins above the follwing can be used to align the object outside of the refrence object: + +- `LV_ALIGN_OUT_TOP_LEFT` +- `LV_ALIGN_OUT_TOP_MID` +- `LV_ALIGN_OUT_TOP_RIGHT` +- `LV_ALIGN_OUT_BOTTOM_LEFT` +- `LV_ALIGN_OUT_BOTTOM_MID` +- `LV_ALIGN_OUT_BOTTOM_RIGHT` +- `LV_ALIGN_OUT_LEFT_TOP` +- `LV_ALIGN_OUT_LEFT_MID` +- `LV_ALIGN_OUT_LEFT_BOTTOM` +- `LV_ALIGN_OUT_RIGHT_TOP` +- `LV_ALIGN_OUT_RIGHT_MID` +- `LV_ALIGN_OUT_RIGHT_BOTTOM` + +For example to align a label above a button and center the label is horizontally: +```c +lv_obj_align_to(label, btn, LV_ALIGN_OUT_TOP_MID, 0, -10); +``` + +Not that - unlike with `lv_obj_align()` - `lv_obj_align_to()` can not realign the object if its coordinates or the reference object's coordinates changes. ## Size ### Simple way -`lv_obj_set_size/width/height/_fit` +The width and the height of an object can be set easily as well: +```c +lv_obj_set_width(obj, 200); +lv_obj_set_height(obj, 100); +lv_obj_set_size(obj, 200, 100); //Or in one function +``` -### Min/max size +Percentage values aer calculated based on the parent's content area size. For example to set the object's height to the screen height: +```c +lv_obj_set_height(obj, lv_pct(100)); +``` -### Transform width +Size setting supports a value: `LV_SIZE_CONTENT`. It means the object's size in the respective direction will be set to involv its the children. +Note that only children on the right and bottom will be considered and children o nthe top and left remains cropped. This limitation makes the behavior more predictible. + +Object with `LV_OBJ_FLAG_HIDDEN` or `LV_OBJ_FLAG_FLOATING` will be ignored by `LV_SIZE_CONTENT` calculation. + +The above functions set the size of the bounding box of the object but the size of the content area can be set as well. It means the obejct's bounding box will be larger with the paddings than the set size. +```c +lv_obj_set_content_width(obj, 50); +lv_obj_set_content_height(obj, 30); +``` + +The size of the bounding box and the content area can be get with the following functions: +```c +lv_coord_t w = lv_obj_get_width(obj); +lv_coord_t h = lv_obj_get_height(obj); +lv_coord_t content_w = lv_obj_get_content_width(obj); +lv_coord_t content_h = lv_obj_get_content_height(obj); +``` + +## Using styles +Under the hood the position, size and alignment properties are style properties. +The above described "simple functions" hide the style related code for the sake of simplicity and set the position, size, and alignment properties in the local styles of the obejct. + +However, using styles as to set the coordinates has some great advantages: +- It makes easy to set the width/height/etc for several obejct togother with ease. E.g. all make all the sliders 100x10 pixels sized. +- It also makes possibel to modify the values in one place. +- The values can be overwritten by other styles. For example `style_btn` makes the object `100x50` by default but adding `style_full_width` overwrites only the width of the object. +- The object can have different position or size in different state. E.g. 100 px wide in `LV_STATE_DEFAULT` but 120 px in `LV_STATE_PRESSED`. +- Style transitions can be used to make the coordinate changes smooth. + + +Here are some examples to set an object's size using a style: +```c +static lv_style_t style; +lv_style_init(&style); +lv_style_set_width(&style, 100); + +lv_obj_t * btn = lv_btn_create(lv_scr_act()); +lv_obj_add_style(btn, &style, LV_PART_MAIN); +``` + +As you will see below there are some other great fetures of size and position setting. +However, to keep the LVGL's API lean only the most common coordinate setting features have a "simple" version and the more complex features can be used via styles. + +### Translations and transformations + +### Translation + +Let's say the there are 3 buttons next to each other. Their position is set as described above. +Now you want to move a buttons up a little when it's pressed. + +One way to achive this is setting a new Y coordinate for pressed state: +```c +static lv_style_t style_normal; +lv_style_init(&style_normal); +lv_style_set_y(&style_normal, 100); + +static lv_style_t style_pressed; +lv_style_init(&style_pressed); +lv_style_set_y(&style_pressed, 80); + +lv_obj_add_style(btn1, &style_normal, LV_STATE_DEFAULT); +lv_obj_add_style(btn1, &style_pressed, LV_STATE_PRESSED); + +lv_obj_add_style(btn2, &style_normal, LV_STATE_DEFAULT); +lv_obj_add_style(btn2, &style_pressed, LV_STATE_PRESSED); + +lv_obj_add_style(btn3, &style_normal, LV_STATE_DEFAULT); +lv_obj_add_style(btn3, &style_pressed, LV_STATE_PRESSED); +``` + +It workes but it's not really flexible becasue the pressed coordinate is hardcoded. If the buttons are not at y=100 `style_pressed` won't work as expected. To solve this translations can be used: +```c +static lv_style_t style_normal; +lv_style_init(&style_normal); +lv_style_set_y(&style_normal, 100); + +static lv_style_t style_pressed; +lv_style_init(&style_pressed); +lv_style_set_translate_y(&style_pressed, -20); + +lv_obj_add_style(btn1, &style_normal, LV_STATE_DEFAULT); +lv_obj_add_style(btn1, &style_pressed, LV_STATE_PRESSED); + +lv_obj_add_style(btn2, &style_normal, LV_STATE_DEFAULT); +lv_obj_add_style(btn2, &style_pressed, LV_STATE_PRESSED); + +lv_obj_add_style(btn3, &style_normal, LV_STATE_DEFAULT); +lv_obj_add_style(btn3, &style_pressed, LV_STATE_PRESSED); +``` + +Translation is applied from the current position of the object. + +Perecentage values can be used in translations as well. In this case the percentage is releative to the size of the object. For example `lv_pct(50)` will move the object with half of its wifth/height. + +The translations is applied when the layouts are calcualted. Therefore, even the layouted objects' position can be translated. + +The translation actually moves the object. It means it makes the scrollbars and `LV_SIZE_CONTENT` sized objects react on the position change. + + +### Transformation +Similarly to the position the size can be changed relative to the current size as well. The transformed width and hight is added on both sides of the object. That is 10 px transformed width amkes the object 2x10 pixel larger. + +Unlike position translation, the size transformation doesn't make the object "really" larget. In other words scrollbars, layouts, `LV_SIZE_CONTENT` will not consider the transformed size. +Hence size transformation if "only" a visual effect. + +This code makes the a button larger when it's pressed: +```c +static lv_style_t style_pressed; +lv_style_init(&style_pressed); +lv_style_set_transform_width(&style_pressed, 10); +lv_style_set_transform_height(&style_pressed, 10); + +lv_obj_add_style(btn, &style_pressed, LV_STATE_PRESSED); +``` + +### Min and Max size +Similarly to CSS, LVGL also support `min-width`, `max-width`, `min-height` and `max-height`. These are limits preventing an obejct's size to be smaller/larger then these values. +They are espically useful if the size is set by percentage or `LV_SIZE_CONTENT`. +```c +static lv_style_t style_max_height; +lv_style_init(&style_max_height); +lv_style_set_y(&style_max_height, 200); + +lv_obj_set_height(obj, lv_pct(100)); +lv_obj_add_style(obj, &style_max_height, LV_STATE_DEFAULT); //Limit height to 200 +``` ## Layout ### Overview +Layouts can update the the position and size of an object's children. They can be used to automatically arrange the children into a line or column, or in much more complicated ways. + +The position and size set by the layout overwrites the "normal" x, y, width, and height settings. + +There is only one function that is the same for every layout: `lv_obj_set_layout(obj, )` sets the layout on an obejct. +For the further settings of the parent and children for a specific layout see the documentions of the given layout. ### Built-in layout +LVGL comes with two very powerful layouts: +- Flexbox +- Grid + +Both are heavily inspired by the CSS layouts with the same name. + +### Flags +There are some flags that can be used on object to affect how they behave with layouts: +- `LV_OBJ_FLAG_HIDDEN` Hidden object are ignored from layout calcualtions. +- `LV_OBJ_FLAG_IGNORE_LAYOUT` The object is simply ignored by the layouts. It's coordinate can be set as usual. +- `LV_OBJ_FLAG_FLOATING` Same as `LV_OBJ_FLAG_IGNORE_LAYOUT` but the object with `LV_OBJ_FLAG_FLOATING` will be ignored from `LV_SIZE_CONTENT` calculations. + +These falgs can be added/remoevd with `lv_obj_add/clear_flag(obj, FLAG);` ### Adding new layouts -### Examples +LVGL can be freely extended by a custom layouts like this: +```c +uint32_t MY_LAYOUT; + +... + +MY_LAYOUT = lv_layout_register(my_layout_update, &user_data); + +... + +void my_layout_update(lv_obj_t * obj, void * user_data) +{ + /*Will be called automatically if required to reposition/resize the children of "obj" */ +} +``` + +Custom style properties can be added too that can be get and used in the update callback. For example: +```c +uint32_t MY_PROP; +... + +LV_STYLE_MY_PROP = lv_style_register_prop(); + +... +static inline void lv_style_set_my_prop(lv_style_t * style, uint32_t value) +{ + lv_style_value_t v = { + .num = (int32_t)value + }; + lv_style_set_prop(style, LV_STYLE_MY_PROP, v); +} + +``` + +## Examples diff --git a/examples/widgets/btn/lv_example_btn_3.c b/examples/widgets/btn/lv_example_btn_3.c index 8b28b657b..633b52fe5 100644 --- a/examples/widgets/btn/lv_example_btn_3.c +++ b/examples/widgets/btn/lv_example_btn_3.c @@ -9,7 +9,7 @@ void lv_example_btn_3(void) { /*Properties to transition*/ static lv_style_prop_t props[] = { - LV_STYLE_TRANSFORM_WIDTH, LV_STYLE_TRANSFORM_HEIGHT, LV_STYLE_TEXT_LETTER_SPACE, 0 + LV_STYLE_TRANSLATE_WIDTH, LV_STYLE_TRANSLATE_HEIGHT, LV_STYLE_TEXT_LETTER_SPACE, 0 }; /*Transition descriptor when going back to the default state. diff --git a/examples/widgets/imgbtn/lv_example_imgbtn_1.c b/examples/widgets/imgbtn/lv_example_imgbtn_1.c index ef51b3f5c..f4cdfbac8 100644 --- a/examples/widgets/imgbtn/lv_example_imgbtn_1.c +++ b/examples/widgets/imgbtn/lv_example_imgbtn_1.c @@ -8,7 +8,7 @@ void lv_example_imgbtn_1(void) LV_IMG_DECLARE(imgbtn_mid); /*Create a transition animation on width transformation and recolor.*/ - static lv_style_prop_t tr_prop[] = {LV_STYLE_TRANSFORM_WIDTH, LV_STYLE_IMG_RECOLOR_OPA, 0}; + static lv_style_prop_t tr_prop[] = {LV_STYLE_TRANSLATE_WIDTH, LV_STYLE_IMG_RECOLOR_OPA, 0}; static lv_style_transition_dsc_t tr; lv_style_transition_dsc_init(&tr, tr_prop, lv_anim_path_linear, 200, 0); diff --git a/scripts/style_api_gen.py b/scripts/style_api_gen.py index 007696996..adb41ccd8 100755 --- a/scripts/style_api_gen.py +++ b/scripts/style_api_gen.py @@ -7,8 +7,8 @@ props = [ {'name': 'CLIP_CORNER', 'style_type': 'num', 'var_type': 'bool' }, {'name': 'TRANSFORM_WIDTH', 'style_type': 'num', 'var_type': 'lv_coord_t' }, {'name': 'TRANSFORM_HEIGHT', 'style_type': 'num', 'var_type': 'lv_coord_t' }, -{'name': 'TRANSFORM_X', 'style_type': 'num', 'var_type': 'lv_coord_t' }, -{'name': 'TRANSFORM_Y', 'style_type': 'num', 'var_type': 'lv_coord_t' }, +{'name': 'TRANSLATE_X', 'style_type': 'num', 'var_type': 'lv_coord_t' }, +{'name': 'TRANSLATE_Y', 'style_type': 'num', 'var_type': 'lv_coord_t' }, {'name': 'TRANSFORM_ZOOM', 'style_type': 'num', 'var_type': 'lv_coord_t' }, {'name': 'TRANSFORM_ANGLE', 'style_type': 'num', 'var_type': 'lv_coord_t' }, {'name': 'OPA', 'style_type': 'num', 'var_type': 'lv_opa_t' }, diff --git a/src/core/lv_obj_pos.c b/src/core/lv_obj_pos.c index 51414f896..faf28c66d 100644 --- a/src/core/lv_obj_pos.c +++ b/src/core/lv_obj_pos.c @@ -113,7 +113,7 @@ void lv_obj_refr_size(lv_obj_t * obj) /*Calculate the sizes in percentage*/ bool pct_w = LV_COORD_IS_PCT(w) ? true : false; - lv_coord_t parent_w = lv_obj_get_width_fit(parent); + lv_coord_t parent_w = lv_obj_get_content_width(parent); if(pct_w) w = (LV_COORD_GET_PCT(w) * parent_w) / 100; lv_coord_t minw = lv_obj_get_style_min_width(obj, LV_PART_MAIN); @@ -138,7 +138,7 @@ void lv_obj_refr_size(lv_obj_t * obj) /*Calculate the sizes in percentage*/ bool pct_h = LV_COORD_IS_PCT(h) ? true : false; - lv_coord_t parent_h = lv_obj_get_height_fit(parent); + lv_coord_t parent_h = lv_obj_get_content_height(parent); if(pct_h) h = (LV_COORD_GET_PCT(h) * parent_h) / 100; lv_coord_t minh = lv_obj_get_style_min_height(obj, LV_PART_MAIN); @@ -164,7 +164,7 @@ void lv_obj_refr_size(lv_obj_t * obj) /*Check if the object inside the parent or not*/ lv_area_t parent_fit_area; - lv_obj_get_coords_fit(parent, &parent_fit_area); + lv_obj_get_content_coords(parent, &parent_fit_area); /*If the object is already out of the parent and its position is changes *surely the scrollbars also changes so invalidate them*/ @@ -317,6 +317,11 @@ uint32_t lv_layout_register(lv_layout_update_cb_t cb, void * user_data) return layout_cnt; /*No -1 to skip 0th index*/ } +void lv_obj_set_align(struct _lv_obj_t * obj, lv_align_t align) +{ + lv_obj_set_style_align(obj, align, 0); +} + void lv_obj_align(lv_obj_t * obj, lv_align_t align, lv_coord_t x_ofs, lv_coord_t y_ofs) { lv_obj_set_style_align(obj, align, 0); @@ -339,45 +344,45 @@ void lv_obj_align_to(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv lv_coord_t ptop = lv_obj_get_style_pad_top(parent, LV_PART_MAIN); switch(align) { case LV_ALIGN_CENTER: - x = lv_obj_get_width_fit(base) / 2 - lv_obj_get_width(obj) / 2; - y = lv_obj_get_height_fit(base) / 2 - lv_obj_get_height(obj) / 2; + x = lv_obj_get_content_width(base) / 2 - lv_obj_get_width(obj) / 2; + y = lv_obj_get_content_height(base) / 2 - lv_obj_get_height(obj) / 2; break; case LV_ALIGN_TOP_LEFT: x = 0; y = 0; break; case LV_ALIGN_TOP_MID: - x = lv_obj_get_width_fit(base) / 2 - lv_obj_get_width(obj) / 2; + x = lv_obj_get_content_width(base) / 2 - lv_obj_get_width(obj) / 2; y = 0; break; case LV_ALIGN_TOP_RIGHT: - x = lv_obj_get_width_fit(base) - lv_obj_get_width(obj); + x = lv_obj_get_content_width(base) - lv_obj_get_width(obj); y = 0; break; case LV_ALIGN_BOTTOM_LEFT: x = 0; - y = lv_obj_get_height_fit(base) - lv_obj_get_height(obj); + y = lv_obj_get_content_height(base) - lv_obj_get_height(obj); break; case LV_ALIGN_BOTTOM_MID: - x = lv_obj_get_width_fit(base) / 2 - lv_obj_get_width(obj) / 2; - y = lv_obj_get_height_fit(base) - lv_obj_get_height(obj); + x = lv_obj_get_content_width(base) / 2 - lv_obj_get_width(obj) / 2; + y = lv_obj_get_content_height(base) - lv_obj_get_height(obj); break; case LV_ALIGN_BOTTOM_RIGHT: - x = lv_obj_get_width_fit(base) - lv_obj_get_width(obj); - y = lv_obj_get_height_fit(base) - lv_obj_get_height(obj); + x = lv_obj_get_content_width(base) - lv_obj_get_width(obj); + y = lv_obj_get_content_height(base) - lv_obj_get_height(obj); break; case LV_ALIGN_LEFT_MID: x = 0; - y = lv_obj_get_height_fit(base) / 2 - lv_obj_get_height(obj) / 2; + y = lv_obj_get_content_height(base) / 2 - lv_obj_get_height(obj) / 2; break; case LV_ALIGN_RIGHT_MID: - x = lv_obj_get_width_fit(base) - lv_obj_get_width(obj); - y = lv_obj_get_height_fit(base) / 2 - lv_obj_get_height(obj) / 2; + x = lv_obj_get_content_width(base) - lv_obj_get_width(obj); + y = lv_obj_get_content_height(base) / 2 - lv_obj_get_height(obj) / 2; break; case LV_ALIGN_OUT_TOP_LEFT: @@ -517,7 +522,7 @@ lv_coord_t lv_obj_get_height(const lv_obj_t * obj) return lv_area_get_height(&obj->coords); } -lv_coord_t lv_obj_get_width_fit(const lv_obj_t * obj) +lv_coord_t lv_obj_get_content_width(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -527,7 +532,7 @@ lv_coord_t lv_obj_get_width_fit(const lv_obj_t * obj) return lv_obj_get_width(obj) - left - right; } -lv_coord_t lv_obj_get_height_fit(const lv_obj_t * obj) +lv_coord_t lv_obj_get_content_height(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -537,7 +542,7 @@ lv_coord_t lv_obj_get_height_fit(const lv_obj_t * obj) return lv_obj_get_height(obj) - top - bottom; } -void lv_obj_get_coords_fit(const lv_obj_t * obj, lv_area_t * area) +void lv_obj_get_content_coords(const lv_obj_t * obj, lv_area_t * area) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -587,14 +592,14 @@ void lv_obj_refr_pos(lv_obj_t * obj) } /*Handle percentage value*/ - lv_coord_t pw = lv_obj_get_width_fit(parent); - lv_coord_t ph = lv_obj_get_height_fit(parent); + lv_coord_t pw = lv_obj_get_content_width(parent); + lv_coord_t ph = lv_obj_get_content_height(parent); if(LV_COORD_IS_PCT(x)) x = (pw * LV_COORD_GET_PCT(x)) / 100; if(LV_COORD_IS_PCT(y)) y = (ph * LV_COORD_GET_PCT(y)) / 100; /*Handle percentage value of translate*/ - lv_coord_t tr_x = lv_obj_get_style_transform_x(obj, LV_PART_MAIN); - lv_coord_t tr_y = lv_obj_get_style_transform_y(obj, LV_PART_MAIN); + lv_coord_t tr_x = lv_obj_get_style_translate_x(obj, LV_PART_MAIN); + lv_coord_t tr_y = lv_obj_get_style_translate_y(obj, LV_PART_MAIN); lv_coord_t w = lv_obj_get_width(obj); lv_coord_t h = lv_obj_get_height(obj); if(LV_COORD_IS_PCT(tr_x)) tr_x = (w * LV_COORD_GET_PCT(tr_x)) / 100; @@ -685,7 +690,7 @@ void lv_obj_move_to(lv_obj_t * obj, lv_coord_t x, lv_coord_t y) lv_area_t parent_fit_area; bool on1 = false; if(parent) { - lv_obj_get_coords_fit(parent, &parent_fit_area); + lv_obj_get_content_coords(parent, &parent_fit_area); /*If the object is already out of the parent and its position is changes *surely the scrollbars also changes so invalidate them*/ diff --git a/src/core/lv_obj_pos.h b/src/core/lv_obj_pos.h index c5e23de8b..70bb6cfcb 100644 --- a/src/core/lv_obj_pos.h +++ b/src/core/lv_obj_pos.h @@ -77,7 +77,7 @@ void lv_obj_refr_size(struct _lv_obj_t * obj); * @note possible values are: * pixel simple set the size accordingly * LV_SIZE_CONTENT set the size to involve all children in the given direction - * LV_SIZE_PCT(x) to set size in percentage of the parent's content area size (the size without paddings). + * lv_pct(x) to set size in percentage of the parent's content area size (the size without paddings). * x should be in [0..1000]% range */ void lv_obj_set_width(struct _lv_obj_t * obj, lv_coord_t w); @@ -89,7 +89,7 @@ void lv_obj_set_width(struct _lv_obj_t * obj, lv_coord_t w); * @note possible values are: * pixel simple set the size accordingly * LV_SIZE_CONTENT set the size to involve all children in the given direction - * LV_SIZE_PCT(x) to set size in percentage of the parent's content area size (the size without paddings). + * lv_pct(x) to set size in percentage of the parent's content area size (the size without paddings). * x should be in [0..1000]% range */ void lv_obj_set_height(struct _lv_obj_t * obj, lv_coord_t h); @@ -143,7 +143,17 @@ void lv_obj_update_layout(const struct _lv_obj_t * obj); uint32_t lv_layout_register(lv_layout_update_cb_t cb, void * user_data); /** - * Align an object to an other object. + * Change the alignment of an object. + * @param obj pointer to an object to align + * @param align type of alignment (see 'lv_align_t' enum) `LV_ALIGN_OUT_...` can't be used. + */ +void lv_obj_set_align(struct _lv_obj_t * obj, lv_align_t align); + +/** + * Change the alignment of an object and set new coordinates. + * Equivalent to: + * lv_obj_set_align(obj, align); + * lv_obj_set_pos(obj, x_ofs, y_ofs); * @param obj pointer to an object to align * @param align type of alignment (see 'lv_align_t' enum) `LV_ALIGN_OUT_...` can't be used. * @param x_ofs x coordinate offset after alignment @@ -239,21 +249,21 @@ lv_coord_t lv_obj_get_height(const struct _lv_obj_t * obj); * @param obj pointer to an object * @return the width which still fits into its parent without causing overflow (making the parent scrollable) */ -lv_coord_t lv_obj_get_width_fit(const struct _lv_obj_t * obj); +lv_coord_t lv_obj_get_content_width(const struct _lv_obj_t * obj); /** * Get the height reduced by the top an bottom padding. * @param obj pointer to an object * @return the height which still fits into the parent without causing overflow (making the parent scrollable) */ -lv_coord_t lv_obj_get_height_fit(const struct _lv_obj_t * obj); +lv_coord_t lv_obj_get_content_height(const struct _lv_obj_t * obj); /** * Get the area reduced by the paddings. * @param obj pointer to an object * @param area the area which still fits into the parent without causing overflow (making the parent scrollable) */ -void lv_obj_get_coords_fit(const struct _lv_obj_t * obj, lv_area_t * area); +void lv_obj_get_content_coords(const struct _lv_obj_t * obj, lv_area_t * area); /** * Get the width occupied by the "parts" of the widget. E.g. the width of all columns of a table. diff --git a/src/core/lv_obj_style.c b/src/core/lv_obj_style.c index 7d0201476..2c1892354 100644 --- a/src/core/lv_obj_style.c +++ b/src/core/lv_obj_style.c @@ -385,10 +385,10 @@ _lv_style_state_cmp_t _lv_obj_style_state_compare(lv_obj_t * obj, lv_state_t sta } /*Check for draw pad changes*/ - if(lv_style_get_prop(style, LV_STYLE_TRANSFORM_WIDTH, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD; - else if(lv_style_get_prop(style, LV_STYLE_TRANSFORM_HEIGHT, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD; - else if(lv_style_get_prop(style, LV_STYLE_TRANSFORM_ANGLE, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD; - else if(lv_style_get_prop(style, LV_STYLE_TRANSFORM_ZOOM, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD; + if(lv_style_get_prop(style, LV_STYLE_TRANSLATE_WIDTH, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD; + else if(lv_style_get_prop(style, LV_STYLE_TRANSLATE_HEIGHT, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD; + else if(lv_style_get_prop(style, LV_STYLE_TRANSLATE_ANGLE, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD; + else if(lv_style_get_prop(style, LV_STYLE_TRANSLATE_ZOOM, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD; else if(lv_style_get_prop(style, LV_STYLE_OUTLINE_OPA, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD; else if(lv_style_get_prop(style, LV_STYLE_OUTLINE_PAD, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD; else if(lv_style_get_prop(style, LV_STYLE_SHADOW_WIDTH, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD; diff --git a/src/core/lv_obj_style_gen.h b/src/core/lv_obj_style_gen.h index 0925a33d0..aace0c9d9 100644 --- a/src/core/lv_obj_style_gen.h +++ b/src/core/lv_obj_style_gen.h @@ -12,37 +12,37 @@ static inline bool lv_obj_get_style_clip_corner(const struct _lv_obj_t * obj, ui static inline lv_coord_t lv_obj_get_style_transform_width(const struct _lv_obj_t * obj, uint32_t part) { - lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSFORM_WIDTH); + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSLATE_WIDTH); return (lv_coord_t)v.num; } static inline lv_coord_t lv_obj_get_style_transform_height(const struct _lv_obj_t * obj, uint32_t part) { - lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSFORM_HEIGHT); + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSLATE_HEIGHT); return (lv_coord_t)v.num; } -static inline lv_coord_t lv_obj_get_style_transform_x(const struct _lv_obj_t * obj, uint32_t part) +static inline lv_coord_t lv_obj_get_style_translate_x(const struct _lv_obj_t * obj, uint32_t part) { - lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSFORM_X); + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSLATE_X); return (lv_coord_t)v.num; } -static inline lv_coord_t lv_obj_get_style_transform_y(const struct _lv_obj_t * obj, uint32_t part) +static inline lv_coord_t lv_obj_get_style_translate_y(const struct _lv_obj_t * obj, uint32_t part) { - lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSFORM_Y); + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSLATE_Y); return (lv_coord_t)v.num; } static inline lv_coord_t lv_obj_get_style_transform_zoom(const struct _lv_obj_t * obj, uint32_t part) { - lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSFORM_ZOOM); + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSLATE_ZOOM); return (lv_coord_t)v.num; } static inline lv_coord_t lv_obj_get_style_transform_angle(const struct _lv_obj_t * obj, uint32_t part) { - lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSFORM_ANGLE); + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSLATE_ANGLE); return (lv_coord_t)v.num; } @@ -541,7 +541,7 @@ static inline void lv_obj_set_style_transform_width(struct _lv_obj_t * obj, lv_c lv_style_value_t v = { .num = (int32_t)value }; - lv_obj_set_local_style_prop(obj, LV_STYLE_TRANSFORM_WIDTH, v, selector); + lv_obj_set_local_style_prop(obj, LV_STYLE_TRANSLATE_WIDTH, v, selector); } static inline void lv_obj_set_style_transform_height(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) @@ -549,23 +549,23 @@ static inline void lv_obj_set_style_transform_height(struct _lv_obj_t * obj, lv_ lv_style_value_t v = { .num = (int32_t)value }; - lv_obj_set_local_style_prop(obj, LV_STYLE_TRANSFORM_HEIGHT, v, selector); + lv_obj_set_local_style_prop(obj, LV_STYLE_TRANSLATE_HEIGHT, v, selector); } -static inline void lv_obj_set_style_transform_x(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) +static inline void lv_obj_set_style_translate_x(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) { lv_style_value_t v = { .num = (int32_t)value }; - lv_obj_set_local_style_prop(obj, LV_STYLE_TRANSFORM_X, v, selector); + lv_obj_set_local_style_prop(obj, LV_STYLE_TRANSLATE_X, v, selector); } -static inline void lv_obj_set_style_transform_y(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) +static inline void lv_obj_set_style_translate_y(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) { lv_style_value_t v = { .num = (int32_t)value }; - lv_obj_set_local_style_prop(obj, LV_STYLE_TRANSFORM_Y, v, selector); + lv_obj_set_local_style_prop(obj, LV_STYLE_TRANSLATE_Y, v, selector); } static inline void lv_obj_set_style_transform_zoom(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) @@ -573,7 +573,7 @@ static inline void lv_obj_set_style_transform_zoom(struct _lv_obj_t * obj, lv_co lv_style_value_t v = { .num = (int32_t)value }; - lv_obj_set_local_style_prop(obj, LV_STYLE_TRANSFORM_ZOOM, v, selector); + lv_obj_set_local_style_prop(obj, LV_STYLE_TRANSLATE_ZOOM, v, selector); } static inline void lv_obj_set_style_transform_angle(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) @@ -581,7 +581,7 @@ static inline void lv_obj_set_style_transform_angle(struct _lv_obj_t * obj, lv_c lv_style_value_t v = { .num = (int32_t)value }; - lv_obj_set_local_style_prop(obj, LV_STYLE_TRANSFORM_ANGLE, v, selector); + lv_obj_set_local_style_prop(obj, LV_STYLE_TRANSLATE_ANGLE, v, selector); } static inline void lv_obj_set_style_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector) diff --git a/src/core/lv_theme.h b/src/core/lv_theme.h index c46617db1..8c5a01838 100644 --- a/src/core/lv_theme.h +++ b/src/core/lv_theme.h @@ -40,6 +40,7 @@ typedef struct _lv_theme_t { const lv_font_t * font_small; const lv_font_t * font_normal; const lv_font_t * font_large; + uint32_t flags; /*Any custom flag used by the theme*/ } lv_theme_t; /********************** diff --git a/src/extra/layouts/flex/lv_flex.c b/src/extra/layouts/flex/lv_flex.c index b07330569..3bee4807e 100644 --- a/src/extra/layouts/flex/lv_flex.c +++ b/src/extra/layouts/flex/lv_flex.c @@ -136,7 +136,7 @@ static void flex_update(lv_obj_t * cont, void * user_data) bool rtl = lv_obj_get_base_dir(cont) == LV_BIDI_DIR_RTL ? true : false; lv_coord_t track_gap = !f.row ? lv_obj_get_style_pad_column(cont, LV_PART_MAIN) : lv_obj_get_style_pad_row(cont, LV_PART_MAIN); lv_coord_t item_gap = f.row ? lv_obj_get_style_pad_column(cont, LV_PART_MAIN) : lv_obj_get_style_pad_row(cont, LV_PART_MAIN); - lv_coord_t max_main_size = (f.row ? lv_obj_get_width_fit(cont) : lv_obj_get_height_fit(cont)); + lv_coord_t max_main_size = (f.row ? lv_obj_get_content_width(cont) : lv_obj_get_content_height(cont)); lv_coord_t abs_y = cont->coords.y1 + lv_obj_get_style_pad_top(cont, LV_PART_MAIN) - lv_obj_get_scroll_y(cont); lv_coord_t abs_x = cont->coords.x1 + lv_obj_get_style_pad_left(cont, LV_PART_MAIN) - lv_obj_get_scroll_x(cont); @@ -178,7 +178,7 @@ static void flex_update(lv_obj_t * cont, void * user_data) if(track_cnt) total_track_cross_size -= track_gap; /*No gap after the last track*/ /*Place the tracks to get the start position*/ - lv_coord_t max_cross_size = (f.row ? lv_obj_get_height_fit(cont) : lv_obj_get_width_fit(cont)); + lv_coord_t max_cross_size = (f.row ? lv_obj_get_content_height(cont) : lv_obj_get_content_width(cont)); place_content(track_cross_place, max_cross_size, total_track_cross_size, track_cnt, cross_pos, &gap); } @@ -401,8 +401,8 @@ static void children_repos(lv_obj_t * cont, flex_t * f, int32_t item_first_id, i /*Handle percentage value of translate*/ - lv_coord_t tr_x = lv_obj_get_style_transform_x(item, LV_PART_MAIN); - lv_coord_t tr_y = lv_obj_get_style_transform_y(item, LV_PART_MAIN); + lv_coord_t tr_x = lv_obj_get_style_translate_x(item, LV_PART_MAIN); + lv_coord_t tr_y = lv_obj_get_style_translate_y(item, LV_PART_MAIN); lv_coord_t w = lv_obj_get_width(item); lv_coord_t h = lv_obj_get_height(item); if(LV_COORD_IS_PCT(tr_x)) tr_x = (w * LV_COORD_GET_PCT(tr_x)) / 100; diff --git a/src/extra/layouts/flex/lv_flex.h b/src/extra/layouts/flex/lv_flex.h index f5f1ae586..679e989bd 100644 --- a/src/extra/layouts/flex/lv_flex.h +++ b/src/extra/layouts/flex/lv_flex.h @@ -97,8 +97,6 @@ void lv_obj_set_flex_place(lv_obj_t * obj, lv_flex_place_t main_place, lv_flex_p */ void lv_obj_set_flex_grow(lv_obj_t * obj, uint8_t grow); - - static inline void lv_style_set_flex_flow(lv_style_t * style, lv_flex_flow_t value) { lv_style_value_t v = { diff --git a/src/extra/layouts/grid/lv_grid.c b/src/extra/layouts/grid/lv_grid.c index 89c92afd4..73a69470b 100644 --- a/src/extra/layouts/grid/lv_grid.c +++ b/src/extra/layouts/grid/lv_grid.c @@ -208,11 +208,11 @@ static void calc(struct _lv_obj_t * cont, _lv_grid_calc_t * calc_out) lv_coord_t w_set = lv_obj_get_style_width(cont, LV_PART_MAIN); lv_coord_t h_set = lv_obj_get_style_height(cont, LV_PART_MAIN); bool auto_w = w_set == LV_SIZE_CONTENT ? true : false; - lv_coord_t cont_w = lv_obj_get_width_fit(cont); + lv_coord_t cont_w = lv_obj_get_content_width(cont); calc_out->grid_w = grid_place(cont_w, auto_w, get_grid_col_place(cont), col_gap, calc_out->col_num, calc_out->w, calc_out->x, rev); bool auto_h = h_set == LV_SIZE_CONTENT ? true : false; - lv_coord_t cont_h = lv_obj_get_height_fit(cont); + lv_coord_t cont_h = lv_obj_get_content_height(cont); calc_out->grid_h = grid_place(cont_h, auto_h, get_grid_row_place(cont), row_gap, calc_out->row_num, calc_out->h, calc_out->y, false); LV_ASSERT_MEM_INTEGRITY(); @@ -233,7 +233,7 @@ static void calc_free(_lv_grid_calc_t * calc) static void calc_cols(lv_obj_t * cont, _lv_grid_calc_t * c) { const lv_coord_t * col_templ = get_col_dsc(cont); - lv_coord_t cont_w = lv_obj_get_width_fit(cont); + lv_coord_t cont_w = lv_obj_get_content_width(cont); c->col_num = count_tracks(col_templ); c->x = lv_mem_buf_get(sizeof(lv_coord_t) * c->col_num); @@ -338,7 +338,7 @@ static void calc_rows(lv_obj_t * cont, _lv_grid_calc_t * c) } lv_coord_t row_gap = lv_obj_get_style_pad_row(cont, LV_PART_MAIN); - lv_coord_t cont_h = lv_obj_get_height_fit(cont) - row_gap * (c->row_num - 1); + lv_coord_t cont_h = lv_obj_get_content_height(cont) - row_gap * (c->row_num - 1); lv_coord_t free_h = cont_h - grid_h; if(free_h < 0) free_h = 0; @@ -447,8 +447,8 @@ static void item_repos(lv_obj_t * item, _lv_grid_calc_t * c, item_repos_hint_t * } /*Handle percentage value of translate*/ - lv_coord_t tr_x = lv_obj_get_style_transform_x(item, LV_PART_MAIN); - lv_coord_t tr_y = lv_obj_get_style_transform_y(item, LV_PART_MAIN); + lv_coord_t tr_x = lv_obj_get_style_translate_x(item, LV_PART_MAIN); + lv_coord_t tr_y = lv_obj_get_style_translate_y(item, LV_PART_MAIN); lv_coord_t w = lv_obj_get_width(item); lv_coord_t h = lv_obj_get_height(item); if(LV_COORD_IS_PCT(tr_x)) tr_x = (w * LV_COORD_GET_PCT(tr_x)) / 100; diff --git a/src/extra/widgets/msgbox/lv_msgbox.c b/src/extra/widgets/msgbox/lv_msgbox.c index 224dd57a5..862419fae 100644 --- a/src/extra/widgets/msgbox/lv_msgbox.c +++ b/src/extra/widgets/msgbox/lv_msgbox.c @@ -53,7 +53,7 @@ lv_obj_t * lv_msgbox_create(const char * title, const char * txt, const char * b LV_ASSERT_MALLOC(mbox); if(mbox == NULL) return NULL; - lv_coord_t w = lv_obj_get_width_fit(parent); + lv_coord_t w = lv_obj_get_content_width(parent); if(w > 2 * LV_DPI_DEF) w = 2 * LV_DPI_DEF; lv_obj_set_size(mbox, w, LV_SIZE_CONTENT); diff --git a/src/extra/widgets/tabview/lv_tabview.c b/src/extra/widgets/tabview/lv_tabview.c index 8acc34329..452812864 100644 --- a/src/extra/widgets/tabview/lv_tabview.c +++ b/src/extra/widgets/tabview/lv_tabview.c @@ -245,7 +245,7 @@ static void cont_scroll_end_event_cb(lv_event_t * e) lv_point_t p; lv_obj_get_scroll_end(cont, &p); - lv_coord_t w = lv_obj_get_width_fit(cont); + lv_coord_t w = lv_obj_get_content_width(cont); lv_coord_t t = (p.x + w/ 2) / w; if(t < 0) t = 0; lv_tabview_set_act(tv, t, LV_ANIM_ON); diff --git a/src/extra/widgets/tileview/lv_tileview.c b/src/extra/widgets/tileview/lv_tileview.c index ba45b5e2c..9975b6619 100644 --- a/src/extra/widgets/tileview/lv_tileview.c +++ b/src/extra/widgets/tileview/lv_tileview.c @@ -77,8 +77,8 @@ void lv_obj_set_tile(lv_obj_t * tv, lv_obj_t * tile_obj, lv_anim_enable_t anim_e void lv_obj_set_tile_id(lv_obj_t * tv, uint32_t col_id, uint32_t row_id, lv_anim_enable_t anim_en) { - lv_coord_t w = lv_obj_get_width_fit(tv); - lv_coord_t h = lv_obj_get_height_fit(tv); + lv_coord_t w = lv_obj_get_content_width(tv); + lv_coord_t h = lv_obj_get_content_height(tv); lv_coord_t tx = col_id * w; lv_coord_t ty = row_id * h; @@ -117,7 +117,7 @@ static void lv_tileview_tile_constructor(const lv_obj_class_t * class_p, lv_obj_ LV_UNUSED(class_p); lv_obj_t * parent = lv_obj_get_parent(obj); lv_obj_set_size(obj, LV_PCT(100), LV_PCT(100)); - lv_obj_set_pos(obj, create_col_id * lv_obj_get_width_fit(parent), create_row_id * lv_obj_get_height_fit(parent)); + lv_obj_set_pos(obj, create_col_id * lv_obj_get_content_width(parent), create_row_id * lv_obj_get_content_height(parent)); lv_tileview_tile_t * tile = (lv_tileview_tile_t *)obj; tile->dir = create_dir; @@ -132,8 +132,8 @@ static void tileview_event_cb(lv_event_t * e) lv_event_code_t code = lv_event_get_code(e); lv_obj_t * tv = lv_event_get_target(e); if(code == LV_EVENT_SCROLL_END) { - lv_coord_t w = lv_obj_get_width_fit(tv); - lv_coord_t h = lv_obj_get_height_fit(tv); + lv_coord_t w = lv_obj_get_content_width(tv); + lv_coord_t h = lv_obj_get_content_height(tv); lv_point_t scroll_end; lv_obj_get_scroll_end(tv, &scroll_end); diff --git a/src/misc/lv_style.c b/src/misc/lv_style.c index b195080bd..0239a980e 100644 --- a/src/misc/lv_style.c +++ b/src/misc/lv_style.c @@ -198,11 +198,11 @@ lv_res_t lv_style_get_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_va return lv_style_get_prop_inlined(style, prop, value); } -void lv_style_transition_dsc_init(lv_style_transition_dsc_t * tr, const lv_style_prop_t * props, lv_anim_path_cb_t path_xcb, uint32_t time, uint32_t delay) +void lv_style_transition_dsc_init(lv_style_transition_dsc_t * tr, const lv_style_prop_t * props, lv_anim_path_cb_t path_cb, uint32_t time, uint32_t delay) { lv_memset_00(tr, sizeof(lv_style_transition_dsc_t)); tr->props = props; - tr->path_cb = path_xcb == NULL ? lv_anim_path_linear : path_xcb; + tr->path_cb = path_cb == NULL ? lv_anim_path_linear : path_cb; tr->time = time; tr->delay = delay; } @@ -211,7 +211,7 @@ lv_style_value_t lv_style_prop_get_default(lv_style_prop_t prop) { lv_style_value_t value; switch(prop) { - case LV_STYLE_TRANSFORM_ZOOM: + case LV_STYLE_TRANSLATE_ZOOM: value.num = LV_IMG_ZOOM_NONE; break; case LV_STYLE_BG_COLOR: diff --git a/src/misc/lv_style.h b/src/misc/lv_style.h index 090e03c66..9385a48af 100644 --- a/src/misc/lv_style.h +++ b/src/misc/lv_style.h @@ -114,12 +114,12 @@ typedef enum { /*Group 0*/ LV_STYLE_RADIUS = 1, LV_STYLE_CLIP_CORNER = 2, - LV_STYLE_TRANSFORM_WIDTH = 3 | LV_STYLE_PROP_EXT_DRAW, - LV_STYLE_TRANSFORM_HEIGHT = 4 | LV_STYLE_PROP_EXT_DRAW, - LV_STYLE_TRANSFORM_X = 5 | LV_STYLE_PROP_PARENT_LAYOUT_REFR, - LV_STYLE_TRANSFORM_Y = 6 | LV_STYLE_PROP_PARENT_LAYOUT_REFR, - LV_STYLE_TRANSFORM_ZOOM = 7 | LV_STYLE_PROP_EXT_DRAW, - LV_STYLE_TRANSFORM_ANGLE = 8 | LV_STYLE_PROP_EXT_DRAW, + LV_STYLE_TRANSLATE_WIDTH = 3 | LV_STYLE_PROP_EXT_DRAW, + LV_STYLE_TRANSLATE_HEIGHT = 4 | LV_STYLE_PROP_EXT_DRAW, + LV_STYLE_TRANSLATE_X = 5 | LV_STYLE_PROP_PARENT_LAYOUT_REFR, + LV_STYLE_TRANSLATE_Y = 6 | LV_STYLE_PROP_PARENT_LAYOUT_REFR, + LV_STYLE_TRANSLATE_ZOOM = 7 | LV_STYLE_PROP_EXT_DRAW, + LV_STYLE_TRANSLATE_ANGLE = 8 | LV_STYLE_PROP_EXT_DRAW, LV_STYLE_OPA = 9 | LV_STYLE_PROP_INHERIT, LV_STYLE_COLOR_FILTER_DSC = 10, diff --git a/src/misc/lv_style_gen.h b/src/misc/lv_style_gen.h index 6506a6560..b05d8371b 100644 --- a/src/misc/lv_style_gen.h +++ b/src/misc/lv_style_gen.h @@ -19,7 +19,7 @@ static inline void lv_style_set_transform_width(lv_style_t * style, lv_coord_t v lv_style_value_t v = { .num = (int32_t)value }; - lv_style_set_prop(style, LV_STYLE_TRANSFORM_WIDTH, v); + lv_style_set_prop(style, LV_STYLE_TRANSLATE_WIDTH, v); } static inline void lv_style_set_transform_height(lv_style_t * style, lv_coord_t value) @@ -27,23 +27,23 @@ static inline void lv_style_set_transform_height(lv_style_t * style, lv_coord_t lv_style_value_t v = { .num = (int32_t)value }; - lv_style_set_prop(style, LV_STYLE_TRANSFORM_HEIGHT, v); + lv_style_set_prop(style, LV_STYLE_TRANSLATE_HEIGHT, v); } -static inline void lv_style_set_transform_x(lv_style_t * style, lv_coord_t value) +static inline void lv_style_set_translate_x(lv_style_t * style, lv_coord_t value) { lv_style_value_t v = { .num = (int32_t)value }; - lv_style_set_prop(style, LV_STYLE_TRANSFORM_X, v); + lv_style_set_prop(style, LV_STYLE_TRANSLATE_X, v); } -static inline void lv_style_set_transform_y(lv_style_t * style, lv_coord_t value) +static inline void lv_style_set_translate_y(lv_style_t * style, lv_coord_t value) { lv_style_value_t v = { .num = (int32_t)value }; - lv_style_set_prop(style, LV_STYLE_TRANSFORM_Y, v); + lv_style_set_prop(style, LV_STYLE_TRANSLATE_Y, v); } static inline void lv_style_set_transform_zoom(lv_style_t * style, lv_coord_t value) @@ -51,7 +51,7 @@ static inline void lv_style_set_transform_zoom(lv_style_t * style, lv_coord_t va lv_style_value_t v = { .num = (int32_t)value }; - lv_style_set_prop(style, LV_STYLE_TRANSFORM_ZOOM, v); + lv_style_set_prop(style, LV_STYLE_TRANSLATE_ZOOM, v); } static inline void lv_style_set_transform_angle(lv_style_t * style, lv_coord_t value) @@ -59,7 +59,7 @@ static inline void lv_style_set_transform_angle(lv_style_t * style, lv_coord_t v lv_style_value_t v = { .num = (int32_t)value }; - lv_style_set_prop(style, LV_STYLE_TRANSFORM_ANGLE, v); + lv_style_set_prop(style, LV_STYLE_TRANSLATE_ANGLE, v); } static inline void lv_style_set_opa(lv_style_t * style, lv_opa_t value) diff --git a/src/widgets/lv_btnmatrix.c b/src/widgets/lv_btnmatrix.c index eed8c536c..8a38e4a51 100644 --- a/src/widgets/lv_btnmatrix.c +++ b/src/widgets/lv_btnmatrix.c @@ -103,8 +103,8 @@ void lv_btnmatrix_set_map(lv_obj_t * obj, const char * map[]) lv_coord_t prow = lv_obj_get_style_pad_row(obj, LV_PART_MAIN); lv_coord_t pcol = lv_obj_get_style_pad_column(obj, LV_PART_MAIN); - lv_coord_t max_w = lv_obj_get_width_fit(obj); - lv_coord_t max_h = lv_obj_get_height_fit(obj); + lv_coord_t max_w = lv_obj_get_content_width(obj); + lv_coord_t max_h = lv_obj_get_content_height(obj); /*Count the lines to calculate button height*/ uint8_t row_cnt = 1; diff --git a/src/widgets/lv_chart.c b/src/widgets/lv_chart.c index 3c2ae7a43..0f19e64ea 100644 --- a/src/widgets/lv_chart.c +++ b/src/widgets/lv_chart.c @@ -279,7 +279,7 @@ void lv_chart_get_point_pos_by_id(lv_obj_t * obj, lv_chart_series_t * ser, uint1 return; } - lv_coord_t w = (lv_obj_get_width_fit(obj) * chart->zoom_x) >> 8; + lv_coord_t w = (lv_obj_get_content_width(obj) * chart->zoom_x) >> 8; if(chart->type & LV_CHART_TYPE_LINE) { p_out->x = (w * id) / (chart->point_cnt - 1); @@ -305,7 +305,7 @@ void lv_chart_get_point_pos_by_id(lv_obj_t * obj, lv_chart_series_t * ser, uint1 p_out->x += lv_obj_get_style_pad_left(obj, LV_PART_MAIN); p_out->x -= lv_obj_get_scroll_left(obj); - lv_coord_t h = (lv_obj_get_height_fit(obj) * chart->zoom_y) >> 8; + lv_coord_t h = (lv_obj_get_content_height(obj) * chart->zoom_y) >> 8; p_out->y = (int32_t)((int32_t)ser->points[id] - chart->ymin[ser->y_axis]) * h; p_out->y = p_out->y / (chart->ymax[ser->y_axis] - chart->ymin[ser->y_axis]); @@ -645,8 +645,8 @@ static void lv_chart_event(lv_event_t * e) chart->tick[LV_CHART_AXIS_PRIMARY_Y].draw_size, chart->tick[LV_CHART_AXIS_SECONDARY_Y].draw_size); } else if(code == LV_EVENT_GET_SELF_SIZE) { lv_point_t * p = lv_event_get_param(e); - p->x = (lv_obj_get_width_fit(obj) * chart->zoom_x) >> 8; - p->y = (lv_obj_get_height_fit(obj) * chart->zoom_y) >> 8; + p->x = (lv_obj_get_content_width(obj) * chart->zoom_x) >> 8; + p->y = (lv_obj_get_content_height(obj) * chart->zoom_y) >> 8; } else if(code == LV_EVENT_DRAW_MAIN) { const lv_area_t * clip_area = lv_event_get_param(e); draw_div_lines(obj, clip_area); @@ -674,8 +674,8 @@ static void draw_div_lines(lv_obj_t * obj, const lv_area_t * clip_area) lv_point_t p2; lv_coord_t pad_left = lv_obj_get_style_pad_left(obj, LV_PART_MAIN); lv_coord_t pad_top = lv_obj_get_style_pad_top(obj, LV_PART_MAIN); - lv_coord_t w = (lv_obj_get_width_fit(obj) * chart->zoom_x) >> 8; - lv_coord_t h = (lv_obj_get_height_fit(obj) * chart->zoom_y) >> 8; + lv_coord_t w = (lv_obj_get_content_width(obj) * chart->zoom_x) >> 8; + lv_coord_t h = (lv_obj_get_content_height(obj) * chart->zoom_y) >> 8; lv_draw_line_dsc_t line_dsc; lv_draw_line_dsc_init(&line_dsc); @@ -739,8 +739,8 @@ static void draw_series_line(lv_obj_t * obj, const lv_area_t * clip_area) lv_point_t p2; lv_coord_t pad_left = lv_obj_get_style_pad_left(obj, LV_PART_MAIN); lv_coord_t pad_top = lv_obj_get_style_pad_top(obj, LV_PART_MAIN); - lv_coord_t w = (lv_obj_get_width_fit(obj) * chart->zoom_x) >> 8; - lv_coord_t h = (lv_obj_get_height_fit(obj) * chart->zoom_y) >> 8; + lv_coord_t w = (lv_obj_get_content_width(obj) * chart->zoom_x) >> 8; + lv_coord_t h = (lv_obj_get_content_height(obj) * chart->zoom_y) >> 8; lv_coord_t x_ofs = obj->coords.x1 + pad_left - lv_obj_get_scroll_left(obj); lv_coord_t y_ofs = obj->coords.y1 + pad_top - lv_obj_get_scroll_top(obj); lv_chart_series_t * ser; @@ -896,8 +896,8 @@ static void draw_series_bar(lv_obj_t * obj, const lv_area_t * clip_area) lv_area_t col_a; lv_coord_t pad_left = lv_obj_get_style_pad_left(obj, LV_PART_MAIN); lv_coord_t pad_top = lv_obj_get_style_pad_top(obj, LV_PART_MAIN); - lv_coord_t w = (lv_obj_get_width_fit(obj) * chart->zoom_x) >> 8; - lv_coord_t h = (lv_obj_get_height_fit(obj) * chart->zoom_y) >> 8; + lv_coord_t w = (lv_obj_get_content_width(obj) * chart->zoom_x) >> 8; + lv_coord_t h = (lv_obj_get_content_height(obj) * chart->zoom_y) >> 8; int32_t y_tmp; lv_chart_series_t * ser; uint32_t ser_cnt = _lv_ll_get_len(&chart->series_ll); @@ -1065,7 +1065,7 @@ static void draw_y_ticks(lv_obj_t * obj, const lv_area_t * clip_area, lv_chart_a lv_point_t p2; lv_coord_t pad_top = lv_obj_get_style_pad_top(obj, LV_PART_MAIN); - lv_coord_t h = (lv_obj_get_height_fit(obj) * chart->zoom_y) >> 8; + lv_coord_t h = (lv_obj_get_content_height(obj) * chart->zoom_y) >> 8; lv_coord_t y_ofs = obj->coords.y1 + pad_top - lv_obj_get_scroll_top(obj); lv_coord_t label_gap; @@ -1172,7 +1172,7 @@ static void draw_x_ticks(lv_obj_t * obj, const lv_area_t * clip_area) lv_point_t p2; lv_coord_t pad_left = lv_obj_get_style_pad_left(obj, LV_PART_MAIN); - lv_coord_t w = (lv_obj_get_width_fit(obj) * chart->zoom_x) >> 8; + lv_coord_t w = (lv_obj_get_content_width(obj) * chart->zoom_x) >> 8; lv_coord_t x_ofs = obj->coords.x1 + pad_left - lv_obj_get_scroll_left(obj); lv_coord_t y_ofs = obj->coords.y2; @@ -1265,7 +1265,7 @@ static void draw_axes(lv_obj_t * obj, const lv_area_t * mask) static uint32_t get_index_from_x(lv_obj_t * obj, lv_coord_t x) { lv_chart_t * chart = (lv_chart_t *)obj; - lv_coord_t w = (lv_obj_get_width_fit(obj) * chart->zoom_x) >> 8; + lv_coord_t w = (lv_obj_get_content_width(obj) * chart->zoom_x) >> 8; lv_coord_t pad_left = lv_obj_get_style_pad_left(obj, LV_PART_MAIN); x-= pad_left; @@ -1282,7 +1282,7 @@ static void invalidate_point(lv_obj_t * obj, uint16_t i) lv_chart_t * chart = (lv_chart_t *)obj; if(i >= chart->point_cnt) return; - lv_coord_t w = (lv_obj_get_width_fit(obj) * chart->zoom_x) >> 8; + lv_coord_t w = (lv_obj_get_content_width(obj) * chart->zoom_x) >> 8; lv_coord_t scroll_left = lv_obj_get_scroll_left(obj); if(chart->type == LV_CHART_TYPE_LINE) { lv_coord_t x_ofs = obj->coords.x1 + lv_obj_get_style_pad_left(obj, LV_PART_MAIN) - scroll_left; diff --git a/src/widgets/lv_dropdown.c b/src/widgets/lv_dropdown.c index 24c4c6936..8e25677b4 100644 --- a/src/widgets/lv_dropdown.c +++ b/src/widgets/lv_dropdown.c @@ -511,10 +511,10 @@ void lv_dropdown_open(lv_obj_t * dropdown_obj) lv_obj_set_x(label, 0); break; case LV_TEXT_ALIGN_RIGHT: - lv_obj_set_x(label, lv_obj_get_width_fit(dropdown->list) - lv_obj_get_width(label)); + lv_obj_set_x(label, lv_obj_get_content_width(dropdown->list) - lv_obj_get_width(label)); break; case LV_TEXT_ALIGN_CENTER: - lv_obj_set_x(label, lv_obj_get_width_fit(dropdown->list) / 2 - lv_obj_get_width(label) / 2); + lv_obj_set_x(label, lv_obj_get_content_width(dropdown->list) / 2 - lv_obj_get_width(label) / 2); break; } @@ -1029,7 +1029,7 @@ static void position_to_selected(lv_obj_t * dropdown_obj) lv_obj_t * label = get_label(dropdown_obj); if(label == NULL) return; - if(lv_obj_get_height(label) <= lv_obj_get_height_fit(dropdown_obj)) return; + if(lv_obj_get_height(label) <= lv_obj_get_content_height(dropdown_obj)) return; const lv_font_t * font = lv_obj_get_style_text_font(label, LV_PART_MAIN); lv_coord_t font_h = lv_font_get_line_height(font); diff --git a/src/widgets/lv_label.c b/src/widgets/lv_label.c index aa0a3faf3..ddec0a391 100644 --- a/src/widgets/lv_label.c +++ b/src/widgets/lv_label.c @@ -294,10 +294,10 @@ void lv_label_get_letter_pos(const lv_obj_t * obj, uint32_t char_id, lv_point_t pos->x = 0; break; case LV_TEXT_ALIGN_RIGHT: - pos->x = lv_obj_get_width_fit(obj); + pos->x = lv_obj_get_content_width(obj); break; case LV_TEXT_ALIGN_CENTER: - pos->x = lv_obj_get_width_fit(obj) / 2; + pos->x = lv_obj_get_content_width(obj) / 2; break; } return; diff --git a/src/widgets/lv_meter.c b/src/widgets/lv_meter.c index e65f0ced7..57a925af3 100644 --- a/src/widgets/lv_meter.c +++ b/src/widgets/lv_meter.c @@ -288,7 +288,7 @@ static void lv_meter_event(lv_event_t * e) if(code == LV_EVENT_DRAW_MAIN) { const lv_area_t * clip_area = lv_event_get_param(e); lv_area_t scale_area; - lv_obj_get_coords_fit(obj, &scale_area); + lv_obj_get_content_coords(obj, &scale_area); draw_arcs(obj, clip_area, &scale_area); draw_ticks_and_labels(obj, clip_area, &scale_area); @@ -617,7 +617,7 @@ static void inv_arc(lv_obj_t * obj, lv_meter_indicator_t * indic, int32_t old_va bool rounded = lv_obj_get_style_arc_rounded(obj, LV_PART_ITEMS); lv_area_t scale_area; - lv_obj_get_coords_fit(obj, &scale_area); + lv_obj_get_content_coords(obj, &scale_area); lv_coord_t r_out = lv_area_get_width(&scale_area) / 2; lv_point_t scale_center; @@ -639,7 +639,7 @@ static void inv_arc(lv_obj_t * obj, lv_meter_indicator_t * indic, int32_t old_va static void inv_line(lv_obj_t * obj, lv_meter_indicator_t * indic, int32_t value) { lv_area_t scale_area; - lv_obj_get_coords_fit(obj, &scale_area); + lv_obj_get_content_coords(obj, &scale_area); lv_coord_t r_out = lv_area_get_width(&scale_area) / 2; lv_point_t scale_center; diff --git a/src/widgets/lv_roller.c b/src/widgets/lv_roller.c index 00ba380b5..1cae20497 100644 --- a/src/widgets/lv_roller.c +++ b/src/widgets/lv_roller.c @@ -567,10 +567,10 @@ static void refr_position(lv_obj_t * obj, lv_anim_enable_t anim_en) lv_text_align_t align = lv_obj_get_style_text_align(label, LV_PART_MAIN); switch(align) { case LV_TEXT_ALIGN_CENTER: - lv_obj_set_x(label, (lv_obj_get_width_fit(obj) - lv_obj_get_width(label)) / 2); + lv_obj_set_x(label, (lv_obj_get_content_width(obj) - lv_obj_get_width(label)) / 2); break; case LV_TEXT_ALIGN_RIGHT: - lv_obj_set_x(label, lv_obj_get_width_fit(obj) - lv_obj_get_width(label)); + lv_obj_set_x(label, lv_obj_get_content_width(obj) - lv_obj_get_width(label)); break; case LV_TEXT_ALIGN_LEFT: lv_obj_set_x(label, 0); @@ -582,7 +582,7 @@ static void refr_position(lv_obj_t * obj, lv_anim_enable_t anim_en) const lv_font_t * font = lv_obj_get_style_text_font(obj, LV_PART_MAIN); lv_coord_t line_space = lv_obj_get_style_text_line_space(obj, LV_PART_MAIN); lv_coord_t font_h = lv_font_get_line_height(font); - lv_coord_t h = lv_obj_get_height_fit(obj); + lv_coord_t h = lv_obj_get_content_height(obj); uint16_t anim_time = lv_obj_get_style_anim_time(obj, LV_PART_MAIN); /*Normally the animation's `end_cb` sets correct position of the roller if infinite. @@ -707,7 +707,7 @@ static void inf_normalize(lv_obj_t * obj) const lv_font_t * font = lv_obj_get_style_text_font(obj, LV_PART_MAIN); lv_coord_t line_space = lv_obj_get_style_text_line_space(obj, LV_PART_MAIN); lv_coord_t font_h = lv_font_get_line_height(font); - lv_coord_t h = lv_obj_get_height_fit(obj); + lv_coord_t h = lv_obj_get_content_height(obj); lv_obj_t * label = get_label(obj); diff --git a/src/widgets/lv_textarea.c b/src/widgets/lv_textarea.c index 114d00786..9e0271343 100644 --- a/src/widgets/lv_textarea.c +++ b/src/widgets/lv_textarea.c @@ -410,7 +410,7 @@ void lv_textarea_set_cursor_pos(lv_obj_t * obj, int32_t pos) lv_obj_scroll_to_y(obj, cur_pos.y, LV_ANIM_ON); } /*Check the bottom*/ - lv_coord_t h = lv_obj_get_height_fit(obj); + lv_coord_t h = lv_obj_get_content_height(obj); if(cur_pos.y + font_h - lv_obj_get_scroll_top(obj) > h) { lv_obj_scroll_to_y(obj, cur_pos.y - h + font_h, LV_ANIM_ON); } @@ -855,7 +855,7 @@ static void lv_textarea_event(lv_event_t * e) else if(code == LV_EVENT_SIZE_CHANGED) { /*Set the label width according to the text area width*/ if(ta->label) { - lv_obj_set_width(ta->label, lv_obj_get_width_fit(obj)); + lv_obj_set_width(ta->label, lv_obj_get_content_width(obj)); lv_obj_set_pos(ta->label, 0, 0); lv_label_set_text(ta->label, NULL); /*Refresh the label*/