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

Subscribers

People subscribed via source and target branches

to all changes: