Self-adaptive adjustment method and system for front-end interface component
By defining the data structure of component scaling and setting the scaling factor, establishing the corresponding relationship of layout parameters, it solves the problem of difficult scaling of custom components under different devices and resolutions, and realizes flexible adaptation and efficient scaling of interface components.
Patent Information
- Application Number
- CN202411024535.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-29
- Publication Date
- 2024-11-08
AI Technical Summary
In software development, when custom components need to be scaled to meet the display needs of different devices and resolutions, increasing data volume makes scaling difficult.
By defining and initializing the data structure of component scaling, setting the scaling factor, and establishing the correspondence between layout parameters and index values, new layout parameters are calculated to achieve flexible scaling of components.
Effectively manage and adjust the layout parameters of interface components to ensure operational efficiency and accuracy, provide efficient component scaling methods, and adapt to display needs of different environments.
Smart Images

Figure CN118915944A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of page content display, and in particular to a method and system for adaptively adjusting a front-end interface component. Background Art
[0002] With the development of modern software applications, especially the widespread use of graphical user interfaces (GUIs), users have an increasing demand for customizability and adaptability of interfaces. Environmental factors such as different devices, different screen sizes or different resolutions require that the software interface can flexibly adapt to these changes to provide the best user experience. Therefore, the scaling function of components has become an indispensable part of software development.
[0003] In the process of software development, developers need to use custom components to achieve specific functions and appearances. However, these custom components, like standard components, need to have scaling functions to adapt to display requirements in different environments. Different components will have a lot of associated data, and the increase in data volume will create trouble for component scaling.
[0004] In order to solve this problem, a solution is proposed to achieve flexible scaling of components through close connection of component data. Summary of the invention
[0005] In view of the above-mentioned defects, the purpose of the present invention is to propose a method and system for adaptively adjusting front-end interface components, which extracts scaling parameters when needed to solve the adaptation problem of the interface under different devices and resolutions.
[0006] To achieve this object, the present invention adopts the following technical solutions:
[0007] A method for adaptively adjusting a front-end interface component, comprising:
[0008] Define and initialize a component scaling data structure, the data structure is used to manage the layout parameters of the component;
[0009] Set the scaling factor of the component, define the container of the component, and obtain the first layout parameters of the current component and its subcomponents;
[0010] Establishing a corresponding relationship between the data structure and the first layout parameter, and storing the data structure and the corresponding index value into a key-value pair;
[0011] A request for scaling an interface component is received, a first layout parameter of the component to be scaled is obtained, a second layout parameter is calculated according to the scaling factor and the first layout parameter, and the component is scaled according to the second layout parameter.
[0012] Preferably, the first layout parameter includes coordinate data of the component, width of the component and height of the component;
[0013] The container of the component is defined, and obtaining the first layout parameter of the current component and its subcomponents includes:
[0014] Define the component's container QMap, and traverse all the child components of the component through the findChildren method;
[0015] All subcomponents of the traversal component include:
[0016] Get the coordinate data of the current component according to the geometry method, get the width of the current component according to the width method, and get the current height according to the height method.
[0017] Preferably, the data structure is a structure, each structure corresponds to a component, and the first layout parameter also includes a font size value of the component;
[0018] The establishing a corresponding relationship between the data structure and the first layout parameter, and storing the data structure and the corresponding index value into a key-value pair includes:
[0019] Creating a first member variable of the structure, and establishing a corresponding relationship between the first member variable and the coordinate data of the component, the width of the component, and the height of the component;
[0020] Creating a second member variable of the structure, and establishing a corresponding relationship between the second member variable and the font size value of the component;
[0021] Construct a Map key-value pair according to the index value and the structure, and arrange them in the order of the index value.
[0022] Preferably, obtaining the first layout parameter of the component to be scaled includes:
[0023] Create an iterator, traverse the Map key-value pairs according to the iterator, and loop to obtain the first layout parameters of the components in the QMap container.
[0024] Preferably, scaling the component according to the second layout parameter comprises:
[0025] The component scaling interface scales the component according to the coordinate data of the component, the width of the component and the height of the component in the second layout parameters;
[0026] The font scaling interface scales the font according to the font size value in the second layout parameter.
[0027] An adaptive adjustment system for a front-end interface component, comprising:
[0028] Initialization module, used to define and initialize component scaling data structures;
[0029] The layout parameter acquisition module is used to set the scaling factor of the component, define the container of the component, and obtain the first layout parameters of the current component and its subcomponents;
[0030] A key-value pair generation module, used to establish a corresponding relationship between the data structure and the first layout parameter, and store the data structure and the corresponding index value into the key-value pair;
[0031] The component scaling module is used to receive a request for scaling an interface component, obtain a first layout parameter of the component to be scaled, calculate a second layout parameter based on the scaling factor and the first layout parameter, and scale the component based on the second layout parameter.
[0032] Furthermore, in the layout parameter acquisition module:
[0033] The first layout parameters include coordinate data of the component, width of the component and height of the component;
[0034] The container of the component is defined, and obtaining the first layout parameter of the current component and its subcomponents includes:
[0035] Define the component's container QMap, and traverse all the child components of the component through the findChildren method;
[0036] All subcomponents of the traversal component include:
[0037] Get the coordinate data of the current component according to the geometry method, get the width of the current component according to the width method, and get the current height according to the height method.
[0038] Furthermore, the data structure is a structure, each structure corresponds to a component, and the first layout parameter also includes a font size value of the component;
[0039] In the key-value pair generation module, establishing a corresponding relationship between the data structure and the first layout parameter, and storing the data structure and the corresponding index value into the key-value pair includes:
[0040] Creating a first member variable of the structure, and establishing a corresponding relationship between the first member variable and the coordinate data of the component, the width of the component, and the height of the component;
[0041] Creating a second member variable of the structure, and establishing a corresponding relationship between the second member variable and the font size value of the component;
[0042] Construct a Map key-value pair according to the index value and the structure, and arrange them in the order of the index value.
[0043] Preferably, in the key-value pair generation module, obtaining the first layout parameter of the component to be scaled includes:
[0044] Create an iterator, traverse the Map key-value pairs according to the iterator, and loop to obtain the first layout parameters of the components in the QMap container.
[0045] Preferably, in the component scaling module, scaling the component according to the second layout parameter comprises:
[0046] The component scaling interface scales the component according to the coordinate data of the component, the width of the component and the height of the component in the second layout parameters;
[0047] The font scaling interface scales the font according to the font size value in the second layout parameter.
[0048] One of the above technical solutions has the following advantages or beneficial effects:
[0049] By defining and initializing the data structure for component scaling and setting the scaling factor, the layout parameters of the interface components can be effectively managed and adjusted. By establishing a corresponding relationship between the data structure and the first layout parameter and storing it in a key-value pair, it can ensure that all subcomponents are found and sorted in an orderly manner, so that the corresponding values can be quickly found through the key. By using containers and iterators to manage and traverse the layout parameters of components, an efficient way is provided to operate the various components of the interface while ensuring the efficiency and accuracy of the operation. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0051] Figure 1 is a flow chart of a method for adaptively adjusting a front-end interface component provided by an embodiment of the present invention;
[0052] Figure 2 It is a functional module diagram of the adaptive adjustment system of the front-end interface component of the present invention. DETAILED DESCRIPTION
[0053] Embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and cannot be understood as limiting the present invention.
[0054] In this application, the terms "comprises", "comprising" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprising a ..." does not exclude the presence of other identical elements in the process, method, article or device comprising the element.
[0055] like Figure 1 As shown, a preferred embodiment of the present application includes:
[0056] Step S1: define and initialize a component scaling data structure, where the data structure is used to manage component layout parameters;
[0057] Step S2: Set the scaling factor of the component, define the container of the component, and obtain the first layout parameters of the current component and its subcomponents;
[0058] Step S3: establishing a corresponding relationship between the data structure and the first layout parameter, and storing the data structure and the corresponding index value into a key-value pair;
[0059] Step S4: receiving a request for scaling an interface component, obtaining a first layout parameter of the component to be scaled, calculating a second layout parameter according to the scaling factor and the first layout parameter, and scaling the component according to the second layout parameter.
[0060] Specifically, in step S1, first, define and specify the form of a certain data structure, and before using the data structure, allocate memory space for it and set the initial value. The data structure here can be a way of organizing and storing data such as an object or an array. The data structure used here is used to manage the layout parameters of the component. In step S2, it is necessary to specify a scaling factor, which can be a ratio or a specific value. If the scaling factor is not set properly, it will cause crosstalk, incomplete display, display out of bounds, etc. between components, so it is necessary to set a specific scaling factor for a specific component. The component is divided into a standard type component and a custom type component. The standard type component is mainly a component provided by the development environment system itself, including a button type component, an input box type component, a table type component, a text box type component, etc. The custom type component is mainly because the standard type component cannot meet the specific requirements of the product or when a composite component is required, it is generally necessary to customize the component through a program. Create a container for the component, which is used to store and manage the role of component information, and obtain the first layout parameters of the current component and subcomponent, that is, the coordinates, size and other data of the component, and store them in the container. In step S3, the layout parameters of the components are grouped together using a data structure, which is convenient for unified acquisition when used, and the data structure corresponding to each component is orderly distinguished using an index value, so that data can be quickly acquired through the key value. In step S4, after receiving a request to scale the components of the interface, the first layout parameter of the corresponding component is obtained from the key-value pair according to the key value, and the scaling factor is set using the previous step, and the second layout parameter is calculated with the first layout parameter, that is, the layout parameter of the scaled component, and the component is scaled according to the second layout parameter, providing an efficient way to operate the various components of the interface while ensuring the efficiency and accuracy of the operation.
[0061] Further, in this embodiment, the first layout parameter includes coordinate data of the component, width of the component and height of the component;
[0062] The container of the component is defined, and obtaining the first layout parameter of the current component and its subcomponents includes:
[0063] Define the component's container QMap, and traverse all child components of the component through the findChildren() method;
[0064] All subcomponents of the traversal component include:
[0065] Get the coordinate data of the current component according to the geometry() method, get the width of the current component according to the width() method, and get the current height according to the height() method.
[0066] Specifically, QMap is an associative container in Qt, which is used to store components and their corresponding first layout parameters. Each component can be uniquely identified, for example, using the pointer or name of the component as the key and the first layout parameter (coordinate data, width, height) as the value. For each subcomponent, perform the following steps: Use the geometry() method to obtain the coordinate data of the current component. The geometry() method returns a QRect object containing the coordinate position data (x, y) of the component. Use the width() method to obtain the width of the current component. Use the height() method to obtain the height of the current component. Store these parameters in QMap for subsequent use. By using QMap to store components and their layout parameters, the readability, maintainability and performance of the program can be improved. This design can effectively manage the data required for interface layout.
[0067] In another embodiment of the present application, the data structure is a structure, each structure corresponds to a component, and the first layout parameter also includes a font size value of the component;
[0068] The establishing a corresponding relationship between the data structure and the first layout parameter, and storing the data structure and the corresponding index value into a key-value pair includes:
[0069] Creating a first member variable of the structure, and establishing a corresponding relationship between the first member variable and the coordinate data of the component, the width of the component, and the height of the component;
[0070] Creating a second member variable of the structure, and establishing a corresponding relationship between the second member variable and the font size value of the component;
[0071] Construct a Map key-value pair according to the index value and the structure, and arrange them in the order of the index value.
[0072] Among them, a structure is a custom data structure used to organize data in a programming language. It allows developers to combine data items of different types to form a single data unit. These data items can have different data types (such as integers, floating-point numbers, characters, arrays, and even other structures) and are stored in memory in a defined order.
[0073] Specifically, in the structure, two member variables are created, namely the first member variable and the second member variable, which correspond to the coordinate data, width and height of the component and the font size value of the component, respectively. For example, the variable e_data_geometry_width_height of the scaling_struct_ structure is associated with the component coordinates (x, y), width width, and height height; the variable e_data_font of the scaling_struct_t structure is associated with the component font font. The scaling_struct_t structure and the traversal index value are used to construct a Map key-value pair, that is,<index,scaling_struct_t> , each index value corresponds to a set of structure data, and they are stored by sorting them by index.
[0074] To further illustrate, the obtaining of the first layout parameter of the component to be scaled includes:
[0075] Create an iterator, traverse the Map key-value pairs according to the iterator, and loop to obtain the first layout parameters of the components in the QMap container.
[0076] Specifically, when you need to scale a component, use QMapIterator<key,value> The iterator traverses the Map key-value pairs. In each iteration, iter.key() can get the key and iter.value() can get the value to get the layout parameters of the components in the container. For example, first get the first layout parameters of the parent component according to the index, and then get the first layout parameters of the child component according to the index. This can effectively manage and operate the data stored in QMap and access specific properties or information of each component as needed.
[0077] Further, scaling the component according to the second layout parameter includes:
[0078] The component scaling interface scales the component according to the coordinate data of the component, the width of the component and the height of the component in the second layout parameters;
[0079] The font scaling interface scales the font according to the font size value in the second layout parameter.
[0080] Specifically, the component is first scaled by the component's coordinate data, width, and height. The scaling effect of the component is achieved by changing the component's coordinates and size, so that the component can adapt and adjust according to different layout parameters. The position of the component is recalculated according to the new layout parameters to ensure its correct position in the layout. The font of the component is then scaled, and the font size of the text is adjusted according to the font size value in the layout parameters, which improves the user experience, ensures the clarity and readability of the text, and makes the interface design of the application more flexible and responsive.
[0081] like Figure 2 As shown, a structural schematic diagram of an embodiment of the adaptive adjustment system of the front-end interface component provided by the present application, the device for adjusting the transmission power can implement the entire process of the adaptive adjustment method of the front-end interface component, specifically including:
[0082] Initialization module, used to define and initialize component scaling data structures;
[0083] The layout parameter acquisition module is used to set the scaling factor of the component, define the container of the component, and obtain the first layout parameters of the current component and its subcomponents;
[0084] A key-value pair generation module, used to establish a corresponding relationship between the data structure and the first layout parameter, and store the data structure and the corresponding index value into the key-value pair;
[0085] The component scaling module is used to receive a request for scaling an interface component, obtain a first layout parameter of the component to be scaled, calculate a second layout parameter based on the scaling factor and the first layout parameter, and scale the component based on the second layout parameter.
[0086] Furthermore, in the layout parameter acquisition module:
[0087] The first layout parameters include coordinate data of the component, width of the component and height of the component;
[0088] The container of the component is defined, and obtaining the first layout parameter of the current component and its subcomponents includes:
[0089] Define the component's container QMap, and traverse all the child components of the component through the findChildren method;
[0090] All subcomponents of the traversal component include:
[0091] Get the coordinate data of the current component according to the geometry method, get the width of the current component according to the width method, and get the current height according to the height method.
[0092] Furthermore, the data structure is a structure, each structure corresponds to a component, and the first layout parameter also includes a font size value of the component;
[0093] In the key-value pair generation module, establishing a corresponding relationship between the data structure and the first layout parameter, and storing the data structure and the corresponding index value into the key-value pair includes:
[0094] Creating a first member variable of the structure, and establishing a corresponding relationship between the first member variable and the coordinate data of the component, the width of the component, and the height of the component;
[0095] Creating a second member variable of the structure, and establishing a corresponding relationship between the second member variable and the font size value of the component;
[0096] Construct a Map key-value pair according to the index value and the structure, and arrange them in the order of the index value.
[0097] Further, in the key-value pair generation module, obtaining the first layout parameter of the component to be scaled includes:
[0098] Create an iterator, traverse the Map key-value pairs according to the iterator, and loop to obtain the first layout parameters of the components in the QMap container.
[0099] Further, in the component scaling module, scaling the component according to the second layout parameter includes:
[0100] The component scaling interface scales the component according to the coordinate data of the component, the width of the component and the height of the component in the second layout parameters;
[0101] The font scaling interface scales the font according to the font size value in the second layout parameter.
[0102] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "illustrative embodiments", "examples", "specific examples", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.
[0103] Although the embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the claims and their equivalents.
Claims
1. A method for adaptively adjusting a front-end interface component, characterized in that: include: Define and initialize a component scaling data structure, the data structure is used to manage the layout parameters of the component; Set the scaling factor of the component, define the container of the component, and obtain the first layout parameters of the current component and its subcomponents; Establishing a corresponding relationship between the data structure and the first layout parameter, and storing the data structure and the corresponding index value into a key-value pair; A request for scaling an interface component is received, a first layout parameter of the component to be scaled is obtained, a second layout parameter is calculated according to the scaling factor and the first layout parameter, and the component is scaled according to the second layout parameter.
2. The adaptive adjustment method according to claim 1, characterized in that: The first layout parameters include coordinate data of the component, width of the component and height of the component; The container of the component is defined, and obtaining the first layout parameter of the current component and its subcomponents includes: Define the component's container QMap, and traverse all the child components of the component through the findChildren method; All subcomponents of the traversal component include: Get the coordinate data of the current component according to the geometry method, get the width of the current component according to the width method, and get the current height according to the height method.
3. The adaptive adjustment method according to claim 2, characterized in that: The data structure is a structure, each structure corresponds to a component, and the first layout parameter also includes a font size value of the component; The establishing a corresponding relationship between the data structure and the first layout parameter, and storing the data structure and the corresponding index value into a key-value pair includes: Creating a first member variable of the structure, and establishing a corresponding relationship between the first member variable and the coordinate data of the component, the width of the component, and the height of the component; Creating a second member variable of the structure, and establishing a corresponding relationship between the second member variable and the font size value of the component; Construct a Map key-value pair according to the index value and the structure, and arrange them in the order of the index value.
4. The adaptive adjustment method according to claim 3, characterized in that: The obtaining of the first layout parameter of the component to be scaled includes: Create an iterator, traverse the Map key-value pairs according to the iterator, and loop to obtain the first layout parameters of the components in the QMap container.
5. The adaptive adjustment method according to claim 3, characterized in that: Scaling the component according to the second layout parameter includes: The component scaling interface scales the component according to the coordinate data of the component, the width of the component and the height of the component in the second layout parameters; The font scaling interface scales the font according to the font size value in the second layout parameter.
6. An adaptive adjustment system for a front-end interface component, characterized in that: include: Initialization module, used to define and initialize component scaling data structures; The layout parameter acquisition module is used to set the scaling factor of the component, define the container of the component, and obtain the first layout parameters of the current component and its subcomponents; A key-value pair generation module, used to establish a corresponding relationship between the data structure and the first layout parameter, and store the data structure and the corresponding index value into the key-value pair; The component scaling module is used to receive a request for scaling an interface component, obtain a first layout parameter of the component to be scaled, calculate a second layout parameter based on the scaling factor and the first layout parameter, and scale the component based on the second layout parameter.
7. The adaptive adjustment system according to claim 6, characterized in that: In the layout parameter acquisition module: The first layout parameters include coordinate data of the component, width of the component and height of the component; The container of the component is defined, and obtaining the first layout parameter of the current component and its subcomponents includes: Define the component's container QMap, and traverse all the child components of the component through the findChildren method; All subcomponents of the traversal component include: Get the coordinate data of the current component according to the geometry method, get the width of the current component according to the width method, and get the current height according to the height method.
8. The adaptive adjustment system according to claim 7, characterized in that: The data structure is a structure, each structure corresponds to a component, and the first layout parameter also includes a font size value of the component; In the key-value pair generation module, establishing a corresponding relationship between the data structure and the first layout parameter, and storing the data structure and the corresponding index value into the key-value pair includes: Creating a first member variable of the structure, and establishing a corresponding relationship between the first member variable and the coordinate data of the component, the width of the component, and the height of the component; Creating a second member variable of the structure, and establishing a corresponding relationship between the second member variable and the font size value of the component; Construct a Map key-value pair according to the index value and the structure, and arrange them in the order of the index value.
9. The adaptive adjustment system according to claim 8, characterized in that: In the key-value pair generation module, obtaining the first layout parameter of the component to be scaled includes: Create an iterator, traverse the Map key-value pairs according to the iterator, and loop to obtain the first layout parameters of the components in the QMap container.
10. The adaptive adjustment system according to claim 8, characterized in that: In the component scaling module, scaling the component according to the second layout parameter includes: The component scaling interface scales the component according to the coordinate data of the component, the width of the component and the height of the component in the second layout parameters; The font scaling interface scales the font according to the font size value in the second layout parameter.
