Dillo v3.1.1-98-g318d1f14
Loading...
Searching...
No Matches
dw_table_aligned.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.H>
24#include <FL/Fl_Window.H>
25
26#include "dw/core.hh"
27#include "dw/fltkcore.hh"
28#include "dw/fltkviewport.hh"
29#include "dw/table.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 Table Aligned");
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 (1);
53 styleAttrs.setBorderStyle (BORDER_OUTSET);
54 styleAttrs.setBorderColor (Color::create (layout, 0x808080));
55
56 FontAttrs fontAttrs;
57 fontAttrs.name = "Bitstream Charter";
58 fontAttrs.size = 14;
59 fontAttrs.weight = 400;
60 fontAttrs.style = FONT_STYLE_NORMAL;
61 fontAttrs.letterSpacing = 0;
63 styleAttrs.font = dw::core::style::Font::create (layout, &fontAttrs);
64
65 styleAttrs.color = Color::create (layout, 0x000000);
66 styleAttrs.backgroundColor = Color::create (layout, 0xa0a0a0);
67 styleAttrs.hBorderSpacing = 5;
68 styleAttrs.vBorderSpacing = 5;
69
70 Style *tableStyle = Style::create (&styleAttrs);
71
72 Table *table = new Table (false);
73 table->setStyle (tableStyle);
74 layout->setWidget (table);
75
76 tableStyle->unref();
77
78 styleAttrs.borderWidth.setVal (1);
79 styleAttrs.setBorderStyle (BORDER_INSET);
80
81 Style *cellStyle = Style::create (&styleAttrs);
82
83 styleAttrs.borderWidth.setVal (0);
84 styleAttrs.margin.setVal (0);
85 styleAttrs.backgroundColor = NULL;
86 styleAttrs.cursor = CURSOR_TEXT;
87 styleAttrs.textAlignChar = '.';
88
89 Style *wordStyle = Style::create (&styleAttrs);
90
91 AlignedTableCell *ref = NULL;
92 for(int i = 0; i < 10; i++) {
93 //for(int i = 0; i < 1; i++) {
94 AlignedTableCell *cell = new AlignedTableCell (ref, false);
95 cell->setStyle (cellStyle);
96 ref = cell;
97 table->addRow (wordStyle);
98 table->addCell (cell, 1, 1);
99
100 char buf[16];
101 for(int j = 0; j < i; j++)
102 buf[j] = '0' + j;
103 buf[i] = '.';
104 for(int j = i + 1; j < 11; j++)
105 buf[j] = '0' + (j - 1);
106 buf[11] = 0;
107
108 cell->addText (buf, wordStyle);
109 cell->flush ();
110 }
111
112 wordStyle->unref();
113 cellStyle->unref();
114
115 window->resizable(viewport);
116 window->show();
117 int errorCode = Fl::run();
118
119 delete layout;
120
121 return errorCode;
122}
int main(void)
Definition bookmarks.c:1613
A Widget for rendering tables.
Definition table.hh:326
void addCell(Widget *widget, int colspan, int rowspan)
Definition table.cc:468
void addRow(core::style::Style *style)
Definition table.cc:584
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.