shape_maker/src/main.rs

73 lines
2.7 KiB
Rust
Raw Normal View History

2022-07-27 09:19:45 +00:00
use bevy::{prelude::*, window::PresentMode, winit::WinitSettings};
use bevy_egui::{egui, EguiContext, EguiPlugin};
use bevy_prototype_lyon::prelude::*;
use shape_maker::*;
/// This example demonstrates the following functionality and use-cases of bevy_egui:
/// - rendering loaded assets;
/// - toggling hidpi scaling (by pressing '/' button);
/// - configuring egui contexts during the startup.
fn main() {
App::new()
.insert_resource(ClearColor(Color::rgb(0.1, 0.1, 0.12)))
.insert_resource(Msaa { samples: 4 })
// Optimal power saving and present mode settings for desktop apps.
.insert_resource(WinitSettings::desktop_app())
.insert_resource(WindowDescriptor {
present_mode: PresentMode::Mailbox,
title: "Shape Maker".to_string(),
..Default::default()
})
.insert_resource(ButtonsColors::default())
.insert_resource(UiState::default())
.add_plugins(DefaultPlugins)
.add_plugin(EguiPlugin)
.add_plugin(ShapePlugin)
.add_startup_system(configure_visuals)
.add_system(action_bar_sys)
.run();
}
fn configure_visuals(mut egui_ctx: ResMut<EguiContext>) {
egui_ctx.ctx_mut().set_visuals(egui::Visuals {
window_rounding: 0.0.into(),
..Default::default()
});
}
fn action_bar_sys(
mut egui_ctx: ResMut<EguiContext>,
mut state: ResMut<UiState>,
colors: Res<ButtonsColors>,
) {
egui::Window::new("buttons_float")
.default_pos((50.0, 20.0))
.title_bar(false)
.resizable(false)
.show(egui_ctx.ctx_mut(), |ui| {
ui.horizontal(|hui| {
let modify_color = if let Action::Modify = state.current_action { colors.clicked } else { colors.regular };
let create_color = if let Action::Create = state.current_action { colors.clicked } else { colors.regular };
let delete_color = if let Action::Delete = state.current_action { colors.clicked } else { colors.regular };
if hui.button(egui::RichText::new("M").color(modify_color)).clicked() {
state.current_action = Action::Modify;
}
if hui.button(egui::RichText::new("C").color(create_color)).clicked() {
state.current_action = Action::Create;
}
if hui.button(egui::RichText::new("D").color(delete_color)).clicked() {
state.current_action = Action::Delete;
}
hui.label(" | ");
if hui.button(" I ").clicked() {
println!("Image loading is still not supported!");
}
hui.label(": :");
});
});
}