style.h Source File - ClanLib SDK
Description: style.h Source File

style.h
1/*
2** ClanLib SDK
3** Copyright (c) 1997-2020 The ClanLib Team
4**
5** This software is provided 'as-is', without any express or implied
6** warranty. In no event will the authors be held liable for any damages
7** arising from the use of this software.
8**
9** Permission is granted to anyone to use this software for any purpose,
10** including commercial applications, and to alter it and redistribute it
11** freely, subject to the following restrictions:
12**
13** 1. The origin of this software must not be misrepresented; you must not
14** claim that you wrote the original software. If you use this software
15** in a product, an acknowledgment in the product documentation would be
16** appreciated but is not required.
17** 2. Altered source versions must be plainly marked as such, and must not be
18** misrepresented as being the original software.
19** 3. This notice may not be removed or altered from any source distribution.
20**
21** Note: Some of the libraries ClanLib may link to may have additional
22** requirements or restrictions.
23**
24** File Author(s):
25**
26** Magnus Norddahl
27** Mark Page
28*/
29
30#pragma once
31
32#include "../../Core/Text/string_format.h"
33#include "../../Core/Math/cl_math.h"
34#include "../../Display/2D/color.h"
35#include "style_get_value.h"
36#include "property_hash.h"
37#include <memory>
38
39namespace clan
40{
41 class StyleImpl;
42 class StyleGetValue;
43
45 class Style
46 {
47 public:
48 Style();
49 Style(const Style &) = delete;
50 ~Style();
51 Style &operator=(const Style &) = delete;
52
61 void set(const std::string &properties);
62
63 template <class Arg1, typename... Values>
64 void set(const std::string &properties, Arg1 arg1, Values... values)
65 {
66 set(string_format(properties, arg1, values...));
67 }
68
70 StyleGetValue declared_value(PropertyHash hash) const;
71
73 static std::string to_rgba(const Colorf &c)
74 {
75 return string_format(
76 "rgba(%1,%2,%3,%4)",
77 clamp((int)std::round(c.r * 255), 0, 255),
78 clamp((int)std::round(c.g * 255), 0, 255),
79 clamp((int)std::round(c.b * 255), 0, 255),
80 c.a);
81 }
82
83 private:
84 std::unique_ptr<StyleImpl> impl;
85 };
86}
clan::Colorf
Floating point color description class (for float).
Definition color.h:799
clan::PropertyHash
Definition property_hash.h:35
clan::StyleGetValue
Style value returned by style classes.
Definition style_get_value.h:40
clan::Style::set
void set(const std::string &properties, Arg1 arg1, Values... values)
Definition style.h:64
clan::Style::~Style
~Style()
clan::Style::set
void set(const std::string &properties)
clan::Style::Style
Style(const Style &)=delete
clan::Style::Style
Style()
clan::Style::operator=
Style & operator=(const Style &)=delete
clan::Style::declared_value
StyleGetValue declared_value(PropertyHash hash) const
Retrieve the declared value for a property.
clan::Style::to_rgba
static std::string to_rgba(const Colorf &c)
Static helper that generates a "rgba(%1,%2,%3,%4)" string for the given color.
Definition style.h:73
clan::clamp
C clamp(A val, B minval, C maxval)
Definition cl_math.h:97
clan::string_format
std::string string_format(const std::string &format)
See clan::StringFormat for details.
Definition string_format.h:157
clan
Definition clanapp.h:36
clan::Key::c
@ c
Definition keys.h:83
clan::StyleTokenType::hash
@ hash
Syntax error.
Definition style_token.h:43