Skip to content

Instantly share code, notes, and snippets.

@cart
Last active July 25, 2020 10:26
Show Gist options
  • Save cart/d5e9a282fcec62e65eb5c619c8a760eb to your computer and use it in GitHub Desktop.
Save cart/d5e9a282fcec62e65eb5c619c8a760eb to your computer and use it in GitHub Desktop.
// Anchors
.spawn(ButtonComponents {
node: Node::with_size(Anchors::CENTER, Size {
Dimension::Points(150.0),
Dimension::Points(70.0)
}),
material: button_materials.normal,
..Default::default()
})
.with_children(|parent| {
parent.spawn(TextComponents {
node: Node::with_margins(Anchors::FULL, Margins::new(
Dimension::Points(0.0),
Dimension::Points(0.0),
Dimension::Points(12.0),
Dimension::Points(0.0)),
text: Text {
value: "Button".to_string(),
font: asset_server.load("assets/fonts/FiraSans-Bold.ttf").unwrap(),
style: TextStyle {
font_size: 40.0,
color: Color::rgb(0.8, 0.8, 0.8),
align: TextAlign::Center,
},
},
..Default::default()
});
});
// Flex
.spawn(NodeComponents {
flex: Flex {
size: Size {
width: Dimension::Percent(1.0),
height: Dimension::Percent(1.0),
},
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..Default::default()
},
material: materials.add(Color::NONE.into()),
..Default::default()
})
.with_children(|parent| {
parent
.spawn(ButtonComponents {
flex: Flex {
size: Size {
width: Dimension::Points(150.0),
height: Dimension::Points(70.0),
},
..Default::default()
},
material: button_materials.normal,
..Default::default()
})
.with_children(|parent| {
parent.spawn(TextComponents {
flex: Flex {
size: Size {
width: Dimension::Percent(1.0),
height: Dimension::Percent(1.0),
},
margin: Rect {
top: Dimension::Points(10.0),
..Default::default()
},
..Default::default()
},
text: Text {
value: "Button".to_string(),
font: asset_server.load("assets/fonts/FiraSans-Bold.ttf").unwrap(),
style: TextStyle {
font_size: 40.0,
color: Color::rgb(0.8, 0.8, 0.8),
align: TextAlign::Center,
},
},
..Default::default()
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment