Skip to main content

rustapi/actions/
editing_slice.rs

1use crate::prelude::*;
2
3pub struct EditingSlice {
4    id: TheId,
5    nodeui: TheNodeUI,
6}
7
8impl Action for EditingSlice {
9    fn new() -> Self
10    where
11        Self: Sized,
12    {
13        let mut nodeui: TheNodeUI = TheNodeUI::default();
14
15        let item = TheNodeUIItem::IntEditSlider(
16            "actionEditingSlicePos".into(),
17            "".into(),
18            "".into(),
19            0,
20            -100000..=100000,
21            false,
22        );
23        nodeui.add_item(item);
24
25        let item = TheNodeUIItem::IntEditSlider(
26            "actionEditingSliceHeight".into(),
27            "".into(),
28            "".into(),
29            2,
30            1..=10,
31            false,
32        );
33        nodeui.add_item(item);
34
35        let item = TheNodeUIItem::Markdown("desc".into(), "".into());
36        nodeui.add_item(item);
37
38        Self {
39            id: TheId::named(&fl!("action_editing_slice")),
40            nodeui,
41        }
42    }
43
44    fn id(&self) -> TheId {
45        self.id.clone()
46    }
47
48    fn info(&self) -> String {
49        fl!("action_editing_slice_desc")
50    }
51
52    fn role(&self) -> ActionRole {
53        ActionRole::Editor
54    }
55
56    fn accel(&self) -> Option<TheAccelerator> {
57        None
58    }
59
60    fn is_applicable(&self, _map: &Map, _ctx: &mut TheContext, server_ctx: &ServerContext) -> bool {
61        server_ctx.editing_surface.is_none() && server_ctx.editor_view_mode == EditorViewMode::D2
62    }
63
64    fn apply_project(
65        &self,
66        _project: &mut Project,
67        _ui: &mut TheUI,
68        ctx: &mut TheContext,
69        server_ctx: &mut ServerContext,
70    ) {
71        let pos = self
72            .nodeui
73            .get_i32_value("actionEditingSlicePos")
74            .unwrap_or(0);
75        let height = self
76            .nodeui
77            .get_i32_value("actionEditingSliceHeight")
78            .unwrap_or(2)
79            .max(1);
80
81        server_ctx.editing_slice = pos as f32;
82        server_ctx.editing_slice_height = height as f32;
83
84        ctx.ui.send(TheEvent::Custom(
85            TheId::named("Update Client Properties"),
86            TheValue::Empty,
87        ));
88    }
89
90    fn params(&self) -> TheNodeUI {
91        self.nodeui.clone()
92    }
93
94    fn handle_event(
95        &mut self,
96        event: &TheEvent,
97        _project: &mut Project,
98        _ui: &mut TheUI,
99        _ctx: &mut TheContext,
100        _server_ctx: &mut ServerContext,
101    ) -> bool {
102        self.nodeui.handle_event(event)
103    }
104}