examples: Add C# buttons/popup example.
authorLauro Moura <lauromoura@expertisesolutions.com.br>
Wed, 13 Dec 2017 04:51:48 +0000 (01:51 -0300)
committerWonki Kim <wonki_.kim@samsung.com>
Wed, 10 Jan 2018 11:08:13 +0000 (20:08 +0900)
src/Makefile_Efl_Mono.am
src/examples/elementary/Makefile.am
src/examples/elementary/efl_ui_unit_converter.cs [new file with mode: 0644]

index 4715fff..5b2f993 100644 (file)
@@ -194,6 +194,16 @@ lib/efl_mono/libefl_mono.dll: $(efl_mono_files_dist) lib/efl_mono/$(am__dirstamp
        @rm -f lib/efl_mono/libefl_mono.dll
        $(AM_V_MCS) $(MCS) $(MCS_FLAGS) -out:$@ -t:library $(filter %.cs, $(^))
 
+lib/efl_mono/libefl_mono.dll.config:
+       echo "<configuration>" > $@
+       echo "  <dllmap dll=\"eina\" target=\"$(abs_top_builddir)/src/lib/eina/.libs/libeina.so\"/>" >> $@
+       echo "  <dllmap dll=\"ecore\" target=\"$(abs_top_builddir)/src/lib/ecore/.libs/libecore.so\"/>" >> $@
+       echo "  <dllmap dll=\"eo\" target=\"$(abs_top_builddir)/src/lib/eo/.libs/libeo.so\"/>" >> $@
+       echo "  <dllmap dll=\"evas\" target=\"$(abs_top_builddir)/src/lib/evas/.libs/libevas.so\"/>" >> $@
+       echo "  <dllmap dll=\"eldbus\" target=\"$(abs_top_builddir)/src/lib/eldbus/.libs/libeldbus.so\"/>" >> $@
+       echo "  <dllmap dll=\"elementary\" target=\"$(abs_top_builddir)/src/lib/elementary/.libs/libelementary.so\"/>" >> $@
+       echo "</configuration>" >> $@
+
 if HAVE_WIN32
 efl_mono_dll_dest = $(DESTDIR)$(bindir)
 else
@@ -348,6 +358,16 @@ tests/efl_mono/libefl_mono_test.dll: $(efl_mono_test_eolian_mono_files) tests/ef
        @rm -f tests/efl_mono/libefl_mono_test.dll
        $(AM_V_MCS) $(MCS) $(MCS_FLAGS) -r:$(abs_builddir)/lib/efl_mono/libefl_mono.dll -out:$@ -t:library $(filter %.cs, $(^))
 
+tests/efl_mono/efl_mono$(EXEEXT).config:
+       echo "<configuration>" > $@
+       echo "  <dllmap dll=\"eina\" target=\"$(abs_top_builddir)/src/lib/eina/.libs/libeina.so\"/>" >> $@
+       echo "  <dllmap dll=\"ecore\" target=\"$(abs_top_builddir)/src/lib/ecore/.libs/libecore.so\"/>" >> $@
+       echo "  <dllmap dll=\"eo\" target=\"$(abs_top_builddir)/src/lib/eo/.libs/libeo.so\"/>" >> $@
+       echo "  <dllmap dll=\"evas\" target=\"$(abs_top_builddir)/src/lib/evas/.libs/libevas.so\"/>" >> $@
+       echo "  <dllmap dll=\"eldbus\" target=\"$(abs_top_builddir)/src/lib/eldbus/.libs/libeldbus.so\"/>" >> $@
+       echo "  <dllmap dll=\"elementary\" target=\"$(abs_top_builddir)/src/lib/elementary/.libs/libelementary.so\"/>" >> $@
+       echo "</configuration>" >> $@
+
 # C Sharp test executable
 AM_TESTS_ENVIRONMENT += MONO='mono'; export MONO;
 AM_TESTS_ENVIRONMENT += MONO_BUILDPATH='$(abs_top_builddir)'; export MONO_BUILDPATH;
@@ -357,7 +377,6 @@ if HAVE_WIN32
 AM_TESTS_ENVIRONMENT += PATH='$(PATH):$(TEST_PATHS):$(WIN_ADD_TEST_PATHS)'; export PATH;
 else
 AM_TESTS_ENVIRONMENT += LD_LIBRARY_PATH='$(LD_LIBRARY_PATH):$(TEST_PATHS)'; export LD_LIBRARY_PATH;
-endif
 
 check_PROGRAMS += tests/efl_mono/efl_mono
 TESTS += tests/efl_mono/mono_test_driver.sh
@@ -377,15 +396,7 @@ tests_efl_mono_efl_mono_SOURCES = \
      tests/efl_mono/Value.cs \
      tests/efl_mono/ValueEolian.cs
 
-lib/efl_mono/libefl_mono.dll.config:
-       echo "<configuration>" > $@
-       echo "  <dllmap dll=\"eina\" target=\"$(abs_top_builddir)/src/lib/eina/.libs/libeina.so\"/>" >> $@
-       echo "  <dllmap dll=\"eo\" target=\"$(abs_top_builddir)/src/lib/eo/.libs/libeo.so\"/>" >> $@
-       echo "  <dllmap dll=\"evas\" target=\"$(abs_top_builddir)/src/lib/evas/.libs/libevas.so\"/>" >> $@
-       echo "  <dllmap dll=\"elementary\" target=\"$(abs_top_builddir)/src/lib/elementary/.libs/libelementary.so\"/>" >> $@
-       echo "</configuration>" >> $@
-
-tests/efl_mono/efl_mono$(EXEEXT): $(tests_efl_mono_efl_mono_SOURCES) tests/efl_mono/$(am__dirstamp) lib/efl_mono/libefl_mono.dll tests/efl_mono/libefl_mono_test.dll
+tests/efl_mono/efl_mono$(EXEEXT): $(tests_efl_mono_efl_mono_SOURCES) tests/efl_mono/$(am__dirstamp) lib/efl_mono/libefl_mono.dll tests/efl_mono/libefl_mono_test.dll tests/efl_mono/efl_mono$(EXEEXT).config
        @rm -f $@
        $(AM_V_MCS) $(MCS) $(MCS_FLAGS) -r:$(abs_top_builddir)/src/lib/efl_mono/libefl_mono.dll -r:$(abs_top_builddir)/src/tests/efl_mono/libefl_mono_test.dll -out:$@ $(filter %.cs, $(^))
 
@@ -395,5 +406,10 @@ tests/efl_mono/%.eo.cs: tests/efl_mono/%.eo $(_EOLIAN_MONO_DEP)
        $(MKDIR_P) $(dir $@); \
        $(EOLIAN_MONO) $(EOLIAN_FLAGS) $(EOLIAN_MONO_FLAGS) --dllimport "@DLIB_PREFIX_MONO@efl_mono_native_test@DLIB_SUFFIX_MONO@" -o $@ $(ALL_EO_REFS) $<
 
+CLEANFILES += tests/efl_mono/libefl_mono_test.dll tests/efl_mono/test_testing.eo.cs tests/efl_mono/test_numberwrapper.eo.cs tests/efl_mono/test_testing.eo.c tests/efl_mono/test_numberwrapper.eo.c tests/efl_mono/test_testing.eo.h tests/efl_mono/test_numberwrapper.eo.h
+
+endif
+
+
 endif
 endif
index 320d333..22b6471 100644 (file)
@@ -265,6 +265,30 @@ nodist_codegen_example_SOURCES = \
 codegen_example_generated.c \
 codegen_example_generated.h
 
+if HAVE_CSHARP
+
+if HAVE_WIN32
+MCS_FLAGS := $(MCS_FLAGS)
+MCS_FLAGS += -define:WIN32
+endif
+
+efl_ui_slider_mono_exe_SOURCES = \
+       efl_ui_slider_mono.cs
+
+efl_ui_slider_mono(EXEEXT): $(efl_ui_slider_mono_exe_SOURCES) $(am_dirstamp) $(top_builddir)/src/lib/efl_mono/libefl_mono.dll$(EXEEXT)
+       @rm -f efl_ui_slider_mono$(EXEEXT)
+       $(AM_V_MCS) $(MCS) $(MCS_FLAGS) -r:$(abs_top_builddir)/src/lib/efl_mono/libefl_mono.dll$(EXEEXT) -out:$@ $(filter %.cs, $(^))
+
+efl_ui_unit_converter_exe_SOURCES = \
+       efl_ui_unit_converter.cs
+
+efl_ui_unit_converter: $(efl_ui_unit_converter_exe_SOURCES) $(am_dirstamp) $(top_builddir)/src/lib/efl_mono/libefl_mono.dll
+       @rm -f efl_ui_unit_converter
+       $(AM_V_MCS) $(MCS) $(MCS_FLAGS) -r:$(abs_top_builddir)/src/lib/efl_mono/libefl_mono.dll -out:$@ $(filter %.cs, $(^))
+
+
+endif
+
 examples_PROGRAMS = \
 actionslider_example_01 \
 bg_example_01 \
@@ -443,7 +467,8 @@ efl_ui_slider_mono$(EXEEXT): $(efl_ui_slider_mono_SOURCES) $(am_dirstamp) $(top_
        $(AM_V_MCS) $(MCS) $(MCS_FLAGS) -r:$(abs_top_builddir)/src/lib/efl_mono/libefl_mono.dll -out:$@ $(filter %.cs, $(^))
 
 examples_PROGRAMS += \
-       efl_ui_slider_mono
+       efl_ui_slider_mono \
+       efl_ui_unit_converter
 
 endif
 
diff --git a/src/examples/elementary/efl_ui_unit_converter.cs b/src/examples/elementary/efl_ui_unit_converter.cs
new file mode 100644 (file)
index 0000000..f167e68
--- /dev/null
@@ -0,0 +1,152 @@
+using System;
+
+public class Example
+{
+
+    private static double KMS_PER_MILE = 1.609344;
+
+    private static double KmsToMiles(double kms)
+    {
+        return kms / KMS_PER_MILE;
+    }
+    private static double MilesToKms(double miles)
+    {
+        return miles * KMS_PER_MILE;
+    }
+
+    private static void ShowErrorPopup(efl.ui.Win win, string message)
+    {
+        efl.ui.Popup_Alert popup = new efl.ui.Popup_AlertConcrete(win);
+        efl.ui.Text popup_text = new efl.ui.TextConcrete(popup);
+        popup_text.SetText($"Error: {message}");
+        popup.SetContent(popup_text);
+        popup.SetVisible(true);
+        popup.SetButton(efl.ui.popup_alert.Button.Positive, "Ok");
+        popup.SetSize(150, 30);
+        popup.CLICKED += (object sender, efl.ui.CLICKED_Args e) => {
+            popup.SetParent(null);
+            popup.Del();
+        };
+    }
+
+#if WIN32 // Passed to the C# compiler with -define:WIN32
+    // Mono on Windows by default uses multi-thread apartments for COM stuff while
+    // OLE - used by ecore win32 DnD requires single threading for COM.
+    [STAThreadAttribute()]
+#endif
+    public static void Main() {
+        efl.All.Init(efl.Components.Ui);
+
+        efl.ui.Win win = new efl.ui.WinConcrete(null);
+        win.SetText("C# Unit Converter");
+        win.SetAutohide(true);
+
+        efl.ui.Box_Flow box = new efl.ui.Box_FlowConcrete(win);
+        box.SetDirection(efl.ui.Dir.Horizontal);
+
+        efl.ui.Box_Flow miles_box = new efl.ui.Box_FlowConcrete(box);
+        miles_box.SetDirection(efl.ui.Dir.Down);
+
+        box.Pack(miles_box);
+
+        efl.ui.Text miles_label = new efl.ui.TextConcrete(miles_box);
+        miles_label.SetText("Miles:");
+        miles_label.SetSize(120, 30);
+        miles_label.SetVisible(true);
+
+        efl.ui.text.Editable miles_input = new efl.ui.text.EditableConcrete(miles_box);
+        miles_input.SetText("");
+        miles_input.SetScrollable(true);
+        miles_input.SetSize(120, 30);
+        miles_input.SetVisible(true);
+
+        efl.ui.Button miles_button = new efl.ui.ButtonConcrete(miles_box);
+        miles_button.SetText("To Km");
+        miles_button.SetSize(120, 30);
+        miles_button.SetVisible(true);
+
+        miles_box.Pack(miles_label);
+        miles_box.Pack(miles_input);
+        miles_box.Pack(miles_button);
+
+
+        efl.ui.Box_Flow kms_box = new efl.ui.Box_FlowConcrete(box);
+        kms_box.SetDirection(efl.ui.Dir.Down);
+
+        box.Pack(kms_box);
+
+        efl.ui.Text kms_label = new efl.ui.TextConcrete(kms_box);
+        kms_label.SetText("Kilometers:");
+        kms_label.SetSize(120, 30);
+        kms_label.SetVisible(true);
+
+        efl.ui.text.Editable kms_input = new efl.ui.text.EditableConcrete(kms_box);
+        kms_input.SetText("");
+        kms_input.SetScrollable(true);
+        kms_input.SetSize(120, 30);
+        kms_input.SetVisible(true);
+
+        efl.ui.Button kms_button = new efl.ui.ButtonConcrete(kms_box);
+        kms_button.SetText("To Miles");
+        kms_button.SetSize(120, 30);
+        kms_button.SetVisible(true);
+
+        kms_box.Pack(kms_label);
+        kms_box.Pack(kms_input);
+        kms_box.Pack(kms_button);
+
+        kms_button.CLICKED += (object sender, EventArgs e) => {
+            try
+            {
+                string text = kms_input.GetText();
+                Console.WriteLine("Text is [{0}]", text);
+                double val = double.Parse(text);
+                miles_input.SetText(String.Format("{0:f3}", KmsToMiles(val)));
+                kms_input.SetFocus(true);
+            }
+            catch (FormatException ex)
+            {
+                Console.WriteLine("Exception {0} caught", ex);
+                ShowErrorPopup(win, "Invalid number");
+            }
+        };
+
+        miles_button.CLICKED += (object sender, EventArgs e) => {
+            try
+            {
+                string text = miles_input.GetText();
+                Console.WriteLine("Text is [{0}]", text);
+                double val = double.Parse(text);
+                kms_input.SetText(String.Format("{0:f3}", MilesToKms(val)));
+                miles_input.SetFocus(true);
+            }
+            catch (FormatException ex)
+            {
+                Console.WriteLine("Exception {0} cautght", ex);
+                ShowErrorPopup(win, "Invalid number");
+            }
+        };
+
+        kms_box.SetVisible(true);
+        miles_box.SetVisible(true);
+
+        eina.Position2D pos;
+
+        pos.X = 20;
+        pos.Y = 30;
+        box.SetPosition(pos);
+        box.SetVisible(true);
+
+        pos.X = 200;
+        pos.Y = 200;
+        win.SetPosition(pos);
+
+        win.SetSize(400,120);
+        win.SetVisible(true);
+
+        efl.ui.Config.Run();
+
+        efl.All.Shutdown();
+    }
+
+}