sciplot  0.3.1
A modern C++ plotting library powered by gnuplot
TextSpecsOf.hpp
1 // sciplot - a modern C++ scientific plotting library powered by gnuplot
2 // https://github.com/sciplot/sciplot
3 //
4 // Licensed under the MIT License <http://opensource.org/licenses/MIT>.
5 //
6 // Copyright (c) 2018-2021 Allan Leal
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
25 
26 #pragma once
27 
28 // sciplot includes
29 #include <sciplot/Default.hpp>
30 #include <sciplot/specs/FontSpecsOf.hpp>
31 #include <sciplot/Utils.hpp>
32 
33 namespace sciplot {
34 
36 template <typename DerivedSpecs>
37 class TextSpecsOf : public FontSpecsOf<DerivedSpecs>
38 {
39  public:
42 
44  auto textColor(std::string color) -> DerivedSpecs&;
45 
51  auto enhanced(bool value=true) -> DerivedSpecs&;
52 
54  auto repr() const -> std::string;
55 
56  private:
58  std::string m_color;
59 
61  std::string m_enhanced;
62 };
63 
65 class TextSpecs : public TextSpecsOf<TextSpecs> {};
66 
67 template <typename DerivedSpecs>
69 {
70  enhanced(true);
71  textColor(internal::DEFAULT_TEXTCOLOR);
72 }
73 
74 template <typename DerivedSpecs>
75 auto TextSpecsOf<DerivedSpecs>::textColor(std::string color) -> DerivedSpecs&
76 {
77  m_color = "'" + color + "'";
78  return static_cast<DerivedSpecs&>(*this);
79 }
80 
81 template <typename DerivedSpecs>
82 auto TextSpecsOf<DerivedSpecs>::enhanced(bool value) -> DerivedSpecs&
83 {
84  m_enhanced = value ? "enhanced" : "noenhanced";
85  return static_cast<DerivedSpecs&>(*this);
86 }
87 
88 template <typename DerivedSpecs>
89 auto TextSpecsOf<DerivedSpecs>::repr() const -> std::string
90 {
91  std::stringstream ss;
92  ss << m_enhanced << " textcolor " << m_color << " ";
93  ss << FontSpecsOf<DerivedSpecs>::repr();
94  return internal::removeExtraWhitespaces(ss.str());
95 }
96 
97 } // namespace sciplot
auto textColor(std::string color) -> DerivedSpecs &
Set the color of the text (e.g., "blue", "#404040")
Definition: TextSpecsOf.hpp:75
TextSpecsOf()
Construct a default TextSpecsOf instance.
Definition: TextSpecsOf.hpp:68
auto repr() const -> std::string
Convert this TextSpecsOf object into a gnuplot formatted string.
Definition: TextSpecsOf.hpp:89
The class used to attach text options to a type.
Definition: TextSpecsOf.hpp:38
The class used to specify text options.
Definition: TextSpecsOf.hpp:65
auto enhanced(bool value=true) -> DerivedSpecs &
Set the enhanced mode of the text.
Definition: TextSpecsOf.hpp:82
The class used to attach font options to a type.
Definition: FontSpecsOf.hpp:37