Skip to content

Commit 4aa481a

Browse files
committed
Consistent naming for public API
Removed public refernces to pane, only div should be used.
1 parent 635a121 commit 4aa481a

File tree

17 files changed

+96
-94
lines changed

17 files changed

+96
-94
lines changed

examples/hello_svelte/Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[workspace]
12
[package]
23
name = "hello_svelte"
34
version = "0.1.0"
@@ -9,8 +10,8 @@ crate-type = ["cdylib", "rlib"]
910

1011
[dependencies]
1112
div = { path = "../../" }
12-
wasm-bindgen = "0.2.68"
13-
wasm-bindgen-futures = "0.4.18"
13+
wasm-bindgen = "0.2"
14+
wasm-bindgen-futures = "0.4"
1415

1516
[dependencies.web-sys]
1617
version = "0.3"

examples/hello_world/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[workspace]
12
[package]
23
name = "hello_world"
34
version = "0.1.0"
@@ -9,5 +10,5 @@ crate-type = ["cdylib", "rlib"]
910

1011
[dependencies]
1112
div = { path = "../../" }
12-
wasm-bindgen = "0.2.68"
13+
wasm-bindgen = "0.2"
1314

examples/hello_world/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ pub fn main() {
1313
let w = 500;
1414
let h = 500;
1515
let html = "Hello world";
16-
div::new_pane(x, y, w, h, html);
16+
div::new(x, y, w, h, html);
1717
}

examples/reposition/Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[workspace]
12
[package]
23
name = "reposition"
34
version = "0.1.0"
@@ -9,8 +10,8 @@ crate-type = ["cdylib", "rlib"]
910

1011
[dependencies]
1112
div = { path = "../../" }
12-
wasm-bindgen = "0.2.68"
13-
stdweb = "0.4.20"
13+
wasm-bindgen = "0.2"
14+
stdweb = "0.4"
1415

1516
[dependencies.web-sys]
1617
version = "0.3"

