Dillo v3.1.1-98-g318d1f14
Loading...
Searching...
No Matches
dw_border_test.cc
Go to the documentation of this file.
1/*
2 * Dillo Widget
3 *
4 * Copyright 2005-2007 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"
29#include "dw/textblock.hh"
30#include "dw/listitem.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 Border Test");
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 styleAttrs.borderWidth.setVal (2);
53 styleAttrs.setBorderColor (Color::create (layout, 0xffffff));
54 styleAttrs.setBorderStyle (BORDER_INSET);
55 styleAttrs.padding.setVal (5);
56
57 FontAttrs fontAttrs;
58 fontAttrs.name = "Bitstream Charter";
59 fontAttrs.size = 14;
60 fontAttrs.weight = 400;
61 fontAttrs.style = FONT_STYLE_NORMAL;
62 fontAttrs.letterSpacing = 0;
64 styleAttrs.font = dw::core::style::Font::create (layout, &fontAttrs);
65
66 styleAttrs.color = Color::create (layout, 0x000000);
67 styleAttrs.backgroundColor = Color::create (layout, 0xffffff);
68
69 Style *widgetStyle1 = Style::create (&styleAttrs);
70
71 styleAttrs.backgroundColor = Color::create (layout, 0xffff80);
72 styleAttrs.margin.setVal (0);
73 styleAttrs.borderWidth.setVal (1);
74 styleAttrs.setBorderColor (Color::create (layout, 0x4040ff));
75 styleAttrs.setBorderStyle (BORDER_SOLID);
76 styleAttrs.padding.setVal (1);
77
78 Style *widgetStyle2 = Style::create (&styleAttrs);
79
80 Textblock *textblock1 = new Textblock (false);
81 textblock1->setStyle (widgetStyle1);
82 layout->setWidget (textblock1);
83
84 widgetStyle1->unref();
85
86 styleAttrs.borderWidth.setVal (0);
87 styleAttrs.padding.setVal (0);
88 styleAttrs.backgroundColor = NULL;
89 styleAttrs.cursor = CURSOR_TEXT;
90
91 Style *wordStyle = Style::create (&styleAttrs);
92
93 const char *words1[] = { "Some", "random", "text.", NULL };
94 const char *words2[] = { "A", "nested", "paragraph.", NULL };
95
96 for(int i = 0; words1[i]; i++) {
97 if(i != 0)
98 textblock1->addSpace (wordStyle);
99 textblock1->addText (words1[i], wordStyle);
100 }
101
102 for(int i = 0; i < 1; i++) {
103 textblock1->addParbreak(0, wordStyle);
104
105 Textblock *textblock2 = new Textblock (false);
106 textblock1->addWidget (textblock2, widgetStyle2);
107
108 for(int j = 0; words2[j]; j++) {
109 if(j != 0)
110 textblock2->addSpace (wordStyle);
111 textblock2->addText (words2[j], wordStyle);
112 }
113
114 textblock2->flush ();
115 }
116
117 textblock1->flush ();
118
119 window->resizable(viewport);
120 window->show();
121 int errorCode = Fl::run();
122
123 widgetStyle2->unref();
124 wordStyle->unref();
125 delete layout;
126
127 return errorCode;
128}
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
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.