style.h
1 /*
2 ** UICore
3 ** Copyright (c) 1997-2015 The UICore 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 UICore may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 */
28 
29 #pragma once
30 
31 #include "../../Core/Text/string_format.h"
32 #include "../../Core/Math/cl_math.h"
33 #include "../../Core/Math/color.h"
34 #include "style_get_value.h"
35 #include <memory>
36 
37 namespace uicore
38 {
39  class StyleImpl;
40  class StyleGetValue;
41 
43  class Style
44  {
45  public:
46  Style();
47  Style(const Style &) = delete;
48  ~Style();
49  Style &operator=(const Style &) = delete;
50 
59  void set(const std::string &properties);
60 
61  template <class Arg1, typename... Values>
62  void set(const std::string &properties, Arg1 arg1, Values... values)
63  {
64  set(string_format(properties, arg1, values...));
65  }
66 
68  StyleGetValue declared_value(const char *property_name) const;
69  StyleGetValue declared_value(const std::string &property_name) const { return declared_value(property_name.c_str()); }
70 
72  static std::string to_rgba(const Colorf &c)
73  {
74  return string_format(
75  "rgba(%1,%2,%3,%4)",
76  clamp((int)std::round(c.x * 255), 0, 255),
77  clamp((int)std::round(c.y * 255), 0, 255),
78  clamp((int)std::round(c.z * 255), 0, 255),
79  c.w);
80  }
81 
82  private:
83  std::unique_ptr<StyleImpl> impl;
84  };
85 }
std::string string_format(const std::string &format)
See uicore::StringFormat for details.
Definition: string_format.h:147
Type x
Definition: vec4.h:74
Style & operator=(const Style &)=delete
Floating point color description class (for float).
Definition: color.h:630
Style property set.
Definition: style.h:43
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:72
void set(const std::string &properties)
Type y
Definition: vec4.h:75
Type w
Definition: vec4.h:77
void set(const std::string &properties, Arg1 arg1, Values...values)
Definition: style.h:62
StyleGetValue declared_value(const char *property_name) const
Retrieve the declared value for a property.
Style value returned by style classes.
Definition: style_get_value.h:39
Type z
Definition: vec4.h:76
StyleGetValue declared_value(const std::string &property_name) const
Definition: style.h:69
Definition: Application/application.h:35