mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-14 15:08:36 +00:00
Collapsing header + misc
This commit is contained in:
parent
90d777ce93
commit
43e72afe85
@ -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 {
|
||||
@ -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);
|
||||
})
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
25
src/lib.rs
25
src/lib.rs
@ -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")]
|
||||
@ -201,6 +203,7 @@ 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 {
|
||||
@ -208,6 +211,13 @@ impl<'fr> Frame<'fr> {
|
||||
}
|
||||
opened
|
||||
}
|
||||
pub fn show_metrics_window(&self) -> bool {
|
||||
let mut opened = true;
|
||||
unsafe {
|
||||
ffi::igShowMetricsWindow(&mut opened);
|
||||
}
|
||||
opened
|
||||
}
|
||||
}
|
||||
|
||||
// Window
|
||||
@ -215,6 +225,12 @@ 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>) {
|
||||
@ -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
|
||||
@ -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 {}
|
||||
|
||||
|
||||
56
src/widgets.rs
Normal file
56
src/widgets.rs
Normal file
@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user