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

style_set_value.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*/
28
29#pragma once
30
31#include <string>
32#include "../../Display/2D/color.h"
33#include "style_value_type.h"
34#include "style_dimension.h"
35
36namespace clan
37{
39 class StyleSetValue
40 {
41 public:
43 StyleValueType type = StyleValueType::undefined;
44
46 std::string text;
47
49 float number = 0.0f;
50
52 StyleDimension dimension = StyleDimension::px;
53
55 Colorf color;
56
58 bool is_undefined() const { return type == StyleValueType::undefined; }
59
61 bool is_keyword() const { return type == StyleValueType::keyword; }
62 bool is_keyword(const char *keyword) const { return is_keyword() && text == keyword; }
63 bool is_keyword(const std::string &keyword) const { return is_keyword() && text == keyword; }
64
66 bool is_length() const { return type == StyleValueType::length; }
67
69 bool is_angle() const { return type == StyleValueType::angle; }
70
72 bool is_time() const { return type == StyleValueType::time; }
73
75 bool is_frequency() const { return type == StyleValueType::frequency; }
76
78 bool is_resolution() const { return type == StyleValueType::resolution; }
79
81 bool is_percentage() const { return type == StyleValueType::percentage; }
82
84 bool is_number() const { return type == StyleValueType::number; }
85
87 bool is_string() const { return type == StyleValueType::string; }
88
90 bool is_url() const { return type == StyleValueType::url; }
91
93 bool is_color() const { return type == StyleValueType::color; }
94
96 static StyleSetValue from_keyword(const std::string &keyword) { StyleSetValue v; v.type = StyleValueType::keyword; v.text = keyword; return v; }
97
99 static StyleSetValue from_string(const std::string &text) { StyleSetValue v; v.type = StyleValueType::string; v.text = text; return v; }
100
102 static StyleSetValue from_length(float length, StyleDimension dimension = StyleDimension::px) { StyleSetValue v; v.type = StyleValueType::length; v.number = length; v.dimension = dimension; return v; }
103
105 static StyleSetValue from_angle(float angle, StyleDimension dimension = StyleDimension::rad) { StyleSetValue v; v.type = StyleValueType::angle; v.number = angle; v.dimension = dimension; return v; }
106
108 static StyleSetValue from_time(float t, StyleDimension dimension = StyleDimension::s) { StyleSetValue v; v.type = StyleValueType::time; v.number = t; v.dimension = dimension; return v; }
109
111 static StyleSetValue from_frequency(float freq, StyleDimension dimension = StyleDimension::hz) { StyleSetValue v; v.type = StyleValueType::frequency; v.number = freq; v.dimension = dimension; return v; }
112
114 static StyleSetValue from_resolution(float resolution, StyleDimension dimension = StyleDimension::dppx) { StyleSetValue v; v.type = StyleValueType::resolution; v.number = resolution; v.dimension = dimension; return v; }
115
117 static StyleSetValue from_percentage(float percentage) { StyleSetValue v; v.type = StyleValueType::percentage; v.number = percentage; return v; }
118
120 static StyleSetValue from_number(float number) { StyleSetValue v; v.type = StyleValueType::number; v.number = number; return v; }
121
123 static StyleSetValue from_url(const std::string &url) { StyleSetValue v; v.type = StyleValueType::url; v.text = url; return v; }
124
126 static StyleSetValue from_color(const Colorf &color) { StyleSetValue v; v.type = StyleValueType::color; v.color = color; return v; }
127 };
128}
clan::Colorf
Floating point color description class (for float).
Definition color.h:799
clan::StyleSetValue
Style value variable.
Definition style_set_value.h:40
clan::StyleSetValue::is_string
bool is_string() const
Check if value is a string.
Definition style_set_value.h:87
clan::StyleSetValue::is_resolution
bool is_resolution() const
Check if value is a resolution.
Definition style_set_value.h:78
clan::StyleSetValue::is_frequency
bool is_frequency() const
Check if value is a frequency.
Definition style_set_value.h:75
clan::StyleSetValue::from_string
static StyleSetValue from_string(const std::string &text)
Create style value from a string.
Definition style_set_value.h:99
clan::StyleSetValue::from_angle
static StyleSetValue from_angle(float angle, StyleDimension dimension=StyleDimension::rad)
Create style value from an angle.
Definition style_set_value.h:105
clan::StyleSetValue::from_number
static StyleSetValue from_number(float number)
Create style value from a number.
Definition style_set_value.h:120
clan::StyleSetValue::is_keyword
bool is_keyword() const
Check if value is a keyword.
Definition style_set_value.h:61
clan::StyleSetValue::from_color
static StyleSetValue from_color(const Colorf &color)
Create style value from a color.
Definition style_set_value.h:126
clan::StyleSetValue::from_url
static StyleSetValue from_url(const std::string &url)
Create style value from an url.
Definition style_set_value.h:123
clan::StyleSetValue::from_frequency
static StyleSetValue from_frequency(float freq, StyleDimension dimension=StyleDimension::hz)
Create style value from a frequency.
Definition style_set_value.h:111
clan::StyleSetValue::is_time
bool is_time() const
Check if value is a time.
Definition style_set_value.h:72
clan::StyleSetValue::dimension
StyleDimension dimension
Dimension used by value.
Definition style_set_value.h:52
clan::StyleSetValue::is_length
bool is_length() const
Check if value is a length.
Definition style_set_value.h:66
clan::StyleSetValue::from_percentage
static StyleSetValue from_percentage(float percentage)
Create style value from a percentage.
Definition style_set_value.h:117
clan::StyleSetValue::is_keyword
bool is_keyword(const std::string &keyword) const
Definition style_set_value.h:63
clan::StyleSetValue::is_angle
bool is_angle() const
Check if value is an angle.
Definition style_set_value.h:69
clan::StyleSetValue::is_url
bool is_url() const
Check if value is an url.
Definition style_set_value.h:90
clan::StyleSetValue::is_percentage
bool is_percentage() const
Check if value is a percentage.
Definition style_set_value.h:81
clan::StyleSetValue::number
float number
Value number.
Definition style_set_value.h:49
clan::StyleSetValue::from_keyword
static StyleSetValue from_keyword(const std::string &keyword)
Create style value from a keyword.
Definition style_set_value.h:96
clan::StyleSetValue::type
StyleValueType type
Variant type.
Definition style_set_value.h:43
clan::StyleSetValue::is_color
bool is_color() const
Check if value is a color.
Definition style_set_value.h:93
clan::StyleSetValue::color
Colorf color
Value color.
Definition style_set_value.h:55
clan::StyleSetValue::from_length
static StyleSetValue from_length(float length, StyleDimension dimension=StyleDimension::px)
Create style value from a length.
Definition style_set_value.h:102
clan::StyleSetValue::text
std::string text
Text when the type is a text string.
Definition style_set_value.h:46
clan::StyleSetValue::is_number
bool is_number() const
Check if value is a number.
Definition style_set_value.h:84
clan::StyleSetValue::is_keyword
bool is_keyword(const char *keyword) const
Definition style_set_value.h:62
clan::StyleSetValue::from_time
static StyleSetValue from_time(float t, StyleDimension dimension=StyleDimension::s)
Create style value from a time.
Definition style_set_value.h:108
clan::StyleSetValue::from_resolution
static StyleSetValue from_resolution(float resolution, StyleDimension dimension=StyleDimension::dppx)
Create style value from a resolution.
Definition style_set_value.h:114
clan::StyleSetValue::is_undefined
bool is_undefined() const
Check if value is undefined.
Definition style_set_value.h:58
clan
Definition clanapp.h:36
clan::StyleValueType
StyleValueType
Style value type.
Definition style_value_type.h:35
clan::StyleValueType::time
@ time
value is an angle
clan::StyleValueType::length
@ length
value is a keyword
clan::StyleValueType::url
@ url
value is a text string
clan::StyleValueType::undefined
@ undefined
clan::StyleValueType::color
@ color
value is an url
clan::StyleValueType::angle
@ angle
value is a color
clan::StyleValueType::number
@ number
value is a percentage number
clan::StyleValueType::string
@ string
value is a number
clan::StyleValueType::resolution
@ resolution
value is a frequency
clan::StyleValueType::percentage
@ percentage
value is a length
clan::StyleValueType::keyword
@ keyword
value undefined
clan::StyleValueType::frequency
@ frequency
value is a time
clan::Key::v
@ v
clan::Key::t
@ t
clan::StyleDimension
StyleDimension
Unit of a style value.
Definition style_dimension.h:35
clan::StyleDimension::s
@ s
turns (1 in a full circle)
clan::StyleDimension::hz
@ hz
milliseconds
clan::StyleDimension::px
@ px
clan::StyleDimension::rad
@ rad
gradians/gons/grades (400 in a full circle)
clan::StyleDimension::dppx
@ dppx
dots per cm
clan::StyleTokenType::percentage
@ percentage
Number.