InputColors.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (c) 2023, MacDue <macdue@dueutil.tech>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Optional.h>
  8. #include <LibGfx/Color.h>
  9. #include <LibGfx/Palette.h>
  10. namespace Web::Painting {
  11. // Note: the color names reflect what the colors would be for a light theme,
  12. // not necessary the actual colors.
  13. struct InputColors {
  14. Color accent;
  15. Color base;
  16. Color dark_gray;
  17. Color gray;
  18. Color mid_gray;
  19. Color light_gray;
  20. Color background_color(bool enabled) { return enabled ? base : light_gray; }
  21. Color border_color(bool enabled) { return enabled ? gray : mid_gray; }
  22. static Color get_shade(Color color, float amount, bool is_dark_theme)
  23. {
  24. return color.mixed_with(is_dark_theme ? Color::Black : Color::White, amount);
  25. }
  26. };
  27. static InputColors compute_input_colors(Palette const& palette, Optional<Color> accent_color)
  28. {
  29. // These shades have been picked to work well for all themes and have enough variation to paint
  30. // all input states (disabled, enabled, checked, etc).
  31. bool dark_theme = palette.is_dark();
  32. auto base_text_color = palette.color(ColorRole::BaseText);
  33. auto accent = accent_color.value_or(palette.color(ColorRole::Accent));
  34. auto base = InputColors::get_shade(base_text_color.inverted(), 0.8f, dark_theme);
  35. auto dark_gray = InputColors::get_shade(base_text_color, 0.3f, dark_theme);
  36. auto gray = InputColors::get_shade(dark_gray, 0.4f, dark_theme);
  37. auto mid_gray = InputColors::get_shade(gray, 0.3f, dark_theme);
  38. auto light_gray = InputColors::get_shade(mid_gray, 0.3f, dark_theme);
  39. return InputColors {
  40. .accent = accent,
  41. .base = base,
  42. .dark_gray = dark_gray,
  43. .gray = gray,
  44. .mid_gray = mid_gray,
  45. .light_gray = light_gray
  46. };
  47. }
  48. }