Logo ROOT   6.12/07
Reference Guide
TStyle.hxx
Go to the documentation of this file.
1 /// \file ROOT/TStyle.hxx
2 /// \ingroup Gpad ROOT7
3 /// \author Axel Naumann <axel@cern.ch>
4 /// \date 2017-10-10
5 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6 /// is welcome!
7 
8 /*************************************************************************
9  * Copyright (C) 1995-2017, Rene Brun and Fons Rademakers. *
10  * All rights reserved. *
11  * *
12  * For the licensing terms see $ROOTSYS/LICENSE. *
13  * For the list of contributors see $ROOTSYS/README/CREDITS. *
14  *************************************************************************/
15 
16 #ifndef ROOT7_TStyle
17 #define ROOT7_TStyle
18 
19 #include <ROOT/TColor.hxx>
20 
21 #include <RStringView.h>
22 
23 #include <string>
24 #include <tuple>
25 #include <unordered_map>
26 
27 namespace ROOT {
28 namespace Experimental {
29 
30 /** \class ROOT::Experimental::TStyle
31  A set of defaults for graphics attributes, e.g. for histogram fill color, line width, frame offsets etc.
32  */
33 
34 class TStyle {
35 public:
36  /// A map of attribute name to attribute value for an attribute type `PRIMITIVE`.
37  template <class PRIMITIVE> using Attrs_t = std::unordered_map<std::string, PRIMITIVE>;
38  using AllAttrs_t = std::tuple<Attrs_t<TColor>, Attrs_t<long long>, Attrs_t<double>>;
39 
40 private:
41  /// Mapping of user coordinates to normal coordinates.
42  std::string fName; // Name of the attribute set.
43  AllAttrs_t fAttrs; // Pairs of name / attribute values.
44 
45 public:
46  /// Default constructor, creating an unnamed, empty style.
47  TStyle() = default;
48 
49  /// Creates a named but empty style.
50  explicit TStyle(std::string_view name): fName(name) {}
51 
52  /// Constructor taking user coordinate system, position and extent.
53  TStyle(std::string_view name, AllAttrs_t&& attrs): fName(name), fAttrs(std::move(attrs)) {}
54 
55  const std::string& GetName() const { return fName; }
56 
57  /// Register a copy of `style` in the global style collection, possibly replacing a global style with the same name.
58  static void Register(const TStyle& style);
59 
60  /// Get the `TStyle` named `name` from the global style collection, or `nullptr` if that doesn't exist.
62 
63  /// Get the current TStyle.
64  static TStyle &GetCurrent();
65 
66  /// Set the current TStyle by copying `style` into the static current style object.
67  static void SetCurrent(const TStyle& style)
68  {
69  GetCurrent() = style;
70  }
71 };
72 
73 } // namespace Experimental
74 } // namespace ROOT
75 
76 #endif // ROOT7_TStyle
std::unordered_map< std::string, PRIMITIVE > Attrs_t
A map of attribute name to attribute value for an attribute type PRIMITIVE.
Definition: TStyle.hxx:37
static TStyle * Get(std::string_view name)
Get the TStyle named name from the global style collection, or nullptr if that doesn&#39;t exist...
Definition: TStyle.cxx:46
std::string fName
Mapping of user coordinates to normal coordinates.
Definition: TStyle.hxx:42
basic_string_view< char > string_view
Definition: RStringView.h:35
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
A set of defaults for graphics attributes, e.g.
Definition: TStyle.hxx:34
STL namespace.
static TStyle & GetCurrent()
Get the current TStyle.
Definition: TStyle.cxx:72
static void SetCurrent(const TStyle &style)
Set the current TStyle by copying style into the static current style object.
Definition: TStyle.hxx:67
TStyle(std::string_view name)
Creates a named but empty style.
Definition: TStyle.hxx:50
TStyle()=default
Default constructor, creating an unnamed, empty style.
const std::string & GetName() const
Definition: TStyle.hxx:55
static void Register(const TStyle &style)
Register a copy of style in the global style collection, possibly replacing a global style with the s...
Definition: TStyle.cxx:41
TCanvas * style()
Definition: style.C:1
std::tuple< Attrs_t< TColor >, Attrs_t< long long >, Attrs_t< double > > AllAttrs_t
Definition: TStyle.hxx:38
TStyle(std::string_view name, AllAttrs_t &&attrs)
Constructor taking user coordinate system, position and extent.
Definition: TStyle.hxx:53
char name[80]
Definition: TGX11.cxx:109