(
ctx: &mut ScriptContext<'_, API>,
idx: usize,
)
| 197 | } |
| 198 | } |
| 199 | |
| 200 | pub fn toggle_scene_node_slot<API: ScriptAPI + ?Sized>( |
| 201 | ctx: &mut ScriptContext<'_, API>, |
| 202 | idx: usize, |
| 203 | ) { |
| 204 | let Some(key) = with_state!(ctx.run, EditorState, ctx.id, |state| { |
| 205 | if state.doc_text.is_empty() { |
| 206 | None |
| 207 | } else { |
| 208 | let doc = cached_scene_doc_shared(&state.doc_text); |
| 209 | scene_tree_view( |
| 210 | &doc, |
| 211 | state.selected_key, |
| 212 | &state.scene_filter, |
| 213 | &state.collapsed_scene_keys, |
| 214 | ) |
| 215 | .keys |
| 216 | .get(idx) |
| 217 | .copied() |
| 218 | } |
| 219 | }).unwrap_or_default() else { |
| 220 | return; |
| 221 | }; |
| 222 | let has_children = with_state!(ctx.run, EditorState, ctx.id, |state| { |
| 223 | if state.doc_text.is_empty() { |
| 224 | false |
| 225 | } else { |
| 226 | let doc = cached_scene_doc_shared(&state.doc_text); |
| 227 | scene_child_count(&doc, key) > 0 |
| 228 | } |
| 229 | }).unwrap_or_default(); |
| 230 | if !has_children { |
| 231 | return; |
| 232 | } |
| 233 | let changed = with_state_mut!(ctx.run, EditorState, ctx.id, |state| { |
| 234 | if let Some(pos) = state |
| 235 | .collapsed_scene_keys |
| 236 | .iter() |
| 237 | .position(|collapsed| *collapsed == key) |
| 238 | { |
| 239 | state.collapsed_scene_keys.remove(pos); |
| 240 | state.log = "expand node".to_string(); |
| 241 | return true; |
| 242 | } |
| 243 | state.collapsed_scene_keys.push(key); |
| 244 | state.log = "collapse node".to_string(); |
| 245 | true |
| 246 | }) |
| 247 | .unwrap_or(false); |
| 248 | if changed { |
| 249 | refresh_scene_panel(ctx); |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | pub fn set_scene_node_slot_open<API: ScriptAPI + ?Sized>( |
nothing calls this directly
no test coverage detected