Skip to main content

style/values/computed/
tree_counting.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5//! Computed types for CSS tree-counting functions.
6//! https://drafts.csswg.org/css-values-5/#tree-counting
7
8/// Holds the resolved sibling-index() and sibling-count() values for an element.
9#[derive(Clone, Copy, Debug)]
10pub struct TreeCountingResult {
11    /// The 1-based index of the element among its siblings.
12    pub sibling_index: u32,
13    /// The total number of siblings of the element, including itself.
14    pub sibling_count: u32,
15}
16
17impl TreeCountingResult {
18    /// Creates a new TreeCountingResult with the given index and count.
19    pub fn new(sibling_index: u32, sibling_count: u32) -> Self {
20        TreeCountingResult {
21            sibling_index,
22            sibling_count,
23        }
24    }
25
26    /// Creates a default TreeCountingResult.
27    pub fn default() -> Self {
28        TreeCountingResult::new(1, 1)
29    }
30}