Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.1

0.6.1 / src / web / painting / input_colors.lucb

#==============================================================================================
#
#   input_colors - Painting::InputColors: the shades form controls are painted with
#
#   DESCRIPTION:
#       Port of Libraries/LibWeb/Painting/InputColors.h (lines 1-57). The color names reflect
#       what the colors would be for a light theme, not necessarily the actual colors.
#
#       Copyright (c) 2023, MacDue <macdue@dueutil.tech>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

## Ported from Libraries/LibWeb/Painting/InputColors.h:26 Web::Painting::InputColors::background_color.
pub func paint_input_colors_background_color(this: PaintInputColors*, enabled: bool) -> gfx.Color:
    return this.base if enabled else this.light_gray

## Ported from Libraries/LibWeb/Painting/InputColors.h:27 Web::Painting::InputColors::border_color.
pub func paint_input_colors_border_color(this: PaintInputColors*, enabled: bool) -> gfx.Color:
    return this.gray if enabled else this.mid_gray

## Ported from Libraries/LibWeb/Painting/InputColors.h:29 Web::Painting::InputColors::get_shade.
pub func paint_input_colors_get_shade(color: gfx.Color, amount: f32, color_scheme: CssPreferredColorScheme) -> gfx.Color:
    let base_color = css_system_color_canvas(color_scheme)
    return gfx.color_mixed_with(&color, base_color, amount)

## Ported from Libraries/LibWeb/Painting/InputColors.h:36 Web::Painting::compute_input_colors.
## (Static in the C++ header; public until region r53's form-control paintables call it.)
pub func paint_compute_input_colors(color_scheme: CssPreferredColorScheme, accent_color: gfx.Color?) -> PaintInputColors:
    # These shades have been picked to work well for all themes and have enough variation to paint
    # all input states (disabled, enabled, checked, etc).
    let base_text_color = css_system_color_canvas_text(color_scheme)
    let accent = accent_color else css_system_color_accent_color(color_scheme)
    let base = paint_input_colors_get_shade(gfx.color_inverted(&base_text_color), 0.8, color_scheme)
    let dark_gray = paint_input_colors_get_shade(base_text_color, 0.3, color_scheme)
    let gray = paint_input_colors_get_shade(dark_gray, 0.4, color_scheme)
    let mid_gray = paint_input_colors_get_shade(gray, 0.3, color_scheme)
    let light_gray = paint_input_colors_get_shade(mid_gray, 0.3, color_scheme)
    return PaintInputColors(accent = accent, base = base, dark_gray = dark_gray, gray = gray, mid_gray = mid_gray, light_gray = light_gray)