From 86ee32273f09719278000f4151fac63ca9e00057 Mon Sep 17 00:00:00 2001 From: Joonas Javanainen Date: Fri, 12 Jul 2019 20:44:05 +0300 Subject: [PATCH] Add window scrolling API --- CHANGELOG.markdown | 4 +++ src/window/mod.rs | 1 + src/window/scroll.rs | 66 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 src/window/scroll.rs diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index 3043353..04dd3aa 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -2,6 +2,10 @@ ## [Unreleased] +### Added + +- Window scrolling API + ### Changed - Redesigned window API diff --git a/src/window/mod.rs b/src/window/mod.rs index 949aef6..11b93ed 100644 --- a/src/window/mod.rs +++ b/src/window/mod.rs @@ -8,6 +8,7 @@ use crate::sys; use crate::{Condition, Ui}; pub(crate) mod content_region; +pub(crate) mod scroll; bitflags! { /// Window hover check option flags diff --git a/src/window/scroll.rs b/src/window/scroll.rs new file mode 100644 index 0000000..8b48157 --- /dev/null +++ b/src/window/scroll.rs @@ -0,0 +1,66 @@ +use crate::sys; +use crate::Ui; + +/// # Window scrolling +impl<'ui> Ui<'ui> { + /// Returns the horizontal scrolling position. + /// + /// Value is between 0.0 and self.scroll_max_x(). + pub fn scroll_x(&self) -> f32 { + unsafe { sys::igGetScrollX() } + } + /// Returns the vertical scrolling position. + /// + /// Value is between 0.0 and self.scroll_max_y(). + pub fn scroll_y(&self) -> f32 { + unsafe { sys::igGetScrollY() } + } + /// Returns the maximum horizontal scrolling position. + /// + /// Roughly equal to content size X - window size X. + pub fn scroll_max_x(&self) -> f32 { + unsafe { sys::igGetScrollMaxX() } + } + /// Returns the maximum vertical scrolling position. + /// + /// Roughly equal to content size Y - window size Y. + pub fn scroll_max_y(&self) -> f32 { + unsafe { sys::igGetScrollMaxY() } + } + /// Set the horizontal scrolling position + pub fn set_scroll_x(&self, scroll_x: f32) { + unsafe { sys::igSetScrollX(scroll_x) }; + } + /// Set the vertical scroll position + pub fn set_scroll_y(&self, scroll_y: f32) { + unsafe { sys::igSetScrollY(scroll_y) }; + } + /// Adjust vertical scroll position to make the current cursor position visible + pub fn set_scroll_here_y(&self) { + unsafe { sys::igSetScrollHereY(0.5) }; + } + /// Adjust vertical scroll position to make the current cursor position visible. + /// + /// center_y_ratio: + /// + /// - `0.0`: top + /// - `0.5`: center + /// - `1.0`: bottom + pub fn set_scroll_here_y_with_ratio(&self, center_y_ratio: f32) { + unsafe { sys::igSetScrollHereY(center_y_ratio) }; + } + /// Adjust vertical scroll position to make the given position visible + pub fn set_scroll_from_pos_y(&self, local_y: f32) { + unsafe { sys::igSetScrollFromPosY(local_y, 0.5) }; + } + /// Adjust vertical scroll position to make the given position visible. + /// + /// center_y_ratio: + /// + /// - `0.0`: top + /// - `0.5`: center + /// - `1.0`: bottom + pub fn set_scroll_from_pos_y_with_ratio(&self, local_y: f32, center_y_ratio: f32) { + unsafe { sys::igSetScrollFromPosY(local_y, center_y_ratio) }; + } +}