Page MenuHomePhabricator

evas_common: parse color in rgb()/rgba() format
ClosedPublic

Authored by ali.alzyod on Jul 12 2019, 3:22 PM.

Details

Summary

evas_common_format_color_parse: support rgb()/rgba() format

efl user can now specify colors in text formats and styles as rgb(0-255,0-255,0-255) & rgba(0-255,0-255,0-255,0-255) format.

This is related to task: T8068

Test Plan
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1

#include <Eina.h>
#include <Elementary.h>
#include <Efl_Ui.h>

static void
_gui_quit_cb(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
{
   efl_exit(0);
}

static void
_gui_setup()
{
   Eo *win, *box;

   win = efl_add(EFL_UI_WIN_CLASS, efl_main_loop_get(),
                 efl_ui_win_type_set(efl_added, EFL_UI_WIN_TYPE_BASIC),
                 efl_text_set(efl_added, "Hello World"),
                 efl_ui_win_autodel_set(efl_added, EINA_TRUE));

   // when the user clicks "close" on a window there is a request to delete
   efl_event_callback_add(win, EFL_UI_WIN_EVENT_DELETE_REQUEST, _gui_quit_cb, NULL);

   box = efl_add(EFL_UI_BOX_CLASS, win,
                efl_content_set(win, efl_added),
                efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(360, 240)));

   efl_add(EFL_UI_TEXT_CLASS, box,
           efl_text_markup_set(efl_added,
           "<color=rgb(255,0,0)>this is red color line(color = red)<color><br>"),
           efl_gfx_hint_weight_set(efl_added, 1.0, 0.9),
           efl_gfx_hint_align_set(efl_added, 0.5, 0.5),
           efl_text_multiline_set(efl_added,EINA_TRUE),
           efl_pack(box, efl_added));

   efl_add(EFL_UI_BUTTON_CLASS, box,
           efl_text_set(efl_added, "Quit"),
           efl_gfx_hint_weight_set(efl_added, 1.0, 0.1),
           efl_pack(box, efl_added),
           efl_event_callback_add(efl_added, EFL_UI_EVENT_CLICKED,
                                  _gui_quit_cb, efl_added));
}

EAPI_MAIN void
efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
{
   _gui_setup();
}
EFL_MAIN()

Diff Detail

Repository
rEFL core/efl
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
ali.alzyod created this revision.Jul 12 2019, 3:22 PM

It seems that this patch has no reviewers specified. If you are unsure who can review your patch, please check this wiki page and see if anyone can be added: https://phab.enlightenment.org/w/maintainers_reviewers/

ali.alzyod requested review of this revision.Jul 12 2019, 3:22 PM
ali.alzyod retitled this revision from evas_common: parse color in rgb() formate to evas_common: parse color in rgb() format.Jul 12 2019, 3:26 PM
ali.alzyod edited the summary of this revision. (Show Details)
ali.alzyod edited the test plan for this revision. (Show Details)
ali.alzyod edited the summary of this revision. (Show Details)Jul 16 2019, 11:32 PM
ali.alzyod updated this revision to Diff 23541.Jul 20 2019, 5:31 AM
ali.alzyod edited the summary of this revision. (Show Details)
  • rgba and rgb
ali.alzyod retitled this revision from evas_common: parse color in rgb() format to evas_common: parse color in rgb()/rgba() format.Jul 20 2019, 5:32 AM
ali.alzyod edited the summary of this revision. (Show Details)
ali.alzyod edited the summary of this revision. (Show Details)Jul 24 2019, 3:26 AM
ali.alzyod edited the summary of this revision. (Show Details)Jul 24 2019, 11:32 PM

Nice patch, could you add a test to src/tests/evas?

ali.alzyod added a comment.EditedJul 30 2019, 7:42 AM

@cedric Can you please suggest how to test this ?

I mean are there any similar case, in which you compare the output/content of canvas object with other object.

@cedric Can you please suggest how to test this ?

I was thinking of reading back the markup which I think is regenerated instead of being stored and so check that the color was properly understood.

ali.alzyod added a comment.EditedJul 31 2019, 9:55 AM

@cedric the challenge is that markup saved as it is, I mean when you set color = "anytext", it will stay "anytext" even if is not understood internally.

regard to T8086
If possible and approved I like to move same functionality to efl_gfx_color where user can set string as color and internally efl understand it.
I think efl_gfx_color already have function for efl_gfx_color_color_code_set, now we can have efl_gfx_color_string_set and it will understand any string format color for colors

@cedric the challenge is that markup saved as it is, I mean when you set color = "anytext", it will stay "anytext" even if is not understood internally.

Dang, in that case, well, I do not have any good suggestion then. Will land this then.

regard to T8086
If possible and approved I like to move same functionality to efl_gfx_color where user can set string as color and internally efl understand it.
I think efl_gfx_color already have function for efl_gfx_color_color_code_set, now we can have efl_gfx_color_string_set and it will understand any string format color for colors

That proposal make sense.

Can you rebase this patch?

It does still fail to apply for me. Could you retry?

ali.alzyod updated this revision to Diff 23860.Aug 1 2019, 4:00 PM

clear lines

cedric accepted this revision.Aug 19 2019, 11:32 AM
This revision is now accepted and ready to land.Aug 19 2019, 11:32 AM
This revision was automatically updated to reflect the committed changes.
tasn added a subscriber: tasn.Oct 8 2019, 3:27 AM

I just noticed this, and I have one major comment. I don't know if you were aiming to mirror html/css when doing this, but assume you were, you have a mistake. In CSS the alpha value of rgba() is a float between 0 and 1. You made it an int of values 0-255...

ali.alzyod added a comment.EditedOct 8 2019, 3:34 AM

This is related to T8067
At this point I am not using CSS styles, But in some point in future we will have something like evas_textblock_css_style_set("color:rgba(255,255,255,1.0);"); which will be converted to EFL style which is "color=rgba(255,255,255,255)"

I prefer using byte value since all other values are bytes too,

tasn added a comment.Oct 8 2019, 3:53 AM

OK, just wanted to flag it because it looks like css but it behaves quite differently.

ali.alzyod added a comment.EditedOct 8 2019, 7:22 AM
In D9309#192156, @tasn wrote:

OK, just wanted to flag it because it looks like css but it behaves quite differently.

Thank you for the note, I think we can make it handle the two cases (if the last parameter is a float, then expect the value to be between 0.0 - 1.0), or to be more flexible we can read any parameter in float range other than int range.

tasn added a comment.Oct 9 2019, 5:50 AM

Don't think you can do that, because rgba(255, 0, 0, 1) would behave differently to rgba(255, 0, 0, 1.0) which is hella confusing.