polybar-dwm/include/utils/color.hpp
Patrick Ziegler fd556525a8
New Tag Parser (#2303)
* refactor(color): Use enum class for color type

* Add testcases for tag parser

* Make tag parser a pull-style parser

Being able to parse single elements at a time gives us more fine-grained
error messages, we can also parse as much as possible and only stop
after an exception.

* fix(color): Parser did not check for invalid chars

* tag parser: First full implementation

* tag parser: Fix remaining failing tests

* tag parser: Replace old parser

* tag parser: Treat alignment as formatting tag

Makes the structure less complex and the alignment tags really are
formatting tags, they are structurally no different from the %{R} tag.

* tag parser: Cleanup type definitions

All type definitions for tags now live in tags/types.hpp, the parser.hpp
only contains the definitions necessary for actually calling the parser,
this shouldn't be included in many places (only places that actually do
parsing). But many places need the definitions for the tags themselves.

* Rename components/parser to tags/dispatch

* tag parser: Cleanup

* Add changelog
2020-12-17 20:37:28 +01:00

67 lines
1.6 KiB
C++

#pragma once
#include <cstdlib>
#include "common.hpp"
POLYBAR_NS
/**
* Represents immutable 32-bit color values.
*/
class rgba {
public:
enum class type { NONE = 0, ARGB, ALPHA_ONLY };
explicit rgba();
explicit rgba(uint32_t value, type type = type::ARGB);
explicit rgba(string hex);
operator string() const;
operator uint32_t() const;
bool operator==(const rgba& other) const;
uint32_t value() const;
type type() const;
double alpha_d() const;
double red_d() const;
double green_d() const;
double blue_d() const;
uint8_t alpha_i() const;
uint8_t red_i() const;
uint8_t green_i() const;
uint8_t blue_i() const;
bool has_color() const;
rgba apply_alpha_to(rgba other) const;
rgba try_apply_alpha_to(rgba other) const;
private:
/**
* Color value in the form ARGB or A000 depending on the type
*
* Cannot be const because we have to assign to it in the constructor and initializer lists are not possible.
*/
uint32_t m_value;
/**
* NONE marks this instance as invalid. If such a color is encountered, it
* should be treated as if no color was set.
*
* ALPHA_ONLY is used for color strings that only have an alpha channel (#AA)
* these kinds should be combined with another color that has RGB channels
* before they are used to render anything.
*
* Cannot be const because we have to assign to it in the constructor and initializer lists are not possible.
*/
enum type m_type { type::NONE };
};
namespace color_util {
string simplify_hex(string hex);
} // namespace color_util
POLYBAR_NS_END