Getting started with duilib, getting started with duilib

Source: Internet
Author: User
Tags list of attributes

Getting started with duilib, getting started with duilib

Reprint please explain the original source: http://blog.csdn.net/zhuhongshu/article/details/43816875


In the QQ group, friends who have just started to learn duilib often join us and ask questions about attribute usage and layout. To avoid repeated answers, I will write an introductory article today to briefly explain what duilib needs to pay attention to and how to learn duilib.


Albert L has written brief duilib getting started tutorials and duilib advanced tutorials, which is a good getting started tutorial. With nine demos provided by duilib, you can learn all the functions of duilib. Therefore, we strongly recommend that you take a good look at these functions. Many people, including me, read their own demos to learn duilib. Each demo describes several features of duilib. The nine demos show almost all functions of duilib. However, there are some shortcomings in the introductory tutorials and nine demos of Alberta. The most important reason is the lack of descriptions on the properties and layout of controls. So I will focus on the control and layout in this article.


The most important thing to learn about duilib is to understand the attributes and features of various controls and containers, and how to layout them. Understanding these three points, coupled with a basic duilib framework, is no big problem with duilib.


Learning controls:


The Getting Started tutorials and demos have introduced the usage of various controls. However, some people often ask about the usage of a property in the group. In fact, the attribute list is included in the duilib root directory. xml, which is a very useful file. I always open the attribute list when writing the layout. The attribute list describes various properties of each control and the message type that each control sends.


Unfortunately, the property list file does not fully describe all the properties of all controls, which contains omissions. To know the most complete properties of a control, open the duilib project, open the source file of the control you need, and find the SetAttribute function, duilib reads the properties of the control in the xml file through this function and assigns values to the real control. Therefore, this function has the most complete attribute description.


In my self-maintained duilib library, I also try to add the missing and extended attributes to the attribute list. xml, you can use the list of attributes that I added if needed.


The best way to learn how to use controls is to build a project, write an xml file, and test the usage of various controls and their attributes. Duilib can use xml to describe controls. Of course, you can also use c ++ code to dynamically add controls and set properties.


It is easy to Add controls dynamically. A new control sets properties and calls the Add function of the container to Add the new control. But the problem is that many new friends directly use the SetAttribute function or the ApplyAttributeList function to set attributes for the control. We strongly oppose this practice. These two functions read the xml configuration file and set properties for the control. They actually call other related functions of the control to complete attribute assignment. When dynamically creating a control, we should directly call the function corresponding to an attribute, which is more efficient and readable than the SetAttribute function or ApplyAttributeList function.



Learning layout:


I personally think that layout is the most important thing for beginners of duilib. I have previously written an article about layout, "the role of various la s of duilib, the significance and usage of relative layout and absolute layout describes the functions of each layout control, so I will not repeat it.


However, I would like to emphasize that duilib's new duilib users should delete duilib's built-in designer first and use the editing tool to hand-print the layout on their own. (In fact, I have seen many duilib beginners asking me about the designer usage. I can't help writing this blog)


The reasons for not using the designer are as follows:

1. The duilib built-in designer is not complete, and there are many bugs in it. They often crash on their own, leading to the loss of the layout just written.

2. The number of widgets supported by the designer is insufficient. Many widgets cannot be described by the designer.

3. the xml file exported by the designer uses a considerable amount of redundant code, but does not have any set attributes, or the configured attributes are not saved.

4. The designer uses the absolute layout by default, that is, the float attribute is true.

5. In fact, handwriting layout will give you a better understanding of various controls and containers.


A friend who has used duilib's designer for a while will generally give up on him for the above reasons. At least none of my friends who use duilib use the designer. To be honest, if you understand duilib layout, you can directly think of layout without the designer. Therefore, the layout of learning is particularly important!


To be honest, if anyone wants to use the designer, the duilib designer can let us learn how to develop the designer. First of all, I need to feel the author of duilib's designer, because it is very difficult to write the designer, but it is not fully developed, and I am not able to develop a good designer myself. I would like to use a great designer, like ~~


When getting started with duilib, my friends often ask why my form is getting bigger, but the controls in it are not adaptive in size and position. This is what I want to emphasize. A beginner duilib friend can look at your xml layout file without special requirements. We strongly recommend that you do not use the float attribute or pos attribute, the reason is that I explained in the layout blog that we should use more relative la S.



Summary:


If you can learn the demo carefully and understand the usage of controls and la S, you can start using duilib. However, if you want to use duilib well, it is essential to read and modify the duilib source code. Because duilib has many bugs, other blog posts on my blog describe how to fix some bugs, otherwise, you may not be able to find the cause when using duilib. I won't talk about how to learn duilib's source code. There are more than 30 thousand lines of code. It is not difficult to read duilib's source code as long as you are willing to read it.


I maintained duilib and uilib: Click to open the link


Redrain 2015.2.14

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.