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

[FEATURE] gradient colors #782

Open
ghost opened this issue May 28, 2024 · 4 comments
Open

[FEATURE] gradient colors #782

ghost opened this issue May 28, 2024 · 4 comments

Comments

@ghost
Copy link

ghost commented May 28, 2024

Is your feature request related to a problem? Please describe.
only a static color for a foreground/background is allowed right now, which limits creativity

Describe the solution you'd like
being able to set the foreground/background color, to a horizontal/vertical/diagonal gradient.
ideally, we would have a Gradient trait with a fn get_color(pos: XY, size: XY) -> Color that would allow users to make their own gradients which would fit their needs

Describe alternatives you've considered
if having gradients isnt very important you can just use a static color, if you need them the only option is using the Canvas or writing your own View

Additional context
was already mentioned here, seems like theres no progress on it tho
i could write the code for this, but im not sure what the api should look like
heres a gist with a proof-of-concept

@gyscos
Copy link
Owner

gyscos commented May 28, 2024

Hi, and thanks for the report!

Being able to use gradients sounds very fun indeed! I haven't spent much time thinking about it though so I'm not sure yet what the API would look like - in particular:

  • How to unify the styling with the current flat colors styles
    • And possibly with a future "opacity" concept where views can be partially transparent, letting lower layers be seen through.
  • How to make it easily configurable in json/yaml for theme files
  • Support for "absolute positioning" gradient, where the gradient is defined on the entire terminal window but only applied to a single view

@gyscos
Copy link
Owner

gyscos commented Jun 28, 2024

The latest couple of commits bring some gradient features:

  • cursive::style::gradient defines a few new types:
    • Linear is a piecewise 1D (linear) gradient (converts a float between 0 and 1 to a RGB color).
    • Angled, Radial and Bilinear are 2D gradients: they assign a color to each cell of a grid (sometimes using a Linear internally).

A few places make use of these:

  • cursive::utils::markup::gradient can apply a Linear gradient to a StyledString, either for the front or background color.
  • cursive::views::GradientView takes a 2D gradient, and applies it to a wrapped view, either using local coordinates (the gradient stretches to the extend of the view), or "global" coordinates (the gradient is calculated using the absolute position of the view in the terminal), which can give nice effects when used by multiple views.

Finally, a gradient example has been added, which uses all of these.

@ghost
Copy link
Author

ghost commented Jun 29, 2024

thanks! Is there anything yet to add, or can we close the issue?

@gyscos
Copy link
Owner

gyscos commented Jul 2, 2024

thanks! Is there anything yet to add, or can we close the issue?

Well, it depends if your use-case was solved :)

There's an endless list of potential improvements: support for more 2D gradients (diamond, conical, ...), composite 2D gradients, LCH/HSB/HSL color space interpolation, more gradient presets, user-expandable list of presets that can be loaded by the builder module, animated gradients, ...

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

1 participant