termux_gui/components/
space.rs

1//! Space component
2
3use serde_json::json;
4use crate::activity::Activity;
5use crate::view::View;
6use crate::error::Result;
7
8/// A Space creates empty space in layouts
9/// 
10/// Space is useful for creating gaps between UI elements or pushing elements apart.
11/// You can control its size using width, height, and layout params.
12pub struct Space {
13    view: View,
14    aid: i64,
15}
16
17impl Space {
18    /// Create a new Space
19    pub fn new(activity: &mut Activity, parent: Option<i64>) -> Result<Self> {
20        let mut params = json!({
21            "aid": activity.id()
22        });
23        
24        // Only set parent if explicitly provided
25        if let Some(parent_id) = parent {
26            params["parent"] = json!(parent_id);
27        }
28        
29        let response = activity.send_read(&json!({
30            "method": "createSpace",
31            "params": params
32        }))?;
33        
34        let id = response
35            .as_i64()
36            .ok_or_else(|| crate::error::GuiError::InvalidResponse("Invalid id".to_string()))?;
37        
38        Ok(Space {
39            view: View::new(id),
40            aid: activity.id(),
41        })
42    }
43    
44    /// Get the view ID
45    pub fn id(&self) -> i64 {
46        self.view.id()
47    }
48    
49    /// Get the underlying View
50    pub fn view(&self) -> &View {
51        &self.view
52    }
53}