加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

高级控件 Advanced Widgets :Using GIndexGroup and GindexCombo

发布时间:2020-12-14 16:46:17 所属栏目:大数据 来源:网络整理
导读:Advanced Widgets :Using GIndexGroup and GindexCombo 在这个教程中我们将会建立一个叫做GINDEXAPP的简单工程来展示怎么用GIndexGroup和GIndexCombo。我们假设你已经了解前文中APP开发的过程。 GindexGroup可以让你给窗体部件归类,GIndexCombo就像一个指针

Advanced Widgets :Using GIndexGroup and GindexCombo


在这个教程中我们将会建立一个叫做GINDEXAPP的简单工程来展示怎么用GIndexGroup和GIndexCombo。我们假设你已经了解前文中APP开发的过程。
GindexGroup可以让你给窗体部件归类,GIndexCombo就像一个指针让你可以在不同的GindexGroup中切换来减少窗体的占用面积和在生成APP GUI时占用更少的资源来使APP的运行效果更佳。
在下面的图中你可以比较普通的布置方案和用GindexGroup的不同。如果在这个例子里你只有5个相似的部件,或许你想同时显示它们,设想你如果有6个部件你就没有其余的空间来放置它,你只能把它们放在不同的Tab上,这不是一个好的解决方案。


尽管使用GIndexGroup和GIndexCombo 是进阶的教程,但它们不难。本质上,GIndexCombo就是GIndexGroup的选择器。
当你创建一个GIndexGroup,你需要拖一个GIndexCombo且只有一个在窗体里,之后你可以拖任何你想要的窗体部件进去。然后你就能马上得到GIndexCombo的最多能产生的数目。保存后,你将在manifest文件中看到一个.wg文件。


这个新的文件包含了你刚刚加入的窗体部件:

import ifx.davex.app.manifest.*;

class Gindexgroup_example {
  public GCombo gcombo_example;
  public GInteger ginteger_example;
  public GCheck gcheck_example;

  public Gindexgroup_example (DaveEnv daveEnv,String widgetName,int index){
    gcombo_example = new GCombo(widgetName:"gcombo_example",options:["Option 1","Option 2"],value:"Option 1",enabled:true,visible:true,isMandatoryValue:false,parentWidgetName:widgetName)
    ginteger_example = new GInteger(widgetName:"ginteger_example",value:1024,minValue:0,maxValue:4096,parentWidgetName:widgetName)
    gcheck_example = new GCheck(widgetName:"gcheck_example",value:false,parentWidgetName:widgetName)
  }
}

在此同时,一些新的代码在GINDEXAPP_GUI.manifest文件中生成:

abstract class GINDEXAPP_GUI extends AppManifest {
  // Begin : UI variable section
  public GInteger ginteger_number_of_items;
  public GIndexCombo gindexcombo_item;
  public GIndexGroup gindexgroup_example;
  public RArray<Gindexgroup_example> rArraygindexgroup_example = RArray(16);


  public GINDEXAPP_GUI(DaveEnv daveEnv){

    ginteger_number_of_items = GInteger(widgetName:"ginteger_number_of_items",value:5,minValue:1,maxValue:16,isMandatoryValue:false)
    gindexcombo_item = GIndexCombo(widgetName:"gindexcombo_item",options:["ITEM_0","ITEM_1","ITEM_2","ITEM_3","ITEM_4","ITEM_5","ITEM_6","ITEM_7","ITEM_8","ITEM_9","ITEM_10","ITEM_11","ITEM_12","ITEM_13","ITEM_14","ITEM_15"],value:"ITEM_0")
    gindexgroup_example = GIndexGroup(widgetName:"gindexgroup_example",text:"GIndexGroup",gIndexCombo:gindexcombo_item,rArray:rArraygindexgroup_example)
    for(int i=0; i<16; i++){
      rArraygindexgroup_example[i] = new Gindexgroup_example(daveEnv,"gindexgroup_example",i)
    }

  }
  // End : UI variable section
}

在这个例子中,我们最多允许了16个部件(组),但我们只显示5组。这是因为我们定义GIndexCombo.maxChoices = 16,然后一个新的RArry对象被定义为16,定义了包含了所有可能的GIndexGroup窗体部件。最大可以选择的数目必须和GInteger中定义的maxChoices数目一致:


在这里,我们有一个RArry对象包含了每一个GIndexGroup,有了GIndexCombo我们可以通过GUI选择显示GIndexGroup。在下面的图中你可以看到上面例子展示的原理图:


你可以更改显示数量的多少,但你不能更改选择的数量,因为它是固定的。为了改变显示的数量,你可以通过定义GIndexCombo.options来实现。需要注意List必须和RArray size拥有相当的长度,你可以在manifest中如下定义:

