Logo ROOT   6.18/05
Reference Guide
RStyle.hxx
Go to the documentation of this file.
1/// \file ROOT/RStyle.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_RStyle
17#define ROOT7_RStyle
18
19#include <ROOT/RColor.hxx>
20
21#include <ROOT/RStringView.hxx>
22
23#include <string>
24#include <tuple>
25#include <unordered_map>
26
27namespace ROOT {
28namespace Experimental {
29
30/** \class ROOT::Experimental::RStyle
31 A set of defaults for graphics attributes, e.g. for histogram fill color, line width, frame offsets etc.
32 */
33
34class RStyle {
35public:
36 /// A map of attribute name to string attribute values/
37 using Attrs_t = std::unordered_map<std::string, std::string>;
38
39private:
40 /// Mapping of user coordinates to normal coordinates.
41 std::string fName; // Name of the attribute set.
42 Attrs_t fAttrs; // Pairs of name / attribute values.
43
44public:
45 /// Default constructor, creating an unnamed, empty style.
46 RStyle() = default;
47
48 /// Creates a named but empty style.
50
51 /// Constructor taking the style name and a set of attributes (e.g. read from the config files).
52 RStyle(std::string_view name, Attrs_t &&attrs): fName(name), fAttrs(std::move(attrs)) {}
53
54 /// Get this stryle's name. (No setter as that would upset the unordered_map.)
55 const std::string &GetName() const { return fName; }
56
57 /// Get the style value as a string, given an attribute name.
58 /// Strips leading "foo." from the name until the first entry in the style is found.
59 /// E.g. if the default style has not entry for "Hist.1D.Fill.Color", the value might
60 /// be initialized to the default style's entry for the more general "1D.Fill.Color".
61 /// The className is the name of a CSS-style class, possibly overriding the generic attribute.
62 std::string GetAttribute(const std::string &attrName, const std::string &className = {}) const;
63
64 /// Move-register `style` in the global style collection, possibly replacing a global style with the same name.
65 static RStyle &Register(RStyle &&style);
66
67 /// Get the `RStyle` named `name` from the global style collection, or `nullptr` if that doesn't exist.
69
70 /// Get the current RStyle.
71 static RStyle &GetCurrent();
72
73 /// Set the current RStyle by copying `style` into the static current style object.
74 static void SetCurrent(const RStyle &style) { GetCurrent() = style; }
75};
76
77} // namespace Experimental
78} // namespace ROOT
79
80#endif // ROOT7_RStyle
char name[80]
Definition: TGX11.cxx:109
A set of defaults for graphics attributes, e.g.
Definition: RStyle.hxx:34
RStyle(std::string_view name)
Creates a named but empty style.
Definition: RStyle.hxx:49
static RStyle & Register(RStyle &&style)
Move-register style in the global style collection, possibly replacing a global style with the same n...
Definition: RStyle.cxx:49
static RStyle & GetCurrent()
Get the current RStyle.
Definition: RStyle.cxx:81
RStyle()=default
Default constructor, creating an unnamed, empty style.
static RStyle * Get(std::string_view name)
Get the RStyle named name from the global style collection, or nullptr if that doesn't exist.
Definition: RStyle.cxx:56
std::string fName
Mapping of user coordinates to normal coordinates.
Definition: RStyle.hxx:41
static void SetCurrent(const RStyle &style)
Set the current RStyle by copying style into the static current style object.
Definition: RStyle.hxx:74
std::unordered_map< std::string, std::string > Attrs_t
A map of attribute name to string attribute values/.
Definition: RStyle.hxx:37
RStyle(std::string_view name, Attrs_t &&attrs)
Constructor taking the style name and a set of attributes (e.g. read from the config files).
Definition: RStyle.hxx:52
std::string GetAttribute(const std::string &attrName, const std::string &className={}) const
Get the style value as a string, given an attribute name.
Definition: RStyle.cxx:87
const std::string & GetName() const
Get this stryle's name. (No setter as that would upset the unordered_map.)
Definition: RStyle.hxx:55
basic_string_view< char > string_view
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
TCanvas * style()
Definition: style.C:1