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中最基本的数据抽象,它代表一个不可变.可分区.里面的元素 ...
随机推荐
- ubuntu启动tomcat出错解决方案
从终端进入tomcat的bin目录,然后执行startup.sh,出现以下异常: Cannot find ./catalina.sh The file is absent or does not ha ...
- JS学习之路
前言 接触js也有四五年的时间了,对js的认识也逐渐加深,想把自己这几年学习js的经历记录一下. 总则-都是对象,都是引用 在接触js前用的比较多的是java,在刚开始接触js的时候,老实讲,我是有点 ...
- Leetcode: Convex Polygon
Given a list of points that form a polygon when joined sequentially, find if this polygon is convex ...
- c/c++ qsort 函数的简单使用(1)
#include <stdio.h> #include <stdlib.h> //打印数组元素 void print(int arr[], int n){ ; i < n ...
- Hihocoder 1079 离散化
离散化这里有很多种方式 利用结构体记录最初的索引在按位置排序再记录排名即为离散的位置再按索引排回来 或者用数组记录排序后直接对原位置二分直接去找离散应在的位置 或者对数组排序后直接map 3 20 1 ...
- spring ioc三种注入方式
spring ioc三种注入方式 IOC ,全称 (Inverse Of Control) ,中文意思为:控制反转 什么是控制反转? 控制反转是一种将组件依赖关系的创建和管理置于程序外部的技术. 由容 ...
- Windows Phone 十一、MVVM模式
MVVM 模式介绍 模型-视图-视图模型 (MVVM) 是一种用来分离 UI 和非 UI 代码的应用设计模式 MVVM – 模型(Model) MVVM 中的 Model 与 MVC 中的一致,用于封 ...
- 纳尼,java可以在接口中实现非抽象方法了?
纳尼,接口中可以定义实例方法了?! 纳尼,接口中还可以定义静态方法了?! 没错,在Java8中新增了很多新的特性,其中就包括可以在接口中添加方法和变量. 首先我们来看下代码 public interf ...
- js基础教程四之无缝滚动
前面学习了相关js的一些基础知识,这节主要针对定时器作综合运用: 无缝滚动-基础 效果演示: *物体运动基础 *让div移动起来 *offsetLeft的作用 *用定时器让物体连续移动 <sty ...
- Openbox中指定目录打开程序
现在遇到这样的情况,在浏览器的下载中,点击在文件夹中显示, 结果这个使用系统调用的是Baobab,一款分析磁盘使用情况的软件,而不是使用目录浏览程序,例如nautilus 查询后知道,系统使用xdg- ...