Skip to content

Commit

Permalink
init effort
Browse files Browse the repository at this point in the history
  • Loading branch information
sanbox-irl committed Sep 30, 2021
1 parent 804ebd8 commit b23e048
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 20 deletions.
1 change: 1 addition & 0 deletions imgui-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ exclude = ["third-party/*.json", "third-party/*.lua", "third-party/imgui/*/"]

[dependencies]
chlorine = "1.0.7"
mint = "0.5"

[build-dependencies]
cc = "1.0"
Expand Down
6 changes: 6 additions & 0 deletions imgui-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ impl From<ImVec2> for (f32, f32) {
}
}

impl From<mint::Vector2<f32>> for ImVec2 {
fn from(o: mint::Vector2<f32>) -> Self {
Self { x: o.x, y: o.y }
}
}

impl ImVec4 {
#[inline]
pub const fn new(x: f32, y: f32, z: f32, w: f32) -> ImVec4 {
Expand Down
1 change: 1 addition & 0 deletions imgui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ exclude = ["/resources"]
[dependencies]
bitflags = "1"
imgui-sys = { version = "0.8.1-alpha.0", path = "../imgui-sys" }
mint = "0.5.6"
parking_lot = "0.11"

[features]
Expand Down
1 change: 1 addition & 0 deletions imgui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ mod test;
mod utils;
mod widget;
mod window;
mod math;

// Used by macros. Underscores are just to make it clear it's not part of the
// public API.
Expand Down
1 change: 1 addition & 0 deletions imgui/src/math.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub type MintVec2 = mint::Vector2<f32>;
45 changes: 25 additions & 20 deletions imgui/src/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use bitflags::bitflags;
use std::f32;
use std::ptr;

use crate::math::MintVec2;
use crate::sys;
use crate::{Condition, Ui};

Expand Down Expand Up @@ -165,13 +166,13 @@ pub struct Window<'ui, 'a, Label> {
name: Label,
opened: Option<&'a mut bool>,
flags: WindowFlags,
pos: [f32; 2],
pos: MintVec2,
pos_cond: Condition,
pos_pivot: [f32; 2],
size: [f32; 2],
pos_pivot: MintVec2,
size: MintVec2,
size_cond: Condition,
size_constraints: Option<([f32; 2], [f32; 2])>,
content_size: [f32; 2],
size_constraints: Option<(MintVec2, MintVec2)>,
content_size: MintVec2,
collapsed: bool,
collapsed_cond: Condition,
focused: bool,
Expand All @@ -186,13 +187,13 @@ impl<'ui, 'a, Label: AsRef<str>> Window<'ui, 'a, Label> {
name,
opened: None,
flags: WindowFlags::empty(),
pos: [0.0, 0.0],
pos: [0.0, 0.0].into(),
pos_cond: Condition::Never,
pos_pivot: [0.0, 0.0],
size: [0.0, 0.0],
pos_pivot: [0.0, 0.0].into(),
size: [0.0, 0.0].into(),
size_cond: Condition::Never,
size_constraints: None,
content_size: [0.0, 0.0],
content_size: [0.0, 0.0].into(),
collapsed: false,
collapsed_cond: Condition::Never,
focused: false,
Expand All @@ -213,8 +214,8 @@ impl<'ui, 'a, Label: AsRef<str>> Window<'ui, 'a, Label> {
}
/// Sets the window position, which is applied based on the given condition value
#[inline]
pub fn position(mut self, position: [f32; 2], condition: Condition) -> Self {
self.pos = position;
pub fn position(mut self, position: impl Into<MintVec2>, condition: Condition) -> Self {
self.pos = position.into();
self.pos_cond = condition;
self
}
Expand All @@ -224,32 +225,36 @@ impl<'ui, 'a, Label: AsRef<str>> Window<'ui, 'a, Label> {
/// For example, pass [0.5, 0.5] to center the window on the position.
/// Does nothing if window position is not also set with `position()`.
#[inline]
pub fn position_pivot(mut self, pivot: [f32; 2]) -> Self {
self.pos_pivot = pivot;
pub fn position_pivot(mut self, pivot: impl Into<MintVec2>) -> Self {
self.pos_pivot = pivot.into();
self
}
/// Sets the window size, which is applied based on the given condition value
#[inline]
pub fn size(mut self, size: [f32; 2], condition: Condition) -> Self {
self.size = size;
pub fn size(mut self, size: impl Into<MintVec2>, condition: Condition) -> Self {
self.size = size.into();
self.size_cond = condition;
self
}
/// Sets window size constraints.
///
/// Use -1.0, -1.0 on either X or Y axis to preserve current size.
#[inline]
pub fn size_constraints(mut self, size_min: [f32; 2], size_max: [f32; 2]) -> Self {
self.size_constraints = Some((size_min, size_max));
pub fn size_constraints(
mut self,
size_min: impl Into<MintVec2>,
size_max: impl Into<MintVec2>,
) -> Self {
self.size_constraints = Some((size_min.into(), size_max.into()));
self
}
/// Sets the window content size, which can be used to enforce scrollbars.
///
/// Does not include window decorations (title bar, menu bar, etc.). Set one of the values to
/// 0.0 to leave the size automatic.
#[inline]
pub fn content_size(mut self, size: [f32; 2]) -> Self {
self.content_size = size;
pub fn content_size(mut self, size: impl Into<MintVec2>) -> Self {
self.content_size = size.into();
self
}
/// Sets the window collapse state, which is applied based on the given condition value
Expand Down Expand Up @@ -513,7 +518,7 @@ impl<'ui, 'a, Label: AsRef<str>> Window<'ui, 'a, Label> {
)
};
}
if self.content_size[0] != 0.0 || self.content_size[1] != 0.0 {
if self.content_size.x != 0.0 || self.content_size.y != 0.0 {
unsafe { sys::igSetNextWindowContentSize(self.content_size.into()) };
}
if self.collapsed_cond != Condition::Never {
Expand Down

0 comments on commit b23e048

Please sign in to comment.