summaryrefslogtreecommitdiff
path: root/tests/test_widgets_1.cc
blob: c6e2fede1fb35652022412036a891feb9caf4828 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
 * RTFL
 *
 * Copyright 2013-2015 Sebastian Geerken <sgeerken@dillo.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <FL/Fl_Window.H>
#include <FL/Fl.H>

#include "dw/core.hh"
#include "dw/fltkcore.hh"
#include "dw/fltkviewport.hh"

#include "dwr/graph.hh"
#include "dwr/label.hh"
#include "dwr/hbox.hh"
#include "dwr/vbox.hh"
#include "dwr/toggle.hh"

using namespace dw;
using namespace dw::core;
using namespace dw::core::style;
using namespace dw::fltk;

using namespace rtfl::dw;

int main(int argc, char **argv)
{
   FltkPlatform *platform = new FltkPlatform ();
   Layout *layout = new Layout (platform);

   Fl_Window *window = new Fl_Window(500, 400, "Dw Example");
   window->box(FL_NO_BOX);
   window->begin();

   FltkViewport *viewport = new FltkViewport (0, 0, 500, 400);
   layout->attachView (viewport);

   StyleAttrs styleAttrs;
   styleAttrs.initValues ();
   styleAttrs.padding.setVal (5);

   FontAttrs fontAttrs;
   fontAttrs.name = "DejaVu Sans";
   fontAttrs.size = 14;
   fontAttrs.weight = 400;
   fontAttrs.style = FONT_STYLE_NORMAL;
   fontAttrs.letterSpacing = 0;
   fontAttrs.fontVariant = FONT_VARIANT_NORMAL;
   styleAttrs.font = style::Font::create (layout, &fontAttrs);

   styleAttrs.color = Color::create (layout, 0x000000);
   styleAttrs.backgroundColor = Color::create (layout, 0xffffff);

   Style *graphStyle = Style::create (&styleAttrs);
   Graph *graph = new Graph ();
   graph->setStyle (graphStyle);
   layout->setWidget (graph);
   graphStyle->unref();

   styleAttrs.borderWidth.setVal (1);
   styleAttrs.setBorderStyle (BORDER_OUTSET);
   styleAttrs.setBorderColor (Color::create (layout, 0x000000));
   Style *textblockStyle = Style::create (&styleAttrs);

   styleAttrs.borderWidth.setVal (0);
   styleAttrs.padding.setVal (0);
   Style *textStyle = Style::create (&styleAttrs);

   graph->setRefStyle (textblockStyle);

   HBox *n1 = new HBox (false);
   n1->setStyle (textblockStyle);
   graph->addNode (n1);   

   Label *l11 = new Label ("Hello <i>w<b>or</i>ld!</b>");
   l11->setStyle (textblockStyle);
   n1->addChild (l11);

   Label *l12 = new Label ("More text ...");
   l12->setStyle (textblockStyle);
   n1->addChild (l12);

   VBox *n2 = new VBox (false);
   n2->setStyle (textblockStyle);
   graph->addNode (n2);

   Label *l21 = new Label ("Ἐν ἀρχῇ ἦν ὁ Λόγος, καὶ ὁ Λόγος ἦν πρὸς τὸν Θεόν, "
                           "καὶ Θεὸς ἦν ὁ Λόγος.");
   l21->setStyle (textblockStyle);
   n2->addChild (l21);

   Label *l22 = new Label ("Οὗτος ἦν ἐν ἀρχῇ πρὸς τὸν Θεόν. πάντα δι' αὐτοῦ "
                           "ἐγένετο, καὶ χωρὶς αὐτοῦ ἐγένετο οὐδὲ ἕν ὃ "
                           "γέγονεν.");
   l22->setStyle (textblockStyle);
   n2->addChild (l22);

   Toggle *n3 = new Toggle (true);
   n3->setStyle (textblockStyle);
   graph->addNode (n3);

   Label *l31 = new Label ("small");
   l31->setStyle (textblockStyle);
   n3->setSmall (l31);

   Label *l33 = new Label ("LLLAAAAARRRRRGGGEEE");
   l33->setStyle (textblockStyle);
   n3->setLarge (l33);
   
   Label *n4 = new Label ("#4");
   n4->setStyle (textblockStyle);
   graph->addNode (n4);

   graph->addEdge (n1, n2);
   graph->addEdge (n1, n3);
   graph->addEdge (n2, n1);

   textStyle->unref();
   textblockStyle->unref();

   window->resizable(viewport);
   window->show();
   int errorCode = Fl::run();

   delete layout;

   return errorCode;
}