use crate::window::WxWidget;
use wxdragon_sys as ffi;
pub trait WxScrollable: WxWidget {
fn show_position(&self, position: i64) {
let handle = self.handle_ptr();
if !handle.is_null() {
unsafe {
ffi::wxd_Window_ShowPosition(handle, position);
}
}
}
fn scroll_into_view(&self, position: i64, key_code: i32) {
let handle = self.handle_ptr();
if !handle.is_null() {
unsafe {
ffi::wxd_Window_ScrollIntoView(handle, position, key_code);
}
}
}
fn is_position_visible(&self, position: i64) -> bool {
let handle = self.handle_ptr();
if !handle.is_null() {
unsafe { ffi::wxd_Window_IsPositionVisible(handle, position) }
} else {
false
}
}
fn scroll_to_end(&self) {
let handle = self.handle_ptr();
if !handle.is_null() {
unsafe {
let last_pos = ffi::wxd_Window_GetLastPosition(handle);
if last_pos > 0 {
ffi::wxd_Window_ShowPosition(handle, last_pos);
}
}
}
}
fn scroll_to_beginning(&self) {
self.show_position(0);
}
fn auto_scroll_if_at_end(&self, threshold: i64) -> bool {
let handle = self.handle_ptr();
if handle.is_null() {
return false;
}
unsafe {
let last_pos = ffi::wxd_Window_GetLastPosition(handle);
if last_pos <= threshold {
return false; }
let near_end_pos = last_pos - threshold;
if ffi::wxd_Window_IsPositionVisible(handle, near_end_pos) {
ffi::wxd_Window_ShowPosition(handle, last_pos);
true
} else {
false }
}
}
}