honeycomb_render/
options.rs1use bevy::prelude::*;
2use bevy_egui::egui::Color32;
3
4use crate::resources::{DartGizmos, EdgeGizmos};
5
6pub struct OptionsPlugin;
8
9impl Plugin for OptionsPlugin {
10 fn build(&self, app: &mut App) {
11 app.insert_resource(DartRenderColor::default())
13 .insert_resource(VertexRenderColor::default())
14 .insert_resource(EdgeRenderColor::default())
15 .insert_resource(FaceRenderColor::default())
16 .insert_resource(VolumeRenderColor::default());
17 app.insert_resource(DartShrink::default())
19 .insert_resource(FaceShrink::default())
20 .insert_resource(VolumeShrink::default());
21 app.insert_resource(DartWidth(2.0))
23 .insert_resource(VertexWidth(0.1))
24 .insert_resource(EdgeWidth(1.0));
25 app.insert_resource(DartHeadMul::default());
27 app.add_systems(
29 Update,
30 update_config
31 .run_if(resource_changed::<DartWidth>.and_then(not(resource_added::<DartWidth>)))
32 .run_if(
33 resource_changed::<VertexWidth>.and_then(not(resource_added::<VertexWidth>)),
34 )
35 .run_if(resource_changed::<EdgeWidth>.and_then(not(resource_added::<EdgeWidth>))),
36 );
37 }
38}
39
40pub fn update_config(
41 mut config_store: ResMut<GizmoConfigStore>,
42 dw: ResMut<DartWidth>,
43 _v_width: ResMut<VertexWidth>,
44 edw: ResMut<EdgeWidth>,
45) {
46 let (dart_config, _) = config_store.config_mut::<DartGizmos>();
47 dart_config.line_width = dw.0;
48 let (edge_config, _) = config_store.config_mut::<EdgeGizmos>();
49 edge_config.line_width = edw.0;
50}
51
52macro_rules! declare_newtype_resource {
53 ($name: ident, $inr: ty) => {
54 #[derive(Resource)]
56 pub struct $name(pub $inr);
57 };
58 ($name: ident, $inr: ty, $def: expr) => {
59 #[derive(Resource)]
61 pub struct $name(pub $inr);
62
63 impl Default for $name {
64 fn default() -> Self {
65 Self($def)
66 }
67 }
68 };
69 ($name: ident, $inr1: ty, $inr2: ty, $def: expr) => {
70 #[derive(Resource)]
72 pub struct $name(pub $inr1, pub $inr2);
73
74 impl Default for $name {
75 fn default() -> Self {
76 Self($def.0, $def.1)
77 }
78 }
79 };
80}
81
82declare_newtype_resource!(DartRenderColor, bool, Color32, (true, Color32::BLACK));
88#[rustfmt::skip]
89declare_newtype_resource!(VertexRenderColor, bool, Color32, (true, Color32::GOLD));
90declare_newtype_resource!(EdgeRenderColor, bool, Color32, (false, Color32::YELLOW));
91declare_newtype_resource!(FaceRenderColor, bool, Color32, (false, Color32::RED));
92declare_newtype_resource!(VolumeRenderColor, bool, Color32, (false, Color32::DARK_RED));
93
94declare_newtype_resource!(DartShrink, f32, -0.1);
97declare_newtype_resource!(FaceShrink, f32, -0.2);
98declare_newtype_resource!(VolumeShrink, f32, 0.0);
99
100declare_newtype_resource!(DartWidth, f32);
103declare_newtype_resource!(VertexWidth, f32);
104declare_newtype_resource!(EdgeWidth, f32);
105
106declare_newtype_resource!(DartHeadMul, f32, 0.05);