Newer
Older
fn setup(mut commands: Commands, mut font_system: ResMut<CosmicFontSystem>) {
commands.spawn(Camera2dBundle::default());
let root = commands
.spawn(NodeBundle {
style: Style {
display: Display::Flex,
width: Val::Percent(100.),
height: Val::Percent(100.),
..default()
},
..default()
})
.id();
let mut attrs = Attrs::new();
attrs = attrs.family(Family::Name("Victor Mono"));
attrs = attrs.color(bevy_color_to_cosmic(Color::PURPLE));
// spawn editor
let cosmic_edit = commands
.spawn(CosmicEditBundle {
buffer: CosmicBuffer::new(&mut font_system, Metrics::new(14., 18.)).with_text(
&mut font_system,
"😀😀😀 x => y\nRead only widget",
attrs,
),
commands.entity(root).with_children(|parent| {
parent
.spawn(ButtonBundle {
style: Style {
width: Val::Percent(100.),
height: Val::Percent(100.),
..default()
},
background_color: BackgroundColor(Color::WHITE),
..default()
})
// add cosmic source
.insert(CosmicSource(cosmic_edit));
let font_bytes: &[u8] = include_bytes!("../assets/fonts/VictorMono-Regular.ttf");
let font_config = CosmicFontConfig {
fonts_dir_path: None,
font_bytes: Some(vec![font_bytes]),
load_system_fonts: true,
};
.add_plugins(CosmicEditPlugin {
font_config,
..default()
})