Skip to content

Commit d21e51d

Browse files
committed
Positions as i32
1 parent d6eff89 commit d21e51d

File tree

7 files changed

+26
-24
lines changed

7 files changed

+26
-24
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
## Unreleased (v0.4)
2+
- (breaking) Changed type of positions from `u32` to `i32` (for pane and global frame). Negative offsets are valid and sometimes necessary.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "div"
3-
version = "0.3.0"
3+
version = "0.4.0"
44
authors = ["Jakob Meier <[email protected]>"]
55
edition = "2018"
66
license = "MIT/Apache-2.0"

src/div_handle.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl DivHandle {
2828
///
2929
/// The provided parameters are taken in the original scale when initializing,
3030
/// taking any calls to the global div::resize() into consideration.
31-
pub fn reposition(&self, x: u32, y: u32) -> Result<(), DivError> {
31+
pub fn reposition(&self, x: i32, y: i32) -> Result<(), DivError> {
3232
state::exec_mut(|state| state.update_pane(&self, Some(x), Some(y), None, None))
3333
}
3434
/// Adjust the size of the div.
@@ -43,7 +43,7 @@ impl DivHandle {
4343
///
4444
/// The provided parameters are taken in the original scale when initializing,
4545
/// taking any calls to the global div::resize() into consideration.
46-
pub fn reposition_and_resize(&self, x: u32, y: u32, w: u32, h: u32) -> Result<(), DivError> {
46+
pub fn reposition_and_resize(&self, x: i32, y: i32, w: u32, h: u32) -> Result<(), DivError> {
4747
state::exec_mut(|state| state.update_pane(&self, Some(x), Some(y), Some(w), Some(h)))
4848
}
4949
/// Set CSS property of div

src/global.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::*;
44
///
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).
7-
pub fn reposition(x: u32, y: u32) -> Result<(), DivError> {
7+
pub fn reposition(x: i32, y: i32) -> Result<(), DivError> {
88
state::exec_mut(|state| state.global_reposition(x, y))
99
}
1010

src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub fn init_to(id: &str) -> Result<(), DivError> {
4242
/// ```
4343
pub fn init_ex_with_element(
4444
root: Element,
45-
pos: (u32, u32),
45+
pos: (i32, i32),
4646
size: Option<(u32, u32)>,
4747
) -> Result<(), DivError> {
4848
state::set_state(GlobalState {
@@ -69,7 +69,7 @@ pub fn init_ex_with_element(
6969
/// ```
7070
pub fn init_ex(
7171
id: Option<&str>,
72-
pos: (u32, u32),
72+
pos: (i32, i32),
7373
size: Option<(u32, u32)>,
7474
) -> Result<(), DivError> {
7575
let root = get_root(id)?;
@@ -89,7 +89,7 @@ fn get_root(id: Option<&str>) -> Result<Element, DivError> {
8989

9090
/// Creates a new div at the defined position with the given HTML as content.
9191
/// Use the returned DivHandle to manipulate the div.
92-
pub fn new(x: u32, y: u32, w: u32, h: u32, html: &str) -> Result<DivHandle, DivError> {
92+
pub fn new(x: i32, y: i32, w: u32, h: u32, html: &str) -> Result<DivHandle, DivError> {
9393
let css = "";
9494
let classes = "";
9595
state::exec_mut(|state| state.new_pane(x, y, w, h, html, css, classes))
@@ -117,8 +117,8 @@ pub fn new(x: u32, y: u32, w: u32, h: u32, html: &str) -> Result<DivHandle, DivE
117117
/// ).unwrap();
118118
/// ```
119119
pub fn new_styled<'a, C, CSS, S1, S2, S3>(
120-
x: u32,
121-
y: u32,
120+
x: i32,
121+
y: i32,
122122
w: u32,
123123
h: u32,
124124
html: &str,
@@ -155,8 +155,8 @@ where
155155
/// The most direct way would be to use `wasm_bindgen_futures::spawn_local`
156156
/// ## Example
157157
/// ```rust
158-
/// const X: u32 = 100;
159-
/// const Y: u32 = 100;
158+
/// const X: i32 = 100;
159+
/// const Y: i32 = 100;
160160
/// const W: u32 = 500;
161161
/// const H: u32 = 500;
162162
/// let future = async {
@@ -186,8 +186,8 @@ pub fn load_js_classes(
186186

187187
/// Creates a new div and fills it with a JS class.
188188
pub fn from_js_class(
189-
x: u32,
190-
y: u32,
189+
x: i32,
190+
y: i32,
191191
w: u32,
192192
h: u32,
193193
class_handle: JsClassHandle,

src/pane.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use web_sys::HtmlElement;
1313
pub(crate) struct Pane {
1414
node: HtmlElement,
1515
displayed: bool,
16-
x: u32,
17-
y: u32,
16+
x: i32,
17+
y: i32,
1818
w: u32,
1919
h: u32,
2020
}
@@ -23,8 +23,8 @@ impl<PS: PaneStorage, CS: ClassStorage> GlobalState<PS, CS> {
2323
/// Creates a new pane from specified html and shows it
2424
pub(crate) fn new_pane(
2525
&mut self,
26-
x: u32,
27-
y: u32,
26+
x: i32,
27+
y: i32,
2828
w: u32,
2929
h: u32,
3030
html: &str,
@@ -95,8 +95,8 @@ impl<PS: PaneStorage, CS: ClassStorage> GlobalState<PS, CS> {
9595
pub(crate) fn update_pane(
9696
&mut self,
9797
pane_handle: &DivHandle,
98-
x: Option<u32>,
99-
y: Option<u32>,
98+
x: Option<i32>,
99+
y: Option<i32>,
100100
w: Option<u32>,
101101
h: Option<u32>,
102102
) -> Result<(), DivError> {
@@ -108,7 +108,7 @@ impl<PS: PaneStorage, CS: ClassStorage> GlobalState<PS, CS> {
108108
v.redraw(self.pos, self.zoom)?;
109109
Ok(())
110110
}
111-
pub(crate) fn global_reposition(&mut self, x: u32, y: u32) -> Result<(), DivError> {
111+
pub(crate) fn global_reposition(&mut self, x: i32, y: i32) -> Result<(), DivError> {
112112
self.pos = (x, y);
113113
self.nodes.for_each(&|pane: &mut Pane| {
114114
let el = pane.get_element()?;
@@ -142,9 +142,9 @@ impl Pane {
142142
pub(crate) fn get_element(&self) -> Result<&HtmlElement, DivError> {
143143
Ok(&self.node)
144144
}
145-
pub(crate) fn redraw(&self, (x, y): (u32, u32), (fx, fy): (f32, f32)) -> Result<(), DivError> {
146-
let x = x + (fx * self.x as f32) as u32;
147-
let y = y + (fy * self.y as f32) as u32;
145+
pub(crate) fn redraw(&self, (x, y): (i32, i32), (fx, fy): (f32, f32)) -> Result<(), DivError> {
146+
let x = x + (fx * self.x as f32) as i32;
147+
let y = y + (fy * self.y as f32) as i32;
148148
let w = (fx * self.w as f32) as u32;
149149
let h = (fy * self.h as f32) as u32;
150150

src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ where
55
CS: ClassStorage,
66
{
77
pub(crate) root: web_sys::Element,
8-
pub(crate) pos: (u32, u32),
8+
pub(crate) pos: (i32, i32),
99
pub(crate) size: Option<(u32, u32)>,
1010
pub(crate) zoom: (f32, f32),
1111
pub(crate) nodes: PS,

0 commit comments

Comments
 (0)