Skip to content

Commit

Permalink
Collapsing header + misc
Browse files Browse the repository at this point in the history
  • Loading branch information
Gekkio committed Aug 20, 2015
1 parent 90d777c commit 43e72af
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 6 deletions.
25 changes: 25 additions & 0 deletions examples/test_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,25 @@ fn main() {
}
}

fn show_user_guide<'a>(frame: &Frame<'a>) {
frame.bullet_text(im_str!("Double-click on title bar to collapse window."));
frame.bullet_text(im_str!("Click and drag on lower right corner to resize window."));
frame.bullet_text(im_str!("Click and drag on any empty space to move window."));
frame.bullet_text(im_str!("Mouse Wheel to scroll."));
frame.bullet_text(im_str!("TAB/SHIFT+TAB to cycle through keyboard editable fields."));
frame.bullet_text(im_str!("CTRL+Click on a slider or drag box to input text."));
frame.bullet_text(im_str!(
"While editing text:
- Hold SHIFT or use mouse to select text
- CTRL+Left/Right to word jump
- CTRL+A or double-click to select all
- CTRL+X,CTRL+C,CTRL+V clipboard
- CTRL+Z,CTRL+Y undo/redo
- ESCAPE to revert
- You can apply arithmetic operators +,*,/ on numerical values.
Use +- to subtract."));
}

fn show_test_window<'a>(frame: &Frame<'a>, state: &mut State) -> bool {
if state.show_app_main_menu_bar { show_example_app_main_menu_bar(frame, state) }
if state.show_app_fixed_overlay {
Expand All @@ -101,6 +120,7 @@ fn show_test_window<'a>(frame: &Frame<'a>, state: &mut State) -> bool {
frame.separator();
frame.text(im_str!("By Omar Cornut and all github contributors."));
frame.text(im_str!("ImGui is licensed under the MIT License, see LICENSE for more information."));
show_user_guide(frame);
})
}

Expand Down Expand Up @@ -157,6 +177,11 @@ fn show_test_window<'a>(frame: &Frame<'a>, state: &mut State) -> bool {
}
});
});
frame.spacing();
if frame.collapsing_header(im_str!("Help")).build() {
frame.text_wrapped(im_str!("This window is being created by the show_test_window() function. Please refer to the code for programming reference.\n\nUser Guide:"));
show_user_guide(frame);
}
})
}

Expand Down
25 changes: 19 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ pub use ffi::{
ImVec2, ImVec4
};
pub use menus::{Menu, MenuItem};
pub use widgets::{CollapsingHeader};
pub use window::{Window};

pub mod ffi;
mod menus;
mod widgets;
mod window;

#[cfg(feature = "glium")]
Expand Down Expand Up @@ -201,20 +203,34 @@ impl<'fr> Frame<'fr> {
}
Ok(())
}
pub fn show_user_guide(&self) { unsafe { ffi::igShowUserGuide() }; }
pub fn show_test_window(&self) -> bool {
let mut opened = true;
unsafe {
ffi::igShowTestWindow(&mut opened);
}
opened
}
pub fn show_metrics_window(&self) -> bool {
let mut opened = true;
unsafe {
ffi::igShowMetricsWindow(&mut opened);
}
opened
}
}

// Window
impl<'fr> Frame<'fr> {
pub fn window<'p>(&self) -> Window<'fr, 'p> { Window::new() }
}

// Layout
impl<'fr> Frame<'fr> {
pub fn separator(&self) { unsafe { ffi:: igSeparator() }; }
pub fn spacing(&self) { unsafe { ffi::igSpacing() }; }
}

// Widgets
impl<'fr> Frame<'fr> {
pub fn text<'b>(&self, text: ImStr<'b>) {
Expand Down Expand Up @@ -253,6 +269,9 @@ impl<'fr> Frame<'fr> {
ffi::igBulletText(fmt_ptr(), text.as_ptr());
}
}
pub fn collapsing_header<'p>(&self, label: ImStr<'p>) -> CollapsingHeader<'fr, 'p> {
CollapsingHeader::new(label)
}
}

// Widgets: Menus
Expand All @@ -275,12 +294,6 @@ impl<'fr> Frame<'fr> {
pub fn menu_item<'p>(&self, label: ImStr<'p>) -> MenuItem<'fr, 'p> { MenuItem::new(label) }
}

impl<'fr> Frame<'fr> {
pub fn separator(&self) {
unsafe { ffi:: igSeparator() };
}
}

struct RenderDrawListsState(*mut ffi::ImDrawData);
unsafe impl Sync for RenderDrawListsState {}

Expand Down
56 changes: 56 additions & 0 deletions src/widgets.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use std::marker::PhantomData;
use std::ptr;

use super::ffi;
use super::{Frame, ImStr};

pub struct CollapsingHeader<'fr, 'p> {
label: ImStr<'p>,
str_id: Option<ImStr<'p>>,
display_frame: bool,
default_open: bool,
_phantom: PhantomData<&'fr Frame<'fr>>
}

impl<'fr, 'p> CollapsingHeader<'fr, 'p> {
pub fn new(label: ImStr<'p>) -> Self {
CollapsingHeader {
label: label,
str_id: None,
display_frame: true,
default_open: false,
_phantom: PhantomData
}
}
#[inline]
pub fn str_id(self, str_id: ImStr<'p>) -> Self {
CollapsingHeader {
str_id: Some(str_id),
.. self
}
}
#[inline]
pub fn display_frame(self, display_frame: bool) -> Self {
CollapsingHeader {
display_frame: display_frame,
.. self
}
}
#[inline]
pub fn default_open(self, default_open: bool) -> Self {
CollapsingHeader {
default_open: default_open,
.. self
}
}
pub fn build(self) -> bool {
unsafe {
ffi::igCollapsingHeader(
self.label.as_ptr(),
self.str_id.map(|x| x.as_ptr()).unwrap_or(ptr::null()),
self.display_frame,
self.default_open
)
}
}
}

0 comments on commit 43e72af

Please sign in to comment.