WO2020140932A1 - Method and device for generating interface codes - Google Patents

Method and device for generating interface codes Download PDF

Info

Publication number
WO2020140932A1
WO2020140932A1 PCT/CN2020/070059 CN2020070059W WO2020140932A1 WO 2020140932 A1 WO2020140932 A1 WO 2020140932A1 CN 2020070059 W CN2020070059 W CN 2020070059W WO 2020140932 A1 WO2020140932 A1 WO 2020140932A1
Authority
WO
WIPO (PCT)
Prior art keywords
information
interface
code
layout
layer
Prior art date
Application number
PCT/CN2020/070059
Other languages
French (fr)
Chinese (zh)
Inventor
涂挺鹏
Original Assignee
阿里巴巴集团控股有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 阿里巴巴集团控股有限公司 filed Critical 阿里巴巴集团控股有限公司
Publication of WO2020140932A1 publication Critical patent/WO2020140932A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/38Creation or generation of source code for implementing user interfaces
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/34Graphical or visual programming

Definitions

  • This application relates to the field of electronic technology, in particular to a method and device for generating interface codes.
  • the present application is proposed to provide a method and device for generating an interface code that solves the above problems or at least partially solves the above problems.
  • a method for generating interface codes includes:
  • an interface code is generated.
  • a method for generating interface code includes:
  • an interface code is generated based on the image data to be processed.
  • an electronic device includes:
  • a first memory and a first processor wherein,
  • the first memory is used to store programs
  • the first processor coupled to the first memory, is used to execute the program stored in the first memory for:
  • an interface code is generated.
  • an electronic device includes:
  • a second memory, a second processor and a second display wherein,
  • the second memory is used to store programs
  • the second display coupled with the second processor, is used to display an operation interface for the user to input image data to be processed
  • the second processor coupled to the second memory, is used to execute the program stored in the second memory for:
  • an interface code is generated based on the image data to be processed.
  • the interface element information is first derived from the image file to be processed, the layout information of the interface is determined according to the interface element information, and then the interface code is automatically generated according to the layout information. It can be seen that, in the technical solution provided by the embodiments of the present application, the interface code is automatically generated by processing the image file to be processed, which not only improves the development efficiency and development cycle, but also reduces the burden on the programmer.
  • FIG. 1 is a schematic flowchart of a generation method provided by an embodiment of this application.
  • FIG. 2 is a schematic flowchart of a generating method provided by another embodiment of this application.
  • FIG. 3 is a structural block diagram of a generating device provided by an embodiment of the present application.
  • FIG. 4 is a structural block diagram of a generation device provided by an embodiment of the present application.
  • FIG. 5 is a structural block diagram of an electronic device provided by an embodiment of the present invention.
  • FIG. 6 is a structural block diagram of an electronic device provided by another embodiment of the present invention.
  • FIG. 7 is a schematic flowchart of a generating method provided by an embodiment of the present application.
  • FIG. 8 is a schematic flowchart of a layout method provided by an embodiment of this application.
  • FIG. 9 is an operation interface diagram provided by an embodiment of the present application.
  • the UI design draft is delivered to the programmer.
  • the programmer writes the code according to the UI design draft to get the interface code.
  • the designer can see the real UI effect of the code for visual walkthrough.
  • This development method has low development efficiency and a long development cycle.
  • embodiments of the present application provide a method for automatically generating interface codes based on image files to be processed.
  • FIG. 1 shows a schematic flowchart of a method for generating an interface code provided by an embodiment of the present application. As shown in Figure 1, the method includes:
  • the image file to be processed may be a design draft or a design drawing. among them.
  • the design draft refers to the original file created by the UI designer through the design software.
  • the original file usually contains multiple layers; the design drawing refers to the image generated based on the design draft, for example: a screenshot.
  • the image file to be processed may be a design draft or design drawing corresponding to a UI module.
  • Design software such as: Sketch, Photoshop, etc.
  • These design software usually open an application program interface (ie plug-in) to the user, and can export interface element information related to the design draft through the application program interface of the design software, and cache the exported interface element information in a cache space, for example: Clipboard.
  • the plug-in will traverse all layers of the image file to be processed, and perform type analysis and data extraction on all layers.
  • the interface element information may include: attribute information of each interface element.
  • the attribute information may include at least one of the following items: name, type, coordinates, width and height, drawing order, fill content, and style of fill content.
  • the types of interface elements may include but are not limited to: text type, picture type, shape type, input type, textArea type.
  • interface element information can be derived from the cache space, and layout identification can be performed to obtain layout information.
  • the layout information includes: the parent-child node relationship between each interface element and the distribution information of each child node under each parent node.
  • the interface element corresponding to the parent node is located below the interface element corresponding to its child node, that is, the drawing order of the interface element corresponding to the parent node is prior to the drawing order of the interface element corresponding to its child node.
  • the specific relationship between the parent node and the child node may include: inclusion relationship and cross relationship. Inclusion relationship means that all the interface elements corresponding to the child nodes overlap with the interface elements corresponding to the parent node.
  • the cross relationship means that the interface elements corresponding to the child nodes only partially overlap the interface elements corresponding to the parent node.
  • Interface codes corresponding to multiple code language types can be generated according to actual needs.
  • Code language types include but are not limited to: HTML (HyperText Markup Language, Hyper Text Markup Language), Vue, Rax.
  • the interface element information is first derived from the image file to be processed, the layout information of the interface is determined according to the interface element information, and then the interface code is automatically generated according to the layout information. It can be seen that, in the technical solution provided by the embodiments of the present application, the interface code is automatically generated by processing the image file to be processed, which not only improves the development efficiency and development cycle, but also reduces the burden on the programmer.
  • the "determining the layout information of the interface based on the interface element information" in 102 above may be specifically implemented by the following steps:
  • the parent-child node relationship between each interface element may be determined based on the position information and drawing order information of each interface element.
  • the position information includes coordinates and width and height.
  • the interface element drawn first among the two interface elements is used as the parent node, and the interface element drawn later is used as the child node of the parent node; after traversing all interface elements, the parent-child node relationship between all interface elements can be obtained.
  • determining the parent-child node relationship between each interface element based on the attribute information of each interface element in the interface element information may be implemented by the following steps:
  • the designated interface elements may be: picture interface elements and text interface elements. It is unreasonable to use picture interface elements and text interface elements as parent nodes. Therefore: in the initial parent-child node relationship, if a designated interface element exists as a parent node, a first container node is added to the initial parent node relationship to accommodate the designated interface element and the Specify the child node of the class interface element to obtain the parent-child node relationship.
  • the child nodes of node A have B and C, and the parent node of node A is node Q.
  • Node A is a picture-type interface element, so a first container node D is added, and D is the parent node of A, B, and C, and the parent node of D is Q.
  • each node acts as both a parent node and a child node.
  • the root node can only be a parent node, and the leaf node can only be a child node.
  • the first type of parent node refers to: its child node is the parent node of the above-mentioned containing relationship; the second type of parent node refers to: its child node is the parent node of the above-mentioned cross-relationship.
  • the “determining the distribution information of at least one first child node of the first type parent node” in 1021 above specifically includes determining the row and column information of the at least one first child node according to the position information of the at least one first child node And information about the distance between the first child nodes in the at least one first child node.
  • the distribution information of at least one first child node of the first type of parent node includes: row and column information of the at least one first child node and information about the surrounding distance of each first child node in the at least one first child node.
  • the row and column information of at least one first child node may be obtained by row and column scanning; and then the boundary scan is performed on the at least one first child node according to the row and column information to obtain information about the surrounding distance of each first child node.
  • the four-week spacing information includes: left spacing, right spacing, top spacing, and bottom spacing.
  • the “determining the distribution information of at least one second child node of the second type parent node” in 1021 above specifically includes: according to the position information of the second type parent node and the at least one second child node, check The at least one second child node performs an absolute positioning layout to obtain distribution information of the at least one second child node.
  • the interface element corresponding to the parent node of the second type and the interface element corresponding to the second child node have a cross relationship, so the calculation is performed according to the position information of the parent node of the second type and the position information of at least one second child node to obtain at least one The absolute coordinate information of the second child node relative to the parent node of the second type.
  • the relationship between the parent-child node and the distribution information of at least one child node of each parent node may be combined to obtain layout information of the interface.
  • the boundary repair can be performed on the two interface elements so that the boundary between the two interface elements does not overlap.
  • a scalable layout attribute (that is, a flex layout attribute) can be added to the layout information.
  • the above method may further include:
  • the telescopic layout attributes include: horizontal centering, vertical centering, and equal-spaced layouts (that is, there are multiple spacings in a row or column, and the difference between any two spacings in the multiple spacings is less than the first error value).
  • the spacing rules corresponding to various types of scaling layout attributes can be set in advance according to various types of scaling layout attributes in practical applications; subsequently, the spacing rules corresponding to various types of scaling layout attributes can be determined according to the surrounding space information of the first child node on each row Matching, the telescopic layout attributes corresponding to the spacing rules on the match are used as the telescopic layout attributes of each row; according to the surrounding space information of the first child node on each column, to match the spacing rules corresponding to various types of telescopic layout attributes, The scaling layout attribute corresponding to the spacing rule on the match is used as the scaling layout attribute of each column. .
  • the spacing rule corresponding to horizontal centering is: the difference between the left spacing of the row and the right spacing of the row is less than the second error value; the first row includes the first child nodes A and B arranged from left to right, the first child The left pitch Z1 of the node A is the left pitch of the first row, and the right pitch Z2 of the first child node B is the right pitch of the first row.
  • the telescopic layout attribute of the first row is horizontally centered.
  • a scalable layout attribute of any row is added to the first-type parent node.
  • a second container node is added to each row to accommodate the first child node on each row, and for each row The newly added second container node adds a scalable layout attribute corresponding to each row, wherein the second container node of each row is a child node of the parent node of the first type.
  • the second container node of each row is the parent node of the first child node on each row.
  • the redundant scaling layout under certain rules can be eliminated Attributes, for example, left-aligned are usually default telescopic layout attributes, so left-aligned telescopic layout attributes can be eliminated.
  • Code coding may be performed according to various possible layout information in advance to obtain code layout information.
  • Code encoding may be performed according to attribute information of various possible interface elements in advance to obtain attribute information at the code level.
  • subsequent code layout information can be matched from the code base according to the layout information.
  • the code level attribute information of each node in the code layout information is matched from the code library.
  • the interface elements in the layout information correspond one-to-one with the nodes in the code layout information.
  • each of the interface elements includes: a first interface element.
  • the attribute information at the code level of the first node corresponding to the first interface element in the code layout information is matched from the code library
  • the display attributes of the first node at the code level are matched.
  • the display attributes may include: the filling content and the style of the filling content.
  • the "generating interface code based on the layout information" in 103 above also includes:
  • the semantic naming is mainly to re-assign the naming of each interface element, and the naming is obtained by parsing the attribute information of the interface element.
  • the semantic naming rules include: default rules, grouping rules, NLP (Neuro-Linguistic Programming), natural language analysis, image recognition, and business rules.
  • users can also manually modify the corresponding fields of the corresponding interface elements. Specifically, the field to be handwritten input by the user and the field to be modified manually bound by the user can be received; the field to be modified manually bound by the user is replaced with the field written by the user to complete the automatic mapping of the field.
  • the layout information can be scanned to identify the structure loop body; and the structure loop body is marked in the layout information; in this way, according to the layout information, the code layout simplified by the loop syntax can be matched from the code base information.
  • the layer attribute information includes name, type, coordinates, width and height, drawing order, filling content and style of filling content.
  • the layer attribute information of each layer can be exported by using the application program interface provided by the design software.
  • the step of performing preset rule processing on the layer attribute information of each layer includes at least one of the following:
  • the first item delete layer attribute information of useless layers by performing layer redundancy and sequence check on each layer.
  • the useless layer refers to a layer completely covered by other layers or a layer that does not cause a change in the user interface during the drawing of the user interface.
  • the second item correct the layer type of the layer with the wrong layer type by checking the layer type of each layer.
  • shape type layer is easy to be recognized as a picture type layer, so it needs to be corrected.
  • Item 3 By performing layer merge verification on the layers, merge multiple layers with merge association into one layer.
  • connection status and pixel differences of multiple layers it is determined whether the multiple layers have a merged association. For example, if there are overlapping parts at the boundaries of multiple layers and the pixel difference of multiple layers is less than a preset threshold, it is determined that multiple images have merge relevance.
  • first, second, and third items above can also use OpenCV to implement layer verification.
  • Item 4 Modify the layer attribute information of each layer in combination with the design rules of the design tool of the image file to be processed.
  • the design rules of different design tools are different. Therefore, the layer attribute information of each layer needs to be modified according to the design rules of different design tools.
  • Item 5 Convert the layer attribute information of each layer into data in a preset format.
  • the preset format may be a Json format.
  • Json format is a lightweight data exchange format. It needs to be added that: before converting the layer attribute information of each layer into data in a preset format, upload the picture corresponding to the picture type interface element to the server, for example: CDN (Content Delivery Network, content distribution Network), and receive the picture storage address returned by the server, and use the picture storage address as part of the attribute information of the picture type interface element.
  • CDN Content Delivery Network, content distribution Network
  • OCR optical character recognition
  • OCR recognition can be performed on the design drawing to obtain multiple text layers.
  • the overall OCR recognition is performed on the design drawing to obtain multiple text ROI (region of interest). From each text ROI, extract the words through the inner and outer contours. After the words are extracted, the words are processed: color aggregation and extraction of the word information such as text color, position, font size and so on. You can bind the text ROI and the word information extracted from the text ROI. After extracting all the words in the design drawing, look for the connected area of the word, and bind each connected area with the word information contained in each connected area. After obtaining multiple Unicom areas, you can merge similar Unicom areas based on the text color, position, and font size of the words in the Unicom area. Treat each connected area as a text-like layer.
  • the class picture layer contains a floating layer; if it contains a floating layer, the floating layer is separated, and the class picture layer after the floating layer is separated is determined as a picture type layer.
  • If there is text in the image-like layer identify the block containing the text to determine whether the block is a shape-like layer; when the block is a shape-like layer, further determine whether the block is an input or textarea layer; if If it is not an input or textarea layer, the block is determined to be a shape type layer.
  • the block is removed from the picture-like layer, and image restoration is performed on the picture-like layer. Determine whether the repaired class picture layer contains a floating layer; if it contains a floating layer, separate the floating layer, and determine the class picture layer after separating the floating layer as the picture type layer.
  • the UI module vision can be directly rendered by executing the interface code to achieve the effect seen in the visual draft, and can ensure the degree of visual restoration, improve the efficiency of the initial module development of the development, and shorten the development and vision. Coordination cycle.
  • FIG. 2 shows a schematic flowchart of a method for generating an interface code provided by another embodiment of the present application. As shown in Figure 2, the method includes:
  • the image data to be processed may be an image file to be processed or interface element information derived from the image file to be processed.
  • the image file to be processed may be a design draft or a design drawing.
  • the design draft refers to the original file created by the UI designer through the design software.
  • the original file usually contains multiple layers; the design drawing refers to the image generated based on the design draft, for example: a screenshot.
  • the image file to be processed may be a design draft or design drawing corresponding to a UI module.
  • the first control is displayed on the operation interface, and in response to the user's touch operation on the first control, an interface code generation instruction is generated.
  • an interface code generation instruction is generated.
  • a language input button can also be displayed on the operation interface, and the user long presses the language to input language information; according to the user's language information, an interface code generation instruction is generated.
  • an operation interface is provided for the user, and the user imports the image file to be processed in the operation interface; in response to the user's interface code generation instruction triggered by the operation interface, the interface is generated based on the image file to be processed Code. It can be seen that, in the technical solution provided by the embodiments of the present application, the interface code is automatically generated by processing the image file to be processed, which not only improves the development efficiency and development cycle, but also reduces the burden on the programmer.
  • the above method may further include:
  • Code language types include but are not limited to: HTML (HyperText Markup Language, Hyper Text Markup Language), Vue, Rax. Subsequently, the interface code of the code language type selected by the user can be generated.
  • HTML HyperText Markup Language
  • Vue Hyper Text Markup Language
  • Rax Rax
  • the above method may further include:
  • generating an interface code based on the to-be-processed image data specifically includes:
  • the image data to be processed is interface element information derived from the image file to be processed.
  • the above 202 "generating an interface code based on the image data to be processed" specifically includes the following steps:
  • the interface element information may be pasted at the data pasting box 701 on the operation interface shown in FIG. 9.
  • the design software plug-in can cache the interface element information exported from the image file to be processed in the clipboard.
  • the semantically named rules may include rules configured by default and rules manually bound by the user. The user can perform manual binding through the "shortcut binding" operation area 703 on the operation interface shown in FIG. 9.
  • Multi-DSL domain-specific language, domain-specific language
  • DSL can be HTML, Vue, Rax, etc.
  • step 52 may specifically include the following steps:
  • a first container node is added to accommodate the picture/text type interface element as a parent node and its child nodes
  • FIG. 3 shows a structural block diagram of an apparatus for generating an interface code provided by another embodiment of the present application.
  • the apparatus includes: a first determination module 301, a second determination module 302, and a first generation module 303. among them,
  • the first determining module 301 is used to determine interface element information of the image file to be processed
  • the second determining module 302 is configured to determine layout information of the interface based on the interface element information
  • the first generating module 303 is configured to generate an interface code according to the layout information.
  • the interface element information is first derived from the image file to be processed, the layout information of the interface is determined according to the interface element information, and then the interface code is automatically generated according to the layout information. It can be seen that, in the technical solution provided by the embodiments of the present application, the interface code is automatically generated by processing the image file to be processed, which not only improves the development efficiency and development cycle, but also reduces the burden on the programmer.
  • the second determination module 302 is specifically used to:
  • the layout information is determined according to the parent-child node relationship and distribution information of at least one child node of each parent node.
  • the second determination module 302 is specifically used to:
  • a first container node is added to the initial parent node relationship to accommodate the designated class interface element and the designated class The child node of the interface element to obtain the parent-child node relationship.
  • each parent node includes a first-type parent node; a second determination module 302 is specifically used to:
  • the row and column information of the at least one first child node and the surrounding distance information of each first child node in the at least one first child node are determined.
  • the above device further includes:
  • a third determining module configured to determine the telescopic layout attributes of each row and the telescopic layout attributes of each column according to the information about the surrounding distance of each first sub-node in the at least one first sub-node;
  • the fourth determining module is used to determine a correction plan for the layout information according to the scalable layout attributes of each row and the scalable layout attributes of each column.
  • the fourth determination module is specifically used for:
  • a second container node is added to each row to accommodate the first child node on each row, and new The added second container node adds a telescopic layout attribute corresponding to each row, where the second container node of each row is a child node of the parent node of the first type.
  • each of the parent nodes includes a second type of parent node; the second determination module 302 is specifically used to:
  • the position information of the second-type parent node and the at least one second child node perform absolute positioning layout on the at least one second child node to obtain distribution information of the at least one second child node.
  • the first generation module 303 is specifically used for:
  • the corresponding code layout information is matched from the code library
  • the attribute information of each node at the code level is added to the code layout information to obtain the interface code.
  • each of the interface elements includes: a first interface element; and, a first generation module 303 is specifically used to:
  • the display attributes of the first interface element are matched in the code library.
  • the first generation module 303 is also used to:
  • each interface element in the layout information is renamed according to the semantic naming rules.
  • the interface element information includes: attribute information of each interface element
  • the attribute information includes at least one of the following items: name, type, coordinates, width and height, drawing order, filling content, and style of filling content.
  • the first determining module 301 is specifically used to:
  • Layer attribute information of each layer from the image file to be processed, where the layer attribute information includes name, type, coordinates, width and height, drawing order, filling content, and style of filling content;
  • the first determining module 301 is specifically configured to execute at least one of the following:
  • the image file to be processed is a design drawing; the first determining module 301 is specifically used to:
  • FIG. 4 shows a structural block diagram of an apparatus for generating an interface code provided by another embodiment of the present application.
  • the device includes:
  • the first display module 401 is used to display an operation interface for the user to input image data to be processed
  • the second generation module 402 is configured to generate an interface code based on the to-be-processed image data in response to an interface code generation instruction triggered by the user through the operation interface.
  • an operation interface is provided for the user, and the user imports the image file to be processed on the operation interface; in response to the user's interface code generation instruction triggered by the operation interface, the interface is generated based on the image file to be processed Code. It can be seen that, in the technical solution provided by the embodiments of the present application, the interface code is automatically generated by processing the image file to be processed, which not only improves the development efficiency and development cycle, but also reduces the burden on the programmer.
  • the first display module 401 is also used to:
  • a control corresponding to at least one code language type is displayed on the operation interface for the user to select.
  • the above device further includes:
  • a third generation module configured to generate the interface code generation instruction in response to the user's trigger operation on the control corresponding to the first code language type, and the interface code generation instruction carries the first code language type;
  • the second generation module is specifically used for:
  • an interface code is generated based on the image data to be processed.
  • the image data to be processed is interface element information derived from the image file to be processed, and the second generation module is specifically used to:
  • an interface code is generated.
  • FIG. 5 is a schematic structural diagram of an electronic device provided by an embodiment of the present application.
  • the electronic device includes: a first memory 1101 and a first processor 1102.
  • the first memory 1101 may be configured to store various other data to support operations on the electronic device. Examples of these data include instructions for any applications or methods that operate on the electronic device.
  • the first memory 1101 may be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read only memory (EEPROM), erasable In addition to programmable read only memory (EPROM), programmable read only memory (PROM), read only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
  • SRAM static random access memory
  • EEPROM electrically erasable programmable read only memory
  • EPROM programmable read only memory
  • ROM read only memory
  • magnetic memory flash memory
  • flash memory magnetic disk or optical disk.
  • the first processor 1102 is coupled to the first memory 1101, and is used to execute the program stored in the first memory 1101 for:
  • an interface code is generated.
  • the electronic device further includes: a first communication component 1103, a first display 1104, a first power component 1105, a first audio component 1106 and other components.
  • FIG. 5 only schematically shows some components, and does not mean that the electronic device includes only the components shown in FIG. 5.
  • the embodiments of the present application also provide a computer-readable storage medium storing a computer program, which when executed by a computer can implement the steps or functions of the object positioning method provided by the foregoing embodiments.
  • FIG. 6 shows a schematic structural diagram of an electronic device provided by an embodiment of the present application.
  • the electronic device includes a second display 1204, a second memory 1201, and a second processor 1202.
  • the second memory 1201 may be configured to store various other data to support operations on the electronic device. Examples of these data include instructions for any applications or methods operating on the electronic device.
  • the second memory 1201 may be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read only memory (EEPROM), erasable In addition to programmable read only memory (EPROM), programmable read only memory (PROM), read only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
  • SRAM static random access memory
  • EEPROM electrically erasable programmable read only memory
  • EPROM programmable read only memory
  • ROM read only memory
  • magnetic memory flash memory
  • flash memory magnetic disk or optical disk.
  • the second display 1204 is coupled to the second processor 1202, and is used to display an operation interface for the user to input image data to be processed;
  • the second processor 1202 is coupled to the second memory 1201, and is used to execute the program stored in the second memory 1201 for:
  • an interface code is generated based on the image data to be processed.
  • the electronic device further includes: a second communication component 1203, a second power component 1205, a second audio component 1206, and other components. Only some components are schematically shown in FIG. 6, which does not mean that the electronic device includes only the components shown in FIG.
  • the embodiments of the present application also provide a computer-readable storage medium storing a computer program, which when executed by a computer can realize the steps or functions of the object positioning method provided by the foregoing embodiments.
  • the device embodiments described above are only schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, may be located One place, or can be distributed to multiple network elements. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art can understand and implement without paying creative labor.
  • each embodiment can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware.
  • the above technical solutions can be embodied in the form of software products in essence or part of the contribution to the existing technology, and the computer software products can be stored in computer-readable storage media, such as ROM/RAM, magnetic Discs, optical discs, etc., include several instructions to enable a computer device (which may be a personal computer, server, or network device, etc.) to perform the methods described in the various embodiments or some parts of the embodiments.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Human Computer Interaction (AREA)
  • Processing Or Creating Images (AREA)
  • User Interface Of Digital Computer (AREA)

