css_length.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2013 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 "../../Core/Text/string_help.h"
32 
33 namespace clan
34 {
37 
38 class CSSLength
39 {
40 public:
41  enum Type
42  {
52  };
53 
55  : type(type_px), value(0.0f)
56  {
57  }
58 
60  : type(type), value(value)
61  {
62  }
63 
64  std::string to_string() const
65  {
66  if (value == 0.0f)
67  return "0";
68  std::string v = StringHelp::float_to_text(value);
69  switch (type)
70  {
71  default:
72  case type_mm:
73  return v + "mm";
74  case type_cm:
75  return v + "cm";
76  case type_in:
77  return v + "in";
78  case type_pt:
79  return v + "pt";
80  case type_pc:
81  return v + "pc";
82  case type_px:
83  return v + "px";
84  case type_em:
85  return v + "em";
86  case type_ex:
87  return v + "ex";
88  case type_computed_px:
89  return v + "computed-px";
90  }
91  }
92 
94  float value;
95 };
96 
98 }
Type type
Definition: css_length.h:93
Definition: css_length.h:45
Definition: css_length.h:43
static std::string float_to_text(float value, int num_decimal_places=6)
Float to text.
Definition: css_length.h:47
std::string to_string() const
Definition: css_length.h:64
Type
Definition: css_length.h:41
Definition: css_length.h:50
Definition: css_length.h:51
Definition: css_length.h:49
Definition: css_length.h:48
CSSLength()
Definition: css_length.h:54
Definition: css_length.h:38
float value
Definition: css_length.h:94
Definition: css_length.h:44
Definition: css_length.h:46
CSSLength(float value, Type type)
Definition: css_length.h:59