Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rstyle.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_rcanvas
3///
4/// This ROOT 7 example demonstrates how to customize RLine object using RStyle
5/// "normal" coordinates' system.
6///
7/// \macro_image (rcanvas_js)
8/// \macro_code
9///
10/// \date 2019-10-04
11/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
12/// is welcome!
13/// \author Iliana Betsou
14
15#include "ROOT/RCanvas.hxx"
16#include "ROOT/RText.hxx"
17#include "ROOT/RLine.hxx"
18#include "ROOT/RDirectory.hxx"
19#include <string>
20
21using namespace ROOT::Experimental;
22
23void rstyle()
24{
25 auto canvas = RCanvas::Create("Use RStyle for line styling");
26 double num = 0.3;
27
28 for (int i = 10; i > 0; i--){
29 num = num + 0.05;
30
31 auto text = canvas->Add<RText>(RPadPos{.3_normal, 1_normal*num}, std::to_string(i));
32 text->text.size = 0.04;
33 text->text.align = RAttrText::kRightCenter;
34 text->text.font = RAttrFont::kArialOblique;
35
36 auto line = canvas->Add<RLine>(RPadPos(.32_normal,1_normal*num), RPadPos(.8_normal, 1_normal*num));
37 line->SetId(std::string("obj") + std::to_string(i));
38 line->SetCssClass(std::string("user_class_") + std::to_string(i % 3));
39 }
40
41 auto style = std::make_shared<RStyle>();
42
43 style->AddBlock(".user_class_1").AddInt("line_style", 4); // all lines with user_class_1 should get style 1
44 style->AddBlock(".user_class_2").AddDouble("line_width", 5.); // all lines with user_class_2 should get line width 5
45 style->AddBlock("#obj7").AddString("line_color", "#0000FF"); // line with id obj7 should be blue
46
47 style->AddBlock("line").AddString("line_color", "red"); // all lines should get red color
48
49 canvas->UseStyle(style);
50
51 canvas->Show();
52
53 // after leaving function scope style will be destroyed, one has to preserve it
54 RDirectory::Heap().Add("rstyle", style);
55}
A position (horizontal and vertical) in a RPad.
Definition RPadPos.hxx:28
void Show()
Show canvas.
Definition TCanvas.cxx:2238
TText * text
TLine * line
TCanvas * style()
Definition style.C:1