Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rtext_align.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_rcanvas
3///
4/// This macro demonstrate the text align attribute for RText.
5///
6/// \macro_image (rcanvas_js)
7/// \macro_code
8///
9/// \date 2021-07-07
10/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
11/// is welcome!
12/// \author Sergey Linev <s.linev@gsi.de>
13
14/*************************************************************************
15 * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
16 * All rights reserved. *
17 * *
18 * For the licensing terms see $ROOTSYS/LICENSE. *
19 * For the list of contributors see $ROOTSYS/README/CREDITS. *
20 *************************************************************************/
21
22#include "ROOT/RCanvas.hxx"
23#include "ROOT/RColor.hxx"
24#include "ROOT/RText.hxx"
25#include "ROOT/RBox.hxx"
26#include "ROOT/RPadPos.hxx"
27
28using namespace ROOT::Experimental;
29
30void rtext_align()
31{
32 auto canvas = RCanvas::Create("RText align example");
33
34 auto box = canvas->Add<RBox>(RPadPos(0.1_normal, 0.1_normal), RPadPos(0.9_normal, 0.9_normal));
35 box->border.style = RAttrLine::kStyle6;
36
37 auto drawText = [&canvas](double x, double y, RAttrText::EAlign align, const std::string &lbl) {
38 auto dbox = canvas->Add<RBox>(RPadPos(x-0.003, y-0.003), RPadPos(x+0.003, y+0.003));
39 dbox->fill.color = RColor::kRed;
40 dbox->fill.style = RAttrFill::kSolid;
41
42 auto text = canvas->Add<RText>(RPadPos(x, y), lbl);
43 text->text.size = 0.07;
44 text->text.align = align;
45 };
46
47 drawText(0.1, 0.9, RAttrText::kLeftTop, "kLeftTop");
48
49 drawText(0.1, 0.5, RAttrText::kLeftCenter, "kLeftCenter");
50
51 drawText(0.1, 0.1, RAttrText::kLeftBottom, "kLeftBottom");
52
53 drawText(0.9, 0.9, RAttrText::kRightTop, "kRightTop");
54
55 drawText(0.9, 0.5, RAttrText::kRightCenter, "kRightCenter");
56
57 drawText(0.9, 0.1, RAttrText::kRightBottom, "kRightBottom");
58
59 drawText(0.5, 0.5, RAttrText::kCenter, "kCenter");
60
61 drawText(0.5, 0.9, RAttrText::kCenterTop, "kCenterTop");
62
63 drawText(0.5, 0.1, RAttrText::kCenterBottom, "kCenterBottom");
64
65 canvas->Show();
66}
Option_t Option_t TPoint TPoint const char text
A position (horizontal and vertical) in a RPad.
Definition RPadPos.hxx:28
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition fillpatterns.C:1
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17