Abstract

Provided are a method and device for generating interface codes. Wherein, the method comprises the following steps: determining interface element information of an image file to be processed (101); determining layout information of an interface based on the interface element information (102); and generating interface codes according to the layout information (103). In the technical solution provided by the method, the automatic generation of the interface codes through the processing of the image file to be processed not only improves development efficiency and development cycle, but also reduces burden on programmers.

Description

界面代码的生成方法及设备Method and equipment for generating interface code
本申请要求2019年01月06日递交的申请号为201910010012.5、发明名称为“界面代码的生成方法及设备”中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application requires the priority of the Chinese patent application with the application number 201910010012.5 and the invention titled "Interface Code Generation Method and Equipment" submitted on January 06, 2019, the entire content of which is incorporated by reference in this application.
技术领域Technical field
本申请涉及电子技术领域,尤其涉及一种界面代码的生成方法及设备。This application relates to the field of electronic technology, in particular to a method and device for generating interface codes.
背景技术Background technique
目前,互联网下业务发展迅速,各类产品迭代迅速。如何提高用户界面的开发效率,快速对接高速发展的互联网业务是一项重要使命。At present, business under the Internet is developing rapidly, and various products are iterating rapidly. It is an important mission to improve the efficiency of user interface development and quickly connect to the rapid development of Internet services.
然而,现有的用户界面开发过程中,需要设计师先依靠设计工具设计出用户界面的设计稿,编程人员根据设计师设计出的设计稿,通过人工编写代码的方式得到用户界面的界面代码。这种开发方式的开发效率低且开发周期较长。However, in the current user interface development process, designers need to rely on the design tools to design the design draft of the user interface first. The programmers obtain the interface code of the user interface by manually writing the code according to the design draft designed by the designer. The development efficiency of this development method is low and the development cycle is long.
发明内容Summary of the invention
鉴于上述问题,提出了本申请以提供一种解决上述问题或至少部分地解决上述问题的界面代码的生成方法及设备。In view of the above problems, the present application is proposed to provide a method and device for generating an interface code that solves the above problems or at least partially solves the above problems.
于是,在本申请的一个实施例中,提供了一种界面代码的生成方法。该方法包括:Therefore, in an embodiment of the present application, a method for generating interface codes is provided. The method includes:
确定待处理图像文件的界面元素信息;Determine the interface element information of the image file to be processed;
基于所述界面元素信息,确定界面的布局信息;Determine the layout information of the interface based on the interface element information;
根据所述布局信息,生成界面代码。According to the layout information, an interface code is generated.
在本申请的另一个实施例中,提供了一种界面代码的生成方法。该方法包括:In another embodiment of the present application, a method for generating interface code is provided. The method includes:
显示操作界面,以供用户输入待处理图像数据;Display operation interface for users to input image data to be processed;
响应于所述用户通过所述操作界面触发的界面代码生成指令,基于所述待处理图像数据,生成界面代码。In response to an interface code generation instruction triggered by the user through the operation interface, an interface code is generated based on the image data to be processed.
在本申请的又一实施例中,提供了一种电子设备。该电子设备,包括:In yet another embodiment of the present application, an electronic device is provided. The electronic device includes:
第一存储器和第一处理器,其中,A first memory and a first processor, wherein,
所述第一存储器,用于存储程序;The first memory is used to store programs;
所述第一处理器,与所述第一存储器耦合,用于执行所述第一存储器中存储的所述程序,以用于:The first processor, coupled to the first memory, is used to execute the program stored in the first memory for:
确定待处理图像文件的界面元素信息;Determine the interface element information of the image file to be processed;
基于所述界面元素信息,确定界面的布局信息;Determine the layout information of the interface based on the interface element information;
根据所述布局信息,生成界面代码。According to the layout information, an interface code is generated.
在本申请的又一实施例中,提供了一种电子设备。该电子设备,包括:In yet another embodiment of the present application, an electronic device is provided. The electronic device includes:
第二存储器、第二处理器和第二显示器,其中,A second memory, a second processor and a second display, wherein,
所述第二存储器,用于存储程序;The second memory is used to store programs;
所述第二显示器,与所述第二处理器耦合,用于显示操作界面,以供用户输入待处理图像数据;The second display, coupled with the second processor, is used to display an operation interface for the user to input image data to be processed;
所述第二处理器,与所述第二存储器耦合,用于执行所述第二存储器中存储的所述程序,以用于:The second processor, coupled to the second memory, is used to execute the program stored in the second memory for:
响应于所述用户通过所述操作界面触发的界面代码生成指令,基于所述待处理图像数据,生成界面代码。In response to an interface code generation instruction triggered by the user through the operation interface, an interface code is generated based on the image data to be processed.
本申请实施例提供的技术方案中,先从待处理图像文件中导出界面元素信息,根据界面元素信息,确定出界面的布局信息,再根据布局信息自动生成界面代码。可见,本申请实施例提供的技术方案中,通过对待处理图像文件的处理进行界面代码的自动生成,不仅提高开发效率以及开发周期,还能为编程人员减负。In the technical solution provided by the embodiment of the present application, the interface element information is first derived from the image file to be processed, the layout information of the interface is determined according to the interface element information, and then the interface code is automatically generated according to the layout information. It can be seen that, in the technical solution provided by the embodiments of the present application, the interface code is automatically generated by processing the image file to be processed, which not only improves the development efficiency and development cycle, but also reduces the burden on the programmer.
附图说明BRIEF DESCRIPTION
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作一简单地介绍,显而易见地,下面描述中的附图是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly explain the embodiments of the present invention or the technical solutions in the prior art, the following will briefly introduce the drawings used in the description of the embodiments or the prior art. Obviously, the drawings in the following description These are some embodiments of the present invention. For those of ordinary skill in the art, without paying any creative work, other drawings can be obtained based on these drawings.
图1为本申请一实施例提供的生成方法的流程示意图;FIG. 1 is a schematic flowchart of a generation method provided by an embodiment of this application;
图2为本申请又一实施例提供的生成方法的流程示意图;2 is a schematic flowchart of a generating method provided by another embodiment of this application;
图3为本申请一实施例提供的生成装置的结构框图;3 is a structural block diagram of a generating device provided by an embodiment of the present application;
图4为本申请一实施例提供的生成装置的结构框图;4 is a structural block diagram of a generation device provided by an embodiment of the present application;
图5为本发明一实施例提供的电子设备的结构框图;5 is a structural block diagram of an electronic device provided by an embodiment of the present invention;
图6为本发明又一实施例提供的电子设备的结构框图;6 is a structural block diagram of an electronic device provided by another embodiment of the present invention;
图7为本申请一实施例提供的生成方法的流程示意图;7 is a schematic flowchart of a generating method provided by an embodiment of the present application;
图8为本申请一实施例提供的布局方法的流程示意图;8 is a schematic flowchart of a layout method provided by an embodiment of this application;
图9为本申请一实施例提供的一操作界面图。FIG. 9 is an operation interface diagram provided by an embodiment of the present application.
具体实施方式detailed description
为了使本技术领域的人员更好地理解本发明方案,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述。In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be described clearly and completely in conjunction with the drawings in the embodiments of the present invention.
在本发明的说明书、权利要求书及上述附图中描述的一些流程中,包含了按照特定顺序出现的多个操作,这些操作可以不按照其在本文中出现的顺序来执行或并行执行。操作的序号如101、102等,仅仅是用于区分各个不同的操作,序号本身不代表任何的执行顺序。另外,这些流程可以包括更多或更少的操作,并且这些操作可以按顺序执行或并行执行。需要说明的是,本文中的“第一”、“第二”等描述,是用于区分不同的消息、设备、模块等,不代表先后顺序,也不限定“第一”和“第二”是不同的类型。Some processes described in the specification, claims, and drawings of the present invention include multiple operations that occur in a specific order. These operations may not be performed in the order in which they appear in this document or in parallel. The sequence numbers of operations such as 101 and 102 are only used to distinguish different operations, and the sequence numbers themselves do not represent any execution order. In addition, these processes may include more or fewer operations, and these operations may be performed sequentially or in parallel. It should be noted that the descriptions of "first" and "second" in this article are used to distinguish different messages, devices, modules, etc., and do not represent the order, nor limit "first" and "second". Are different types.
现有技术中,设计人员设计好UI(User Interface,用户界面)设计稿后,将UI设计稿交付给编程人员。编程人员根据UI设计稿进行代码编写得到界面代码。在编程人员编写好界面代码后,设计人员才能看到代码实现的真实UI效果,以进行视觉走查。这种开发方式开发效率低下且开发周期较长。In the prior art, after the designer designs the UI (User Interface, user interface) design draft, the UI design draft is delivered to the programmer. The programmer writes the code according to the UI design draft to get the interface code. After the programmer writes the interface code, the designer can see the real UI effect of the code for visual walkthrough. This development method has low development efficiency and a long development cycle.
为了提高开发效率和缩短开发周期,本申请实施例提供了一种基于待处理图像文件自动生成界面代码的方法。In order to improve development efficiency and shorten the development cycle, embodiments of the present application provide a method for automatically generating interface codes based on image files to be processed.
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述。显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。The technical solutions in the embodiments of the present invention will be described clearly and completely in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, but not all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work fall within the protection scope of the present invention.
图1示出了本申请一实施例提供的界面代码的生成方法的流程示意图。如图1所示,该方法包括:FIG. 1 shows a schematic flowchart of a method for generating an interface code provided by an embodiment of the present application. As shown in Figure 1, the method includes:
101、确定待处理图像文件的界面元素信息。101. Determine interface element information of an image file to be processed.
102、基于所述界面元素信息,确定界面的布局信息。102. Determine the layout information of the interface based on the interface element information.
103、根据所述布局信息,生成界面代码。103. Generate interface codes according to the layout information.
上述101中,待处理图像文件可以为设计稿或设计图。其中。设计稿指的是UI设计师通过设计软件制作出来的原始文件,该原始文件中通常会包含有多个图层;设计图指的是基于设计稿生成的图片,例如:截图。具体实施时,待处理图像文件可以为一UI模块对应的设计稿或设计图。In the above 101, the image file to be processed may be a design draft or a design drawing. among them. The design draft refers to the original file created by the UI designer through the design software. The original file usually contains multiple layers; the design drawing refers to the image generated based on the design draft, for example: a screenshot. During specific implementation, the image file to be processed may be a design draft or design drawing corresponding to a UI module.
设计师常用的设计软件如:Sketch、Photoshop等。这些设计软件通常会向用户开放一应用程序接口(即插件),可通过设计软件的应用程序接口导出与设计稿相关的界面元素信息,并将导出的界面元素信息缓存在一缓存空间,例如:剪切板。在导出过程中,该插件会遍历待处理图像文件的所有图层,并对所有图层进行类型解析以及数据提取。Designers commonly used design software such as: Sketch, Photoshop, etc. These design software usually open an application program interface (ie plug-in) to the user, and can export interface element information related to the design draft through the application program interface of the design software, and cache the exported interface element information in a cache space, for example: Clipboard. During the export process, the plug-in will traverse all layers of the image file to be processed, and perform type analysis and data extraction on all layers.
其中,界面元素信息中可包括:各界面元素的属性信息。属性信息可包括以下项中的至少一项:名称、类型、坐标、宽高、绘制顺序、填充内容以及填充内容的样式。界面元素的类型可包括但不限于:文本类型、图片类型、shape类型、input类型、textArea类型。Among them, the interface element information may include: attribute information of each interface element. The attribute information may include at least one of the following items: name, type, coordinates, width and height, drawing order, fill content, and style of fill content. The types of interface elements may include but are not limited to: text type, picture type, shape type, input type, textArea type.
上述102中,可从缓存空间中导出界面元素信息,进行布局识别,得到布局信息。布局信息中包括:各界面元素之间的父子节点关系以及各父节点下的各子节点的分布信息。In the above 102, interface element information can be derived from the cache space, and layout identification can be performed to obtain layout information. The layout information includes: the parent-child node relationship between each interface element and the distribution information of each child node under each parent node.
父节点对应的界面元素位于其子节点对应的界面元素的下方,即父节点对应的界面元素的绘制顺序先于其子节点对应的界面元素的绘制顺序。父节点与子节点之间的具体关系可包括:包含关系和交叉关系。包含关系指的是子节点对应的界面元素全部与父节点对应的界面元素重叠。交叉关系指的是子节点对应的界面元素只部分与父节点对应的界面元素重叠。The interface element corresponding to the parent node is located below the interface element corresponding to its child node, that is, the drawing order of the interface element corresponding to the parent node is prior to the drawing order of the interface element corresponding to its child node. The specific relationship between the parent node and the child node may include: inclusion relationship and cross relationship. Inclusion relationship means that all the interface elements corresponding to the child nodes overlap with the interface elements corresponding to the parent node. The cross relationship means that the interface elements corresponding to the child nodes only partially overlap the interface elements corresponding to the parent node.
上述103中,对界面的布局信息进行代码转换,以得到界面代码。可根据实际需要生成多种代码语言类型对应的界面代码。代码语言类型包括但不限于:HTML(HyperText Markup Language,超级文本标记语言)、Vue、Rax。In the above 103, code conversion is performed on the layout information of the interface to obtain the interface code. Interface codes corresponding to multiple code language types can be generated according to actual needs. Code language types include but are not limited to: HTML (HyperText Markup Language, Hyper Text Markup Language), Vue, Rax.
本申请实施例提供的技术方案中,先从待处理图像文件中导出界面元素信息,根据界面元素信息,确定出界面的布局信息,再根据布局信息自动生成界面代码。可见,本申请实施例提供的技术方案中,通过对待处理图像文件的处理进行界面代码的自动生成,不仅提高开发效率以及开发周期,还能为编程人员减负。In the technical solution provided by the embodiment of the present application, the interface element information is first derived from the image file to be processed, the layout information of the interface is determined according to the interface element information, and then the interface code is automatically generated according to the layout information. It can be seen that, in the technical solution provided by the embodiments of the present application, the interface code is automatically generated by processing the image file to be processed, which not only improves the development efficiency and development cycle, but also reduces the burden on the programmer.
在一种可实现的方案中,上述102中“基于所述界面元素信息,确定界面的布局信息”,具体可采用如下步骤来实现:In a practical solution, the "determining the layout information of the interface based on the interface element information" in 102 above may be specifically implemented by the following steps:
1021、基于所述界面元素信息中各界面元素的属性信息,确定各界面元素之间的父子节点关系以及各父节点的至少一个子节点的分布信息。1021: Based on attribute information of each interface element in the interface element information, determine a parent-child node relationship between each interface element and distribution information of at least one child node of each parent node.
1022、根据所述父子节点关系及各父节点的至少一个子节点的分布信息,确定所述布局信息。1022. Determine the layout information according to the parent-child node relationship and distribution information of at least one child node of each parent node.
上述1021中,可基于各界面元素的位置信息及绘制顺序信息,确定所述各界面元素 之间的父子节点关系。其中,位置信息包括坐标和宽高。In the above 1021, the parent-child node relationship between each interface element may be determined based on the position information and drawing order information of each interface element. Among them, the position information includes coordinates and width and height.
具体可根据各界面元素中任意两个界面元素的位置信息确定任意两个界面元素之间是否存在重叠部分;当两个界面元素之间存在重叠部分时,根据该两个界面元素的绘制顺序信息,将这两个界面元素中先绘制的界面元素作为父节点,将后绘制的界面元素作为该父节点的子节点;遍历所有界面元素后,即可得到所有界面元素之间的父子节点关系。Specifically, it can be determined whether there is an overlap between any two interface elements according to the position information of any two interface elements in each interface element; when there is an overlap between the two interface elements, according to the drawing order information of the two interface elements The interface element drawn first among the two interface elements is used as the parent node, and the interface element drawn later is used as the child node of the parent node; after traversing all interface elements, the parent-child node relationship between all interface elements can be obtained.
为了提高确定出的父子节点关系的合理性,上述1021中的“基于所述界面元素信息中各界面元素的属性信息,确定各界面元素之间的父子节点关系”,可采用如下步骤来实现:In order to improve the rationality of the determined parent-child node relationship, “determining the parent-child node relationship between each interface element based on the attribute information of each interface element in the interface element information” in 1021 above may be implemented by the following steps:
S11、基于各界面元素的位置信息及绘制顺序信息,确定所述各界面元素之间的初始父子节点关系。S11. Determine the initial parent-child node relationship between the interface elements based on the position information and drawing sequence information of the interface elements.
S12、在所述初始父子节点关系中,若存在指定类界面元素作为父节点的情况,则在所述初始父节点关系中新增一第一容器节点来容纳所述指定类界面元素及所述指定类界面元素的子节点,以得到所述父子节点关系。S12. In the initial parent-child node relationship, if a designated interface element exists as a parent node, a first container node is added to the initial parent node relationship to accommodate the designated interface element and the Specify the child node of the class interface element to obtain the parent-child node relationship.
上述S11中的初始父子节点关系的具体确定过程可参见上述相应内容,在此不再赘述。The specific determination process of the initial parent-child node relationship in the above S11 may refer to the corresponding content above, and will not be repeated here.
上述S12中,指定类界面元素可以为:图片类界面元素和文本类界面元素。由于图片类界面元素和文本类界面元素作为父节点,是不合理的。故:在所述初始父子节点关系中,若存在指定类界面元素作为父节点的情况,则在所述初始父节点关系中新增一第一容器节点来容纳所述指定类界面元素及所述指定类界面元素的子节点,以得到所述父子节点关系。In the above S12, the designated interface elements may be: picture interface elements and text interface elements. It is unreasonable to use picture interface elements and text interface elements as parent nodes. Therefore: in the initial parent-child node relationship, if a designated interface element exists as a parent node, a first container node is added to the initial parent node relationship to accommodate the designated interface element and the Specify the child node of the class interface element to obtain the parent-child node relationship.
具体来说:在初始父节点关系中:节点A的子节点有B和C,且节点A的父节点为节点Q。节点A为图片类界面元素,故新增一个第一容器节点D,由D作为A、B和C的父节点,且D的父节点为Q。Specifically: In the initial parent node relationship: the child nodes of node A have B and C, and the parent node of node A is node Q. Node A is a picture-type interface element, so a first container node D is added, and D is the parent node of A, B, and C, and the parent node of D is Q.
在父子节点关系中除根节点和叶子节点以外,每个节点既作为父节点也作为子节点。根节点只能作为父节点,叶子节点只能作为子节点。父子节点关系中通常会存在两种类型的父节点:第一类父节点和第二类父节点。第一类父节点指的是:与其子节点为上述包含关系的父节点;第二类父节点指的是:与其子节点为上述交叉关系的父节点。In the parent-child node relationship, except for the root node and the leaf node, each node acts as both a parent node and a child node. The root node can only be a parent node, and the leaf node can only be a child node. There are usually two types of parent nodes in the parent-child node relationship: the first type of parent node and the second type of parent node. The first type of parent node refers to: its child node is the parent node of the above-mentioned containing relationship; the second type of parent node refers to: its child node is the parent node of the above-mentioned cross-relationship.
上述1021中“确定第一类父节点的至少一个第一子节点的分布信息”,具体为:根据所述至少一个第一子节点的位置信息,确定所述至少一个第一子节点的行列信息以及 所述至少一个第一子节点中各第一子节点的四周间距信息。The “determining the distribution information of at least one first child node of the first type parent node” in 1021 above specifically includes determining the row and column information of the at least one first child node according to the position information of the at least one first child node And information about the distance between the first child nodes in the at least one first child node.
其中,第一类父节点的至少一个第一子节点的分布信息包括:所述至少一个第一子节点的行列信息以及所述至少一个第一子节点中各第一子节点的四周间距信息。Wherein, the distribution information of at least one first child node of the first type of parent node includes: row and column information of the at least one first child node and information about the surrounding distance of each first child node in the at least one first child node.
具体实施时,可通过行列扫描得到至少一个第一子节点的行列信息;再根据行列信息,对所述至少一个第一子节点进行边界扫描,以得到各第一子节点的四周间距信息。通常,四周间距信息包括:左间距、右间距、上间距和下间距。In a specific implementation, the row and column information of at least one first child node may be obtained by row and column scanning; and then the boundary scan is performed on the at least one first child node according to the row and column information to obtain information about the surrounding distance of each first child node. Generally, the four-week spacing information includes: left spacing, right spacing, top spacing, and bottom spacing.
上述1021中“确定所述第二类父节点的至少一个第二子节点的分布信息”,具体为:根据所述第二类父节点以及所述至少一个第二子节点的位置信息,对所述至少一个第二子节点进行绝对定位布局,以得到所述至少一个第二子节点的分布信息。The “determining the distribution information of at least one second child node of the second type parent node” in 1021 above specifically includes: according to the position information of the second type parent node and the at least one second child node, check The at least one second child node performs an absolute positioning layout to obtain distribution information of the at least one second child node.
第二类父节点对应的界面元素与第二子节点对应的界面元素之间为交叉关系,故根据第二类父节点的位置信息以及至少一个第二子节点的位置信息进行计算,得到至少一个第二子节点相对于第二类父节点的绝对坐标信息。The interface element corresponding to the parent node of the second type and the interface element corresponding to the second child node have a cross relationship, so the calculation is performed according to the position information of the parent node of the second type and the position information of at least one second child node to obtain at least one The absolute coordinate information of the second child node relative to the parent node of the second type.
上述1022中,可对所述父子节点关系及各父节点的至少一个子节点的分布信息进行组合,以得到界面的布局信息。In the above 1022, the relationship between the parent-child node and the distribution information of at least one child node of each parent node may be combined to obtain layout information of the interface.
为了提高各界面元素之间的父子节点关系的准确度,需要对界面元素信息中可能存在的溢出以及微小交叉等情况进行修整。例如:当两个界面元素的边界的重叠程度低于重叠阈值时,可对两个界面元素进行边界修复,以使两个界面元素的边界不重叠。In order to improve the accuracy of the parent-child node relationship between each interface element, it is necessary to modify the possible overflow and small cross in the interface element information. For example, when the overlapping degree of the boundary between the two interface elements is lower than the overlap threshold, the boundary repair can be performed on the two interface elements so that the boundary between the two interface elements does not overlap.
为了更加贴近实际开发中人工写代码的场景,以提高界面代码的实际可用性以及维护性,可在布局信息中添加伸缩布局属性(即flex布局属性)。具体的,上述方法,还可包括:In order to be more close to the scenario of manually writing code in actual development, and to improve the actual usability and maintainability of the interface code, a scalable layout attribute (that is, a flex layout attribute) can be added to the layout information. Specifically, the above method may further include:
104、根据所述至少一个第一子节点中各第一子节点的四周间距信息,确定各行的伸缩布局属性和各列的伸缩布局属性。104. Determine, according to the surrounding information of the first child nodes in the at least one first child node, the stretchable layout attributes of each row and the stretchable layout attributes of each column.
105、根据所述各行的伸缩布局属性和各列的伸缩布局属性,确定对所述布局信息的修正方案。105. Determine a correction scheme for the layout information according to the scalable layout attributes of each row and the scalable layout attributes of each column.
上述104中,伸缩布局属性包括:水平居中、垂直居中、间隔同等布局(即一行或一列中存在多个间距,多个间距中任两个间距的差值小于第一误差值)等。可事先根据实际应用中各类伸缩布局属性,设置各类伸缩布局属性对应的间距规则;后续,根据每一行上的第一子节点的四周间距信息,来与各类伸缩布局属性对应的间距规则进行匹配,将匹配上的间距规则对应的伸缩布局属性作为每一行的伸缩布局属性;根据每一列上的第一子节点的四周间距信息,来与各类伸缩布局属性对应的间距规则进行匹配,将匹配 上的间距规则对应的伸缩布局属性作为每一列的伸缩布局属性。。In the above 104, the telescopic layout attributes include: horizontal centering, vertical centering, and equal-spaced layouts (that is, there are multiple spacings in a row or column, and the difference between any two spacings in the multiple spacings is less than the first error value). The spacing rules corresponding to various types of scaling layout attributes can be set in advance according to various types of scaling layout attributes in practical applications; subsequently, the spacing rules corresponding to various types of scaling layout attributes can be determined according to the surrounding space information of the first child node on each row Matching, the telescopic layout attributes corresponding to the spacing rules on the match are used as the telescopic layout attributes of each row; according to the surrounding space information of the first child node on each column, to match the spacing rules corresponding to various types of telescopic layout attributes, The scaling layout attribute corresponding to the spacing rule on the match is used as the scaling layout attribute of each column. .
例如:水平居中对应的间距规则为:行的左间距与行的右间距的差值小于第二误差值;第一行上包括从左到右排列的第一子节点A和B,第一子节点A的左间距Z1即为第一行的左间距,第一子节点B的右间距Z2即为第一行的右间距。当Z1和Z2的差值小于第二误差值时,第一行的伸缩布局属性即为水平居中。For example: the spacing rule corresponding to horizontal centering is: the difference between the left spacing of the row and the right spacing of the row is less than the second error value; the first row includes the first child nodes A and B arranged from left to right, the first child The left pitch Z1 of the node A is the left pitch of the first row, and the right pitch Z2 of the first child node B is the right pitch of the first row. When the difference between Z1 and Z2 is less than the second error value, the telescopic layout attribute of the first row is horizontally centered.
上述105中,所述各行的伸缩布局属性一致时,在所述布局信息中,为所述第一类父节点添加任一行的伸缩布局属性。In the above 105, when the scalable layout attributes of each row are consistent, in the layout information, a scalable layout attribute of any row is added to the first-type parent node.
所述各列的伸缩布局属性一致时,在所述布局信息中,为所述第一类父节点添加任一列的伸缩布局属性。When the telescopic layout attributes of the columns are consistent, add the telescopic layout attributes of any column to the parent node of the first type in the layout information.
所述各行的伸缩布局属性不一致且所述各列的伸缩布局属性也不一致时,在所述布局信息中,为各行新增一第二容器节点以容纳各行上的第一子节点,并为各行新增的所述第二容器节点添加各行对应的伸缩布局属性,其中,各行的所述第二容器节点为所述第一类父节点的子节点。此外,各行的第二容器节点为各行上的第一子节点的父节点。When the telescopic layout attributes of the rows are inconsistent and the telescopic layout attributes of the columns are also inconsistent, in the layout information, a second container node is added to each row to accommodate the first child node on each row, and for each row The newly added second container node adds a scalable layout attribute corresponding to each row, wherein the second container node of each row is a child node of the parent node of the first type. In addition, the second container node of each row is the parent node of the first child node on each row.
在为各行新增一第二容器节点以容纳各行上的第一子节点,并为各行新增的所述第二容器节点添加各行对应的伸缩布局属性后,可剔除一定规则下多余的伸缩布局属性,例如:左对齐通常为默认伸缩布局属性,故左对齐的伸缩布局属性可剔除。After adding a second container node to each row to accommodate the first child node on each row, and adding the scaling layout attribute corresponding to each row to the second container node newly added to each row, the redundant scaling layout under certain rules can be eliminated Attributes, for example, left-aligned are usually default telescopic layout attributes, so left-aligned telescopic layout attributes can be eliminated.
进一步的,上述103中“根据所述布局信息,生成界面代码”,具体可采用如下步骤来实现:Further, the "generating interface code according to the layout information" in 103 above may be specifically implemented by the following steps:
1031、根据所述布局信息,从代码库中匹配出相应的代码布局信息。1031. According to the layout information, corresponding code layout information is matched from the code base.
1032、根据所述布局信息中各界面元素的属性信息,从所述代码库中匹配出所述代码布局信息中各节点在代码层面的属性信息。1032. According to the attribute information of each interface element in the layout information, match the attribute information of each node in the code layout information at the code level from the code library.
1033、将所述各节点在代码层面的属性信息添加至所述代码布局信息中,以得到所述界面代码。1033: Add attribute information of each node at the code level to the code layout information to obtain the interface code.
可事先根据各种可能存在的布局信息进行代码编码,以得到代码布局信息。可事先根据各种可能存在的界面元素的属性信息进行代码编码,以得到代码层面的属性信息。将各种可能存在的布局信息对应的代码布局信息以及各种可能存在的界面元素的属性信息对应的代码层面的属性信息,存入代码库中。Code coding may be performed according to various possible layout information in advance to obtain code layout information. Code encoding may be performed according to attribute information of various possible interface elements in advance to obtain attribute information at the code level. Store code layout information corresponding to various possible layout information and code level attribute information corresponding to various possible interface element attribute information into the code library.
这样,后续即可根据布局信息,从代码库中匹配出相应的代码布局信息。根据布局信息中各界面元素的属性信息,从所述代码库中匹配出代码布局信息中各节点在代码层面的属性信息。其中,布局信息中的界面元素与代码布局信息中的节点一一对应。In this way, subsequent code layout information can be matched from the code base according to the layout information. According to the attribute information of each interface element in the layout information, the code level attribute information of each node in the code layout information is matched from the code library. Among them, the interface elements in the layout information correspond one-to-one with the nodes in the code layout information.
在一种可实现的方案中,所述各界面元素包括:第一界面元素。上述1032中“根据所述第一界面元素的属性信息,从所述代码库中匹配出所述代码布局信息中与所述第一界面元素对应的第一节点在代码层面的属性信息”,具体为:根据所述第一界面元素的类型属性,在所述代码库中匹配出所述第一节点在代码层面的类型属性;根据所述第一界面元素的显示属性,在所述代码库中匹配出所述第一节点在代码层面的显示属性。其中,显示属性可包括:填充内容以及填充内容的样式。In a feasible solution, each of the interface elements includes: a first interface element. In the above 1032, "according to the attribute information of the first interface element, the attribute information at the code level of the first node corresponding to the first interface element in the code layout information is matched from the code library", specifically Is: according to the type attribute of the first interface element, the type attribute of the first node at the code level is matched in the code library; according to the display attribute of the first interface element, in the code library The display attributes of the first node at the code level are matched. Among them, the display attributes may include: the filling content and the style of the filling content.
为了增加生成的界面代码的可读性,需要将布局信息中各界面元素的命名作为代码布局信息中相应节点的命名。为了更加贴近真实场景下开发的代码编写,上述103中“根据所述布局信息,生成界面代码”,还包括:In order to increase the readability of the generated interface code, the naming of each interface element in the layout information needs to be taken as the naming of the corresponding node in the code layout information. In order to more closely compile the code developed under the real scene, the "generating interface code based on the layout information" in 103 above also includes:
1034、在根据所述布局信息,获取对应的代码布局信息之前,按照语义化命名规则,对所述布局信息中各界面元素进行重新命名。1034. Before acquiring corresponding code layout information according to the layout information, rename each interface element in the layout information according to a semantic naming rule.
语义化命名主要是针对各个界面元素的命名进行重新赋值,通过对界面元素的属性信息进行解析,得到这个命名。语义化命名规则中包括:默认规则、分组规则、NLP(Neuro-Linguistic Programming,神经语言程序学)自然语言分析、图像识别、业务规则。The semantic naming is mainly to re-assign the naming of each interface element, and the naming is obtained by parsing the attribute information of the interface element. The semantic naming rules include: default rules, grouping rules, NLP (Neuro-Linguistic Programming), natural language analysis, image recognition, and business rules.
此外,用户也可手动对相应界面元素的相应字段进行修改。具体地,可接收用户手写输入的字段以及用户手动绑定的待修改字段;将用户手动绑定的待修改字段替换成用户手写输入的字段,即完成字段的自动映射。In addition, users can also manually modify the corresponding fields of the corresponding interface elements. Specifically, the field to be handwritten input by the user and the field to be modified manually bound by the user can be received; the field to be modified manually bound by the user is replaced with the field written by the user to complete the automatic mapping of the field.
为了精简代码,可对布局信息进行扫描,识别出结构循环体;并在布局信息中标记出结构循环体;这样,后续根据布局信息,可从代码库中匹配到由循环语法精简过的代码布局信息。In order to simplify the code, the layout information can be scanned to identify the structure loop body; and the structure loop body is marked in the layout information; in this way, according to the layout information, the code layout simplified by the loop syntax can be matched from the code base information.
进一步的,上述101中“确定待处理图像文件的界面元素信息”,具体可采用如下步骤来实现:Further, the "determining the interface element information of the image file to be processed" in the above 101 can be specifically implemented by the following steps:
1011、从所述待处理图像文件中导出各图层的图层属性信息。1011. Export layer attribute information of each layer from the image file to be processed.
1012、对所述各图层的图层属性信息进行预设规则处理。1012. Perform preset rule processing on the layer attribute information of each layer.
1013、将预测规则处理后的各图层的图层属性信息作为所述界面元素信息中各界面元素的属性信息。1013. Use layer attribute information of each layer processed by the prediction rule as attribute information of each interface element in the interface element information.
其中,所述图层属性信息中包括名称、类型、坐标、宽高、绘制顺序、填充内容以及填充内容的样式。Wherein, the layer attribute information includes name, type, coordinates, width and height, drawing order, filling content and style of filling content.
上述1011中,可借助设计软件提供的应用程序接口来导出各图层的图层属性信息。In the above 1011, the layer attribute information of each layer can be exported by using the application program interface provided by the design software.
上述1012中,可对所述各图层的图层属性信息进行预设规则处理的步骤包括以下至 少一项:In the above 1012, the step of performing preset rule processing on the layer attribute information of each layer includes at least one of the following:
第一项:通过对所述各图层进行图层冗余及顺序校验,删除其中无用图层的图层属性信息。The first item: delete layer attribute information of useless layers by performing layer redundancy and sequence check on each layer.
其中,无用图层指的是被其他图层完全覆盖的图层或者在绘制用户界面过程中没有引起用户界面变化的图层。Among them, the useless layer refers to a layer completely covered by other layers or a layer that does not cause a change in the user interface during the drawing of the user interface.
第二项:通过对所述各图层进行图层类型校验,修正图层类型有误的图层的图层类型。The second item: correct the layer type of the layer with the wrong layer type by checking the layer type of each layer.
例如:shape类型图层很容易被识别成图片类型图层,因此,需要进行修正。For example: shape type layer is easy to be recognized as a picture type layer, so it needs to be corrected.
第三项:通过对所述各图层进行图层合并校验,将具有合并关联性的多个图层合并成一个图层。Item 3: By performing layer merge verification on the layers, merge multiple layers with merge association into one layer.
具体地:根据多个图层的连接状态以及像素差异,来判断多个图层是否具有合并关联性。例如:多个图层的边界存在重合部分且多个图层的像素差异小于预设阈值,则判定多个图像具有合并关联性。Specifically: According to the connection status and pixel differences of multiple layers, it is determined whether the multiple layers have a merged association. For example, if there are overlapping parts at the boundaries of multiple layers and the pixel difference of multiple layers is less than a preset threshold, it is determined that multiple images have merge relevance.
需要补充的是,上述第一项、第二项以及第三项还可借助OpenCV来实现图层校验。It should be added that the first, second, and third items above can also use OpenCV to implement layer verification.
第四项:结合所述待处理图像文件的设计工具的设计规则,对所述各图层的图层属性信息进行修正。Item 4: Modify the layer attribute information of each layer in combination with the design rules of the design tool of the image file to be processed.
不同设计工具的设计规则不同,因此,需要根据不同设计工具的设计规则来对各图层的图层属性信息进行修正。The design rules of different design tools are different. Therefore, the layer attribute information of each layer needs to be modified according to the design rules of different design tools.
第五项:将所述各图层的图层属性信息转换成预设格式的数据。Item 5: Convert the layer attribute information of each layer into data in a preset format.
具体地,预设格式可以为Json格式。Json格式是一种轻量级的数据交换格式。需要补充的是:在将所述各图层的图层属性信息转换成预设格式的数据之前,将图片类型界面元素对应的图片上传至服务端,例如:CDN(Content Delivery Network,即内容分发网络)上进行存储,并接收服务端返回的图片存储地址,将该图片存储地址作为图片类型界面元素的属性信息的一部分。Specifically, the preset format may be a Json format. Json format is a lightweight data exchange format. It needs to be added that: before converting the layer attribute information of each layer into data in a preset format, upload the picture corresponding to the picture type interface element to the server, for example: CDN (Content Delivery Network, content distribution Network), and receive the picture storage address returned by the server, and use the picture storage address as part of the attribute information of the picture type interface element.
当所述待处理图像文件为设计图时,上述1011中“从所述待处理图像文件中导出各图层的图层属性信息”具体可采用如下步骤来实现:When the to-be-processed image file is a design drawing, “exporting layer attribute information of each layer from the to-be-processed image file” in 1011 above may be specifically implemented by using the following steps:
S31、对所述设计图进行文字以及图像识别,以从所述设计图中分离出多个图层。S31. Perform text and image recognition on the design drawing to separate multiple layers from the design drawing.
S32、对所述多个图层进行图层类型识别,以确定所述多个图层的图层类型。S32. Perform layer type identification on the multiple layers to determine the layer types of the multiple layers.
通过OCR(Optical Character Recognition,光学字符识别)识别解析文字入手,分离出文本类型图层。再进一步外扩漫水寻找到其他类型的轮廓,拟合出各个轮廓所对应的 图层类型以及图层的其他属性数据。Through OCR (Opticalcharacterrecognition, optical character recognition) to identify and analyze the text to start, separate the text type layer. Further expand the diffuse water to find other types of contours, and fit the layer type corresponding to each contour and other attribute data of the layer.
具体实施时,可先对设计图进行OCR识别,以得到多个类文本层。具体地,先对设计图进行整体OCR识别,得到多个文字ROI(region of interest,感兴趣区域)。从每一个文字ROI中通过内外轮廓提取单字,提取到单字后,对单字进行单字处理:颜色聚合以及对文本颜色、位置、字体大小等单字信息进行提取。可绑定文字ROI与从该文字ROI中提取到的单字信息。在提取到设计图中所有单字后,寻找单字的联通区域,并绑定每一个联通区域与每一个联通区域所包含的单字信息。得到多个联通区域后,可根据联通区域中单字的文本颜色、位置、字体大小,合并相近联通区域。将最终得到的每一个联通区域作为一个类文本层。In specific implementation, OCR recognition can be performed on the design drawing to obtain multiple text layers. Specifically, the overall OCR recognition is performed on the design drawing to obtain multiple text ROI (region of interest). From each text ROI, extract the words through the inner and outer contours. After the words are extracted, the words are processed: color aggregation and extraction of the word information such as text color, position, font size and so on. You can bind the text ROI and the word information extracted from the text ROI. After extracting all the words in the design drawing, look for the connected area of the word, and bind each connected area with the word information contained in each connected area. After obtaining multiple Unicom areas, you can merge similar Unicom areas based on the text color, position, and font size of the words in the Unicom area. Treat each connected area as a text-like layer.
判断类文本层中的字体是否为标准字体模型,若是,则判定类文本层为文本类型图层;若不是,则将类文本层作为类图片层。Determine whether the font in the text-like layer is a standard font model. If so, determine that the text-like layer is a text-type layer; if not, use the text-like layer as a picture-like layer.
将多个类文本层聚合成文字层;在设计图中去除文本层,并通过噪声去除、强化边缘、连续区域过滤等预处理后,得到稳定图片层;通过图像识别从稳定图片层中确定出多个类图片层的轮廓信息;根据多个类图片层的轮廓信息对设计图进行切割,得到多个类图片层。Aggregate multiple text layers into a text layer; remove the text layer in the design drawing, and obtain a stable picture layer after preprocessing such as noise removal, edge enhancement, and continuous area filtering; determine from the stable picture layer through image recognition Contour information of multiple class picture layers; cut the design drawing according to the contour information of multiple class picture layers to obtain multiple class picture layers.
若类图片层中不存在文本,则判断该类图片层是否包含浮层;若包含浮层,则分离出浮层,并将分离出浮层后的类图片层确定为图片类型图层。If there is no text in the class picture layer, it is judged whether the class picture layer contains a floating layer; if it contains a floating layer, the floating layer is separated, and the class picture layer after the floating layer is separated is determined as a picture type layer.
若类图片层中存在文本,则识别包含文字的区块,以判断该区块是否为类shape层;该区块为类shape层时,进一步判断该区块是不是input或textarea图层;若不是input或textarea图层,则判定该区块为shape类型图层。此外,从类图片层中去除该区块,并对类图片层进行图像修复。判断修复后的类图片层是否包含浮层;若包含浮层,则分离出浮层,并将分离出浮层后的类图片层确定为图片类型图层。If there is text in the image-like layer, identify the block containing the text to determine whether the block is a shape-like layer; when the block is a shape-like layer, further determine whether the block is an input or textarea layer; if If it is not an input or textarea layer, the block is determined to be a shape type layer. In addition, the block is removed from the picture-like layer, and image restoration is performed on the picture-like layer. Determine whether the repaired class picture layer contains a floating layer; if it contains a floating layer, separate the floating layer, and determine the class picture layer after separating the floating layer as the picture type layer.
此外,得到界面代码后,可通过执行界面代码直接渲染所对应的UI模块视觉来达到视觉稿所见所得的效果,并能保障视觉的还原度,提高开发初次模块开发的效率,缩短开发跟视觉的协调周期。In addition, after the interface code is obtained, the UI module vision can be directly rendered by executing the interface code to achieve the effect seen in the visual draft, and can ensure the degree of visual restoration, improve the efficiency of the initial module development of the development, and shorten the development and vision. Coordination cycle.
图2示出了本申请又一实施例提供的界面代码的生成方法的流程示意图。如图2所示,该方法包括:FIG. 2 shows a schematic flowchart of a method for generating an interface code provided by another embodiment of the present application. As shown in Figure 2, the method includes:
201、显示操作界面,以供用户输入待处理图像数据。201. Display an operation interface for the user to input image data to be processed.
202、响应于所述用户通过所述操作界面触发的界面代码生成指令,基于所述待处理图像数据,生成界面代码。202. In response to an interface code generation instruction triggered by the user through the operation interface, generate an interface code based on the image data to be processed.
上述201中,用户可在操作界面导入待处理图像数据。待处理图像数据可以为待处理图像文件或从待处理图像文件中导出的界面元素信息。其中,待处理图像文件可以为设计稿或设计图。设计稿指的是UI设计师通过设计软件制作出来的原始文件,该原始文件中通常会包含有多个图层;设计图指的是基于设计稿生成的图片,例如:截图。具体实施时,待处理图像文件可以为一UI模块对应的设计稿或设计图。In the above 201, the user can import image data to be processed on the operation interface. The image data to be processed may be an image file to be processed or interface element information derived from the image file to be processed. The image file to be processed may be a design draft or a design drawing. The design draft refers to the original file created by the UI designer through the design software. The original file usually contains multiple layers; the design drawing refers to the image generated based on the design draft, for example: a screenshot. During specific implementation, the image file to be processed may be a design draft or design drawing corresponding to a UI module.
上述201中,操作界面上显示有第一控件,响应于用户对第一控件的触控操作,生成界面代码生成指令。当然,操作界面上还可显示有语言输入按钮,用户长按该语言输入语言信息;根据用户的语言信息,生成界面代码生成指令。In the above 201, the first control is displayed on the operation interface, and in response to the user's touch operation on the first control, an interface code generation instruction is generated. Of course, a language input button can also be displayed on the operation interface, and the user long presses the language to input language information; according to the user's language information, an interface code generation instruction is generated.
本申请实施例提供的技术方案中,为用户提供一操作界面,用户在该操作界面导入待处理图像文件;响应于用户对该操作界面触发的界面代码生成指令,基于待处理图像文件,生成界面代码。可见,本申请实施例提供的技术方案中,通过对待处理图像文件的处理进行界面代码的自动生成,不仅提高开发效率以及开发周期,还能为编程人员减负。In the technical solution provided by the embodiment of the present application, an operation interface is provided for the user, and the user imports the image file to be processed in the operation interface; in response to the user's interface code generation instruction triggered by the operation interface, the interface is generated based on the image file to be processed Code. It can be seen that, in the technical solution provided by the embodiments of the present application, the interface code is automatically generated by processing the image file to be processed, which not only improves the development efficiency and development cycle, but also reduces the burden on the programmer.
进一步的,上述方法,还可包括:Further, the above method may further include:
203、在所述操作界面上显示至少一种代码语言类型对应的控件,以供所述用户选择。203. Display at least one control corresponding to the code language type on the operation interface for the user to select.
代码语言类型包括但不限于:HTML(HyperText Markup Language,超级文本标记语言)、Vue、Rax。后续,即可生成用户选择的代码语言类型的界面代码。Code language types include but are not limited to: HTML (HyperText Markup Language, Hyper Text Markup Language), Vue, Rax. Subsequently, the interface code of the code language type selected by the user can be generated.
进一步的,上述方法,还可包括:Further, the above method may further include:
204、响应于所述用户对第一代码语言类型对应的控件的触发操作,生成所述界面代码生成指令,所述界面代码生成指令中携带有所述第一代码语言类型。204. In response to the user's trigger operation on the control corresponding to the first code language type, generate the interface code generation instruction, where the interface code generation instruction carries the first code language type.
相应的,上述202中“基于所述待处理图像数据,生成界面代码”,具体包括:Correspondingly, “generating an interface code based on the to-be-processed image data” in 202 above specifically includes:
2021、确定所述第一代码语言类型对应的代码库。2021: Determine a code library corresponding to the first code language type.
2022、结合所述代码库,基于所述待处理图像数据,生成界面代码。2022. Combine the code base to generate an interface code based on the image data to be processed.
上述2021中,可事先为各种代码语言类型建立对应的代码库。In the above 2021, corresponding code libraries can be established for various code language types in advance.
上述2021的具体实现可参见上述各实施例中相应内容,在此不再赘述。For the specific implementation of the above 2021, refer to the corresponding content in the foregoing embodiments, and details are not described herein again.
进一步的,待处理图像数据为从待处理图像文件中导出的界面元素信息。上述202中“基于所述待处理图像数据,生成界面代码”,具体包括如下几个步骤:Further, the image data to be processed is interface element information derived from the image file to be processed. The above 202 "generating an interface code based on the image data to be processed" specifically includes the following steps:
2023、基于所述界面元素信息,确定界面的布局信息。2023. Based on the interface element information, determine layout information of the interface.
2024、根据所述布局信息,生成界面代码。2024. Generate interface codes according to the layout information.
上述2023以及2024具体可参见上述各实施例中相应内容,在此不再赘述。For details of the above 2023 and 2024, reference may be made to the corresponding content in the foregoing embodiments, and details are not described herein again.
这里需要说明的是:本申请实施例提供的所述方法除了包含上述各步骤外,还可包含上述各实施例中的全部或部分步骤,具体可参见上述实施例中的相应内容,此处不再赘述。It should be noted here that in addition to the above steps, the method provided in the embodiments of the present application may also include all or part of the steps in the above embodiments. For details, please refer to the corresponding content in the above embodiments, not here Repeat again.
下面将结合图7、图8、图9对本申请实施例提供的界面代码的生成方法进行整体介绍:The method for generating the interface code provided by the embodiment of the present application will be described in the following in conjunction with FIGS. 7, 8 and 9:
51、粘贴界面元素信息。51. Paste interface element information.
可在图9显示的操作界面上的数据粘贴框701处粘贴界面元素信息。设计软件插件可将从待处理图像文件中导出的界面元素信息缓存在剪切板中。The interface element information may be pasted at the data pasting box 701 on the operation interface shown in FIG. 9. The design software plug-in can cache the interface element information exported from the image file to be processed in the clipboard.
52、布局识别,以得到布局信息。52. Layout identification to obtain layout information.
53、对界面元素进行语义化命名。53. Semantic naming of interface elements.
语义化命名的规则可包括默认配置的规则和用户手动绑定的规则。用户可通过图9所示的操作界面上的“快捷绑定”操作区域703进行手动绑定。The semantically named rules may include rules configured by default and rules manually bound by the user. The user can perform manual binding through the "shortcut binding" operation area 703 on the operation interface shown in FIG. 9.
54、界面元素信息进行相似性扫描,识别并标记结构循环体。54. Perform a similarity scan on the interface element information to identify and mark structural loops.
55、多DSL(domain-specific language,领域特定语言)转换导出。55. Multi-DSL (domain-specific language, domain-specific language) conversion and export.
其中,DSL可以为HTML、Vue、Rax等。Among them, DSL can be HTML, Vue, Rax, etc.
56、界面代码输出。56. Interface code output.
其中,如图8所示,上述步骤52可具体包括如下步骤:Wherein, as shown in FIG. 8, the above step 52 may specifically include the following steps:
501、对界面元素信息进行顺序扫描。501: Perform a sequential scan of interface element information.
502、边界重叠修整。502. Border overlapping trimming.
即修正部分数据可能存在溢出以及微小交叉的情况。That is, some data may be overflowed and slightly crossed.
503、基于界面元素的位置交叉情况确定初始父子节点关系503. Determine the initial parent-child node relationship based on the position intersection of the interface elements
504、新增第一容器节点以容纳作为父节点的图片/文本类型界面元素及其子节点504. A first container node is added to accommodate the picture/text type interface element as a parent node and its child nodes
505、父子节点关系确认输出。505. The parent-child node relationship confirmation output.
506、对父节点下的子节点进行各行各列边界扫描。506. Perform a boundary scan on each row and column of the child node under the parent node.
507、对父节点下的子节点进行各行各列的Flex布局属性确认。507. Confirm the Flex layout attributes of each row and column of the child node under the parent node.
508、获取所有行的Flex布局属性。508. Get the Flex layout attributes of all rows.
509、判断所有行或所有列的flex布局属性是否可收敛到父节点。509. Determine whether the flex layout attributes of all rows or all columns can converge to the parent node.
510、在父节点上添加flex属性。510. Add the flex attribute to the parent node.
511、为各行新增一个第二容器节点,添加flex属性。511. Add a second container node to each row and add a flex attribute.
512、剔除一定规则下多余的flex属性。512. Exclude the extra flex attribute under certain rules.
513、对父子关系为交叉关系的父子节点进行绝对定位布局。513. Perform absolute positioning and layout on the parent-child nodes whose parent-child relationship is a cross relationship.
514、输出布局信息.。514. Output layout information.
上述步骤的具体实现可参见上述各实施例中相应内容,在此不再赘述。For specific implementation of the above steps, reference may be made to the corresponding content in the foregoing embodiments, and details are not described herein again.
图3示出了本申请又一实施例提供的界面代码的生成装置的结构框图。如图3所示,该装置,包括:第一确定模块301、第二确定模块302和第一生成模块303。其中,FIG. 3 shows a structural block diagram of an apparatus for generating an interface code provided by another embodiment of the present application. As shown in FIG. 3, the apparatus includes: a first determination module 301, a second determination module 302, and a first generation module 303. among them,
第一确定模块301,用于确定待处理图像文件的界面元素信息;The first determining module 301 is used to determine interface element information of the image file to be processed;
第二确定模块302,用于基于所述界面元素信息,确定界面的布局信息;The second determining module 302 is configured to determine layout information of the interface based on the interface element information;
第一生成模块303,用于根据所述布局信息,生成界面代码。The first generating module 303 is configured to generate an interface code according to the layout information.
本申请实施例提供的技术方案中,先从待处理图像文件中导出界面元素信息,根据界面元素信息,确定出界面的布局信息,再根据布局信息自动生成界面代码。可见,本申请实施例提供的技术方案中,通过对待处理图像文件的处理进行界面代码的自动生成,不仅提高开发效率以及开发周期,还能为编程人员减负。In the technical solution provided by the embodiment of the present application, the interface element information is first derived from the image file to be processed, the layout information of the interface is determined according to the interface element information, and then the interface code is automatically generated according to the layout information. It can be seen that, in the technical solution provided by the embodiments of the present application, the interface code is automatically generated by processing the image file to be processed, which not only improves the development efficiency and development cycle, but also reduces the burden on the programmer.
进一步的,第二确定模块302,具体用于:Further, the second determination module 302 is specifically used to:
基于所述界面元素信息中各界面元素的属性信息,确定各界面元素之间的父子节点关系以及各父节点的至少一个子节点的分布信息;Based on attribute information of each interface element in the interface element information, determining a parent-child node relationship between each interface element and distribution information of at least one child node of each parent node;
根据所述父子节点关系及各父节点的至少一个子节点的分布信息,确定所述布局信息。The layout information is determined according to the parent-child node relationship and distribution information of at least one child node of each parent node.
进一步的,第二确定模块302,具体用于:Further, the second determination module 302 is specifically used to:
基于各界面元素的位置信息及绘制顺序信息,确定所述各界面元素之间的初始父子节点关系;Determine the initial parent-child node relationship between each interface element based on the position information and drawing sequence information of each interface element;
在所述初始父子节点关系中,若存在指定类界面元素作为父节点的情况,则在所述初始父节点关系中新增一第一容器节点来容纳所述指定类界面元素及所述指定类界面元素的子节点,以得到所述父子节点关系。In the initial parent-child node relationship, if there is a designated class interface element as a parent node, a first container node is added to the initial parent node relationship to accommodate the designated class interface element and the designated class The child node of the interface element to obtain the parent-child node relationship.
进一步的,所述各父节点中包括第一类父节点;第二确定模块302,具体用于:Further, each parent node includes a first-type parent node; a second determination module 302 is specifically used to:
根据所述至少一个第一子节点的位置信息,确定所述至少一个第一子节点的行列信息以及所述至少一个第一子节点中各第一子节点的四周间距信息。According to the position information of the at least one first child node, the row and column information of the at least one first child node and the surrounding distance information of each first child node in the at least one first child node are determined.
进一步的,上述装置,还包括:Further, the above device further includes:
第三确定模块,用于根据所述至少一个第一子节点中各第一子节点的四周间距信息,确定各行的伸缩布局属性和各列的伸缩布局属性;A third determining module, configured to determine the telescopic layout attributes of each row and the telescopic layout attributes of each column according to the information about the surrounding distance of each first sub-node in the at least one first sub-node;
第四确定模块,用于根据所述各行的伸缩布局属性和各列的伸缩布局属性,确定对 所述布局信息的修正方案。The fourth determining module is used to determine a correction plan for the layout information according to the scalable layout attributes of each row and the scalable layout attributes of each column.
进一步的,第四确定模块,具体用于:Further, the fourth determination module is specifically used for:
所述各行的伸缩布局属性一致时,在所述布局信息中,为所述第一类父节点添加任一行的伸缩布局属性;When the scalable layout attributes of the rows are consistent, add the scalable layout attributes of any row to the first type of parent node in the layout information;
所述各列的伸缩布局属性一致时,在所述布局信息中,为所述第一类父节点添加任一列的伸缩布局属性;When the telescopic layout attributes of the columns are consistent, add the telescopic layout attributes of any column to the first type of parent node in the layout information;
所述各行的伸缩布局属性和所述各列的伸缩布局属性均不一致时,在所述布局信息中,为各行新增一第二容器节点以容纳各行上的第一子节点,并为各行新增的所述第二容器节点添加各行对应的伸缩布局属性,其中,各行的所述第二容器节点为所述第一类父节点的子节点。When the scaling layout attributes of each row and the scaling layout attributes of each column are inconsistent, in the layout information, a second container node is added to each row to accommodate the first child node on each row, and new The added second container node adds a telescopic layout attribute corresponding to each row, where the second container node of each row is a child node of the parent node of the first type.
进一步的,所述各父节点中包括第二类父节点;第二确定模块302,具体用于:Further, each of the parent nodes includes a second type of parent node; the second determination module 302 is specifically used to:
根据所述第二类父节点以及所述至少一个第二子节点的位置信息,对所述至少一个第二子节点进行绝对定位布局,以得到所述至少一个第二子节点的分布信息。According to the position information of the second-type parent node and the at least one second child node, perform absolute positioning layout on the at least one second child node to obtain distribution information of the at least one second child node.
进一步的,第一生成模块303,具体用于:Further, the first generation module 303 is specifically used for:
根据所述布局信息,从代码库中匹配出相应的代码布局信息;According to the layout information, the corresponding code layout information is matched from the code library;
根据所述布局信息中各界面元素的属性信息,从所述代码库中匹配出所述代码布局信息中各节点在代码层面的属性信息;According to the attribute information of each interface element in the layout information, matching the attribute information of each node in the code layout information at the code level from the code library;
将所述各节点在代码层面的属性信息添加至所述代码布局信息中,以得到所述界面代码。The attribute information of each node at the code level is added to the code layout information to obtain the interface code.
进一步的,所述各界面元素包括:第一界面元素;以及,第一生成模块303,具体用于:Further, each of the interface elements includes: a first interface element; and, a first generation module 303 is specifically used to:
根据所述第一界面元素的类型属性,在所述代码库中匹配出所述第一节点在代码层面的类型属性;According to the type attribute of the first interface element, matching the type attribute of the first node at the code level in the code base;
根据所述第一界面元素的显示属性,在所述代码库中匹配出所述第一节点在代码层面的显示属性。According to the display attributes of the first interface element, the display attributes of the first node at the code level are matched in the code library.
进一步的,第一生成模块303,还用于:Further, the first generation module 303 is also used to:
在根据所述布局信息,获取对应的代码布局信息之前,按照语义化命名规则,对所述布局信息中各界面元素进行重新命名。Before acquiring the corresponding code layout information according to the layout information, each interface element in the layout information is renamed according to the semantic naming rules.
进一步的,所述界面元素信息包括:各界面元素的属性信息;Further, the interface element information includes: attribute information of each interface element;
所述属性信息包括以下项中的至少一项:名称、类型、坐标、宽高、绘制顺序、填 充内容以及填充内容的样式。The attribute information includes at least one of the following items: name, type, coordinates, width and height, drawing order, filling content, and style of filling content.
进一步的,第一确定模块301,具体用于:Further, the first determining module 301 is specifically used to:
从所述待处理图像文件中导出各图层的图层属性信息,所述图层属性信息中包括名称、类型、坐标、宽高、绘制顺序、填充内容以及填充内容的样式;Export layer attribute information of each layer from the image file to be processed, where the layer attribute information includes name, type, coordinates, width and height, drawing order, filling content, and style of filling content;
对所述各图层的图层属性信息进行预设规则处理;将预测规则处理后的各图层的图层属性信息作为所述界面元素信息中各界面元素的属性信息。Perform preset rule processing on the layer attribute information of each layer; use the layer attribute information of each layer after the prediction rule processing as the attribute information of each interface element in the interface element information.
进一步的,第一确定模块301,具体用于执行以下至少一项:Further, the first determining module 301 is specifically configured to execute at least one of the following:
通过对所述各图层进行图层冗余及顺序校验,删除其中无用图层的图层属性信息;By performing layer redundancy and sequence check on each layer, the layer attribute information of useless layers is deleted;
通过对所述各图层进行图层类型校验,修正图层类型有误的图层的图层类型;Correct the layer type of the layer with the wrong layer type by checking the layer type of each layer;
通过对所述各图层进行图层合并校验,将具有合并关联性的多个图层合并成一个图层;By performing layer merge verification on each layer, multiple layers with merge relevance are merged into one layer;
结合所述待处理图像文件的设计工具的设计规则,对所述各图层的图层属性信息进行修正;Combine the design rules of the design tool of the image file to be processed to modify the layer attribute information of each layer;
将所述各图层的图层属性信息转换成预设格式的数据。Convert the layer attribute information of each layer into data in a preset format.
进一步的,所述待处理图像文件为设计图;第一确定模块301,具体用于:Further, the image file to be processed is a design drawing; the first determining module 301 is specifically used to:
对所述设计图进行文字以及图像识别,以从所述设计图中分离出多个图层;Performing text and image recognition on the design drawing to separate multiple layers from the design drawing;
对所述多个图层进行图层类型识别,以确定所述多个图层的图层类型。Perform layer type identification on the multiple layers to determine the layer types of the multiple layers.
这里需要说明的是:上述实施例提供的生成装置可实现上述各方法实施例中描述的技术方案,上述各模块或单元具体实现的原理可参见上述各方法实施例中的相应内容,此处不再赘述。It should be noted here that the generating device provided in the above embodiments can implement the technical solutions described in the above method embodiments. For the specific implementation principles of the above modules or units, please refer to the corresponding contents in the above method embodiments. Repeat again.
图4示出了本申请又一实施例提供的界面代码的生成装置的结构框图。该装置,包括:FIG. 4 shows a structural block diagram of an apparatus for generating an interface code provided by another embodiment of the present application. The device includes:
第一显示模块401,用于显示操作界面,以供用户输入待处理图像数据;The first display module 401 is used to display an operation interface for the user to input image data to be processed;
第二生成模块402,用于响应于所述用户通过所述操作界面触发的界面代码生成指令,基于所述待处理图像数据,生成界面代码。The second generation module 402 is configured to generate an interface code based on the to-be-processed image data in response to an interface code generation instruction triggered by the user through the operation interface.
本申请实施例提供的技术方案中,为用户提供一操作界面,用户在该操作界面导入待处理图像文件;响应于用户对该操作界面触发的界面代码生成指令,基于待处理图像文件,生成界面代码。可见,本申请实施例提供的技术方案中,通过对待处理图像文件的处理进行界面代码的自动生成,不仅提高开发效率以及开发周期,还能为编程人员减负。In the technical solution provided by the embodiments of the present application, an operation interface is provided for the user, and the user imports the image file to be processed on the operation interface; in response to the user's interface code generation instruction triggered by the operation interface, the interface is generated based on the image file to be processed Code. It can be seen that, in the technical solution provided by the embodiments of the present application, the interface code is automatically generated by processing the image file to be processed, which not only improves the development efficiency and development cycle, but also reduces the burden on the programmer.
进一步的,第一显示模块401,还用于:Further, the first display module 401 is also used to:
在所述操作界面上显示至少一种代码语言类型对应的控件,以供所述用户选择。A control corresponding to at least one code language type is displayed on the operation interface for the user to select.
进一步的,上述装置,还包括:Further, the above device further includes:
第三生成模块,用于响应于所述用户对第一代码语言类型对应的控件的触发操作,生成所述界面代码生成指令,所述界面代码生成指令中携带有所述第一代码语言类型;A third generation module, configured to generate the interface code generation instruction in response to the user's trigger operation on the control corresponding to the first code language type, and the interface code generation instruction carries the first code language type;
以及,第二生成模块,具体用于:And, the second generation module is specifically used for:
确定所述第一代码语言类型对应的代码库;Determine a code base corresponding to the first code language type;
结合所述代码库,基于所述待处理图像数据,生成界面代码。In combination with the code base, an interface code is generated based on the image data to be processed.
进一步的,待处理图像数据为从待处理图像文件中导出的界面元素信息,第二生成模块,具体用于:Further, the image data to be processed is interface element information derived from the image file to be processed, and the second generation module is specifically used to:
基于所述界面元素信息,确定界面的布局信息;Determine the layout information of the interface based on the interface element information;
根据所述布局信息,生成界面代码。According to the layout information, an interface code is generated.
这里需要说明的是:上述实施例提供的生成装置可实现上述各方法实施例中描述的技术方案,上述各模块或单元具体实现的原理可参见上述各方法实施例中的相应内容,此处不再赘述。It should be noted here that the generating device provided in the above embodiments can implement the technical solutions described in the above method embodiments. For the specific implementation principles of the above modules or units, please refer to the corresponding contents in the above method embodiments. Repeat again.
图5为本申请一实施例提供的电子设备的结构示意图。该电子设备包括:第一存储器1101以及第一处理器1102。第一存储器1101可被配置为存储其它各种数据以支持在电子设备上的操作。这些数据的示例包括用于在电子设备上操作的任何应用程序或方法的指令。第一存储器1101可以由任何类型的易失性或非易失性存储设备或者它们的组合实现,如静态随机存取存储器(SRAM),电可擦除可编程只读存储器(EEPROM),可擦除可编程只读存储器(EPROM),可编程只读存储器(PROM),只读存储器(ROM),磁存储器,快闪存储器,磁盘或光盘。FIG. 5 is a schematic structural diagram of an electronic device provided by an embodiment of the present application. The electronic device includes: a first memory 1101 and a first processor 1102. The first memory 1101 may be configured to store various other data to support operations on the electronic device. Examples of these data include instructions for any applications or methods that operate on the electronic device. The first memory 1101 may be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read only memory (EEPROM), erasable In addition to programmable read only memory (EPROM), programmable read only memory (PROM), read only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
所述第一处理器1102,与所述第一存储器1101耦合,用于执行所述第一存储器1101中存储的所述程序,以用于:The first processor 1102 is coupled to the first memory 1101, and is used to execute the program stored in the first memory 1101 for:
确定待处理图像文件的界面元素信息;Determine the interface element information of the image file to be processed;
基于所述界面元素信息,确定界面的布局信息;Determine the layout information of the interface based on the interface element information;
根据所述布局信息,生成界面代码。According to the layout information, an interface code is generated.
其中,第一处理器1102在执行第一存储器1101中的程序时,除了上面的功能之外,还可实现其它功能,具体可参见前面各实施例的描述。Wherein, when the first processor 1102 executes the program in the first memory 1101, in addition to the above functions, other functions may also be implemented. For details, refer to the description of the foregoing embodiments.
进一步,如图5所示,电子设备还包括:第一通信组件1103、第一显示器1104、第 一电源组件1105、第一音频组件1106等其它组件。图5中仅示意性给出部分组件,并不意味着电子设备只包括图5所示组件。Further, as shown in FIG. 5, the electronic device further includes: a first communication component 1103, a first display 1104, a first power component 1105, a first audio component 1106 and other components. FIG. 5 only schematically shows some components, and does not mean that the electronic device includes only the components shown in FIG. 5.
相应地,本申请实施例还提供一种存储有计算机程序的计算机可读存储介质,所述计算机程序被计算机执行时能够实现上述各实施例提供的物体定位方法的步骤或功能。Correspondingly, the embodiments of the present application also provide a computer-readable storage medium storing a computer program, which when executed by a computer can implement the steps or functions of the object positioning method provided by the foregoing embodiments.
图6示出了本申请一实施例提供的电子设备的结构示意图。如图所示,所述电子设备包括第二显示器1204、第二存储器1201以及第二处理器1202。第二存储器1201可被配置为存储其它各种数据以支持在电子设备上的操作。这些数据的示例包括用于在电子设备上操作的任何应用程序或方法的指令。第二存储器1201可以由任何类型的易失性或非易失性存储设备或者它们的组合实现,如静态随机存取存储器(SRAM),电可擦除可编程只读存储器(EEPROM),可擦除可编程只读存储器(EPROM),可编程只读存储器(PROM),只读存储器(ROM),磁存储器,快闪存储器,磁盘或光盘。FIG. 6 shows a schematic structural diagram of an electronic device provided by an embodiment of the present application. As shown, the electronic device includes a second display 1204, a second memory 1201, and a second processor 1202. The second memory 1201 may be configured to store various other data to support operations on the electronic device. Examples of these data include instructions for any applications or methods operating on the electronic device. The second memory 1201 may be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read only memory (EEPROM), erasable In addition to programmable read only memory (EPROM), programmable read only memory (PROM), read only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
所述第二显示器1204,与所述第二处理器1202耦合,用于显示操作界面,以供用户输入待处理图像数据;The second display 1204 is coupled to the second processor 1202, and is used to display an operation interface for the user to input image data to be processed;
所述第二处理器1202,与所述第二存储器1201耦合,用于执行所述第二存储器1201中存储的所述程序,以用于:The second processor 1202 is coupled to the second memory 1201, and is used to execute the program stored in the second memory 1201 for:
响应于所述用户通过所述操作界面触发的界面代码生成指令,基于所述待处理图像数据,生成界面代码。In response to an interface code generation instruction triggered by the user through the operation interface, an interface code is generated based on the image data to be processed.
其中,第二处理器1202在执行第二存储器1201中的程序时,除了上面的功能之外,还可实现其它功能,具体可参见前面各实施例的描述。Wherein, when the second processor 1202 executes the program in the second memory 1201, in addition to the above functions, other functions may be implemented. For details, refer to the description of the foregoing embodiments.
进一步,如图6所示,电子设备还包括:第二通信组件1203、第二电源组件1205、第二音频组件1206等其它组件。图6中仅示意性给出部分组件,并不意味着电子设备只包括图6所示组件。Further, as shown in FIG. 6, the electronic device further includes: a second communication component 1203, a second power component 1205, a second audio component 1206, and other components. Only some components are schematically shown in FIG. 6, which does not mean that the electronic device includes only the components shown in FIG.
相应地,本申请实施例还提供一种存储有计算机程序的计算机可读存储介质,所述计算机程序被计算机执行时能够实现上述各实施例提供的物体定位方法步骤或功能。Correspondingly, the embodiments of the present application also provide a computer-readable storage medium storing a computer program, which when executed by a computer can realize the steps or functions of the object positioning method provided by the foregoing embodiments.
以上所描述的装置实施例仅仅是示意性的,其中所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。本领域普通技术人员在不付出创造 性的劳动的情况下,即可以理解并实施。The device embodiments described above are only schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, may be located One place, or can be distributed to multiple network elements. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art can understand and implement without paying creative labor.
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到各实施方式可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件。基于这样的理解,上述技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品可以存储在计算机可读存储介质中,如ROM/RAM、磁碟、光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行各个实施例或者实施例的某些部分所述的方法。Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions can be embodied in the form of software products in essence or part of the contribution to the existing technology, and the computer software products can be stored in computer-readable storage media, such as ROM/RAM, magnetic Discs, optical discs, etc., include several instructions to enable a computer device (which may be a personal computer, server, or network device, etc.) to perform the methods described in the various embodiments or some parts of the embodiments.
最后应说明的是:以上实施例仅用以说明本发明的技术方案,而非对其限制;尽管参照前述实施例对本发明进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明各实施例技术方案的精神和范围。Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still The technical solutions described in the foregoing embodiments are modified, or some of the technical features are equivalently replaced; and these modifications or replacements do not deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims (20)

  1. 一种界面代码的生成方法,其特征在于,包括:A method for generating interface code, characterized in that it includes:
    确定待处理图像文件的界面元素信息;Determine the interface element information of the image file to be processed;
    基于所述界面元素信息,确定界面的布局信息;Determine the layout information of the interface based on the interface element information;
    根据所述布局信息,生成界面代码。According to the layout information, an interface code is generated.
  2. 根据权利要求1所述的方法,其特征在于,基于所述界面元素信息,确定界面的布局信息,包括:The method according to claim 1, wherein determining the layout information of the interface based on the interface element information includes:
    基于所述界面元素信息中各界面元素的属性信息,确定各界面元素之间的父子节点关系以及各父节点的至少一个子节点的分布信息;Based on attribute information of each interface element in the interface element information, determining a parent-child node relationship between each interface element and distribution information of at least one child node of each parent node;
    根据所述父子节点关系及各父节点的至少一个子节点的分布信息,确定所述布局信息。The layout information is determined according to the parent-child node relationship and distribution information of at least one child node of each parent node.
  3. 根据权利要求2所述的方法,其特征在于,基于所述界面元素信息中各界面元素的属性信息,确定各界面元素之间的父子节点关系,包括:The method according to claim 2, wherein determining the parent-child node relationship between each interface element based on the attribute information of each interface element in the interface element information includes:
    基于各界面元素的位置信息及绘制顺序信息,确定所述各界面元素之间的初始父子节点关系;Determine the initial parent-child node relationship between each interface element based on the position information and drawing sequence information of each interface element;
    在所述初始父子节点关系中,若存在指定类界面元素作为父节点的情况,则在所述初始父节点关系中新增一第一容器节点来容纳所述指定类界面元素及所述指定类界面元素的子节点,以得到所述父子节点关系。In the initial parent-child node relationship, if there is a designated class interface element as a parent node, a first container node is added to the initial parent node relationship to accommodate the designated class interface element and the designated class The child node of the interface element to obtain the parent-child node relationship.
  4. 根据权利要求2所述的方法,其特征在于,所述各父节点中包括第一类父节点;The method according to claim 2, wherein each parent node includes a first type of parent node;
    以及,确定所述第一类父节点的至少一个第一子节点的分布信息,包括:And, determining the distribution information of at least one first child node of the first type parent node includes:
    根据所述至少一个第一子节点的位置信息,确定所述至少一个第一子节点的行列信息以及所述至少一个第一子节点中各第一子节点的四周间距信息。According to the position information of the at least one first child node, the row and column information of the at least one first child node and the surrounding distance information of each first child node in the at least one first child node are determined.
  5. 根据权利要求4所述的方法,其特征在于,还包括:The method according to claim 4, further comprising:
    根据所述至少一个第一子节点中各第一子节点的四周间距信息,确定各行的伸缩布局属性和各列的伸缩布局属性;Determine the telescopic layout attributes of each row and the telescopic layout attributes of each column according to the surrounding information of each first sub-node among the at least one first sub-node;
    根据所述各行的伸缩布局属性和所述各列的伸缩布局属性,确定对所述布局信息的修正方案。The correction scheme for the layout information is determined according to the scalable layout attributes of each row and the scalable layout attributes of each column.
  6. 根据权利要求5所述的方法,其特征在于,根据所述各行的伸缩布局属性和所述各列的伸缩布局属性,确定对所述布局信息的修正方案,包括:The method according to claim 5, wherein determining the correction scheme for the layout information according to the scalable layout attributes of the rows and the scalable layout attributes of the columns includes:
    所述各行的伸缩布局属性一致时,在所述布局信息中,为所述第一类父节点添加任 一行的伸缩布局属性;When the scalable layout attributes of the rows are consistent, add the scalable layout attributes of any row to the first-type parent node in the layout information;
    所述各列的伸缩布局属性一致时,在所述布局信息中,为所述第一类父节点添加任一列的伸缩布局属性;When the telescopic layout attributes of the columns are consistent, add the telescopic layout attributes of any column to the first type of parent node in the layout information;
    所述各行的伸缩布局属性不一致时且所述各列的伸缩布局属性也不一致时,在所述布局信息中,为各行新增一第二容器节点以容纳各行上的第一子节点,并为各行新增的所述第二容器节点添加各行对应的伸缩布局属性,其中,各行的所述第二容器节点为所述第一类父节点的子节点。When the telescopic layout attributes of the rows are inconsistent and the telescopic layout attributes of the columns are also inconsistent, in the layout information, a second container node is added to each row to accommodate the first child node on each row, and is The second container node newly added in each row adds a telescopic layout attribute corresponding to each row, wherein the second container node in each row is a child node of the parent node of the first type.
  7. 根据权利要求2所述的方法,其特征在于,所述各父节点中包括第二类父节点;The method according to claim 2, wherein each parent node includes a second type of parent node;
    以及,确定所述第二类父节点的至少一个第二子节点的分布信息,包括:And, determining the distribution information of at least one second child node of the second type parent node includes:
    根据所述第二类父节点以及所述至少一个第二子节点的位置信息,对所述至少一个第二子节点进行绝对定位布局,以得到所述至少一个第二子节点的分布信息。According to the position information of the second-type parent node and the at least one second child node, perform absolute positioning layout on the at least one second child node to obtain distribution information of the at least one second child node.
  8. 根据权利要求1至7中任一项所述的方法,其特征在于,根据所述布局信息,生成界面代码,包括:The method according to any one of claims 1 to 7, wherein generating the interface code according to the layout information includes:
    根据所述布局信息,从代码库中匹配出相应的代码布局信息;According to the layout information, the corresponding code layout information is matched from the code library;
    根据所述布局信息中各界面元素的属性信息,从所述代码库中匹配出所述代码布局信息中各节点在代码层面的属性信息;According to the attribute information of each interface element in the layout information, matching the attribute information of each node in the code layout information at the code level from the code library;
    将所述各节点在代码层面的属性信息添加至所述代码布局信息中,以得到所述界面代码。The attribute information of each node at the code level is added to the code layout information to obtain the interface code.
  9. 根据权利要求8所述的方法,其特征在于,所述各界面元素包括:第一界面元素;The method according to claim 8, wherein each of the interface elements comprises: a first interface element;
    以及,根据所述第一界面元素的属性信息,从所述代码库中匹配出所述代码布局信息中与所述第一界面元素对应的第一节点在代码层面的属性信息,包括:And, according to the attribute information of the first interface element, matching code attribute information of the first node corresponding to the first interface element in the code layout information from the code library includes:
    根据所述第一界面元素的类型属性,在所述代码库中匹配出所述第一节点在代码层面的类型属性;According to the type attribute of the first interface element, matching the type attribute of the first node at the code level in the code base;
    根据所述第一界面元素的显示属性,在所述代码库中匹配出所述第一节点在代码层面的显示属性。According to the display attributes of the first interface element, the display attributes of the first node at the code level are matched in the code library.
  10. 根据权利要求8所述的方法,其特征在于,根据所述布局信息,生成界面代码,还包括:The method according to claim 8, wherein generating the interface code according to the layout information further comprises:
    在根据所述布局信息,获取对应的代码布局信息之前,按照语义化命名规则,对所述布局信息中各界面元素进行重新命名。Before acquiring the corresponding code layout information according to the layout information, each interface element in the layout information is renamed according to the semantic naming rules.
  11. 根据权利要求1至7中任一项所述的方法,其特征在于,所述界面元素信息包括:各界面元素的属性信息;The method according to any one of claims 1 to 7, wherein the interface element information includes: attribute information of each interface element;
    所述属性信息包括以下项中的至少一项:名称、类型、坐标、宽高、绘制顺序、填充内容以及填充内容的样式。The attribute information includes at least one of the following items: name, type, coordinates, width and height, drawing order, fill content, and style of the fill content.
  12. 根据权利要求1至7中任一项所述的方法,其特征在于,确定待处理图像文件的界面元素信息,包括:The method according to any one of claims 1 to 7, wherein determining the interface element information of the image file to be processed includes:
    从所述待处理图像文件中导出各图层的图层属性信息,所述图层属性信息中包括名称、类型、坐标、宽高、绘制顺序、填充内容以及填充内容的样式;Export layer attribute information of each layer from the image file to be processed, where the layer attribute information includes name, type, coordinates, width and height, drawing order, filling content, and style of filling content;
    对所述各图层的图层属性信息进行预设规则处理;Perform preset rule processing on the layer attribute information of each layer;
    将预测规则处理后的各图层的图层属性信息作为所述界面元素信息中各界面元素的属性信息。The layer attribute information of each layer processed by the prediction rule is used as the attribute information of each interface element in the interface element information.
  13. 根据权利要求12所述的方法,其特征在于,对所述各图层的图层属性信息进行预设规则处理的步骤包括以下至少一项:The method according to claim 12, wherein the step of performing preset rule processing on the layer attribute information of each layer includes at least one of the following:
    通过对所述各图层进行图层冗余及顺序校验,删除其中无用图层的图层属性信息;By performing layer redundancy and sequence check on each layer, the layer attribute information of useless layers is deleted;
    通过对所述各图层进行图层类型校验,修正图层类型有误的图层的图层类型;Correct the layer type of the layer with the wrong layer type by checking the layer type of each layer;
    通过对所述各图层进行图层合并校验,将具有合并关联性的多个图层合并成一个图层;By performing layer merge verification on each layer, multiple layers with merge relevance are merged into one layer;
    结合所述待处理图像文件的设计工具的设计规则,对所述各图层的图层属性信息进行修正;Combine the design rules of the design tool of the image file to be processed to modify the layer attribute information of each layer;
    将所述各图层的图层属性信息转换成预设格式的数据。Convert the layer attribute information of each layer into data in a preset format.
  14. 根据权利要求12所述的方法,其特征在于,所述待处理图像文件为设计图;The method according to claim 12, wherein the image file to be processed is a design drawing;
    从所述待处理图像文件中导出各图层的图层属性信息,包括:Exporting layer attribute information of each layer from the image file to be processed includes:
    对所述设计图进行文字以及图像识别,以从所述设计图中分离出多个图层;Performing text and image recognition on the design drawing to separate multiple layers from the design drawing;
    对所述多个图层进行图层类型识别,以确定所述多个图层的图层类型。Perform layer type identification on the multiple layers to determine the layer types of the multiple layers.
  15. 一种界面代码的生成方法,其特征在于,包括:A method for generating interface code, characterized in that it includes:
    显示操作界面,以供用户输入待处理图像数据;Display operation interface for users to input image data to be processed;
    响应于所述用户通过所述操作界面触发的界面代码生成指令,基于所述待处理图像数据,生成界面代码。In response to an interface code generation instruction triggered by the user through the operation interface, an interface code is generated based on the image data to be processed.
  16. 根据权利要求15所述的方法,其特征在于,还包括:The method of claim 15, further comprising:
    在所述操作界面上显示至少一种代码语言类型对应的控件,以供所述用户选择。A control corresponding to at least one code language type is displayed on the operation interface for the user to select.
  17. 根据权利要求16所述的方法,其特征在于,还包括:The method of claim 16, further comprising:
    响应于所述用户对第一代码语言类型对应的控件的触发操作,生成所述界面代码生成指令,所述界面代码生成指令中携带有所述第一代码语言类型;Generating the interface code generation instruction in response to the user's trigger operation on the control corresponding to the first code language type, the interface code generation instruction carrying the first code language type;
    以及,基于所述待处理图像文件,生成界面代码,包括:And, generating the interface code based on the image file to be processed includes:
    确定所述第一代码语言类型对应的代码库;Determine a code base corresponding to the first code language type;
    结合所述代码库,基于所述待处理图像数据,生成界面代码。In combination with the code base, an interface code is generated based on the image data to be processed.
  18. 根据权利要求15至17中任一项所述的方法,其特征在于,所述待处理图像数据为从待处理图像文件中导出的界面元素信息;The method according to any one of claims 15 to 17, wherein the image data to be processed is interface element information derived from the image file to be processed;
    基于所述待处理图像数据,生成界面代码,包括:Based on the to-be-processed image data, generating an interface code includes:
    基于所述界面元素信息,确定界面的布局信息;Determine the layout information of the interface based on the interface element information;
    根据所述布局信息,生成界面代码。According to the layout information, an interface code is generated.
  19. 一种电子设备,其特征在于,包括:第一存储器和第一处理器,其中,An electronic device, comprising: a first memory and a first processor, wherein,
    所述第一存储器,用于存储程序;The first memory is used to store programs;
    所述第一处理器,与所述第一存储器耦合,用于执行所述第一存储器中存储的所述程序,以用于:The first processor, coupled to the first memory, is used to execute the program stored in the first memory for:
    确定待处理图像文件的界面元素信息;Determine the interface element information of the image file to be processed;
    基于所述界面元素信息,确定界面的布局信息;Determine the layout information of the interface based on the interface element information;
    根据所述布局信息,生成界面代码。According to the layout information, an interface code is generated.
  20. 一种电子设备,其特征在于,包括:第二存储器、第二处理器和第二显示器,其中,An electronic device, characterized by comprising: a second memory, a second processor and a second display, wherein,
    所述第二存储器,用于存储程序;The second memory is used to store programs;
    所述第二显示器,与所述第二处理器耦合,用于显示操作界面,以供用户输入待处理图像数据;The second display, coupled with the second processor, is used to display an operation interface for the user to input image data to be processed;
    所述第二处理器,与所述第二存储器耦合,用于执行所述第二存储器中存储的所述程序,以用于:The second processor, coupled to the second memory, is used to execute the program stored in the second memory for:
    响应于所述用户通过所述操作界面触发的界面代码生成指令,基于所述待处理图像数据,生成界面代码。In response to an interface code generation instruction triggered by the user through the operation interface, an interface code is generated based on the image data to be processed.
