Skip to content

Commit c450d8f

Browse files
author
mayintao3
committed
feat: 把background-position拆成background-positionx,background-positiony
1 parent cc5f9a2 commit c450d8f

File tree

2 files changed

+36
-30
lines changed

2 files changed

+36
-30
lines changed

src/style_propetries/background_position.rs

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -124,37 +124,41 @@ pub struct BackgroundPosition {
124124

125125
impl ToExpr for BackgroundPosition {
126126
fn to_expr(&self) -> PropertyTuple {
127-
let expr = match self.value.get(0).unwrap() {
128-
ImagePosition::ImagePositionXY(x, y) => Expr::Object(ObjectLit {
129-
span: DUMMY_SP,
130-
props: vec![
131-
PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp {
132-
key: PropName::Ident(Ident::new("x".into(), DUMMY_SP)),
133-
value: generate_expr_with_css_input(x.to_string(), Platform::Harmony).into(),
134-
}))),
135-
PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp {
136-
key: PropName::Ident(Ident::new("y".into(), DUMMY_SP)),
137-
value: generate_expr_with_css_input(y.to_string(), Platform::Harmony).into(),
138-
}))),
139-
]
140-
.into(),
141-
})
142-
.into(),
143-
ImagePosition::TopStart => generate_expr_enum!(style_property_enum::ArkUI_Alignment::ARKUI_ALIGNMENT_TOP_START),
144-
ImagePosition::Top => generate_expr_enum!(style_property_enum::ArkUI_Alignment::ARKUI_ALIGNMENT_TOP),
145-
ImagePosition::TopEnd => generate_expr_enum!(style_property_enum::ArkUI_Alignment::ARKUI_ALIGNMENT_TOP_END),
146-
ImagePosition::Start => generate_expr_enum!(style_property_enum::ArkUI_Alignment::ARKUI_ALIGNMENT_START),
147-
ImagePosition::Center => generate_expr_enum!(style_property_enum::ArkUI_Alignment::ARKUI_ALIGNMENT_CENTER),
148-
ImagePosition::End => generate_expr_enum!(style_property_enum::ArkUI_Alignment::ARKUI_ALIGNMENT_END),
149-
ImagePosition::BottomStart => generate_expr_enum!(style_property_enum::ArkUI_Alignment::ARKUI_ALIGNMENT_BOTTOM_START),
150-
ImagePosition::Bottom => generate_expr_enum!(style_property_enum::ArkUI_Alignment::ARKUI_ALIGNMENT_BOTTOM),
151-
ImagePosition::BottomEnd => generate_expr_enum!(style_property_enum::ArkUI_Alignment::ARKUI_ALIGNMENT_BOTTOM_END),
127+
let property_tuple = match self.value.get(0).unwrap() {
128+
ImagePosition::ImagePositionXY(x, y) => {
129+
PropertyTuple::Array(vec![
130+
(CSSPropertyType::BackgroundPositionX, generate_expr_with_css_input(x.to_string(), Platform::Harmony).into()),
131+
(CSSPropertyType::BackgroundPositionY, generate_expr_with_css_input(y.to_string(), Platform::Harmony).into())
132+
])
133+
},
134+
position => {
135+
let expr = match position {
136+
ImagePosition::TopStart => generate_expr_enum!(style_property_enum::ArkUI_Alignment::ARKUI_ALIGNMENT_TOP_START),
137+
ImagePosition::Top => generate_expr_enum!(style_property_enum::ArkUI_Alignment::ARKUI_ALIGNMENT_TOP),
138+
ImagePosition::TopEnd => generate_expr_enum!(style_property_enum::ArkUI_Alignment::ARKUI_ALIGNMENT_TOP_END),
139+
ImagePosition::Start => generate_expr_enum!(style_property_enum::ArkUI_Alignment::ARKUI_ALIGNMENT_START),
140+
ImagePosition::Center => generate_expr_enum!(style_property_enum::ArkUI_Alignment::ARKUI_ALIGNMENT_CENTER),
141+
ImagePosition::End => generate_expr_enum!(style_property_enum::ArkUI_Alignment::ARKUI_ALIGNMENT_END),
142+
ImagePosition::BottomStart => generate_expr_enum!(style_property_enum::ArkUI_Alignment::ARKUI_ALIGNMENT_BOTTOM_START),
143+
ImagePosition::Bottom => generate_expr_enum!(style_property_enum::ArkUI_Alignment::ARKUI_ALIGNMENT_BOTTOM),
144+
ImagePosition::BottomEnd => generate_expr_enum!(style_property_enum::ArkUI_Alignment::ARKUI_ALIGNMENT_BOTTOM_END),
145+
_ => unreachable!(),
146+
};
147+
148+
PropertyTuple::One(
149+
CSSPropertyType::BackgroundPosition,
150+
expr
151+
)
152+
},
153+
152154
};
153155

154-
PropertyTuple::One(
155-
CSSPropertyType::BackgroundPosition,
156-
expr
157-
)
156+
property_tuple
157+
158+
// PropertyTuple::One(
159+
// CSSPropertyType::BackgroundPosition,
160+
// expr
161+
// )
158162
}
159163

160164
}

src/style_propetries/style_property_type.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,7 @@ pub enum CSSPropertyType {
8484
Content = 79,
8585
WordBreak = 80,
8686
WebkitLineLamp = 81,
87-
AnimationFillMode = 82
87+
AnimationFillMode = 82,
88+
BackgroundPositionX = 83,
89+
BackgroundPositionY = 84,
8890
}

0 commit comments

Comments
 (0)