Dillo v3.1.1-119-g140d9ebd
Loading...
Searching...
No Matches
dw_float_test.cc
Go to the documentation of this file.
1#include <FL/Fl.H>
2#include <FL/Fl_Window.H>
3
4#include "dw/core.hh"
5#include "dw/fltkcore.hh"
6#include "dw/fltkviewport.hh"
7#include "dw/textblock.hh"
8
9using namespace dw;
10using namespace dw::core;
11using namespace dw::core::style;
12using namespace dw::fltk;
13
16
17static void addTextToFloatTimeout (void *data)
18{
19 printf("addTextToFloatTimeout\n");
20
21 const char *fWords[] = { "This", "is", "a", "float,", "which", "is",
22 "set", "aside", "from", "the", "main",
23 "text.", NULL };
24
25 for(int k = 0; fWords[k]; k++) {
26 firstFloat->addText(fWords[k], wordStyle);
28 }
29
31
32 Fl::repeat_timeout (2, addTextToFloatTimeout, NULL);
33}
34
35int main(int argc, char **argv)
36{
39
40 Fl_Window *window = new Fl_Window(400, 600, "Dw Floats Example");
41 window->begin();
42
43 FltkViewport *viewport = new FltkViewport (0, 0, 400, 600);
45
46 StyleAttrs styleAttrs;
47 styleAttrs.initValues ();
48 styleAttrs.margin.setVal (5);
49
50 FontAttrs fontAttrs;
51 fontAttrs.name = "Bitstream Charter";
52 fontAttrs.size = 14;
53 fontAttrs.weight = 400;
54 fontAttrs.style = FONT_STYLE_NORMAL;
55 fontAttrs.letterSpacing = 0;
56 styleAttrs.font = core::style::Font::create (layout, &fontAttrs);
57
58 styleAttrs.color = Color::create (layout, 0x000000);
59 styleAttrs.backgroundColor = Color::create (layout, 0xffffff);
60
61 Style *widgetStyle = Style::create (&styleAttrs);
62
63 styleAttrs.borderWidth.setVal (1);
64 styleAttrs.setBorderColor (Color::create (layout, 0x808080));
65 styleAttrs.setBorderStyle (BORDER_DASHED);
66 styleAttrs.width = createAbsLength(100);
67 styleAttrs.vloat = FLOAT_LEFT;
68 Style *leftFloatStyle = Style::create (&styleAttrs);
69
70 styleAttrs.width = createAbsLength(80);
71 styleAttrs.vloat = FLOAT_RIGHT;
72 Style *rightFloatStyle = Style::create (&styleAttrs);
73
74 Textblock *textblock = new Textblock (false);
75 textblock->setStyle (widgetStyle);
76 layout->setWidget (textblock);
77
79
80 styleAttrs.borderWidth.setVal (0);
81 styleAttrs.width = LENGTH_AUTO;
82 styleAttrs.vloat = FLOAT_NONE;
83 styleAttrs.margin.setVal (0);
84 styleAttrs.backgroundColor = NULL;
85
86 wordStyle = Style::create (&styleAttrs);
87
88 for(int i = 1; i <= 10; i++) {
89 char buf[16];
90 snprintf(buf, sizeof(buf), "%d%s",
91 i, (i == 1 ? "st" : (i == 2 ? "nd" : (i == 3 ? "rd" : "th"))));
92
93 const char *words[] = { "This", "is", "the", buf, "paragraph.",
94 "Here", "comes", "some", "more", "text",
95 "to", "demonstrate", "word", "wrapping.",
96 NULL };
97
98 for(int j = 0; words[j]; j++) {
99 textblock->addText(words[j], wordStyle);
100 textblock->addSpace(wordStyle);
101
102 if ((i == 3 || i == 5) && j == 8) {
103 textblock->addText("[float]", wordStyle);
104 textblock->addSpace(wordStyle);
105
106 Textblock *vloat = new Textblock (false);
107 textblock->addWidget(vloat, i == 3 ? leftFloatStyle : rightFloatStyle);
108
109 const char *fWords[] = { "This", "is", "a", "float,", "which", "is",
110 "set", "aside", "from", "the", "main",
111 "text.", NULL };
112
113 vloat->addText(i == 3 ? "Left:" : "Right:", wordStyle);
114 vloat->addSpace(wordStyle);
115
116 for(int k = 0; fWords[k]; k++) {
117 vloat->addText(fWords[k], wordStyle);
118 vloat->addSpace(wordStyle);
119 }
120
121 vloat->flush ();
122
123 if(i == 3)
124 firstFloat = vloat;
125 }
126 }
127
128 textblock->addParbreak(10, wordStyle);
129 }
130
131 leftFloatStyle->unref();
132 rightFloatStyle->unref();
133
134 textblock->flush ();
135
136 window->resizable(viewport);
137 window->show();
138 Fl::add_timeout (2, addTextToFloatTimeout, NULL);
139 int errorCode = Fl::run();
140
141 wordStyle->unref();
142 delete layout;
143
144 return errorCode;
145}
int main(void)
Definition bookmarks.c:1613
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.
void addParbreak(int space, core::style::Style *style)
Cause a paragraph break.
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
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 * widgetStyle
static Fl_Window * window
static Layout * layout
static FltkPlatform * platform
static FltkViewport * viewport
static Textblock * firstFloat
static void addTextToFloatTimeout(void *data)
static Style * wordStyle
Anything related to Dillo Widget styles is defined here.
Definition style.cc:34
Length createAbsLength(int n)
Returns a length of n pixels.
Definition style.hh:432
@ LENGTH_AUTO
Represents "auto" lengths.
Definition style.hh:495
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.