Kanzi编程基础2 - Kanzi节点读取和属性设置
UI设计师在Kanzi studio把Kanzi的节点做好后,就要编码读取这些节点并根据实际功能去控制刷新它。
Kanzi读取节点的api发生过很多次变化,从2.7、2.8到3.0,每次变化都比较大,可能是因为kanzi引擎的设计思路还不是非常确定。
目前3.3版本可以通过application下的screen里的方法读取,如下:
std::shared_ptr<Node> spNode = app->getScreen()->lookupNode<Node>("RootPage/MainView/RPMGauge/Scene/RPM");
lookuoNode是一个模板方法,需要传入查找的节点的类型,我们可以使用基类型Node(Kanzi所有的节点的基类为Node),然后传入相对于Screen节点的路径。同样,也可以传入一个alias,如果使用的是alias,则要加前缀'#',如"#RPM"(名为RPM的alias需要在Kanzi studio中创建)。
该方法获取到的是该节点的一个智能指针,获取到后就可以通过这个智能指针就可以设置该节点的属性,如可见性、可用性等。
目前可以使用两种方式来设置kanzi节点的属性,
第1种:
使用Node类中的具体方法设置,如里面有setVisible方法,我们可以查找到这个方法的定义
void setVisible(bool value) { setProperty(VisibleProperty, value); }
如spNode->setVisible(false);则设置该节点隐藏。
Node类中定义了很多类似的方法,具体可以查看对应的头文件。
第2种:
使用Node类中的setProperty方法设置,传入属性的名称和值即可。具体的定义如下:
/// Sets the local value of a property.
///
/// \param propertyType The property type identifying the property to set.
/// \param value The value to set.
template <typename DataType>
void setProperty(const PropertyType<DataType>& propertyType, typename PropertyType<DataType>::DataType value)
{
propertyType.setter(getPropertyManager(), this, value);
}
可以看得出来,这个方法比较灵活,只要知道属性的定义,就可以设置所有的属性(包括自定义的属性)。
同样,对应有getProperty方法可以获取所有的属性值。
/// Returns the current value of a property.
///
/// The value returned by this function is the result of the property system evaluating the inputs that can affect the values of properties.
/// The final value is calculated by determining the base value of the property and applying existing modifiers to it.
///
/// Base value is affected by the following inputs where the highest entry in the list determines the base value:
/// 1. Local value set with setProperty or loaded from kzb
/// 2. Value set by a style affecting the property.
/// 3. Value defined by class metadata.
///
/// When the base value is determined the system applies modifiers to the value that can change the value or replace it completely.
/// The following is the list of possible modifiers, where the order of evaluation is determined by the order the modifiers were added or applied.
/// 1. Values defined is states of state manager.
/// 2. Animations.
///
/// If no inputs to the property value can be established the system returns the value registered in the property type metadata.
/// \param propertyType The property type identifying the property to retrieve.
/// \return Returns the evaluated property value.
template <typename DataType>
DataType getProperty(const PropertyType<DataType>& propertyType) const
{
return propertyType.getter(getPropertyManager(), this);
}
基本的节点获取就是那么简单。当然,深入做下去的时候,还会发现满足不了需求的情况,后面的进阶部分会继续介绍。
Kanzi编程基础2 - Kanzi节点读取和属性设置的更多相关文章
- Kanzi编程基础3 - 图片读取与显示
Kanzi开发的时候会遇到需要从外部读取图片的情况.Kanzi2.8版本和3.3版本读取方法稍有不同,我们先看看2.8版本的api. [2.8版本] 1)首先要从文件中读取一张图片 struct Kz ...
- Kanzi编程基础1 - 定时器Timer
Kanzi虽然发生了比较多的版本更迭,api也发生了很多变化,但定时器的头文件一直都在一个地方:#include "user/include/user/ui/message/kzu_mess ...
- 【基础篇】EditText的一些属性设置
设置EditText的背景颜色 private test_editText=null; test_editText= (EditText) findViewById(R.id.EditTextInp ...
- (转)Windows驱动编程基础教程
版权声明 本书是免费电子书. 作者保留一切权利.但在保证本书完整性(包括版权声明.前言.正文内容.后记.以及作者的信息),并不增删.改变其中任何文字内容的前提下,欢迎任何读者 以任何形式(包括 ...
- C#面向对象编程基础-喜课堂笔记
**************[5][C#面向对象编程基础]第1讲:类与对象**************** *************2.1.1_类与对象的概念**** ...
- 用Netty开发中间件:网络编程基础
用Netty开发中间件:网络编程基础 <Netty权威指南>在网上的评价不是很高,尤其是第一版,第二版能稍好些?入手后快速翻看了大半本,不免还是想对<Netty权威指南(第二版)&g ...
- Java网络编程和NIO详解开篇:Java网络编程基础
Java网络编程和NIO详解开篇:Java网络编程基础 计算机网络编程基础 转自:https://mp.weixin.qq.com/s/XXMz5uAFSsPdg38bth2jAA 我们是幸运的,因为 ...
- Linux基础篇–shell脚本编程基础
本章内容概要 编程基础 脚本基本格式 变量 运算 条件测试 配置用户环境 7.1 编程基础程序:指令+数据程序编程风格: 过程式:以指令为中心,数据服务于指令 对象式:以数据为中心 ...
- Spark编程基础_RDD初级编程
摘要:Spark编程基础_RDD初级编程 RDD(Resilient Distributed Dataset)叫做弹性分布式数据集,是Spark中最基本的数据抽象,它代表一个不可变.可分区.里面的元素 ...
随机推荐
- logstash redis kafka传输 haproxy日志
logstash 客户端收集 haproxy tcp日志 input { file { path => "/data/haproxy/logs/haproxy_http.log&qu ...
- 汽车ABS系统-第一周作业
ABS系统也成防抱死系统(Anti-lock Braking System),由罗伯特·博世有限公司所开发的一种在摩托车和汽车中使用,它会根据各车轮角速度信号,计算得到车速.车轮角减速度.车轮滑移率: ...
- jq弹框确认
function delCustomer(id,num){ var r=confirm("友情提醒:确认要删除客户吗?"); if (r==true){ $.ajax({ type ...
- windows远程控制ubuntu---基于ssh
要实现windows下连接ubuntu需要安装以下软件: 1. windows下安装winSCP 2. Ubuntu下安装OpenSSH Server 可以使用命令行安装openSSH Server: ...
- SQLServer中系统存储过程sp_spaceused
sp_spaceused 执行sp_spaceused存储过程的时候可以不用带参数,直接执行,或者exec sp_spaceused都可以,返回两个结果集: 列名 数据类型 描述 database_n ...
- LeetCode: Product of Array Except Self
Dynamic Programming public class Solution { public int[] productExceptSelf(int[] nums) { int[] ans = ...
- 【转载】jQuery动画连续触发、滞后反复执行解决办法
转载: http://www.cnblogs.com/yuejin/archive/2012/12/18/2822595.html jQuery中slideUp .slideDown.animate等 ...
- java布局学习 (一)
Java 程序通过jvm可以很好的移植到其他平台上,但是java 生成的图形界面样式,在不使用布局的情况下,往往需要重新设定大小,才能在新的平台上调整到最佳样式.这是由于组件的最佳大小 往往是与平台相 ...
- JAVA 学习随笔 : JDK Enhancement Process JEP process
是时候寻找一个学习JAVA的路径了 ---- JDK Enhancement Process Oracle发布了JDK增强提案与路线图进程,目的在于鼓励OpenJDK提交者贡献点子和扩展以改进Open ...
- js 函数总结
函数的基本语法如下所示: function functionName(arg0, arg1,...,argN) { statements } 函数如果有返回值则return 后的语句将不会被执行,返回 ...