dora_ssr/dora/
align_node.rs

1/* Copyright (c) 2016-2025 Li Jin <dragon-fly@qq.com>
2
3Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
5The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
7THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
8
9extern "C" {
10	fn alignnode_type() -> i32;
11	fn alignnode_css(slf: i64, style: i64);
12	fn alignnode_new(is_window_root: i32) -> i64;
13}
14use crate::dora::IObject;
15use crate::dora::INode;
16impl INode for AlignNode { }
17/// A node used for aligning layout elements.
18pub struct AlignNode { raw: i64 }
19crate::dora_object!(AlignNode);
20impl AlignNode {
21	pub(crate) fn type_info() -> (i32, fn(i64) -> Option<Box<dyn IObject>>) {
22		(unsafe { alignnode_type() }, |raw: i64| -> Option<Box<dyn IObject>> {
23			match raw {
24				0 => None,
25				_ => Some(Box::new(AlignNode { raw: raw }))
26			}
27		})
28	}
29	/// Sets the layout style of the node.
30	///
31	/// # Arguments
32	///
33	/// * `style` - The layout style to set.
34	/// The following properties can be set through a CSS style string:
35	/// ## Layout direction and alignment
36	/// * direction: Sets the direction (ltr, rtl, inherit).
37	/// * align-items, align-self, align-content: Sets the alignment of different items (flex-start, center, stretch, flex-end, auto).
38	/// * flex-direction: Sets the layout direction (column, row, column-reverse, row-reverse).
39	/// * justify-content: Sets the arrangement of child items (flex-start, center, flex-end, space-between, space-around, space-evenly).
40	/// ## Flex properties
41	/// * flex: Sets the overall size of the flex container.
42	/// * flex-grow: Sets the flex growth value.
43	/// * flex-shrink: Sets the flex shrink value.
44	/// * flex-wrap: Sets whether to wrap (nowrap, wrap, wrap-reverse).
45	/// * flex-basis: Sets the flex basis value or percentage.
46	/// ## Margins and dimensions
47	/// * margin: Can be set by a single value or multiple values separated by commas, percentages or auto for each side.
48	/// * margin-top, margin-right, margin-bottom, margin-left, margin-start, margin-end: Sets the margin values, percentages or auto.
49	/// * padding: Can be set by a single value or multiple values separated by commas or percentages for each side.
50	/// * padding-top, padding-right, padding-bottom, padding-left: Sets the padding values or percentages.
51	/// * border: Can be set by a single value or multiple values separated by commas for each side.
52	/// * width, height, min-width, min-height, max-width, max-height: Sets the dimension values or percentage properties.
53	/// ## Positioning
54	/// * top, right, bottom, left, start, end, horizontal, vertical: Sets the positioning property values or percentages.
55	/// ## Other properties
56	/// * position: Sets the positioning type (absolute, relative, static).
57	/// * overflow: Sets the overflow property (visible, hidden, scroll).
58	/// * display: Controls whether to display (flex, none).
59	pub fn css(&mut self, style: &str) {
60		unsafe { alignnode_css(self.raw(), crate::dora::from_string(style)); }
61	}
62	/// Creates a new AlignNode object.
63	///
64	/// # Arguments
65	///
66	/// * `isWindowRoot` - Whether the node is a window root node. A window root node will automatically listen for window size change events and update the layout accordingly.
67	pub fn new(is_window_root: bool) -> AlignNode {
68		unsafe { return AlignNode { raw: alignnode_new(if is_window_root { 1 } else { 0 }) }; }
69	}
70}