1
- //! Defines operations allowed on PaneHandles
1
+ //! Defines operations allowed on DivHandles
2
2
//!
3
3
//! Almost the entire library interface is defined in this module.
4
4
5
5
use crate :: state;
6
6
use crate :: * ;
7
7
use web_sys:: { HtmlElement , Node } ;
8
8
9
- /// External representation of a Pane .
9
+ /// A light-weight key to refer to the state necessary to manipulate a div .
10
10
///
11
- /// This is a unique identifier that will become invalid once the pane has been deleted.
12
- #[ derive( Debug , Clone , PartialEq , Eq ) ]
13
- pub struct PaneHandle ( pub ( crate ) usize ) ;
11
+ /// This is a unique identifier that will become invalid once the div has been deleted.
12
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
13
+ pub struct DivHandle ( pub ( crate ) usize ) ;
14
14
15
- impl PaneHandle {
16
- /// Hides the pane and all child nodes.
15
+ impl DivHandle {
16
+ /// Hides the div and all child nodes.
17
17
///
18
- /// The pane root node is removed from the DOM but it is kept in memory.
18
+ /// The div node is removed from the DOM but it is kept in memory.
19
19
/// Call `delete` to give up memory or call `show` later to display pane again.
20
20
pub fn hide ( & self ) -> Result < ( ) , DivError > {
21
21
state:: exec_mut ( |state| state. hide_pane ( & self ) )
22
22
}
23
- /// Displays pane again after it has been hidden by calling `hide`
23
+ /// Displays a div again after it has been hidden by calling `hide`
24
24
pub fn show ( & self ) -> Result < ( ) , DivError > {
25
25
state:: exec_mut ( |state| state. show_pane ( & self ) )
26
26
}
27
- /// Adjust the relative position of the pane .
27
+ /// Adjust the relative position of the div .
28
28
///
29
29
/// The provided parameters are taken in the original scale when initializing,
30
30
/// taking any calls to the global div::resize() into consideration.
31
31
pub fn reposition ( & self , x : u32 , y : u32 ) -> Result < ( ) , DivError > {
32
32
state:: exec_mut ( |state| state. update_pane ( & self , Some ( x) , Some ( y) , None , None ) )
33
33
}
34
- /// Adjust the size of the pane .
34
+ /// Adjust the size of the div .
35
35
///
36
36
/// The provided parameters are taken in the original scale when initializing,
37
37
/// taking any calls to the global div::resize() into consideration.
38
38
pub fn resize ( & self , w : u32 , h : u32 ) -> Result < ( ) , DivError > {
39
39
state:: exec_mut ( |state| state. update_pane ( & self , None , None , Some ( w) , Some ( h) ) )
40
40
}
41
- /// Adjust the position and size of the pane in a single call, which is slightly more efficient than calling
41
+ /// Adjust the position and size of the div in a single call, which is slightly more efficient than calling
42
42
/// resize and reposition separately.
43
43
///
44
44
/// The provided parameters are taken in the original scale when initializing,
@@ -47,36 +47,28 @@ impl PaneHandle {
47
47
state:: exec_mut ( |state| state. update_pane ( & self , Some ( x) , Some ( y) , Some ( w) , Some ( h) ) )
48
48
}
49
49
/// Set CSS property of div
50
- pub fn set_css ( & mut self , property : & str , value : & str ) -> Result < ( ) , DivError > {
50
+ pub fn set_css ( & self , property : & str , value : & str ) -> Result < ( ) , DivError > {
51
51
state:: exec ( |state| state. nodes . get ( self ) ?. set_css ( property, value) )
52
52
}
53
53
/// Add a CSS class to the div
54
- pub fn add_class ( & mut self , css_class : & str ) -> Result < ( ) , DivError > {
54
+ pub fn add_class ( & self , css_class : & str ) -> Result < ( ) , DivError > {
55
55
state:: exec ( |state| state. nodes . get ( self ) ?. add_class ( css_class) )
56
56
}
57
57
/// Remove a CSS class to the div
58
- pub fn remove_class ( & mut self , css_class : & str ) -> Result < ( ) , DivError > {
58
+ pub fn remove_class ( & self , css_class : & str ) -> Result < ( ) , DivError > {
59
59
state:: exec ( |state| state. nodes . get ( self ) ?. remove_class ( css_class) )
60
60
}
61
- /// Removes a pane from the DOM and deletes it
61
+ /// Removes a div from the DOM and deletes it
62
62
pub fn delete ( & mut self ) -> Result < ( ) , DivError > {
63
63
state:: exec_mut ( |state| state. delete_pane ( self ) )
64
64
}
65
- /// Get a reference to the DOM element associated with the pane .
66
- /// The provided HTML when creating a new pane will be the child node(s) of the returned element.
65
+ /// Get a reference to the DOM element associated with the div .
66
+ /// The provided HTML when creating a new div will be the child node(s) of the returned element.
67
67
pub fn parent_element ( & self ) -> Result < HtmlElement , DivError > {
68
68
state:: exec ( |state| state. get_node ( & self ) . map ( Clone :: clone) )
69
69
}
70
70
/// Get a reference to the DOM node created by the provided HTML when creating the pane.
71
71
/// If multiple nodes have been created, the first node is returned.
72
- ///
73
- /// The returned [`Node`] is from the crate [`stdweb`], allowing library users to
74
- /// escape the Div crate and access the DOM directly.
75
- ///
76
- /// TODO: Example
77
- ///
78
- /// [`Node`]: https://docs.rs/stdweb/*/stdweb/web/struct.Node.html
79
- /// [`stdweb`]: https://docs.rs/stdweb/*/stdweb/
80
72
pub fn first_inner_node ( & self ) -> Result < Node , DivError > {
81
73
self . parent_element ( ) ?
82
74
. first_child ( )
0 commit comments