Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force font size(width and height) for iconfont #90

Open
chenyinchang opened this issue Jun 19, 2023 · 5 comments
Open

Force font size(width and height) for iconfont #90

chenyinchang opened this issue Jun 19, 2023 · 5 comments

Comments

@chenyinchang
Copy link

chenyinchang commented Jun 19, 2023

I have a problem about iconfont in a long time.
I use "lv_font_conv " which convert a “my_iconfont.c” file. And then try to modify ".c" file which have "offset x" and "offset y" for aligning icons to same column. But I try my best,you can see result below here :
mmexport1687156126177

So, I want to know how force font size instead of compact format

Thanks

@chenyinchang chenyinchang changed the title Froce font size(width and height) for iconfont Force font size(width and height) for iconfont Jun 19, 2023
@kisvegabor
Copy link
Member

Is the WiFi icon + text a single label in the example?

@chenyinchang
Copy link
Author

chenyinchang commented Jun 19, 2023

Is the WiFi icon + text a single label in the example?

no, split two objects (img + label) , I use example : Complex Menu.
And I just change icon on my selection from FontAwesome symbol font and set as 16px + 4bpp to convert as ".c" files.

@chenyinchang
Copy link
Author

chenyinchang commented Jun 19, 2023

Is the WiFi icon + text a single label in the example?

no, split two objects (img + label) , I use example : Complex Menu. And I just change icon on my selection from FontAwesome symbol font and set as 16px + 4bpp to convert as ".c" files.

Event the Complex Menu example icon look really good, But I change icon to something "thin" icon for example "LV_SYMBOL_BLUETOOTH" which seems offset x :
20230619233311

@chenyinchang
Copy link
Author

chenyinchang commented Jun 19, 2023

Is the WiFi icon + text a single label in the example?

no, split two objects (img + label) , I use example : Complex Menu. And I just change icon on my selection from FontAwesome symbol font and set as 16px + 4bpp to convert as ".c" files.

As you can see, I change the partly code:
from img obj to label obj which can adjust padding for every icon

    if (icon) {
        //img = lv_img_create(obj);
        img = lv_label_create(obj);
        //lv_img_set_src(img, icon);
        lv_label_set_text(img, icon);
        lv_obj_set_style_text_font(img, &ui_font_FontAwesome5, LV_PART_MAIN | LV_STATE_DEFAULT);

        if (icon == "\xEF\x83\xAB")
        {
            lv_obj_set_style_pad_left(img, 3, LV_PART_MAIN | LV_STATE_DEFAULT);
        }
        if (icon == LV_SYMBOL_WIFI)
        {
            lv_obj_set_style_pad_left(img, -1, LV_PART_MAIN | LV_STATE_DEFAULT);
        }
    }

and I success (but even though I think a group of iconfonts which in a 'n*n' piexl box center by user setting is really useful. That means I don't have to adjust every single icon padding one by one !)
success

@kisvegabor
Copy link
Member

I think it should be solved in LVGL and not in the font converter. For v9 we will have more "image sizing options" which apply if the widget size of not the same as the mage source size. LVGL will be able to center, tile or zoom the image according to the widget size. In your case setting e.g. lv_obj_set_width(img, 50) and using a center aligned image source would solve the issue, but this feature is not implemented yet.

Until that I recommend this workaround in create_text:

    if(icon) {
        lv_obj_t * wrapper = lv_obj_create(obj);
        lv_obj_remove_style_all(wrapper);
        lv_obj_set_size(wrapper, 50, LV_SIZE_CONTENT);
        img = lv_img_create(wrapper);
        lv_img_set_src(img, icon);
        lv_obj_center(img);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants