Merge lp:~haggai-eran/nuxcodesamples/widgetfactory into lp:nuxcodesamples

Proposed by Haggai Eran
Status: Needs review
Proposed branch: lp:~haggai-eran/nuxcodesamples/widgetfactory
Merge into: lp:nuxcodesamples
Diff against target: 488 lines (+443/-5)
3 files modified
configure.ac (+22/-4)
src/Makefile.am (+5/-1)
src/twf.cpp (+416/-0)
To merge this branch: bzr merge lp:~haggai-eran/nuxcodesamples/widgetfactory
Reviewer Review Type Date Requested Status
Nux Devs Pending
Review via email: mp+103971@code.launchpad.net

Commit message

Introduce a widget factory example program modeled after Gtk's twf program.

Description of the change

Hi,

I wrote this patch to continue working on right-to-left support for Nux. I understand from the last interaction on my merge proposal (https://code.launchpad.net/~haggai-eran/nux/rtl-logical-packing/+merge/103818) that we need to work with Unity designers to decide on the best ways for supporting right-to-left languages. To do that, I thought it would be nice to show a mock program that uses as many widgets of Nux as possible (similar to Gtk's widget factory), and show the designers how we expect that program to look under a right-to-left locale.

In this patch I wrote such a program. I wanted to get Nux developers feedback on it. Does it contain all the interesting widgets in Nux? Are there any missing widgets, or widgets that are used incorrectly?

Thanks,
Haggai Eran

To post a comment you must log in.

Unmerged revisions

11. By Haggai Eran

Enable right-to-left mirroring depending on locale, when RTL support is available.

10. By Haggai Eran

Use ScrollView instead of separate scrollbars in twf.

9. By Haggai Eran

Merge from the nux/nux-samples branch.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'configure.ac'
--- configure.ac 2011-11-04 03:58:56 +0000
+++ configure.ac 2012-04-28 08:28:20 +0000
@@ -139,10 +139,10 @@
139 libpci139 libpci
140 libpcre140 libpcre
141 gstreamer-0.10141 gstreamer-0.10
142 nux-core-1.0 >= 1.16142 nux-core-2.0
143 nux-graphics-1.0 >= 1.16143 nux-graphics-2.0
144 nux-image-1.0 >= 1.16144 nux-image-2.0
145 nux-1.0 >= 1.16145 nux-2.0
146 $GL_PKGS146 $GL_PKGS
147 )147 )
148148
@@ -151,6 +151,24 @@
151AC_SUBST(NUX_SAMPLES_CFLAGS)151AC_SUBST(NUX_SAMPLES_CFLAGS)
152AC_SUBST(NUX_SAMPLES_LIBS)152AC_SUBST(NUX_SAMPLES_LIBS)
153153
154dnl Check if libnux includes right-to-left support.
155AC_MSG_CHECKING([whether Nux contains right-to-left mirroring support.])
156AC_LANG_PUSH([C++])
157SAVED_CXXFLAGS=$CXXFLAGS
158CXXFLAGS="$CXXFLAGS $NUX_SAMPLES_CFLAGS"
159if test "x$GCC" = "xyes"; then
160 CXXFLAGS="$CXXFLAGS -std=c++0x"
161fi
162AC_COMPILE_IFELSE(
163 [AC_LANG_PROGRAM([#include <Nux/Nux.h>],
164 [nux::SetDefaultDirection(nux::RightToLeft);])],
165 [AC_DEFINE([HAVE_NUX_RTL],[1],[Nux contains right-to-left mirroring support.])] [have_nux_rtl='yes'],
166 [have_nux_rtl='no'])
167CXXFLAGS=$SAVED_CXXFLAGS
168LDFLAGS=$SAVED_LDFLAGS
169AC_LANG_POP([C++])
170AC_MSG_RESULT([$have_nux_rtl])
171
154dnl ==========================================================================172dnl ==========================================================================
155173
156if test "x$GCC" = "xyes"; then174if test "x$GCC" = "xyes"; then
157175
=== modified file 'src/Makefile.am'
--- src/Makefile.am 2011-11-04 03:58:56 +0000
+++ src/Makefile.am 2012-04-28 08:28:20 +0000
@@ -6,7 +6,8 @@
6# This tells automake that we want to build binaries, but they shouldn't be6# This tells automake that we want to build binaries, but they shouldn't be
7# installed. For each individual example, add it's binary name here7# installed. For each individual example, add it's binary name here
88
9bin_PROGRAMS = button \9bin_PROGRAMS = twf \
10 button \
10 checkbox \11 checkbox \
11 color-controller \12 color-controller \
12 color-picker \13 color-picker \
@@ -32,6 +33,9 @@
32# This is the individual executable build. For every $exe in noinst_PROGRAMS33# This is the individual executable build. For every $exe in noinst_PROGRAMS
33# you need a $exe_SOURCES and $exe_LDADD so it builds34# you need a $exe_SOURCES and $exe_LDADD so it builds
3435
36twf_SOURCES = twf.cpp
37twf_LDADD = $(NUX_SAMPLES_LIBS)
38
35button_SOURCES = button.cpp39button_SOURCES = button.cpp
36button_LDADD = $(NUX_SAMPLES_LIBS)40button_LDADD = $(NUX_SAMPLES_LIBS)
3741
3842
=== added file 'src/twf.cpp'
--- src/twf.cpp 1970-01-01 00:00:00 +0000
+++ src/twf.cpp 2012-04-28 08:28:20 +0000
@@ -0,0 +1,416 @@
1/*
2 * Copyright 2012 Inalogic Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Haggai Eran <haggai.eran@gmail.com>
18 * Based on the button.cpp file by Jay Taoko <jaytaoko@inalogic.com>
19 *
20 */
21
22#include "config.h"
23
24#include "Nux/Nux.h"
25#include "Nux/HLayout.h"
26#include "Nux/VLayout.h"
27#include "Nux/WindowThread.h"
28#include "Nux/TextureArea.h"
29#include "Nux/Button.h"
30#include "Nux/ToggleButton.h"
31#include "Nux/RadioButton.h"
32#include "Nux/RadioButtonGroup.h"
33#include "Nux/CheckBox.h"
34#include "Nux/AbstractComboBox.h"
35#include "Nux/TextEntry.h"
36#include "Nux/SpinBox.h"
37
38#include "Nux/MenuBar.h"
39#include "Nux/MenuPage.h"
40#include "Nux/ActionItem.h"
41
42#include "Nux/RangeValue.h"
43#include "Nux/HScrollBar.h"
44#include "Nux/VScrollBar.h"
45#include "Nux/HSplitter.h"
46#include "Nux/VSplitter.h"
47
48#include "Nux/RGBValuator.h"
49#include "Nux/ColorEditor.h"
50
51#include "Nux/GroupBox.h"
52#include "Nux/GroupBox2.h"
53#include "Nux/TabView.h"
54
55#include "Nux/StaticText.h"
56
57using namespace nux;
58
59void MenuAction(MenuPage* menu, ActionItem* action)
60{
61 if (strcmp(action->GetLabel(), "Exit") == 0)
62 GetWindowThread()->ExitMainLoop();
63}
64
65View* CreateMenuBar()
66{
67 MenuBar * menu_bar = new MenuBar();
68 MenuPage * menu = new MenuPage("Theme");
69 menu->AddAction("Exit", 0);
70 menu->sigActionTriggered.connect(&MenuAction);
71 menu_bar->AddMenu("Theme", menu);
72 return menu_bar;
73}
74
75Layout* CreateToolBar()
76{
77 HLayout* toolbar = new HLayout();
78
79 Button* first = new Button(); // TODO image
80 first->SetLabel("First");
81 first->SetMaximumWidth(30);
82 toolbar->AddView(first);
83
84 Button* last = new Button(); // TODO image
85 last->SetLabel("Last");
86 last->SetMaximumWidth(30);
87 toolbar->AddView(last);
88
89 toolbar->AddSpace(6);
90
91 // TODO toggle button: note that it doesn't seem to be implemented yet.
92 Button* add = new ToggleButton(); // TODO image
93 add->SetLabel("Add");
94 add->SetMaximumWidth(30);
95 toolbar->AddView(add);
96
97 toolbar->SetMaximumHeight(30);
98 toolbar->SetSpaceBetweenChildren(6);
99
100 return toolbar;
101}
102
103Layout* CreateComboBoxes()
104{
105 VLayout* layout = new VLayout();
106
107 // TODO no non-abstract comboboxes?
108 AbstractComboBox* combobox1 = new AbstractComboBox();
109 layout->AddView(combobox1);
110
111 AbstractComboBox* combobox2 = new AbstractComboBox();
112 layout->AddView(combobox2);
113
114 layout->SetSpaceBetweenChildren(3);
115
116 return layout;
117}
118
119Layout* CreateEntries()
120{
121 VLayout* layout = new VLayout();
122
123 TextEntry* e1 = new TextEntry("TextEntry");
124 e1->SetMaximumHeight(20);
125 layout->AddView(e1);
126
127 TextEntry* e2 = new TextEntry("TextEntry");
128 e2->DisableView();
129 e2->SetMaximumHeight(20);
130 layout->AddView(e2);
131
132 layout->SetSpaceBetweenChildren(3);
133
134 return layout;
135}
136
137Layout* CreateSpinBoxes()
138{
139 HLayout* layout = new HLayout();
140
141 SpinBox* spin1 = new SpinBox();
142 spin1->SetMaximumWidth(50);
143 layout->AddView(spin1, 1, MINOR_POSITION_CENTER, MINOR_SIZE_MATCHCONTENT);
144
145 SpinBox* spin2 = new SpinBox();
146 spin2->DisableView();
147 spin2->SetMaximumWidth(50);
148 layout->AddView(spin2, 1, MINOR_POSITION_CENTER, MINOR_SIZE_MATCHCONTENT);
149
150 layout->SetSpaceBetweenChildren(3);
151 layout->SetContentDistribution(MAJOR_POSITION_SPREAD);
152
153 return layout;
154}
155
156Layout* CreateCheckBoxes()
157{
158 VLayout* layout = new VLayout();
159
160 CheckBox* e1 = new CheckBox("radiobutton1", false);
161 layout->AddView(e1, 1, MINOR_POSITION_CENTER, MINOR_SIZE_MATCHCONTENT);
162
163 CheckBox* e2 = new CheckBox("radiobutton2", true);
164 layout->AddView(e2, 1, MINOR_POSITION_CENTER, MINOR_SIZE_MATCHCONTENT);
165
166 CheckBox* e3 = new CheckBox("radiobutton3", false);
167 e3->DisableView();
168 layout->AddView(e3, 1, MINOR_POSITION_CENTER, MINOR_SIZE_MATCHCONTENT);
169
170 CheckBox* e4 = new CheckBox("radiobutton4", true);
171 e4->DisableView();
172 layout->AddView(e4, 1, MINOR_POSITION_CENTER, MINOR_SIZE_MATCHCONTENT);
173
174 layout->SetContentDistribution(MAJOR_POSITION_SPREAD);
175
176 return layout;
177}
178
179Layout* CreateRadioButtons()
180{
181 VLayout* layout = new VLayout();
182
183 RadioButtonGroup* group = new RadioButtonGroup();
184
185 RadioButton* e1 = new RadioButton("checkbox1", false);
186 group->ConnectButton(e1);
187 layout->AddView(e1, 1, MINOR_POSITION_CENTER, MINOR_SIZE_MATCHCONTENT);
188
189 RadioButton* e2 = new RadioButton("checkbox2", true);
190 group->ConnectButton(e2);
191 layout->AddView(e2, 1, MINOR_POSITION_CENTER, MINOR_SIZE_MATCHCONTENT);
192
193 group = new RadioButtonGroup();
194 RadioButton* e3 = new RadioButton("checkbox3", false);
195 e3->DisableView();
196 group->ConnectButton(e3);
197 layout->AddView(e3, 1, MINOR_POSITION_CENTER, MINOR_SIZE_MATCHCONTENT);
198
199 RadioButton* e4 = new RadioButton("checkbox4", true);
200 e4->DisableView();
201 group->ConnectButton(e4);
202 layout->AddView(e4, 1, MINOR_POSITION_CENTER, MINOR_SIZE_MATCHCONTENT);
203
204 layout->SetContentDistribution(MAJOR_POSITION_SPREAD);
205
206 return layout;
207}
208
209Layout* CreateColumn1()
210{
211 VLayout *layout = new VLayout();
212 // TODO
213 // layout->AddLayout(CreateComboBoxes());
214
215 layout->AddLayout(CreateEntries());
216 layout->AddLayout(CreateSpinBoxes());
217
218 HLayout* checkboxes_and_radiobuttons = new HLayout();
219 checkboxes_and_radiobuttons->AddLayout(CreateCheckBoxes());
220 checkboxes_and_radiobuttons->AddLayout(CreateRadioButtons());
221
222 layout->AddLayout(checkboxes_and_radiobuttons);
223
224 layout->SetSpaceBetweenChildren(12);
225
226 return layout;
227}
228
229Layout* CreateButtons()
230{
231 VLayout* layout = new VLayout();
232
233 Button* e1 = new Button("button1");
234 e1->SetLabel("button1");
235 e1->SetMaximumHeight(20);
236 layout->AddView(e1);
237
238 Button* e2 = new Button("button2");
239 e2->SetLabel("button2");
240 e2->DisableView();
241 e2->SetMaximumHeight(20);
242 layout->AddView(e2);
243
244 layout->SetSpaceBetweenChildren(3);
245
246 return layout;
247}
248
249Layout* CreateToggleButtons()
250{
251 VLayout* layout = new VLayout();
252
253 Button* e1 = new ToggleButton("togglebutton1");
254 e1->SetLabel("togglebutton1");
255 e1->SetMaximumHeight(20);
256 layout->AddView(e1);
257
258 Button* e2 = new ToggleButton("togglebutton2");
259 e2->SetLabel("togglebutton2");
260 e2->DisableView();
261 e2->SetMaximumHeight(20);
262 layout->AddView(e2);
263
264 layout->SetSpaceBetweenChildren(3);
265
266 return layout;
267}
268
269Layout* CreateColumn2()
270{
271 VLayout *layout = new VLayout();
272
273 layout->AddLayout(CreateButtons());
274 layout->AddLayout(CreateToggleButtons());
275 // TODO ComboBox
276 // TODO OptionMenu
277
278 layout->SetSpaceBetweenChildren(12);
279
280 return layout;
281}
282
283Layout* CreateProgressBars()
284{
285 VLayout* layout = new VLayout();
286
287 RangeValue* e1 = new RangeValue(0.5);
288 e1->SetMaximumHeight(20);
289 layout->AddView(e1);
290
291 layout->SetSpaceBetweenChildren(3);
292
293 return layout;
294}
295
296Layout* CreateScrollBars()
297{
298 VLayout* layout = new VLayout();
299
300 ScrollView* scrollview = new ScrollView();
301 StaticText* label = new StaticText("ScrollView: A very long label that won't fit in the scroll-view.\n1\n2\n3\n4\n5\n6");
302 VLayout* innerlayout = new VLayout();
303 innerlayout->AddView(label);
304 scrollview->SetLayout(innerlayout);
305 layout->AddView(scrollview);
306
307 return layout;
308}
309
310Layout* CreateColumn3()
311{
312 VLayout *layout = new VLayout();
313
314 layout->AddLayout(CreateProgressBars());
315 layout->AddLayout(CreateScrollBars());
316
317 //layout->SetSpaceBetweenChildren(12);
318
319 return layout;
320}
321
322Layout* CreateRow1()
323{
324 HLayout* hlayout = new HLayout();
325 hlayout->AddLayout(CreateColumn1());
326 hlayout->AddLayout(CreateColumn2());
327 hlayout->AddLayout(CreateColumn3());
328 // TODO 4th column would be the tree view.
329
330 hlayout->SetSpaceBetweenChildren(12);
331 return hlayout;
332}
333
334Layout* CreateRow2()
335{
336 HLayout* hlayout = new HLayout();
337
338 VSplitter* vsplitter = new VSplitter();
339
340 GroupBox* e1 = new GroupBox();
341 e1->SetCaption("GroupBox");
342 vsplitter->AddWidget(e1, 0.5);
343 GroupBox2* e2 = new GroupBox2();
344 e2->SetCaption("GroupBox2");
345 vsplitter->AddWidget(e2, 0.5);
346
347 hlayout->AddView(vsplitter, 2);
348
349 TabView* tabview = new TabView();
350 tabview->AddTab("tab1", new VLayout());
351 tabview->AddTab("tab2", new VLayout());
352 tabview->AddTab("tab3", new VLayout());
353
354 hlayout->AddView(tabview, 1);
355
356 hlayout->SetSpaceBetweenChildren(12);
357 return hlayout;
358}
359
360Layout* CreateRow3()
361{
362 HLayout* hlayout = new HLayout();
363
364 nux::RGBValuator *color_selector = new nux::RGBValuator(NUX_TRACKER_LOCATION);
365 hlayout->AddView(color_selector);
366 nux::ColorEditor *color_picker = new nux::ColorEditor(NUX_TRACKER_LOCATION);
367 hlayout->AddView(color_picker);
368
369 return hlayout;
370}
371
372void UserInterfaceInitialization(NThread* thread, void* init_data)
373{
374 VLayout *root_layout = new VLayout();
375
376 root_layout->AddView(CreateMenuBar());
377
378 root_layout->AddLayout(CreateToolBar());
379
380 root_layout->AddLayout(CreateRow1());
381 root_layout->AddLayout(CreateRow2());
382 root_layout->AddLayout(CreateRow3());
383
384 GetWindowThread ()->SetLayout (root_layout);
385
386 // Set the background color of the window
387 //ColorLayer background (Color (0xFF222222));
388 //static_cast<WindowThread*> (thread)->SetWindowBackgroundPaintLayer(&background);
389}
390
391int main(int argc, char **argv)
392{
393 // Initialize Nux subsystem
394 NuxInitialize (0);
395
396#if HAVE_NUX_RTL
397 setlocale(LC_ALL, "");
398 if (strcmp(dgettext("gtk30", "default:LTR"), "default:RTL") == 0)
399 SetDefaultDirection(RightToLeft);
400#endif
401
402 // Create a Window thread
403 WindowThread* wt = CreateGUIThread(
404 "thewidgetfactory (nux)",
405 500,
406 500,
407 0,
408 &UserInterfaceInitialization,
409 0);
410
411 // Start the main loop
412 wt->Run (0);
413
414 delete wt;
415 return 0;
416}

Subscribers

People subscribed via source and target branches

to all changes: