diff --git a/imgui-examples/examples/support_gfx/mod.rs b/imgui-examples/examples/support_gfx/mod.rs index ba7d9d0..82efb91 100644 --- a/imgui-examples/examples/support_gfx/mod.rs +++ b/imgui-examples/examples/support_gfx/mod.rs @@ -1,4 +1,4 @@ -use imgui::{FontGlyphRange, ImFontConfig, ImGui, ImVec4, Ui}; +use imgui::{FontGlyphRange, ImFontConfig, ImGui, Ui}; use imgui_gfx_renderer::{Renderer, Shaders}; use imgui_winit_support; use std::time::Instant; @@ -45,12 +45,12 @@ pub fn run bool>(title: String, clear_color: [f32; 4], mut run_ let mut imgui = ImGui::init(); { // Fix incorrect colors with sRGB framebuffer - fn imgui_gamma_to_linear(col: ImVec4) -> ImVec4 { - let x = col.x.powf(2.2); - let y = col.y.powf(2.2); - let z = col.z.powf(2.2); - let w = 1.0 - (1.0 - col.w).powf(2.2); - ImVec4::new(x, y, z, w) + fn imgui_gamma_to_linear(col: [f32; 4]) -> [f32; 4] { + let x = col[0].powf(2.2); + let y = col[1].powf(2.2); + let z = col[2].powf(2.2); + let w = 1.0 - (1.0 - col[3]).powf(2.2); + [x, y, z, w] } let style = imgui.style_mut(); diff --git a/imgui-glium-examples/examples/test_window_impl.rs b/imgui-glium-examples/examples/test_window_impl.rs index b08c24d..244310e 100644 --- a/imgui-glium-examples/examples/test_window_impl.rs +++ b/imgui-glium-examples/examples/test_window_impl.rs @@ -656,7 +656,7 @@ CTRL+click on individual component to input value.\n", ui.popup_modal(im_str!("Delete?")).always_auto_resize(true).build(|| { ui.text("All those beautiful files will be deleted.\nThis operation cannot be undone!\n\n"); ui.separator(); - ui.with_style_var(StyleVar::FramePadding(ImVec2::new(0.0, 0.0)), || { + ui.with_style_var(StyleVar::FramePadding([0.0, 0.0]), || { ui.checkbox(im_str!("Don't ask me next time"), &mut state.dont_ask_me_next_time); if ui.button(im_str!("OK"), (120.0, 0.0)) { @@ -675,7 +675,7 @@ CTRL+click on individual component to input value.\n", ui.popup_modal(im_str!("Stacked 1")).build(|| { ui.text( "Hello from Stacked The First\n\ - Using style.Colors[ImGuiCol_ModalWindowDarkening] for darkening." + Using style[StyleColor::ModalWindowDarkening] for darkening." ); let items = &[im_str!("aaaa"), im_str!("bbbb"), im_str!("cccc"), im_str!("dddd"), im_str!("eeee")]; @@ -773,8 +773,8 @@ fn show_example_menu_file<'a>(ui: &Ui<'a>, state: &mut FileMenuState) { ui.checkbox(im_str!("Check"), &mut state.b); }); ui.menu(im_str!("Colors")).build(|| { - for &col in ImGuiCol::VARIANTS.iter() { - ui.menu_item(imgui::get_style_color_name(col)).build(); + for &col in StyleColor::VARIANTS.iter() { + ui.menu_item(im_str!("{:?}", col)).build(); } }); ui.menu(im_str!("Disabled")).enabled(false).build(|| { @@ -807,7 +807,7 @@ output your content because that would create a feedback loop.", fn show_example_app_fixed_overlay(ui: &Ui, opened: &mut bool) { const DISTANCE: f32 = 10.0; let window_pos = (DISTANCE, DISTANCE); - ui.with_color_var(ImGuiCol::WindowBg, (0.0, 0.0, 0.0, 0.3), || { + ui.with_color_var(StyleColor::WindowBg, [0.0, 0.0, 0.0, 0.3], || { ui.window(im_str!("Example: Fixed Overlay")) .opened(opened) .position(window_pos, Condition::Always) diff --git a/imgui-sys/src/enums.rs b/imgui-sys/src/enums.rs index 65c72d1..36eee3a 100644 --- a/imgui-sys/src/enums.rs +++ b/imgui-sys/src/enums.rs @@ -1,109 +1,3 @@ -/// A color identifier for styling -#[repr(C)] -#[derive(Copy, Clone, Debug, PartialEq, Eq)] -pub enum ImGuiCol { - Text, - TextDisabled, - /// Background of normal windows - WindowBg, - /// Background of child windows - ChildBg, - /// Background of popups, menus, tooltips windows - PopupBg, - Border, - BorderShadow, - /// Background of checkbox, radio button, plot, slider, text input - FrameBg, - FrameBgHovered, - FrameBgActive, - TitleBg, - TitleBgActive, - TitleBgCollapsed, - MenuBarBg, - ScrollbarBg, - ScrollbarGrab, - ScrollbarGrabHovered, - ScrollbarGrabActive, - CheckMark, - SliderGrab, - SliderGrabActive, - Button, - ButtonHovered, - ButtonActive, - Header, - HeaderHovered, - HeaderActive, - Separator, - SeparatorHovered, - SeparatorActive, - ResizeGrip, - ResizeGripHovered, - ResizeGripActive, - PlotLines, - PlotLinesHovered, - PlotHistogram, - PlotHistogramHovered, - TextSelectedBg, - DragDropTarget, - /// Gamepad/keyboard: current highlighted item - NavHighlight, - /// Highlight window when using CTRL+TAB - NavWindowingHighlight, - /// Darken/colorize entire screen behind the CTRL+TAB window list, when active - NavWindowingDimBg, - /// Darken/colorize entire screen behind a modal window, when one is active - ModalWindowDimBg, -} -impl ImGuiCol { - /// All possible `ImGuiCol` variants - pub const VARIANTS: [ImGuiCol; 43] = [ - ImGuiCol::Text, - ImGuiCol::TextDisabled, - ImGuiCol::WindowBg, - ImGuiCol::ChildBg, - ImGuiCol::PopupBg, - ImGuiCol::Border, - ImGuiCol::BorderShadow, - ImGuiCol::FrameBg, - ImGuiCol::FrameBgHovered, - ImGuiCol::FrameBgActive, - ImGuiCol::TitleBg, - ImGuiCol::TitleBgActive, - ImGuiCol::TitleBgCollapsed, - ImGuiCol::MenuBarBg, - ImGuiCol::ScrollbarBg, - ImGuiCol::ScrollbarGrab, - ImGuiCol::ScrollbarGrabHovered, - ImGuiCol::ScrollbarGrabActive, - ImGuiCol::CheckMark, - ImGuiCol::SliderGrab, - ImGuiCol::SliderGrabActive, - ImGuiCol::Button, - ImGuiCol::ButtonHovered, - ImGuiCol::ButtonActive, - ImGuiCol::Header, - ImGuiCol::HeaderHovered, - ImGuiCol::HeaderActive, - ImGuiCol::Separator, - ImGuiCol::SeparatorHovered, - ImGuiCol::SeparatorActive, - ImGuiCol::ResizeGrip, - ImGuiCol::ResizeGripHovered, - ImGuiCol::ResizeGripActive, - ImGuiCol::PlotLines, - ImGuiCol::PlotLinesHovered, - ImGuiCol::PlotHistogram, - ImGuiCol::PlotHistogramHovered, - ImGuiCol::TextSelectedBg, - ImGuiCol::DragDropTarget, - ImGuiCol::NavHighlight, - ImGuiCol::NavWindowingHighlight, - ImGuiCol::NavWindowingDimBg, - ImGuiCol::ModalWindowDimBg, - ]; - pub const COUNT: usize = 43; -} - /// A primary data type #[repr(C)] #[derive(Copy, Clone, Debug, PartialEq, Eq)] @@ -133,27 +27,6 @@ impl ImGuiDataType { ]; } -/// A cardinal direction -#[repr(C)] -#[derive(Copy, Clone, Debug, PartialEq, Eq)] -pub enum ImGuiDir { - None = -1, - Left = 0, - Right, - Up, - Down, -} -impl ImGuiDir { - /// All possible `ImGuiDir` variants, except None - pub const VARIANTS: [ImGuiDir; 4] = [ - // None variant intentionally skipped - ImGuiDir::Left, - ImGuiDir::Right, - ImGuiDir::Up, - ImGuiDir::Down, - ]; -} - /// A key identifier (ImGui-side enum) #[repr(C)] #[derive(Copy, Clone, Debug, PartialEq, Eq)] @@ -345,55 +218,3 @@ impl ImGuiNavInput { pub const COUNT: usize = 16; pub(crate) const COUNT_INTERNAL: usize = 21; } - -/// A variable identifier for styling -#[repr(C)] -#[derive(Copy, Clone, Debug, PartialEq, Eq)] -pub enum ImGuiStyleVar { - Alpha, - WindowPadding, - WindowRounding, - WindowBorderSize, - WindowMinSize, - WindowTitleAlign, - ChildRounding, - ChildBorderSize, - PopupRounding, - PopupBorderSize, - FramePadding, - FrameRounding, - FrameBorderSize, - ItemSpacing, - ItemInnerSpacing, - IndentSpacing, - ScrollbarSize, - ScrollbarRounding, - GrabMinSize, - GrabRounding, - ButtonTextAlign, -} -impl ImGuiStyleVar { - pub const VARIANTS: [ImGuiStyleVar; 21] = [ - ImGuiStyleVar::Alpha, - ImGuiStyleVar::WindowPadding, - ImGuiStyleVar::WindowRounding, - ImGuiStyleVar::WindowBorderSize, - ImGuiStyleVar::WindowMinSize, - ImGuiStyleVar::WindowTitleAlign, - ImGuiStyleVar::ChildRounding, - ImGuiStyleVar::ChildBorderSize, - ImGuiStyleVar::PopupRounding, - ImGuiStyleVar::PopupBorderSize, - ImGuiStyleVar::FramePadding, - ImGuiStyleVar::FrameRounding, - ImGuiStyleVar::FrameBorderSize, - ImGuiStyleVar::ItemSpacing, - ImGuiStyleVar::ItemInnerSpacing, - ImGuiStyleVar::IndentSpacing, - ImGuiStyleVar::ScrollbarSize, - ImGuiStyleVar::ScrollbarRounding, - ImGuiStyleVar::GrabMinSize, - ImGuiStyleVar::GrabRounding, - ImGuiStyleVar::ButtonTextAlign, - ]; -} diff --git a/imgui-sys/src/legacy.rs b/imgui-sys/src/legacy.rs index ee50b9d..2a5df39 100644 --- a/imgui-sys/src/legacy.rs +++ b/imgui-sys/src/legacy.rs @@ -123,8 +123,6 @@ extern "C" { pub fn igPushStyleColorU32(idx: ImGuiCol, col: ImU32); pub fn igPushStyleColor(idx: ImGuiCol, col: ImVec4); pub fn igPopStyleColor(count: c_int); - pub fn igPushStyleVarFloat(idx: ImGuiStyleVar, val: c_float); - pub fn igPushStyleVarVec2(idx: ImGuiStyleVar, val: ImVec2); pub fn igPopStyleVar(count: c_int); pub fn igGetStyleColorVec4(idx: ImGuiCol) -> *const ImVec4; pub fn igGetFont() -> *mut ImFont; diff --git a/imgui-sys/src/lib.rs b/imgui-sys/src/lib.rs index 193cef3..e79e4c7 100644 --- a/imgui-sys/src/lib.rs +++ b/imgui-sys/src/lib.rs @@ -4,26 +4,24 @@ use std::convert::From; pub use self::enums::*; pub use self::flags::*; -pub use self::structs::*; mod bindings; mod enums; mod flags; mod legacy; -mod structs; pub use bindings::{ - igGetIO, CustomRect, ImDrawCallback, ImDrawChannel, ImDrawCmd, ImDrawData, ImDrawData_Clear, - ImDrawData_DeIndexAllBuffers, ImDrawData_ScaleClipRects, ImDrawIdx, ImDrawList, - ImDrawListSharedData, ImDrawListSplitter, ImDrawList_AddBezierCurve, ImDrawList_AddCallback, - ImDrawList_AddCircle, ImDrawList_AddCircleFilled, ImDrawList_AddConvexPolyFilled, - ImDrawList_AddDrawCmd, ImDrawList_AddImage, ImDrawList_AddImageQuad, - ImDrawList_AddImageRounded, ImDrawList_AddLine, ImDrawList_AddPolyline, ImDrawList_AddQuad, - ImDrawList_AddQuadFilled, ImDrawList_AddRect, ImDrawList_AddRectFilled, - ImDrawList_AddRectFilledMultiColor, ImDrawList_AddText, ImDrawList_AddTextFontPtr, - ImDrawList_AddTriangle, ImDrawList_AddTriangleFilled, ImDrawList_ChannelsMerge, - ImDrawList_ChannelsSetCurrent, ImDrawList_ChannelsSplit, ImDrawList_Clear, - ImDrawList_ClearFreeMemory, ImDrawList_CloneOutput, ImDrawList_ImDrawList, + igGetIO, igPushStyleVarFloat, igPushStyleVarVec2, CustomRect, ImDrawCallback, ImDrawChannel, + ImDrawCmd, ImDrawData, ImDrawData_Clear, ImDrawData_DeIndexAllBuffers, + ImDrawData_ScaleClipRects, ImDrawIdx, ImDrawList, ImDrawListSharedData, ImDrawListSplitter, + ImDrawList_AddBezierCurve, ImDrawList_AddCallback, ImDrawList_AddCircle, + ImDrawList_AddCircleFilled, ImDrawList_AddConvexPolyFilled, ImDrawList_AddDrawCmd, + ImDrawList_AddImage, ImDrawList_AddImageQuad, ImDrawList_AddImageRounded, ImDrawList_AddLine, + ImDrawList_AddPolyline, ImDrawList_AddQuad, ImDrawList_AddQuadFilled, ImDrawList_AddRect, + ImDrawList_AddRectFilled, ImDrawList_AddRectFilledMultiColor, ImDrawList_AddText, + ImDrawList_AddTextFontPtr, ImDrawList_AddTriangle, ImDrawList_AddTriangleFilled, + ImDrawList_ChannelsMerge, ImDrawList_ChannelsSetCurrent, ImDrawList_ChannelsSplit, + ImDrawList_Clear, ImDrawList_ClearFreeMemory, ImDrawList_CloneOutput, ImDrawList_ImDrawList, ImDrawList_PathArcTo, ImDrawList_PathArcToFast, ImDrawList_PathBezierCurveTo, ImDrawList_PathClear, ImDrawList_PathFillConvex, ImDrawList_PathLineTo, ImDrawList_PathLineToMergeDuplicate, ImDrawList_PathRect, ImDrawList_PathStroke, @@ -37,15 +35,39 @@ pub use bindings::{ ImFontAtlas_GetGlyphRangesDefault, ImFontAtlas_GetGlyphRangesJapanese, ImFontAtlas_GetGlyphRangesKorean, ImFontAtlas_GetGlyphRangesThai, ImFontAtlas_GetGlyphRangesVietnamese, ImFontAtlas_GetTexDataAsRGBA32, ImFontConfig, - ImFontGlyphRangesBuilder, ImGuiCond, ImGuiCond_, ImGuiCond_Always, ImGuiCond_Appearing, - ImGuiCond_FirstUseEver, ImGuiCond_Once, ImGuiContext, ImGuiID, ImGuiIO, - ImGuiIO_AddInputCharacter, ImGuiIO_AddInputCharactersUTF8, ImGuiIO_ClearInputCharacters, - ImGuiInputTextCallback, ImGuiInputTextCallbackData, ImGuiInputTextCallbackData_DeleteChars, + ImFontGlyphRangesBuilder, ImGuiCol, ImGuiCol_, ImGuiCol_Border, ImGuiCol_BorderShadow, + ImGuiCol_Button, ImGuiCol_ButtonActive, ImGuiCol_ButtonHovered, ImGuiCol_COUNT, + ImGuiCol_CheckMark, ImGuiCol_ChildBg, ImGuiCol_DragDropTarget, ImGuiCol_FrameBg, + ImGuiCol_FrameBgActive, ImGuiCol_FrameBgHovered, ImGuiCol_Header, ImGuiCol_HeaderActive, + ImGuiCol_HeaderHovered, ImGuiCol_MenuBarBg, ImGuiCol_ModalWindowDimBg, ImGuiCol_NavHighlight, + ImGuiCol_NavWindowingDimBg, ImGuiCol_NavWindowingHighlight, ImGuiCol_PlotHistogram, + ImGuiCol_PlotHistogramHovered, ImGuiCol_PlotLines, ImGuiCol_PlotLinesHovered, ImGuiCol_PopupBg, + ImGuiCol_ResizeGrip, ImGuiCol_ResizeGripActive, ImGuiCol_ResizeGripHovered, + ImGuiCol_ScrollbarBg, ImGuiCol_ScrollbarGrab, ImGuiCol_ScrollbarGrabActive, + ImGuiCol_ScrollbarGrabHovered, ImGuiCol_Separator, ImGuiCol_SeparatorActive, + ImGuiCol_SeparatorHovered, ImGuiCol_SliderGrab, ImGuiCol_SliderGrabActive, ImGuiCol_Tab, + ImGuiCol_TabActive, ImGuiCol_TabHovered, ImGuiCol_TabUnfocused, ImGuiCol_TabUnfocusedActive, + ImGuiCol_Text, ImGuiCol_TextDisabled, ImGuiCol_TextSelectedBg, ImGuiCol_TitleBg, + ImGuiCol_TitleBgActive, ImGuiCol_TitleBgCollapsed, ImGuiCol_WindowBg, ImGuiCond, ImGuiCond_, + ImGuiCond_Always, ImGuiCond_Appearing, ImGuiCond_FirstUseEver, ImGuiCond_Once, ImGuiContext, + ImGuiDir, ImGuiDir_, ImGuiDir_COUNT, ImGuiDir_Down, ImGuiDir_Left, ImGuiDir_None, + ImGuiDir_Right, ImGuiDir_Up, ImGuiID, ImGuiIO, ImGuiIO_AddInputCharacter, + ImGuiIO_AddInputCharactersUTF8, ImGuiIO_ClearInputCharacters, ImGuiInputTextCallback, + ImGuiInputTextCallbackData, ImGuiInputTextCallbackData_DeleteChars, ImGuiInputTextCallbackData_HasSelection, ImGuiInputTextCallbackData_ImGuiInputTextCallbackData, ImGuiInputTextCallbackData_InsertChars, ImGuiInputTextCallbackData_destroy, ImGuiListClipper, - ImGuiPayload, ImGuiSizeCallback, ImGuiStorage, ImGuiTextBuffer, ImGuiTextFilter, ImTextureID, - ImU32, ImVec2, ImVec2_Simple, ImVec4, ImVec4_Simple, ImVector_ImFontPtr, ImVector_ImWchar, - ImVector_char, ImWchar, + ImGuiPayload, ImGuiSizeCallback, ImGuiStorage, ImGuiStyle, ImGuiStyleVar, ImGuiStyleVar_, + ImGuiStyleVar_Alpha, ImGuiStyleVar_ButtonTextAlign, ImGuiStyleVar_COUNT, + ImGuiStyleVar_ChildBorderSize, ImGuiStyleVar_ChildRounding, ImGuiStyleVar_FrameBorderSize, + ImGuiStyleVar_FramePadding, ImGuiStyleVar_FrameRounding, ImGuiStyleVar_GrabMinSize, + ImGuiStyleVar_GrabRounding, ImGuiStyleVar_IndentSpacing, ImGuiStyleVar_ItemInnerSpacing, + ImGuiStyleVar_ItemSpacing, ImGuiStyleVar_PopupBorderSize, ImGuiStyleVar_PopupRounding, + ImGuiStyleVar_ScrollbarRounding, ImGuiStyleVar_ScrollbarSize, + ImGuiStyleVar_SelectableTextAlign, ImGuiStyleVar_TabRounding, ImGuiStyleVar_WindowBorderSize, + ImGuiStyleVar_WindowMinSize, ImGuiStyleVar_WindowPadding, ImGuiStyleVar_WindowRounding, + ImGuiStyleVar_WindowTitleAlign, ImGuiStyle_ScaleAllSizes, ImGuiTextBuffer, ImGuiTextFilter, + ImTextureID, ImU32, ImVec2, ImVec2_Simple, ImVec4, ImVec4_Simple, ImVector_ImFontPtr, + ImVector_ImWchar, ImVector_char, ImWchar, }; pub use legacy::*; diff --git a/imgui-sys/src/structs.rs b/imgui-sys/src/structs.rs deleted file mode 100644 index c731333..0000000 --- a/imgui-sys/src/structs.rs +++ /dev/null @@ -1,96 +0,0 @@ -use std::os::raw::c_float; - -use crate::enums::{ImGuiCol, ImGuiDir}; -use crate::{ImVec2, ImVec4}; - -/// Runtime data for styling/colors -#[repr(C)] -#[derive(Clone)] -pub struct ImGuiStyle { - /// Global alpha applies to everything in ImGui. - pub alpha: c_float, - /// Padding within a window. - pub window_padding: ImVec2, - /// Radius of window corners rounding. Set to 0.0 to have rectangular windows. - pub window_rounding: c_float, - /// Thickness of border around windows. Generally set to 0.0 or 1.0. (Other values are not well - /// tested and more CPU/GPU costly). - pub window_border_size: c_float, - /// Minimum window size. This is a global setting. If you want to constraint individual - /// windows, use igSetNextWindowSizeConstraints(). - pub window_min_size: ImVec2, - /// Alignment for title bar text. Defaults to (0.0, 0.5) for left-aligned, vertically centered. - pub window_title_align: ImVec2, - pub window_menu_button_position: ImGuiDir, - /// Radius of child window corners rounding. Set to 0.0 to have rectangular windows. - pub child_rounding: c_float, - /// Thickness of border around child windows. Generally set to 0.0 or 1.0. (Other values are - /// not well tested and more CPU/GPU costly). - pub child_border_size: c_float, - /// Radius of popup window corners rounding. (Note that tooltip windows use window_rounding) - pub popup_rounding: c_float, - /// Thickness of border around popup/tooltip windows. Generally set to 0.0 or 1.0. (Other - /// values are not well tested and more CPU/GPU costly). - pub popup_border_size: c_float, - /// Padding within a framed rectangle (used by most widgets). - pub frame_padding: ImVec2, - /// Radius of frame corners rounding. Set to 0.0 to have rectangular frame (used by most - /// widgets). - pub frame_rounding: c_float, - /// Thickness of border around frames. Generally set to 0.0 or 1.0. (Other values are not well - /// tested and more CPU/GPU costly). - pub frame_border_size: c_float, - /// Horizontal and vertical spacing between widgets/lines. - pub item_spacing: ImVec2, - /// Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider - /// and its label). - pub item_inner_spacing: ImVec2, - /// Expand reactive bounding box for touch-based system where touch position is not accurate - /// enough. Unfortunately we don't sort widgets so priority on overlap will always be given to - /// the first widget. So don't grow this too much! - pub touch_extra_padding: ImVec2, - /// Horizontal indentation when e.g. entering a tree node. Generally == (FontSize + - /// FramePadding.x*2). - pub indent_spacing: c_float, - /// Minimum horizontal spacing between two columns. - pub columns_min_spacing: c_float, - /// Width of the vertical scrollbar, Height of the horizontal scrollbar. - pub scrollbar_size: c_float, - /// Radius of grab corners for scrollbar. - pub scrollbar_rounding: c_float, - /// Minimum width/height of a grab box for slider/scrollbar. - pub grab_min_size: c_float, - /// Radius of grabs corners rounding. Set to 0.0 to have rectangular slider grabs. - pub grab_rounding: c_float, - pub tab_rounding: c_float, - pub tab_border_size: c_float, - /// Alignment of button text when button is larger than text. Defaults to (0.5, 0.5) for - /// horizontally+vertically centered. - pub button_text_align: ImVec2, - pub selectable_text_align: ImVec2, - /// Window position are clamped to be visible within the display area by at least this amount. - /// Only applies to regular windows. - pub display_window_padding: ImVec2, - /// If you cannot see the edges of your screen (e.g. on a TV) increase the safe area padding. - /// Apply to popups/tooltips as well regular windows. NB: Prefer configuring your TV sets - /// correctly! - pub display_safe_area_padding: ImVec2, - /// Scale software rendered mouse cursor (when io.mouse_draw_cursor is enabled). May be removed - /// later. - pub mouse_cursor_scale: c_float, - /// Enable anti-aliasing on lines/borders. Disable if you are really tight on CPU/GPU. - pub anti_aliased_lines: bool, - /// Enable anti-aliasing on filled shapes (rounded rectangles, circles, etc.) - pub anti_aliased_fill: bool, - /// Tessellation tolerance when using igPathBezierCurveTo() without a specific number of - /// segments. Decrease for highly tessellated curves (higher quality, more polygons), increase - /// to reduce quality. - pub curve_tessellation_tol: c_float, - /// Colors for the user interface - pub colors: [ImVec4; ImGuiCol::COUNT], -} - -// ImGuiStyle -extern "C" { - pub fn ImGuiStyle_ScaleAllSizes(this: *mut ImGuiStyle, scale_factor: c_float); -} diff --git a/src/internal.rs b/src/internal.rs index 01dfec1..4926f05 100644 --- a/src/internal.rs +++ b/src/internal.rs @@ -37,3 +37,29 @@ fn test_imvector_memory_layout() { assert_field_offset!(capacity, Capacity); assert_field_offset!(data, Data); } + +/// Marks a type as a transparent wrapper over a raw type +pub trait RawWrapper { + /// Wrapped raw type + type Raw; + /// Returns an immutable reference to the wrapped raw value + unsafe fn raw(&self) -> &Self::Raw; + /// Returns a mutable reference to the wrapped raw value + unsafe fn raw_mut(&mut self) -> &mut Self::Raw; +} + +/// Casting from/to a raw type that has the same layout and alignment as the target type +pub unsafe trait RawCast: Sized { + unsafe fn from_raw(raw: &T) -> &Self { + &*(raw as *const _ as *const Self) + } + unsafe fn from_raw_mut(raw: &mut T) -> &mut Self { + &mut *(raw as *mut _ as *mut Self) + } + unsafe fn raw(&self) -> &T { + &*(self as *const _ as *const T) + } + unsafe fn raw_mut(&mut self) -> &mut T { + &mut *(self as *mut _ as *mut T) + } +} diff --git a/src/lib.rs b/src/lib.rs index 8a8635c..064a1af 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,6 @@ use std::ptr; use std::slice; use std::str; use std::thread; -use sys::ImGuiStyleVar; pub use self::child_frame::ChildFrame; pub use self::color_editors::{ @@ -34,15 +33,16 @@ pub use self::sliders::{ SliderInt4, }; pub use self::string::{ImStr, ImString}; -pub use self::style::StyleVar; +pub use self::style::*; pub use self::sys::{ - ImDrawIdx, ImDrawVert, ImGuiCol, ImGuiColorEditFlags, ImGuiFocusedFlags, ImGuiHoveredFlags, - ImGuiInputTextFlags, ImGuiKey, ImGuiMouseCursor, ImGuiSelectableFlags, ImGuiStyle, - ImGuiTreeNodeFlags, ImGuiWindowFlags, ImVec2, ImVec4, + ImDrawIdx, ImDrawVert, ImGuiColorEditFlags, ImGuiFocusedFlags, ImGuiHoveredFlags, + ImGuiInputTextFlags, ImGuiKey, ImGuiMouseCursor, ImGuiSelectableFlags, ImGuiTreeNodeFlags, + ImGuiWindowFlags, ImVec2, ImVec4, }; pub use self::trees::{CollapsingHeader, TreeNode}; pub use self::window::Window; pub use self::window_draw_list::{ChannelsSplit, ImColor, WindowDrawList}; +use internal::RawCast; mod child_frame; mod color_editors; @@ -91,13 +91,6 @@ pub struct TextureHandle<'a> { pub pixels: &'a [c_uchar], } -pub fn get_style_color_name(color: ImGuiCol) -> &'static ImStr { - unsafe { - let bytes = CStr::from_ptr(sys::igGetStyleColorName(color)).to_bytes_with_nul(); - ImStr::from_utf8_with_nul_unchecked(bytes) - } -} - pub fn get_version() -> &'static str { unsafe { let bytes = CStr::from_ptr(sys::igGetVersion()).to_bytes(); @@ -146,11 +139,11 @@ impl ImGui { fn io_mut(&mut self) -> &mut sys::ImGuiIO { unsafe { &mut *sys::igGetIO() } } - pub fn style(&self) -> &ImGuiStyle { - unsafe { &*sys::igGetStyle() } + pub fn style(&self) -> &Style { + unsafe { Style::from_raw(&*sys::igGetStyle()) } } - pub fn style_mut(&mut self) -> &mut ImGuiStyle { - unsafe { &mut *sys::igGetStyle() } + pub fn style_mut(&mut self) -> &mut Style { + unsafe { Style::from_raw_mut(&mut *sys::igGetStyle()) } } pub fn fonts(&mut self) -> ImFontAtlas { unsafe { ImFontAtlas::from_ptr(self.io_mut().Fonts) } @@ -582,9 +575,9 @@ impl<'ui> Ui<'ui> { pub fn show_default_style_editor(&self) { unsafe { sys::igShowStyleEditor(ptr::null_mut()) }; } - pub fn show_style_editor<'p>(&self, style: &'p mut ImGuiStyle) { + pub fn show_style_editor<'p>(&self, style: &'p mut Style) { unsafe { - sys::igShowStyleEditor(style as *mut ImGuiStyle); + sys::igShowStyleEditor(style.raw_mut()); } } pub fn show_demo_window(&self, opened: &mut bool) { @@ -1502,7 +1495,7 @@ impl<'ui> Ui<'ui> { /// # use imgui::*; /// # let mut imgui = ImGui::init(); /// # let ui = imgui.frame(FrameSize::new(100.0, 100.0, 1.0), 0.1); - /// # let styles = [StyleVar::Alpha(0.2), StyleVar::WindowPadding(ImVec2::new(1.0, 1.0))]; + /// # let styles = [StyleVar::Alpha(0.2), StyleVar::WindowPadding([1.0, 1.0])]; /// ui.with_style_vars(&styles, || { /// ui.text(im_str!("A")); /// ui.text(im_str!("B")); @@ -1520,30 +1513,76 @@ impl<'ui> Ui<'ui> { #[inline] fn push_style_var(&self, style_var: StyleVar) { - use self::StyleVar::*; - use sys::{igPushStyleVarFloat, igPushStyleVarVec2}; + use crate::style::StyleVar::*; + use crate::sys::{igPushStyleVarFloat, igPushStyleVarVec2}; match style_var { - Alpha(v) => unsafe { igPushStyleVarFloat(ImGuiStyleVar::Alpha, v) }, - WindowPadding(v) => unsafe { igPushStyleVarVec2(ImGuiStyleVar::WindowPadding, v) }, - WindowRounding(v) => unsafe { igPushStyleVarFloat(ImGuiStyleVar::WindowRounding, v) }, + Alpha(v) => unsafe { igPushStyleVarFloat(sys::ImGuiStyleVar_Alpha as i32, v) }, + WindowPadding(v) => unsafe { + igPushStyleVarVec2(sys::ImGuiStyleVar_WindowPadding as i32, v.into()) + }, + WindowRounding(v) => unsafe { + igPushStyleVarFloat(sys::ImGuiStyleVar_WindowRounding as i32, v) + }, WindowBorderSize(v) => unsafe { - igPushStyleVarFloat(ImGuiStyleVar::WindowBorderSize, v) + igPushStyleVarFloat(sys::ImGuiStyleVar_WindowBorderSize as i32, v) + }, + WindowMinSize(v) => unsafe { + igPushStyleVarVec2(sys::ImGuiStyleVar_WindowMinSize as i32, v.into()) + }, + WindowTitleAlign(v) => unsafe { + igPushStyleVarVec2(sys::ImGuiStyleVar_WindowTitleAlign as i32, v.into()) + }, + ChildRounding(v) => unsafe { + igPushStyleVarFloat(sys::ImGuiStyleVar_ChildRounding as i32, v) + }, + ChildBorderSize(v) => unsafe { + igPushStyleVarFloat(sys::ImGuiStyleVar_ChildBorderSize as i32, v) + }, + PopupRounding(v) => unsafe { + igPushStyleVarFloat(sys::ImGuiStyleVar_PopupRounding as i32, v) + }, + PopupBorderSize(v) => unsafe { + igPushStyleVarFloat(sys::ImGuiStyleVar_PopupBorderSize as i32, v) + }, + FramePadding(v) => unsafe { + igPushStyleVarVec2(sys::ImGuiStyleVar_FramePadding as i32, v.into()) + }, + FrameRounding(v) => unsafe { + igPushStyleVarFloat(sys::ImGuiStyleVar_FrameRounding as i32, v) + }, + FrameBorderSize(v) => unsafe { + igPushStyleVarFloat(sys::ImGuiStyleVar_FrameBorderSize as i32, v) + }, + ItemSpacing(v) => unsafe { + igPushStyleVarVec2(sys::ImGuiStyleVar_ItemSpacing as i32, v.into()) }, - WindowMinSize(v) => unsafe { igPushStyleVarVec2(ImGuiStyleVar::WindowMinSize, v) }, - ChildRounding(v) => unsafe { igPushStyleVarFloat(ImGuiStyleVar::ChildRounding, v) }, - ChildBorderSize(v) => unsafe { igPushStyleVarFloat(ImGuiStyleVar::ChildBorderSize, v) }, - PopupRounding(v) => unsafe { igPushStyleVarFloat(ImGuiStyleVar::PopupRounding, v) }, - PopupBorderSize(v) => unsafe { igPushStyleVarFloat(ImGuiStyleVar::PopupBorderSize, v) }, - FramePadding(v) => unsafe { igPushStyleVarVec2(ImGuiStyleVar::FramePadding, v) }, - FrameRounding(v) => unsafe { igPushStyleVarFloat(ImGuiStyleVar::FrameRounding, v) }, - FrameBorderSize(v) => unsafe { igPushStyleVarFloat(ImGuiStyleVar::FrameBorderSize, v) }, - ItemSpacing(v) => unsafe { igPushStyleVarVec2(ImGuiStyleVar::ItemSpacing, v) }, ItemInnerSpacing(v) => unsafe { - igPushStyleVarVec2(ImGuiStyleVar::ItemInnerSpacing, v) + igPushStyleVarVec2(sys::ImGuiStyleVar_ItemInnerSpacing as i32, v.into()) + }, + IndentSpacing(v) => unsafe { + igPushStyleVarFloat(sys::ImGuiStyleVar_IndentSpacing as i32, v) + }, + ScrollbarSize(v) => unsafe { + igPushStyleVarFloat(sys::ImGuiStyleVar_ScrollbarSize as i32, v) + }, + ScrollbarRounding(v) => unsafe { + igPushStyleVarFloat(sys::ImGuiStyleVar_ScrollbarRounding as i32, v) + }, + GrabMinSize(v) => unsafe { + igPushStyleVarFloat(sys::ImGuiStyleVar_GrabMinSize as i32, v) + }, + GrabRounding(v) => unsafe { + igPushStyleVarFloat(sys::ImGuiStyleVar_GrabRounding as i32, v) + }, + TabRounding(v) => unsafe { + igPushStyleVarFloat(sys::ImGuiStyleVar_TabRounding as i32, v) + }, + ButtonTextAlign(v) => unsafe { + igPushStyleVarVec2(sys::ImGuiStyleVar_ButtonTextAlign as i32, v.into()) + }, + SelectableTextAlign(v) => unsafe { + igPushStyleVarVec2(sys::ImGuiStyleVar_SelectableTextAlign as i32, v.into()) }, - IndentSpacing(v) => unsafe { igPushStyleVarFloat(ImGuiStyleVar::IndentSpacing, v) }, - GrabMinSize(v) => unsafe { igPushStyleVarFloat(ImGuiStyleVar::GrabMinSize, v) }, - ButtonTextAlign(v) => unsafe { igPushStyleVarVec2(ImGuiStyleVar::ButtonTextAlign, v) }, } } } @@ -1556,18 +1595,18 @@ impl<'ui> Ui<'ui> { /// # use imgui::*; /// # let mut imgui = ImGui::init(); /// # let ui = imgui.frame(FrameSize::new(100.0, 100.0, 1.0), 0.1); - /// ui.with_color_var(ImGuiCol::Text, (1.0, 0.0, 0.0, 1.0), || { + /// ui.with_color_var(StyleColor::Text, [1.0, 0.0, 0.0, 1.0], || { /// ui.text_wrapped(im_str!("AB")); /// }); /// ``` pub fn with_color_var + Copy>( &self, - var: ImGuiCol, + var: StyleColor, color: C, f: F, ) { unsafe { - sys::igPushStyleColor(var, color.into()); + sys::igPushStyleColor(var as _, color.into()); } f(); unsafe { @@ -1582,21 +1621,21 @@ impl<'ui> Ui<'ui> { /// # use imgui::*; /// # let mut imgui = ImGui::init(); /// # let ui = imgui.frame(FrameSize::new(100.0, 100.0, 1.0), 0.1); - /// let red = (1.0, 0.0, 0.0, 1.0); - /// let green = (0.0, 1.0, 0.0, 1.0); - /// # let vars = [(ImGuiCol::Text, red), (ImGuiCol::TextDisabled, green)]; + /// let red = [1.0, 0.0, 0.0, 1.0]; + /// let green = [0.0, 1.0, 0.0, 1.0]; + /// # let vars = [(StyleColor::Text, red), (StyleColor::TextDisabled, green)]; /// ui.with_color_vars(&vars, || { /// ui.text_wrapped(im_str!("AB")); /// }); /// ``` pub fn with_color_vars + Copy>( &self, - color_vars: &[(ImGuiCol, C)], + color_vars: &[(StyleColor, C)], f: F, ) { for &(color_var, color) in color_vars { unsafe { - sys::igPushStyleColor(color_var, color.into()); + sys::igPushStyleColor(color_var as _, color.into()); } } f(); @@ -1610,7 +1649,7 @@ impl<'ui> Ui<'ui> { pub fn with_style_and_color_vars( &self, style_vars: &[StyleVar], - color_vars: &[(ImGuiCol, C)], + color_vars: &[(StyleColor, C)], f: F, ) where F: FnOnce(), @@ -1748,3 +1787,13 @@ pub enum Condition { /// first time) Appearing = sys::ImGuiCond_Appearing as i8, } + +/// A cardinal direction +#[repr(i32)] +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +pub enum Direction { + Left = sys::ImGuiDir_Left, + Right = sys::ImGuiDir_Right, + Up = sys::ImGuiDir_Up, + Down = sys::ImGuiDir_Down, +} diff --git a/src/style.rs b/src/style.rs index db23072..7e0afab 100644 --- a/src/style.rs +++ b/src/style.rs @@ -1,22 +1,453 @@ -use crate::ImVec2; +use std::ops::{Index, IndexMut}; +use crate::internal::RawCast; +use crate::sys; +use crate::Direction; + +/// User interface style/colors +#[repr(C)] +#[derive(Copy, Clone)] +pub struct Style { + /// Global alpha applies to everything + pub alpha: f32, + /// Padding within a window + pub window_padding: [f32; 2], + /// Rounding radius of window corners. + /// + /// Set to 0.0 to have rectangular windows. + pub window_rounding: f32, + /// Thickness of border around windows. + /// + /// Generally set to 0.0 or 1.0 (other values are not well tested and cost more CPU/GPU). + pub window_border_size: f32, + /// Minimum window size + pub window_min_size: [f32; 2], + /// Alignment for title bar text. + /// + /// Defaults to [0.5, 0.5] for left-aligned, vertically centered. + pub window_title_align: [f32; 2], + /// Side of the collapsing/docking button in the title bar (left/right). + /// + /// Defaults to Direction::Left. + pub window_menu_button_position: Direction, + /// Rounding radius of child window corners. + /// + /// Set to 0.0 to have rectangular child windows. + pub child_rounding: f32, + /// Thickness of border around child windows. + /// + /// Generally set to 0.0 or 1.0 (other values are not well tested and cost more CPU/GPU). + pub child_border_size: f32, + /// Rounding radius of popup window corners. + /// + /// Note that tooltip windows use `window_rounding` instead. + pub popup_rounding: f32, + /// Thickness of border around popup/tooltip windows. + /// + /// Generally set to 0.0 or 1.0 (other values are not well tested and cost more CPU/GPU). + pub popup_border_size: f32, + /// Padding within a framed rectangle (used by most widgets) + pub frame_padding: [f32; 2], + /// Rounding radius of frame corners (used by most widgets). + /// + /// Set to 0.0 to have rectangular frames. + pub frame_rounding: f32, + /// Thickness of border around frames. + /// + /// Generally set to 0.0 or 1.0 (other values are not well tested and cost more CPU/GPU). + pub frame_border_size: f32, + /// Horizontal and vertical spacing between widgets/lines + pub item_spacing: [f32; 2], + /// Horizontal and vertical spacing between elements of a composed widget (e.g. a slider and + /// its label) + pub item_inner_spacing: [f32; 2], + /// Expand reactive bounding box for touch-based system where touch position is not accurate + /// enough. + /// + /// Unfortunately we don't sort widgets so priority on overlap will always be given to the + /// first widget, so don't grow this too much. + pub touch_extra_padding: [f32; 2], + /// Horizontal indentation when e.g. entering a tree node. + /// + /// Generally equal to (font size + horizontal frame padding * 2). + pub indent_spacing: f32, + /// Minimum horizontal spacing between two columns + pub columns_min_spacing: f32, + /// Width of the vertical scrollbar, height of the horizontal scrollbar + pub scrollbar_size: f32, + /// Rounding radius of scrollbar grab corners + pub scrollbar_rounding: f32, + /// Minimum width/height of a grab box for slider/scrollbar + pub grab_min_size: f32, + /// Rounding radius of grab corners. + /// + /// Set to 0.0 to have rectangular slider grabs. + pub grab_rounding: f32, + /// Rounding radius of upper corners of tabs. + /// + /// Set to 0.0 to have rectangular tabs. + pub tab_rounding: f32, + /// Thichkness of border around tabs + pub tab_border_size: f32, + /// Alignment of button text when button is larger than text. + /// + /// Defaults to [0.5, 0.5] (centered). + pub button_text_align: [f32; 2], + /// Alignment of selectable text when selectable is larger than text. + /// + /// Defaults to [0.5, 0.5] (top-left aligned). + pub selectable_text_align: [f32; 2], + /// Window positions are clamped to be visible within the display area by at least this amount. + /// + /// Only applies to regular windows. + pub display_window_padding: [f32; 2], + /// If you cannot see the edges of your screen (e.g. on a TV), increase the safe area padding. + /// + /// Also applies to popups/tooltips in addition to regular windows. + pub display_safe_area_padding: [f32; 2], + /// Scale software-rendered mouse cursor. + /// + /// May be removed later. + pub mouse_cursor_scale: f32, + /// Enable anti-aliasing on lines/borders. + /// + /// Disable if you are really tight on CPU/GPU. + pub anti_aliased_lines: bool, + /// Enable anti-aliasing on filled shapes (rounded rectangles, circles, etc.) + pub anti_aliased_fill: bool, + /// Tessellation tolerance when using path_bezier_curve_to without a specific number of + /// segments. + /// + /// Decrease for highly tessellated curves (higher quality, more polygons), increase to reduce + /// quality. + pub curve_tessellation_tol: f32, + /// Style colors. + pub colors: [[f32; 4]; 48], +} + +unsafe impl RawCast for Style {} + +impl Style { + /// Scales all sizes in the style + pub fn scale_all_sizes(&mut self, scale_factor: f32) { + unsafe { + sys::ImGuiStyle_ScaleAllSizes(self.raw_mut(), scale_factor); + } + } + /// Replaces current colors with classic Dear ImGui style + pub fn use_classic_colors(&mut self) -> &mut Self { + unsafe { + sys::igStyleColorsClassic(self.raw_mut()); + } + self + } + /// Replaces current colors with a new, recommended style + pub fn use_dark_colors(&mut self) -> &mut Self { + unsafe { + sys::igStyleColorsDark(self.raw_mut()); + } + self + } + /// Replaces current colors with a light style. Best used with borders and a custom, thicker + /// font + pub fn use_light_colors(&mut self) -> &mut Self { + unsafe { + sys::igStyleColorsLight(self.raw_mut()); + } + self + } +} + +impl Index for Style { + type Output = [f32; 4]; + fn index(&self, index: StyleColor) -> &[f32; 4] { + &self.colors[index as usize] + } +} + +impl IndexMut for Style { + fn index_mut(&mut self, index: StyleColor) -> &mut [f32; 4] { + &mut self.colors[index as usize] + } +} + +/// A color identifier for styling +#[repr(u32)] +#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] +pub enum StyleColor { + Text = sys::ImGuiCol_Text, + TextDisabled = sys::ImGuiCol_TextDisabled, + /// Background of normal windows + WindowBg = sys::ImGuiCol_WindowBg, + /// Background of child windows + ChildBg = sys::ImGuiCol_ChildBg, + /// Background of popups, menus, tooltips windows + PopupBg = sys::ImGuiCol_PopupBg, + Border = sys::ImGuiCol_Border, + BorderShadow = sys::ImGuiCol_BorderShadow, + /// Background of checkbox, radio button, plot, slider, text input + FrameBg = sys::ImGuiCol_FrameBg, + FrameBgHovered = sys::ImGuiCol_FrameBgHovered, + FrameBgActive = sys::ImGuiCol_FrameBgActive, + TitleBg = sys::ImGuiCol_TitleBg, + TitleBgActive = sys::ImGuiCol_TitleBgActive, + TitleBgCollapsed = sys::ImGuiCol_TitleBgCollapsed, + MenuBarBg = sys::ImGuiCol_MenuBarBg, + ScrollbarBg = sys::ImGuiCol_ScrollbarBg, + ScrollbarGrab = sys::ImGuiCol_ScrollbarGrab, + ScrollbarGrabHovered = sys::ImGuiCol_ScrollbarGrabHovered, + ScrollbarGrabActive = sys::ImGuiCol_ScrollbarGrabActive, + CheckMark = sys::ImGuiCol_CheckMark, + SliderGrab = sys::ImGuiCol_SliderGrab, + SliderGrabActive = sys::ImGuiCol_SliderGrabActive, + Button = sys::ImGuiCol_Button, + ButtonHovered = sys::ImGuiCol_ButtonHovered, + ButtonActive = sys::ImGuiCol_ButtonActive, + Header = sys::ImGuiCol_Header, + HeaderHovered = sys::ImGuiCol_HeaderHovered, + HeaderActive = sys::ImGuiCol_HeaderActive, + Separator = sys::ImGuiCol_Separator, + SeparatorHovered = sys::ImGuiCol_SeparatorHovered, + SeparatorActive = sys::ImGuiCol_SeparatorActive, + ResizeGrip = sys::ImGuiCol_ResizeGrip, + ResizeGripHovered = sys::ImGuiCol_ResizeGripHovered, + ResizeGripActive = sys::ImGuiCol_ResizeGripActive, + Tab = sys::ImGuiCol_Tab, + TabHovered = sys::ImGuiCol_TabHovered, + TabActive = sys::ImGuiCol_TabActive, + TabUnfocused = sys::ImGuiCol_TabUnfocused, + TabUnfocusedActive = sys::ImGuiCol_TabUnfocusedActive, + PlotLines = sys::ImGuiCol_PlotLines, + PlotLinesHovered = sys::ImGuiCol_PlotLinesHovered, + PlotHistogram = sys::ImGuiCol_PlotHistogram, + PlotHistogramHovered = sys::ImGuiCol_PlotHistogramHovered, + TextSelectedBg = sys::ImGuiCol_TextSelectedBg, + DragDropTarget = sys::ImGuiCol_DragDropTarget, + /// Gamepad/keyboard: current highlighted item + NavHighlight = sys::ImGuiCol_NavHighlight, + /// Highlight window when using CTRL+TAB + NavWindowingHighlight = sys::ImGuiCol_NavWindowingHighlight, + /// Darken/colorize entire screen behind the CTRL+TAB window list, when active + NavWindowingDimBg = sys::ImGuiCol_NavWindowingDimBg, + /// Darken/colorize entire screen behind a modal window, when one is active + ModalWindowDimBg = sys::ImGuiCol_ModalWindowDimBg, +} + +impl StyleColor { + /// All possible `StyleColor` variants + pub const VARIANTS: [StyleColor; StyleColor::COUNT] = [ + StyleColor::Text, + StyleColor::TextDisabled, + StyleColor::WindowBg, + StyleColor::ChildBg, + StyleColor::PopupBg, + StyleColor::Border, + StyleColor::BorderShadow, + StyleColor::FrameBg, + StyleColor::FrameBgHovered, + StyleColor::FrameBgActive, + StyleColor::TitleBg, + StyleColor::TitleBgActive, + StyleColor::TitleBgCollapsed, + StyleColor::MenuBarBg, + StyleColor::ScrollbarBg, + StyleColor::ScrollbarGrab, + StyleColor::ScrollbarGrabHovered, + StyleColor::ScrollbarGrabActive, + StyleColor::CheckMark, + StyleColor::SliderGrab, + StyleColor::SliderGrabActive, + StyleColor::Button, + StyleColor::ButtonHovered, + StyleColor::ButtonActive, + StyleColor::Header, + StyleColor::HeaderHovered, + StyleColor::HeaderActive, + StyleColor::Separator, + StyleColor::SeparatorHovered, + StyleColor::SeparatorActive, + StyleColor::ResizeGrip, + StyleColor::ResizeGripHovered, + StyleColor::ResizeGripActive, + StyleColor::Tab, + StyleColor::TabHovered, + StyleColor::TabActive, + StyleColor::TabUnfocused, + StyleColor::TabUnfocusedActive, + StyleColor::PlotLines, + StyleColor::PlotLinesHovered, + StyleColor::PlotHistogram, + StyleColor::PlotHistogramHovered, + StyleColor::TextSelectedBg, + StyleColor::DragDropTarget, + StyleColor::NavHighlight, + StyleColor::NavWindowingHighlight, + StyleColor::NavWindowingDimBg, + StyleColor::ModalWindowDimBg, + ]; + /// Total count of `StyleColor` variants + pub const COUNT: usize = sys::ImGuiCol_COUNT as usize; +} + +/// A temporary change in user interface style #[derive(Copy, Clone, Debug, PartialEq)] pub enum StyleVar { + /// Global alpha applies to everything Alpha(f32), - WindowPadding(ImVec2), + /// Padding within a window + WindowPadding([f32; 2]), + /// Rounding radius of window corners WindowRounding(f32), + /// Thickness of border around windows WindowBorderSize(f32), - WindowMinSize(ImVec2), + /// Minimum window size + WindowMinSize([f32; 2]), + /// Alignment for title bar text + WindowTitleAlign([f32; 2]), + /// Rounding radius of child window corners ChildRounding(f32), + /// Thickness of border around child windows ChildBorderSize(f32), + /// Rounding radius of popup window corners PopupRounding(f32), + /// Thickness of border around popup/tooltip windows PopupBorderSize(f32), - FramePadding(ImVec2), + /// Padding within a framed rectangle (used by most widgets) + FramePadding([f32; 2]), + /// Rounding radius of frame corners (used by most widgets) FrameRounding(f32), + /// Thickness of border around frames FrameBorderSize(f32), - ItemSpacing(ImVec2), - ItemInnerSpacing(ImVec2), + /// Horizontal and vertical spacing between widgets/lines + ItemSpacing([f32; 2]), + /// Horizontal and vertical spacing between elements of a composed widget (e.g. a slider and + /// its label) + ItemInnerSpacing([f32; 2]), + /// Horizontal indentation when e.g. entering a tree node IndentSpacing(f32), + /// Width of the vertical scrollbar, height of the horizontal scrollbar + ScrollbarSize(f32), + /// Rounding radius of scrollbar grab corners + ScrollbarRounding(f32), + /// Minimum width/height of a grab box for slider/scrollbar GrabMinSize(f32), - ButtonTextAlign(ImVec2), + /// Rounding radius of grab corners + GrabRounding(f32), + /// Rounding radius of upper corners of tabs + TabRounding(f32), + /// Alignment of button text when button is larger than text + ButtonTextAlign([f32; 2]), + /// Alignment of selectable text when selectable is larger than text + SelectableTextAlign([f32; 2]), +} + +// #[test] +// fn test_style_scaling() { +// let (_guard, mut ctx) = crate::test::test_ctx(); +// let style = ctx.style_mut(); +// style.window_padding = [1.0, 2.0]; +// style.window_rounding = 3.0; +// style.window_min_size = [4.0, 5.0]; +// style.child_rounding = 6.0; +// style.popup_rounding = 7.0; +// style.frame_padding = [8.0, 9.0]; +// style.frame_rounding = 10.0; +// style.item_spacing = [11.0, 12.0]; +// style.item_inner_spacing = [13.0, 14.0]; +// style.touch_extra_padding = [15.0, 16.0]; +// style.indent_spacing = 17.0; +// style.columns_min_spacing = 18.0; +// style.scrollbar_size = 19.0; +// style.scrollbar_rounding = 20.0; +// style.grab_min_size = 21.0; +// style.grab_rounding = 22.0; +// style.tab_rounding = 23.0; +// style.display_window_padding = [24.0, 25.0]; +// style.display_safe_area_padding = [26.0, 27.0]; +// style.mouse_cursor_scale = 28.0; +// style.scale_all_sizes(2.0); +// assert_eq!(style.window_padding, [2.0, 4.0]); +// assert_eq!(style.window_rounding, 6.0); +// assert_eq!(style.window_min_size, [8.0, 10.0]); +// assert_eq!(style.child_rounding, 12.0); +// assert_eq!(style.popup_rounding, 14.0); +// assert_eq!(style.frame_padding, [16.0, 18.0]); +// assert_eq!(style.frame_rounding, 20.0); +// assert_eq!(style.item_spacing, [22.0, 24.0]); +// assert_eq!(style.item_inner_spacing, [26.0, 28.0]); +// assert_eq!(style.touch_extra_padding, [30.0, 32.0]); +// assert_eq!(style.indent_spacing, 34.0); +// assert_eq!(style.columns_min_spacing, 36.0); +// assert_eq!(style.scrollbar_size, 38.0); +// assert_eq!(style.scrollbar_rounding, 40.0); +// assert_eq!(style.grab_min_size, 42.0); +// assert_eq!(style.grab_rounding, 44.0); +// assert_eq!(style.tab_rounding, 46.0); +// assert_eq!(style.display_window_padding, [48.0, 50.0]); +// assert_eq!(style.display_safe_area_padding, [52.0, 54.0]); +// assert_eq!(style.mouse_cursor_scale, 56.0); +// } + +// #[test] +// fn test_style_color_indexing() { +// let (_guard, mut ctx) = crate::test::test_ctx(); +// let style = ctx.style_mut(); +// let value = [0.1, 0.2, 0.3, 1.0]; +// style[StyleColor::Tab] = value; +// assert_eq!(style[StyleColor::Tab], value); +// assert_eq!(style.colors[StyleColor::Tab as usize], value); +// } + +#[test] +fn test_style_memory_layout() { + use std::mem; + assert_eq!(mem::size_of::