PCT/CN2020/070059 2019-01-06 2020-01-02 Method and device for generating interface codes WO2020140932A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910010012.5A CN111414165B (en) 2019-01-06 2019-01-06 Interface code generation method and equipment
CN201910010012.5 2019-01-06

Publications (1)

Publication Number Publication Date
WO2020140932A1 true WO2020140932A1 (en) 2020-07-09

Family

ID=71407281

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/070059 WO2020140932A1 (en) 2019-01-06 2020-01-02 Method and device for generating interface codes

Country Status (2)

Country Link
CN (1) CN111414165B (en)
WO (1) WO2020140932A1 (en)

Families Citing this family (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111857704A (en) * 2020-07-31 2020-10-30 北京爱奇艺科技有限公司 Code generation method and device for layout relationship
CN112328234B (en) * 2020-11-02 2023-12-08 广州博冠信息科技有限公司 Image processing method and device
CN112416363B (en) * 2020-12-09 2024-03-19 锐捷网络股份有限公司 Method and device for generating front-end and back-end CRUD codes
CN113778403A (en) * 2021-01-15 2021-12-10 北京沃东天骏信息技术有限公司 Front-end code generation method and device
CN113051632A (en) * 2021-03-30 2021-06-29 厦门极致互动网络技术股份有限公司 Photoshop-based color derivation method
CN113672227B (en) * 2021-08-30 2024-04-23 北京爱奇艺科技有限公司 User interface code generation method and device, electronic equipment and storage medium
CN113835704B (en) * 2021-09-27 2024-05-10 中电金信软件有限公司 Layout file generation method, device, equipment and storage medium
CN114816409B (en) * 2022-06-27 2022-10-04 北京尽微致广信息技术有限公司 Interface generation method, device and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105354022A (en) * 2015-10-16 2016-02-24 华为技术有限公司 Generation method and device of page layout file
CN108228183A (en) * 2018-01-12 2018-06-29 北京三快在线科技有限公司 Front-end interface code generating method, device, electronic equipment and storage medium
CN108255489A (en) * 2018-01-12 2018-07-06 北京三快在线科技有限公司 Front-end interface code generating method, device, electronic equipment and storage medium
US20180275971A1 (en) * 2016-11-16 2018-09-27 ZigiSoft, LLC Graphical user interface programming system
CN108804093A (en) * 2018-06-15 2018-11-13 联想(北京)有限公司 A kind of code generating method and electronic equipment

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9286038B2 (en) * 2013-06-19 2016-03-15 Microsoft Technology Licensing, Llc Interface development and operation
CN104252356B (en) * 2013-06-28 2018-04-06 腾讯科技(深圳)有限公司 Generate the method and system at interface
US10191889B2 (en) * 2014-07-29 2019-01-29 Board Of Regents, The University Of Texas System Systems, apparatuses and methods for generating a user interface by performing computer vision and optical character recognition on a graphical representation
CN108334386A (en) * 2017-01-20 2018-07-27 阿里巴巴集团控股有限公司 A kind of layout method and system of view component
CN108304183A (en) * 2018-02-26 2018-07-20 北京车和家信息技术有限公司 A kind of user interface creating method, device and electronic equipment

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105354022A (en) * 2015-10-16 2016-02-24 华为技术有限公司 Generation method and device of page layout file
US20180275971A1 (en) * 2016-11-16 2018-09-27 ZigiSoft, LLC Graphical user interface programming system
CN108228183A (en) * 2018-01-12 2018-06-29 北京三快在线科技有限公司 Front-end interface code generating method, device, electronic equipment and storage medium
CN108255489A (en) * 2018-01-12 2018-07-06 北京三快在线科技有限公司 Front-end interface code generating method, device, electronic equipment and storage medium
CN108804093A (en) * 2018-06-15 2018-11-13 联想(北京)有限公司 A kind of code generating method and electronic equipment

Also Published As

Publication number Publication date
CN111414165A (en) 2020-07-14
CN111414165B (en) 2024-04-02

Similar Documents

Publication Publication Date Title
WO2020140932A1 (en) Method and device for generating interface codes
US20230367841A1 (en) System and method for implementing containers which extract and apply semantic page knowledge
Moran et al. Machine learning-based prototyping of graphical user interfaces for mobile apps
EP3433732B1 (en) Converting visual diagrams into code
CN108228183B (en) Front-end interface code generation method and device, electronic equipment and storage medium
US11792257B2 (en) Form engine
CN108255489B (en) Front-end interface code generation method and device, electronic equipment and storage medium
US8595236B2 (en) Searching existing user interfaces to enable design, development and provisioning of user interfaces
CN111190522A (en) Generating three-dimensional digital content from natural language requests
CN102651055A (en) Method and system for generating file based on medical image
WO2016054549A1 (en) Application prototyping tool
CN112416363B (en) Method and device for generating front-end and back-end CRUD codes
US20210019006A1 (en) Adaptive user interface for a multimedia creative design system
CN110705237B (en) Automatic document generation method, data processing device and storage medium
CN111125598A (en) Intelligent data query method, device, equipment and storage medium
CN111352628A (en) Front-end code generation method and device, computer system and readable storage medium
WO2016095502A1 (en) Mathematical formula processing method, device, apparatus and computer storage medium
Kaluarachchi et al. A systematic literature review on automatic website generation
JP7309811B2 (en) Data annotation method, apparatus, electronics and storage medium
US20240061993A1 (en) Multi-component abstract association and fusion method and apparatus in page design
WO2020023951A1 (en) Bidirectional evaluation for general-purpose programming
CN109635681B (en) Document processing method and device
CN112764743B (en) Method for automatically generating software based on data model drive
CN111131660B (en) Image data processing method and device, electronic equipment and storage medium thereof
CN116361279A (en) Cross-platform artificial intelligent data labeling method

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20735853

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20735853

Country of ref document: EP

Kind code of ref document: A1