ArthurSonzogni / FTXUI

:computer: C++ Functional Terminal User Interface. :heart:
MIT License
7.02k stars 427 forks source link

No access to rgb values of ftxui::Color #486

Open jdfa opened 2 years ago

jdfa commented 2 years ago

I am trying to calculate some contrast color value for certain color and facing issue that R G B values are in private section of Color class. ColorInfo might help here, but there is no way to get it from variable color.

ArthurSonzogni commented 2 years ago

Most of the time, the color is using a color palette. So the R/G/B value are not always defined.

What this would correspond is: https://github.com/ArthurSonzogni/FTXUI/blob/master/src/ftxui/screen/color.cpp#L181-L212

Out of curiosity, why do you need to "read" a color? All the data is coming from you, so you should already be aware of the values you provided. Note that ftxui provides a way to interpolate ftxui::Color:

  static Color Interpolate(float t, const Color& a, const Color& b);
jdfa commented 2 years ago

I saw Interpolate, it's not what I am looking for. And also I am working with freely defined color, not the one from palette.

My use case is somewhat similar to case in rgb-tui: There in main picking color control you have cursor which is pointing to current color. That cursor is pretty invisible in dark areas. I need to access red, green and blue channel values to calculate color, which would be visible with current background.

Same idea can be also used in some semi-transparent node decorator which can be used similarly to clear_under but would preserve part of content on background.

ArthurSonzogni commented 2 years ago

I think I would be interested adding support for this, and also to add a transparency field.

clement-roblot commented 1 year ago

Hi there,

I too have a need for a way to read back a Color object. My application is that the user can choose a theme and I want to save the chosen theme. I could indeed just save the name/id of the theme, but saving the actual colors feels more precise and would allow for fully custom themes.

For now my workaround is to Print the color and use a regex to extract the R, G and B fields. :face_with_spiral_eyes: