Dillo v3.1.1-98-g318d1f14
Loading...
Searching...
No Matches
dw_simple_container_test.cc
Go to the documentation of this file.
1/*
2 * Dillo Widget
3 *
4 * Copyright 2014 Sebastian Geerken <sgeerken@dillo.org>
5 * Copyright 2023 Rodrigo Arias Mallo <rodarima@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21
22
23#include <FL/Fl_Window.H>
24#include <FL/Fl.H>
25
26#include "dw/core.hh"
27#include "dw/fltkcore.hh"
28#include "dw/fltkviewport.hh"
30#include "dw/textblock.hh"
31
32using namespace dw;
33using namespace dw::core;
34using namespace dw::core::style;
35using namespace dw::fltk;
36
37int main(int argc, char **argv)
38{
41
42 Fl_Window *window = new Fl_Window(200, 300, "Dw Example");
43 window->box(FL_NO_BOX);
44 window->begin();
45
46 FltkViewport *viewport = new FltkViewport (0, 0, 200, 300);
48
49 StyleAttrs styleAttrs;
50 styleAttrs.initValues ();
51 styleAttrs.margin.setVal (5);
52
53 FontAttrs fontAttrs;
54 fontAttrs.name = "Bitstream Charter";
55 fontAttrs.size = 14;
56 fontAttrs.weight = 400;
57 fontAttrs.style = FONT_STYLE_NORMAL;
58 fontAttrs.letterSpacing = 0;
60 styleAttrs.font = style::Font::create (layout, &fontAttrs);
61
62 styleAttrs.color = Color::create (layout, 0x000000);
63 styleAttrs.backgroundColor = Color::create (layout, 0xffffff);
64
65 Style *textblockStyle1 = Style::create (&styleAttrs);
66
67 styleAttrs.backgroundColor = NULL;
68 styleAttrs.margin.setVal (0);
69
70 Style *textblockStyle2 = Style::create (&styleAttrs);
71 Style *wordStyle = Style::create (&styleAttrs);
72
73 styleAttrs.borderWidth.setVal (5);
74 styleAttrs.setBorderColor (Color::create (layout, 0x800080));
75 styleAttrs.setBorderStyle (BORDER_DASHED);
76 styleAttrs.padding.setVal (5);
77
78 Style *containerStyle = Style::create (&styleAttrs);
79
80 Textblock *textblock1 = new Textblock (false);
81 textblock1->setStyle (textblockStyle1);
82 layout->setWidget (textblock1);
83
84 SimpleContainer *simpleContainer = new SimpleContainer ();
85 simpleContainer->setStyle (containerStyle);
86 textblock1->addWidget (simpleContainer, containerStyle);
87
88 Textblock *textblock2 = new Textblock (false);
89 textblock2->setStyle (textblockStyle2);
90 simpleContainer->setChild (textblock2);
91
92 const char *words[] = { "This", "is", "only", "a", "short", "paragraph.",
93 NULL };
94
95 for(int j = 0; words[j]; j++) {
96 textblock2->addText(words[j], wordStyle);
97 textblock2->addSpace(wordStyle);
98 }
99
100 textblockStyle1->unref();
101 textblockStyle2->unref();
102 containerStyle->unref();
103 wordStyle->unref();
104
105 textblock1->flush ();
106 textblock2->flush ();
107
108 window->resizable(viewport);
109 window->show();
110 int errorCode = Fl::run();
111
112 delete layout;
113
114 return errorCode;
115}
int main(void)
Definition bookmarks.c:1613
Simple widget used for testing concepts.
void setChild(core::Widget *child)
A Widget for rendering text blocks, i.e.
Definition textblock.hh:206
void addWidget(core::Widget *widget, core::style::Style *style)
Add a widget (word type) to the page.
void addSpace(core::style::Style *style)
?
void addText(const char *text, size_t len, core::style::Style *style)
Add a word to the page structure.
The central class for managing and drawing a widget tree.
Definition layout.hh:17
void attachView(View *view)
Attach a view to the layout.
Definition layout.cc:459
void setWidget(Widget *widget)
Definition layout.cc:433
virtual void setStyle(style::Style *style)
Change the style of a widget.
Definition widget.cc:1316
void setVal(int val)
Definition style.hh:510
static Color * create(Layout *layout, int color)
Definition style.cc:529
FontVariant fontVariant
Definition style.hh:688
static Font * create(Layout *layout, FontAttrs *attrs)
Definition style.cc:444
void setBorderStyle(BorderStyle val)
Definition style.hh:588
void setBorderColor(Color *val)
Definition style.hh:585
static Style * create(StyleAttrs *attrs)
Definition style.hh:629
static Style * wordStyle
static Fl_Window * window
static Layout * layout
static FltkPlatform * platform
static FltkViewport * viewport
Anything related to Dillo Widget styles is defined here.
Definition style.cc:34
@ FONT_VARIANT_NORMAL
Definition style.hh:333
The core of Dw is defined in this namespace.
Definition core.hh:23
This namespace contains FLTK implementations of Dw interfaces.
Dw is in this namespace, or sub namespaces of this one.