简体   繁体   English

如何在NativeUI C ++基础结构中解析实际的本机UI小部件?

[英]How are actual native UI widget resolved within the NativeUI C++ infrastructure?

I'd like to know and understand the code which ultimately calls the actual IOS/Android/WP native widgets, when a NativeUI C++ class is used within the MoSync code base. 我想了解和理解在MoSync代码库中使用NativeUI C ++类时最终调用实际IOS / Android / WP本机窗口小部件的代码。

I've taken a quick look at a few classes on GitHub, like Button.cpp etc, but I can't readily see how the real native device widgets are being referenced. 我快速浏览了GitHub上的一些类,例如Button.cpp等,但是我无法轻易看到如何引用真正的本机设备小部件。

I'm not a C/C++ dev (Java) but I was kind of expecting some #ifdefs or something to 'switch' out the respective underlying implementation. 我不是C / C ++开发人员(Java),但我有点期待一些#ifdef或某些东西来“切换”各自的基础实现。 If that's not the case, then that's fine by me, just please indulge my curiosity. 如果不是这种情况,那对我来说很好,请放任我的好奇心。

The C++ Widget classes like the Button.cpp mentioned have their base class in Widget.cpp which creates any widget based on a string argument. 像提到的Button.cpp这样的C ++ 窗口小部件类在Widget.cpp中都有其基类, 该类基于字符串参数创建任何窗口小部件。 Also, any widget properties are effectively set through through string arguments. 而且,任何小部件属性都可以通过字符串参数有效地设置。

my_button = new NativeUI::Widget("button")
my_button->setProperty("text", "OK");

MoSync implements an "IDL" interface for Native UI widgets in WidgetFunctions.idl : MoSync在WidgetFunctions.idl为本机UI小部件实现了“ IDL”接口:

typedef int MAWidgetHandle;
MAWidgetHandle maWidgetCreate(in MAString widgetType);
int maWidgetSetProperty(in MAWidgetHandle widget, in MAString property, in MAString value);

This is a language-independent description of the functions which get called from the NativeUI::Widget through a C call interface: 这是通过C调用接口从NativeUI :: Widget调用的函数的与语言无关的描述:

handle = maWidgetCreate("button");
maWidgetSetProperty(handle,"text","OK");

Until here we are on the MoSync C/C++ layer, which is kind of a VM with a system call interface. 到这里为止,我们位于MoSync C / C ++层上,这是一种具有系统调用接口的VM。 From here it is translated to the languages of the other platforms (Java, C#, etc.) by different methods: 从这里可以通过不同的方法将其翻译为其他平台的语言(Java,C#等):

It can use Java Native Interface (JNI) to call the corresponding functions in the Android runtime in MoSyncNativeUI.java : 它可以使用Java本机接口(JNI)在Android运行时中的MoSyncNativeUI.java中调用相应的函数:

public int maWidgetCreate(String type)
public int maWidgetSetProperty(int widgetHandle, String key, String value)

Or it is compiled into the intermediate "PIPE language", a pseudo assembler dialect, this language is then translated into Visual Studio C# for Windows Phone 7, or into an XCode project for iOS. 或者将其编译为中间的“ PIPE语言”(一种伪汇编方言),然后将该语言转换为Windows Phone 7的Visual Studio C#或iOS的XCode项目。

All platforms implement an UI engine in the "runtime" which is bundled with every app package. 所有平台都在“运行时”中实现了一个UI引擎,该引擎与每个应用程序包捆绑在一起。 This runtime is prebuilt in the corresponding SDK and implements those Native UI calls. 此运行时是在相应的SDK中预先构建的,并实现了那些本机UI调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM