NIM Duilib Framework
repository·master·Indexed 25 days ago
https://github.com/netease-im/nim_duilib_frameworkA comprehensive desktop application development framework that extends the Duilib UI library. It integrates base utilities for threading and memory management, featuring support for DPI scaling, multi-language styling, GIF animations, and CEF (Chromium Embedded Framework) integration. The framework provides a variety of layout containers (Box, HBox, VBox, etc.), interactive controls, and high-performance list components like VirtualListBox.
What's inside nim_duilib_framework
- NIM Duilib is a UI development framework for Windows designed for building desktop applications. It extends the original Duilib by integrating a Google-based library that provides enhanced support for threads, memory management, and closures. It features an abstract rendering interface, allowing for support of various rendering engines.
Overview of NIM Duilib Controls
masterNIM Duilib provides a comprehensive set of UI components (Controls) used to build user interfaces. These controls are organized into a hierarchy where higher-level components (like
Window) act as containers for lower-level interactive elements (likeButton,CheckBox, orSlider).Key component categories include:
- Containers:
Window(the top-level container for all UI elements). - Base Components:
Control(the base class for all UI elements). - Interactive Controls:
Button,CheckBox,Option,Slider,ScrollBar. - Display Controls:
Label,Progress,CircleProgress. - Input Controls:
RichEdit(for rich text input). - Web Integration:
CefControl(for embedding CEF/Chromium-based content).
- Containers:
Overview of NIM Duilib features
masterNIM Duilib is a desktop application development framework rather than just a UI library. It extends the original Duilib and integrates the Google
baselibrary (providing thread, memory, and closure management).Key features include:
- Multi-language support
- Universal styling support
- DPI scaling support
- GIF animation support
- CEF (Chromium Embedded Framework) control support (CEF 2623 supports Windows XP)
- Touch device support (e.g., Surface, Wacom)
- Abstract rendering interface (allows support for other rendering engines)
Available List components in NIM Duilib
masterNIM Duilib provides several types of list components designed for different data presentation needs. Depending on whether you need hierarchical data, simple selection, or high-performance rendering for large datasets, you should choose one of the following:
- Combo: A dropdown-style list component.
- ListBox: A standard list component for displaying items.
- TreeView: A hierarchical list component for tree-like data structures.
- VirtualListBox: A high-performance list component optimized for displaying very large datasets by using virtualization techniques.
Use the NumberEdit control
masterTheNumberEditcontrol is a specialized text box designed for numeric input. It inherits all properties and methods from theRichEditcontrol. UseNumberEditwhen you need to restrict user input to specific numeric formats, such as integers or positive numbers only.NIM Duilib Framework Overview
masterNIM Duilib is a UI framework providing a comprehensive set of components for building desktop applications. The framework is organized into several core categories:
- Containers: Layout management tools like
Box,VBox,HBox,TabBox,TileBox,ChildBox, andScrollableBox. - Lists: Data presentation components including
Combo(dropdowns),TreeView,ListBox, andVirtualListBoxfor high-performance rendering. - Controls: Standard UI elements such as
Button,CheckBox,Option,Label,Progressbars,Slider,ScrollBar, and specialized editors likeRichEditandNumberEdit. - ControlBox Elements: Specialized items used within containers, such as
ListContainerElementandTreeNode. - Utilities: Core framework services including
Window Base,Multi-languagesupport,DPI Manager, andShadoweffects.
- Containers: Layout management tools like
Use ChildBox to embed sub-layouts via XML
masterThe
ChildBoxcontainer allows you to embed a sub-layout into a parent container by specifying an external XML file.ChildBoxinherits all properties and methods from theBoxcontainer; for a complete list of layout properties, refer to theBoxdocumentation.To embed a layout, you must provide the path to an XML file using the
xmlfileproperty or theSetChildLayoutXMLmethod.Use the TreeView component
masterTheTreeViewcomponent is used to display hierarchical tree structures. It inherits all properties and methods from theListBoxcontainer. For standard list container functionality, refer to theListBoxdocumentation.Override WindowImplBase methods to handle window events
masterTo customize window behavior in the Duilib framework, you should inherit from
WindowImplBaseand override its virtual methods. These methods act as event handlers for various Windows messages and framework-specific events.Lifecycle and Initialization
InitWindow(): Called when the window is being initialized. Use this for setup tasks.OnCreate(uMsg, wParam, lParam, bHandled): Triggered when the window is created. Note that if you useInitWindowfor initialization,OnCreatewill be called automatically after it.OnFinalMessage(hWnd): Called when the window is receiving its final messages.OnDestroy(uMsg, wParam, lParam, bHandled): Called when the window is being destroyed.OnClose(uMsg, wParam, lParam, bHandled): Called when the window receives a close message.
Message Handling Pattern
Most event handlers follow a standard signature:
uMsg: The message ID.wParam/lParam: Message parameters.bHandled: A boolean reference. Set this totrueif you have processed the message and want to prevent further processing by the default handler.
Returns
LRESULT(typically 0 if handled).Understand CefControl vs CefNativeControl
masterThe framework provides two ways to integrate CEF (Chromium Embedded Framework) as a
Control:CefControl: Uses the windowed mode for CEF.CefNativeControl: Uses the native mode for CEF, which allows for more direct integration with native windowing systems.
Setup Requirements: CEF supports Windows XP and later versions. To use CEF in C++, you must include the
third_party\cef_wrapperdirectory in your project. Ensure that the CEF binary files (from thebindirectory, e.g.,cef_x64) are placed in the same directory as your application's executable.Use the ListBox container
masterThe
ListBoxis a container component used to manage a list of child items. It inherits all properties and methods fromScrollableBox. Use it to create scrollable lists where items can be added, removed, sorted, or selected.Key capabilities include:
- Adding items to the end (
Add) or at a specific index (AddAt). - Removing items by pointer (
Remove) or by index (RemoveAt). - Navigating selection via
Next()andPrevious(). - Sorting items using a custom comparison function via
SortItems.
- Adding items to the end (
Use ControlBox containers to combine layout and event response
masterA
ControlBoxis a specialized hybrid component that combines the layout capabilities of a container with the event response mechanisms of a control. Unlike standard containers, they are designed to hold specific types of controls that behave as a single functional unit.For example, if you need a button that contains both an icon and text, you should use a
ButtonBoxinstead of manually positioning aControland aLabelinside a standardBox.<ButtonBox width="70" height="30" bkcolor="darkcolor" padding="10,8,8,10"> <Control width="auto" height="auto" bkimage="save.png" mouse="false"/> <Label text="保存" normaltextcolor="white" margin="20" mouse="false"/> </ButtonBox>