honeycomb_render/options/
tab.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
use crate::resources::{
    BetaRenderColor, BetaWidth, DartHeadMul, DartRenderColor, DartShrink, DartWidth,
    EdgeRenderColor, EdgeWidth, FaceRenderColor, FaceShrink, VertexRenderColor, VertexWidth,
    VolumeRenderColor, VolumeShrink,
};
use bevy::prelude::*;
use bevy_mod_picking::picking_core::PickingPluginsSettings;
use bevy_mod_picking::selection::SelectionPluginSettings;
use egui_dock::egui;
// --- main function

/// rendering options drawing function.
pub fn draw_options(ui: &mut egui::Ui, world: &mut World) {
    draw_map_options(ui, world);

    ui.separator(); // ---

    draw_picking_options(ui, world);
}

// --- map options

macro_rules! opt_rendercol {
    ($ui: ident, $world: ident, $param: ident) => {{
        let mut rendercol = $world.resource_mut::<$param>();
        $ui.checkbox(&mut rendercol.0, "");
        $ui.add_enabled_ui(rendercol.0, |ui| draw_color_picker(ui, &mut rendercol.1));
    }};
}

macro_rules! opt_dragvalue {
    ($ui: ident, $world: ident, $param: ident) => {{
        let mut val = $world.resource_mut::<$param>();
        $ui.add(egui::DragValue::new(&mut val.0).speed(0.01));
    }};
}

fn draw_map_options(ui: &mut egui::Ui, world: &mut World) {
    ui.label(egui::RichText::new("Map Rendering").size(15.));
    ui.separator(); // ---

    egui::Grid::new("map_opt_grid")
        .num_columns(6)
        .show(ui, |ui| {
            // column names
            ui.label(egui::RichText::new("Object"));
            ui.label(egui::RichText::new("Render"));
            ui.label(egui::RichText::new("Color"));
            ui.label(egui::RichText::new("Shrink"));
            ui.label(egui::RichText::new("Width"));
            ui.label(egui::RichText::new("Head Factor"));
            ui.end_row();
            // darts
            ui.label("Darts");
            opt_rendercol!(ui, world, DartRenderColor);
            opt_dragvalue!(ui, world, DartShrink);
            opt_dragvalue!(ui, world, DartWidth);
            opt_dragvalue!(ui, world, DartHeadMul);
            ui.end_row();
            // betas
            ui.label("Beta Functions");
            opt_rendercol!(ui, world, BetaRenderColor);
            ui.label("");
            opt_dragvalue!(ui, world, BetaWidth);
            ui.end_row();
            // vertices
            ui.label("Vertices");
            opt_rendercol!(ui, world, VertexRenderColor);
            ui.label("");
            opt_dragvalue!(ui, world, VertexWidth);
            ui.end_row();
            // edges
            ui.label("Edges");
            opt_rendercol!(ui, world, EdgeRenderColor);
            ui.label("");
            opt_dragvalue!(ui, world, EdgeWidth);
            ui.end_row();
            // faces
            ui.label("Faces");
            opt_rendercol!(ui, world, FaceRenderColor);
            opt_dragvalue!(ui, world, FaceShrink);
            ui.end_row();
            // faces
            ui.label("Volumes");
            opt_rendercol!(ui, world, VolumeRenderColor);
            opt_dragvalue!(ui, world, VolumeShrink);
            ui.end_row();
        });
}

fn draw_color_picker(ui: &mut egui::Ui, color: &mut egui::Color32) {
    // create intermediate variable
    let mut egui_color =
        egui::Color32::from_rgba_premultiplied(color.r(), color.g(), color.b(), color.a());
    // insert the color picker
    let color_picker = egui::color_picker::color_edit_button_srgba(
        ui,
        &mut egui_color,
        egui::color_picker::Alpha::Opaque,
    );
    // update the original color variable
    if color_picker.changed() {
        *color = egui::Color32::from_rgba_premultiplied(
            egui_color.r(),
            egui_color.g(),
            egui_color.b(),
            egui_color.a(),
        );
    }
}

// --- picking options

fn draw_picking_options(ui: &mut egui::Ui, world: &mut World) {
    ui.label(egui::RichText::new("Picking").size(15.));
    ui.separator(); // ---

    egui::Grid::new("pick_opt_grid")
        .num_columns(2)
        .show(ui, |ui| {
            ui.label("Enable");
            {
                let mut picking_params = world.resource_mut::<PickingPluginsSettings>();
                ui.checkbox(&mut picking_params.is_enabled, "");
            }
            ui.end_row();
            ui.label("Click nothing deselect all");
            {
                let mut picking_params = world.resource_mut::<SelectionPluginSettings>();
                ui.checkbox(&mut picking_params.click_nothing_deselect_all, "");
            }
        });
}