AUI Framework  master
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
Color.h
    1/*
    2 * AUI Framework - Declarative UI toolkit for modern C++20
    3 * Copyright (C) 2020-2025 Alex2772 and Contributors
    4 *
    5 * SPDX-License-Identifier: MPL-2.0
    6 *
    7 * This Source Code Form is subject to the terms of the Mozilla Public
    8 * License, v. 2.0. If a copy of the MPL was not distributed with this
    9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
   10 */
   11
   12//
   13// Created by Alex2772 on 12/5/2021.
   14//
   15
   16#pragma once
   17
   18
   19#include <AUI/Common/IStringable.h>
   20#include "AUI/Test/UI/ScreenshotAnalyzer.h"
   21
   22struct ViewAssertionAverageColor {
   23    AColor mColor;
   24    aui::float_within_0_1 mInaccuracy;
   25
   26    ViewAssertionAverageColor(const AColor& color, aui::float_within_0_1 inaccuracy = 0.1f) : mColor(color), mInaccuracy(inaccuracy) {}
   27
   28    bool operator()(const _<AView>& v) {
   29        glm::vec3 average(ScreenshotAnalyzer::makeScreenshot().clip(v).averageColor());
   30        auto d = glm::length2(average - glm::vec3(mColor)) / 3;
   31        return d <= mInaccuracy;
   32    }
   33};
   34
   41using averageColor = ViewAssertionAverageColor;
   42
   43struct ViewAssertionPixelColorAt {
   44    using RelativePosition = glm::vec<2, aui::float_within_0_1>;
   45    RelativePosition mRelativePosition;
   46    AColor mColor;
   47    aui::float_within_0_1 mInaccuracy;
   48
   49    ViewAssertionPixelColorAt(RelativePosition relativePosition, const AColor& color, aui::float_within_0_1 inaccuracy = 0.1f): mRelativePosition(relativePosition), mColor(color), mInaccuracy(inaccuracy) {}
   50
   51    bool operator()(const _<AView>& v) {
   52        auto screenshot = ScreenshotAnalyzer::makeScreenshot().clip(v);
   53        auto mappedPos = glm::uvec2(glm::vec2(screenshot.image().size() - 1u) * glm::vec2(mRelativePosition));
   54        auto target = glm::vec3(screenshot.image().get(glm::min(mappedPos, screenshot.image().size() - 1u)));
   55        auto d = glm::length2(target - glm::vec3(mColor)) / 3;
   56        return d <= mInaccuracy;
   57    }
   58};
   59
   73using pixelColorAt = ViewAssertionPixelColorAt;
Represents a 4-component floating point color (RGBA).
Definition AColor.h:26
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:179
Definition Color.h:22
Definition Color.h:43