Skip to content

Instantly share code, notes, and snippets.

@aaaScript
Created October 7, 2020 23:23
Show Gist options
  • Save aaaScript/80fdf7a449beddacab499c39d3287fd9 to your computer and use it in GitHub Desktop.
Save aaaScript/80fdf7a449beddacab499c39d3287fd9 to your computer and use it in GitHub Desktop.
ImGui Crystal Test
require "crsfml"
require "imgui"
require "imgui-sfml"
module TestImGui
include ImGui::TopLevel
def self.set_style
style = ImGui.get_style
style.window_padding = ImVec2.new(15, 15)
style.window_rounding = 0.0_f32
style.child_rounding = 0.0_f32
style.frame_padding = ImVec2.new(5, 5)
style.frame_rounding = 0.0_f32
style.popup_rounding = 0.0_f32
style.item_spacing = ImVec2.new(12, 8)
style.item_inner_spacing = ImVec2.new(8, 6)
style.indent_spacing = 25.0_f32
style.scrollbar_size = 15.0_f32
style.scrollbar_rounding = 0.0_f32
style.grab_min_size = 5.0_f32
style.grab_rounding = 0.0_f32
style.tab_rounding = 0.0_f32
style.colors[ImGuiCol::Text.to_i.to_i] = ImVec4.new(0.80_f32, 0.80_f32, 0.83_f32, 1.00_f32)
style.colors[ImGuiCol::TextDisabled.to_i] = ImVec4.new(0.24_f32, 0.23_f32, 0.29_f32, 1.00_f32)
style.colors[ImGuiCol::WindowBg.to_i] = ImVec4.new(0.06_f32, 0.05_f32, 0.07_f32, 1.00_f32)
style.colors[ImGuiCol::ChildBg.to_i] = ImVec4.new(0.07_f32, 0.07_f32, 0.09_f32, 1.00_f32)
style.colors[ImGuiCol::PopupBg.to_i] = ImVec4.new(0.07_f32, 0.07_f32, 0.09_f32, 1.00_f32)
style.colors[ImGuiCol::Border.to_i] = ImVec4.new(0.2_f32, 0.2_f32, 0.2_f32, 0.88_f32)
style.colors[ImGuiCol::BorderShadow.to_i] = ImVec4.new(0.92_f32, 0.91_f32, 0.88_f32, 0.00_f32)
style.colors[ImGuiCol::FrameBg.to_i] = ImVec4.new(0.10_f32, 0.09_f32, 0.12_f32, 1.00_f32)
style.colors[ImGuiCol::FrameBgHovered.to_i] = ImVec4.new(0.24_f32, 0.23_f32, 0.29_f32, 1.00_f32)
style.colors[ImGuiCol::FrameBgActive.to_i] = ImVec4.new(0.56_f32, 0.56_f32, 0.58_f32, 1.00_f32)
style.colors[ImGuiCol::TitleBg.to_i] = ImVec4.new(0.10_f32, 0.09_f32, 0.12_f32, 1.00_f32)
style.colors[ImGuiCol::TitleBgCollapsed.to_i] = ImVec4.new(0.3_f32, 0.3_f32, 0.3_f32, 0.75_f32)
style.colors[ImGuiCol::TitleBgActive.to_i] = ImVec4.new(0.07_f32, 0.07_f32, 0.09_f32, 1.00_f32)
style.colors[ImGuiCol::MenuBarBg.to_i] = ImVec4.new(0.10_f32, 0.09_f32, 0.12_f32, 1.00_f32)
style.colors[ImGuiCol::ScrollbarBg.to_i] = ImVec4.new(0.10_f32, 0.09_f32, 0.12_f32, 1.00_f32)
style.colors[ImGuiCol::ScrollbarGrab.to_i] = ImVec4.new(0.80_f32, 0.80_f32, 0.83_f32, 0.31_f32)
style.colors[ImGuiCol::ScrollbarGrabHovered.to_i] = ImVec4.new(0.56_f32, 0.56_f32, 0.58_f32, 1.00_f32)
style.colors[ImGuiCol::ScrollbarGrabActive.to_i] = ImVec4.new(0.06_f32, 0.05_f32, 0.07_f32, 1.00_f32)
style.colors[ImGuiCol::CheckMark.to_i] = ImVec4.new(0.80_f32, 0.80_f32, 0.83_f32, 0.31_f32)
style.colors[ImGuiCol::SliderGrab.to_i] = ImVec4.new(0.80_f32, 0.80_f32, 0.83_f32, 0.31_f32)
style.colors[ImGuiCol::SliderGrabActive.to_i] = ImVec4.new(0.06_f32, 0.05_f32, 0.07_f32, 1.00_f32)
style.colors[ImGuiCol::Button.to_i] = ImVec4.new(0.10_f32, 0.09_f32, 0.12_f32, 1.00_f32)
style.colors[ImGuiCol::ButtonHovered.to_i] = ImVec4.new(0.24_f32, 0.23_f32, 0.29_f32, 1.00_f32)
style.colors[ImGuiCol::ButtonActive.to_i] = ImVec4.new(0.56_f32, 0.56_f32, 0.58_f32, 1.00_f32)
style.colors[ImGuiCol::Header.to_i] = ImVec4.new(0.10_f32, 0.09_f32, 0.12_f32, 1.00_f32)
style.colors[ImGuiCol::HeaderHovered.to_i] = ImVec4.new(0.56_f32, 0.56_f32, 0.58_f32, 1.00_f32)
style.colors[ImGuiCol::HeaderActive.to_i] = ImVec4.new(0.06_f32, 0.05_f32, 0.07_f32, 1.00_f32)
style.colors[ImGuiCol::Separator.to_i] = ImVec4.new(0.56_f32, 0.56_f32, 0.58_f32, 1.00_f32)
style.colors[ImGuiCol::SeparatorHovered.to_i] = ImVec4.new(0.24_f32, 0.23_f32, 0.29_f32, 1.00_f32)
style.colors[ImGuiCol::SeparatorActive.to_i] = ImVec4.new(0.56_f32, 0.56_f32, 0.58_f32, 1.00_f32)
style.colors[ImGuiCol::ResizeGrip.to_i] = ImVec4.new(0.00_f32, 0.00_f32, 0.00_f32, 0.00_f32)
style.colors[ImGuiCol::ResizeGripHovered.to_i] = ImVec4.new(0.56_f32, 0.56_f32, 0.58_f32, 1.00_f32)
style.colors[ImGuiCol::ResizeGripActive.to_i] = ImVec4.new(0.06_f32, 0.05_f32, 0.07_f32, 1.00_f32)
style.colors[ImGuiCol::PlotLines.to_i] = ImVec4.new(0.40_f32, 0.39_f32, 0.38_f32, 0.63_f32)
style.colors[ImGuiCol::PlotLinesHovered.to_i] = ImVec4.new(0.25_f32, 1.00_f32, 0.00_f32, 1.00_f32)
style.colors[ImGuiCol::PlotHistogram.to_i] = ImVec4.new(0.40_f32, 0.39_f32, 0.38_f32, 0.63_f32)
style.colors[ImGuiCol::PlotHistogramHovered.to_i] = ImVec4.new(0.25_f32, 1.00_f32, 0.00_f32, 1.00_f32)
style.colors[ImGuiCol::TextSelectedBg.to_i] = ImVec4.new(0.25_f32, 1.00_f32, 0.00_f32, 0.43_f32)
end
window = SF::RenderWindow.new(SF::VideoMode.new(1280, 720), "Test ImGui")
window.framerate_limit = 60
ImGui::SFML.init(window)
# Fonts
io = ImGui.get_io
if File.file?(font_path = "/System/Library/Fonts/Supplemental/Arial Unicode.ttf")
io.fonts.clear
io.fonts.add_font_from_file_ttf(font_path, 46)
io.fonts.build
ImGui::SFML.update_font_texture
end
delta_clock = SF::Clock.new
while window.open?
while (event = window.poll_event)
ImGui::SFML.process_event(event)
if event.is_a? SF::Event::Closed
window.close
end
end
ImGui::SFML.update(window, delta_clock.restart)
self.set_style
ImGui.begin("Log")
ImGui.end
ImGui.begin("Console")
ImGui.end
window.clear(SF::Color.new(29, 30, 35))
ImGui::SFML.render(window)
window.display
end
ImGui::SFML.shutdown
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment