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 <string>
19
20using namespace ROOT::Experimental;
21
22void rstyle()
23{
24 auto canvas = RCanvas::Create("Use RStyle for line styling");
25 double num = 0.3;
26
27 for (int i = 10; i > 0; i--){
28 num = num + 0.05;
29
30 auto text = canvas->Add<RText>(RPadPos{.3_normal, 1_normal*num}, std::to_string(i));
31 text->text.size = 0.04;
32 text->text.align = RAttrText::kRightCenter;
33 text->text.font = RAttrFont::kArialOblique;
34
35 auto line = canvas->Add<RLine>(RPadPos(.32_normal,1_normal*num), RPadPos(.8_normal, 1_normal*num));
36 line->SetId(std::string("obj") + std::to_string(i));
37 line->SetCssClass(std::string("user_class_") + std::to_string(i % 3));
38 }
39
40 auto style = std::make_shared<RStyle>();
41
42 style->AddBlock(".user_class_1").AddInt("line_style", 4); // all lines with user_class_1 should get style 1
43 style->AddBlock(".user_class_2").AddDouble("line_width", 5.); // all lines with user_class_2 should get line width 5
44 style->AddBlock("#obj7").AddString("line_color", "#0000FF"); // line with id obj7 should be blue
45
46 style->AddBlock("line").AddString("line_color", "red"); // all lines should get red color
47
48 canvas->UseStyle(style);
49
50 canvas->Show();
51
52 // after leaving function scope style will be destroyed, one has to preserve it
53 canvas->ClearOnClose(style);
54}
Option_t Option_t style
Option_t Option_t TPoint TPoint const char text
A position (horizontal and vertical) in a RPad.
Definition RPadPos.hxx:28
TLine * line