examples/reposition/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub fn main() {
3434
let html0 = r#"
3535
<div style="border:solid; width: 100%; height: 100%; box-sizing: border-box; border: 5px solid black;"></div>
3636
"#;
37-
div::new_pane(0, 0, w, h, html0).unwrap();
37+
div::new(0, 0, w, h, html0).unwrap();
3838

3939
// Create two div within to show internal scaling behavior
4040
let html1 = r#"
@@ -49,8 +49,8 @@ pub fn main() {
4949
"#;
5050
// pane A will have a dynamic position and size
5151
let (mut ax, mut ay, aw, ah) = (50, 50, 100, 100);
52-
let pane_a = div::new_pane(ax, ay, aw, ah, html1).unwrap();
53-
let _pane_b = div::new_pane(200, 50, 100, 100, html2).unwrap();
52+
let pane_a = div::new(ax, ay, aw, ah, html1).unwrap();
53+
let _pane_b = div::new(200, 50, 100, 100, html2).unwrap();
5454

5555
// Define control variables for zoom of global area and pane A
5656
let mut f = 1.0;

examples/styled/Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[workspace]
12
[package]
23
name = "styled"
34
version = "0.1.0"
@@ -9,8 +10,8 @@ crate-type = ["cdylib", "rlib"]
910

1011
[dependencies]
1112
div = { path = "../../" }
12-
wasm-bindgen = "0.2.68"
13-
stdweb = "0.4.20"
13+
wasm-bindgen = "0.2"
14+
stdweb = "0.4"
1415

1516
[dependencies.web-sys]
1617
version = "0.3"

examples/styled/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub fn main() {
3131
let html0 = "Pane 0<br>Styled with classes";
3232
let classes = ["white-on-black"];
3333
let css: [(&str, &str); 0] = [];
34-
let _pane0 = div::new_styled_pane(100, 100, 200, 100, html0, &classes, &css).unwrap();
34+
let _pane0 = div::new_styled(100, 100, 200, 100, html0, &classes, &css).unwrap();
3535

3636
// Pane 1 with inline styles on pane
3737
let html1 = "Pane 1<br>Stlyed with classes and inline CSS";
@@ -41,7 +41,7 @@ pub fn main() {
4141
("text-decoration", "underline"),
4242
("padding", "5px"),
4343
];
44-
let _pane1 = div::new_styled_pane(125, 300, 200, 100, html1, &classes, &css).unwrap();
44+
let _pane1 = div::new_styled(125, 300, 200, 100, html1, &classes, &css).unwrap();
4545
}
4646

4747
// Small helper function, only for the example. Uses stdweb, DIV-RS does not really help you with this part of CSS.

examples/toggle/Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[workspace]
12
[package]
23
name = "toggle"
34
version = "0.1.0"
@@ -9,8 +10,8 @@ crate-type = ["cdylib", "rlib"]
910

1011
[dependencies]
1112
div = { path = "../../" }
12-
wasm-bindgen = "0.2.68"
13-
stdweb = "0.4.20"
13+
wasm-bindgen = "0.2"
14+
stdweb = "0.4"
1415

1516
[dependencies.web-sys]
1617
version = "0.3"

examples/toggle/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use div::PaneHandle;
1+
use div::DivHandle;
22
use stdweb::web::set_timeout;
33

44
use wasm_bindgen::prelude::*;
@@ -22,15 +22,15 @@ pub fn main() {
2222
</div>
2323
</div>
2424
"#;
25-
let pane0 = div::new_pane(100, 100, 100, 100, html0).unwrap();
26-
let pane1 = div::new_pane(200, 200, 100, 100, html1).unwrap();
25+
let div0 = div::new(100, 100, 100, 100, html0).unwrap();
26+
let div1 = div::new(200, 200, 100, 100, html1).unwrap();
2727

28-
toggle(pane0, pane1);
28+
toggle(div0, div1);
2929
}
3030

3131
// Function that takes to div, shows the first and hides the second
3232
// and then calls itself again delayed, with the two div swapped
33-
fn toggle(a: PaneHandle, b: PaneHandle) {
33+
fn toggle(a: DivHandle, b: DivHandle) {
3434
a.show().expect("Error");
3535
b.hide().expect("Error");
3636
let closure = move || {

examples/www/index.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,32 @@ examples.push(example(
3131
"let w = 500;\n" +
3232
"let h = 500;\n" +
3333
"let html = \"Hello world\";\n" +
34-
"div::new_pane(x, y, w, h, html);",
34+
"div::new(x, y, w, h, html);",
3535
() => {
3636
hello_world.main();
3737
}));
3838
examples.push(example(
3939
"Reposition",
40-
"Use arrow keys to move all panes and +,- to change scaling factor.\n\n" +
40+
"Use arrow keys to move all divs and +,- to change scaling factor.\n\n" +
4141
"div::reposition(x, y)\n" +
4242
"div::resize(w, h)\n\n" +
43-
" Use W,A,S,D to move only one pane and 1,2 for scaling.\n\n" +
44-
"pane_a.reposition(x,y)\n" +
45-
"pane_a.resize(w,h)\n" +
43+
" Use W,A,S,D to move only one div and 1,2 for scaling.\n\n" +
44+
"div_a.reposition(x,y)\n" +
45+
"div_a.resize(w,h)\n" +
4646
"\n\nThis is meant to be used as hovering test over a canvas that needs to be rescaled when the window size changes.",
4747
() => {
4848
reposition.main();
4949
}));
5050
examples.push(example(
5151
"Styled",
52-
"These panes are dynamically styled from within Rust, using CSS.",
52+
"These divs are dynamically styled from within Rust, using CSS.",
5353
() => {
5454
styled.main();
5555
}));
5656
examples.push(example(
5757
"Toggle",
5858
"hi.show()\nbye.hide()\n\n" +
59-
"Two panes are periodically displayed and hidden, as controlled by Rust code.",
59+
"Two divs are periodically displayed and hidden, as controlled by Rust code.",
6060
() => {
6161
toggle.main();
6262
}));

examples/www/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@
4545
"webpack-dev-server": "^3.1.5",
4646
"webpack-merge": "^5.2.0"
4747
}
48-
}
48+
}

src/pane_handle.rs renamed to src/div_handle.rs

+18-26
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
1-
//! Defines operations allowed on PaneHandles
1+
//! Defines operations allowed on DivHandles
22
//!
33
//! Almost the entire library interface is defined in this module.
44
55
use crate::state;
66
use crate::*;
77
use web_sys::{HtmlElement, Node};
88

9-
/// External representation of a Pane.
9+
/// A light-weight key to refer to the state necessary to manipulate a div.
1010
///
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);
1414

15-
impl PaneHandle {
16-
/// Hides the pane and all child nodes.
15+
impl DivHandle {
16+
/// Hides the div and all child nodes.
1717
///
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.
1919
/// Call `delete` to give up memory or call `show` later to display pane again.
2020
pub fn hide(&self) -> Result<(), DivError> {
2121
state::exec_mut(|state| state.hide_pane(&self))
2222
}
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`
2424
pub fn show(&self) -> Result<(), DivError> {
2525
state::exec_mut(|state| state.show_pane(&self))
2626
}
27-
/// Adjust the relative position of the pane.
27+
/// Adjust the relative position of the div.
2828
///
2929
/// The provided parameters are taken in the original scale when initializing,
3030
/// taking any calls to the global div::resize() into consideration.
3131
pub fn reposition(&self, x: u32, y: u32) -> Result<(), DivError> {
3232
state::exec_mut(|state| state.update_pane(&self, Some(x), Some(y), None, None))
3333
}
34-
/// Adjust the size of the pane.
34+
/// Adjust the size of the div.
3535
///
3636
/// The provided parameters are taken in the original scale when initializing,
3737
/// taking any calls to the global div::resize() into consideration.
3838
pub fn resize(&self, w: u32, h: u32) -> Result<(), DivError> {
3939
state::exec_mut(|state| state.update_pane(&self, None, None, Some(w), Some(h)))
4040
}
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
4242
/// resize and reposition separately.
4343
///
4444
/// The provided parameters are taken in the original scale when initializing,
@@ -47,36 +47,28 @@ impl PaneHandle {
4747
state::exec_mut(|state| state.update_pane(&self, Some(x), Some(y), Some(w), Some(h)))
4848
}
4949
/// 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> {
5151
state::exec(|state| state.nodes.get(self)?.set_css(property, value))
5252
}
5353
/// 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> {
5555
state::exec(|state| state.nodes.get(self)?.add_class(css_class))
5656
}
5757
/// 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> {
5959
state::exec(|state| state.nodes.get(self)?.remove_class(css_class))
6060
}
61-
/// Removes a pane from the DOM and deletes it
61+
/// Removes a div from the DOM and deletes it
6262
pub fn delete(&mut self) -> Result<(), DivError> {
6363
state::exec_mut(|state| state.delete_pane(self))
6464
}
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.
6767
pub fn parent_element(&self) -> Result<HtmlElement, DivError> {
6868
state::exec(|state| state.get_node(&self).map(Clone::clone))
6969
}
7070
/// Get a reference to the DOM node created by the provided HTML when creating the pane.
7171
/// 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/
8072
pub fn first_inner_node(&self) -> Result<Node, DivError> {
8173
self.parent_element()?
8274
.first_child()

src/global.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use super::*;
55
/// The position of all existing div is changed immediately, regardless of active / inactive status.
66
/// if div::init() has been used instead of div::init_ex(...), the default origin is (0,0).
77
pub fn reposition(x: u32, y: u32) -> Result<(), DivError> {
8-
state::exec_mut(|state| state.reposition_div(x, y))
8+
state::exec_mut(|state| state.global_reposition(x, y))
99
}
1010

1111
/// Redefines the size of the global frame where all div are within.
@@ -14,5 +14,5 @@ pub fn reposition(x: u32, y: u32) -> Result<(), DivError> {
1414
/// All pane sizes are resized immediately, regardless of active / inactive status.
1515
/// Only has an effect if the size has been defined earlier.
1616
pub fn resize(w: u32, h: u32) -> Result<(), DivError> {
17-
state::exec_mut(|state| state.resize_div(w, h))
17+
state::exec_mut(|state| state.global_resize(w, h))
1818
}

0 commit comments

Comments
 (0)