gindexcombo_item.options = MF(
  {
    List<String> l = new ArrayList(rArraygindexgroup_example.size())
    for (int i = 0; i < ginteger_number_of_items.value; i++)
    {
      l.add("ITEM_$i".toString())
    }
    l
  },List
)

在下面的程序中,我们建立了一列String 元素,我们把non-null放入相应的String元素,当用户通过在APP GUI的GInteger 在ginteger_number_of_items放入数值。其余的值为null,它们将不会在GIndexCombo显示。


就像你看到的,GindexGroup的元素也将会继续在RArry中显示,但它们不在窗体中可见,因为它们在gindexcombo_item.options 列表中对应空值。

你可以用这部件去定义信号,占用资源或生成代码。在下面的代码中你可以看到一些Templates的例子,它们使用了GIndexGroup窗体部件的返回值生成代码:

gindexapp.h file:
#ifndef _GINDEXAPP_H_
#define _GINDEXAPP_H_

#ifdef __cplusplus
extern "C" {
#endif

/***********************************************************************************************************************
** System Header file inclusion **
***********************************************************************************************************************/
#include <DAVE.h>

/***********************************************************************************************************************
** Macros **
***********************************************************************************************************************/

/***********************************************************************************************************************
** Data types (typedefs and enumerations) **
***********************************************************************************************************************/
typedef enum GINDEXAPP_STATUS
{
  GINDEXAPP_STATUS_OK = 0U,// 0 = Status OK
  GINDEXAPP_STATUS_FAILURE = 1U // 1 = Status Failed
} GINDEXAPP_STATUS_t;

/***********************************************************************************************************************
** Data structures **
***********************************************************************************************************************/
typedef struct GINDEXAPP {
  char * gcombo;
  int ginteger;
  bool gcheck;
} GINDEXAPP_t;

/***********************************************************************************************************************
** API prototypes **
***********************************************************************************************************************/


#include "GINDEXAPP_extern.h" /* Included to access the APP Handles at Main.c */

#ifdef __cplusplus
}
#endif

#endif /* GINDEXAPP_H_ */


gindexapp_extern_h.tmpl file:

 out.print("""
#ifndef GINDEXAPP_EXTERN_H_
#define GINDEXAPP_EXTERN_H_

#ifdef __cplusplus
extern "C" {
#endif

/* Extern declaration of GINDEXAPP APP handlers */
""")
for(def app : appInstancesList){

  for (int i = 0; i < app.ginteger_number_of_items.value; i++) { out.print(""" extern GINDEXAPP_t ${app.getInstanceLabel()}_ITEM_$i;""") } } out.print(""" #ifdef __cplusplus } #endif #endif /* GINDEXAPP_EXTERN_H_ */""") gindexapp_conf_c.tmpl file: out.println("#include "gindexapp.h"") for (GINDEXAPP app : appInstancesList) { for (int i = 0; i < app.ginteger_number_of_items.value; i++) { out.print(""" GINDEXAPP_t ${app.getInstanceLabel()}_ITEM_$i = { .gcombo = "${app.rArraygindexgroup_example[i].gcombo_example.value}",.ginteger = ${app.rArraygindexgroup_example[i].ginteger_example.value},.gcheck = ${app.rArraygindexgroup_example[i].gcheck_example.value ? "true" : "false"} }; """) } } 

下图你可以看到这个例子在运行在DAVE? 4中的样子:

它所生成的代码:

gindexapp_extern.h file:

#ifndef GINDEXAPP_EXTERN_H_
#define GINDEXAPP_EXTERN_H_

#ifdef __cplusplus
extern "C" {
#endif

/* Extern declaration of GINDEXAPP APP handlers */

extern GINDEXAPP_t GINDEXAPP_0_ITEM_0;
extern GINDEXAPP_t GINDEXAPP_0_ITEM_1;
extern GINDEXAPP_t GINDEXAPP_1_ITEM_0;

#ifdef __cplusplus
}
#endif

#endif /* GINDEXAPP_EXTERN_H_ */


gindexapp_conf.c file:

#include "gindexapp.h"

GINDEXAPP_t GINDEXAPP_0_ITEM_0 =
{
  .gcombo = "Option 1",.ginteger = 3210,.gcheck = true
};

GINDEXAPP_t GINDEXAPP_0_ITEM_1 =
{
  .gcombo = "Option 1",.ginteger = 1024,.gcheck = false
};

GINDEXAPP_t GINDEXAPP_1_ITEM_0 =
{
  .gcombo = "Option 2",.ginteger = 83,.gcheck = false
};

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读