Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added: AppleClang CMake support #5

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/cmake-build-debug/
12 changes: 5 additions & 7 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
[submodule "external/SFML"]
path = example/external/SFML
url = https://github.com/SFML/SFML
[submodule "external/imgui-sfml"]
path = example/external/imgui-sfml
url = https://github.com/eliasdaler/imgui-sfml
[submodule "external/imgui"]
path = example/external/imgui
url = https://github.com/ocornut/imgui
branch = docking
[submodule "example/external/spdlog"]
path = example/external/spdlog
url = https://github.com/gabime/spdlog
[submodule "example/external/fmt"]
path = example/external/fmt
url = https://github.com/fmtlib/fmt
url = https://github.com/fmtlib/fmt
[submodule "example/external/glfw"]
path = example/external/glfw
url = https://github.com/glfw/glfw.git
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
cmake_minimum_required(VERSION 3.12)
project(ImTerm VERSION 0.1.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

#print values so the user nows why his compiler isnt accepted.
message(STATUS "CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}")
message(STATUS "Compiler: ${CMAKE_CXX_COMPILER}")
message(STATUS "Compiler ID: ${CMAKE_CXX_COMPILER_ID}")

add_library(ImTerm INTERFACE)
add_library(ImTerm::terminal ALIAS ImTerm)

target_include_directories(ImTerm INTERFACE
$<INSTALL_INTERFACE:include/>
$<INSTALL_INTERFACE:include/>
)

#add_subdirectory(example EXCLUDE_FROM_ALL)
add_subdirectory(example EXCLUDE_FROM_ALL)
204 changes: 204 additions & 0 deletions example/Application.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
#include "Application.h"

custom_command_struct cmd_struct; // terminal commands can interact with this structure
ImTerm::terminal<terminal_commands> terminal_log(cmd_struct);


Application::Application(){
terminal_log.set_min_log_level(ImTerm::message::severity::info);

spdlog::set_level(spdlog::level::trace);
spdlog::default_logger()->sinks().push_back(terminal_log.get_terminal_helper());
init();

run();
}



Application::~Application() {
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();

glfwDestroyWindow(m_Window);
glfwTerminate();
}

void Application::init(){
if (!glfwInit()) {
std::cerr << "Failed to initialize GLFW" << std::endl;
exit(-1);
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Necessary for Mac
#endif
m_Window = glfwCreateWindow(800, 600, "ImGui Mac App", nullptr, nullptr);
if (m_Window == nullptr) {
std::cerr << "Failed to create GLFW window" << std::endl;
glfwTerminate();
exit(-1);
}
glfwMakeContextCurrent(m_Window);

if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
std::cerr << "Failed to initialize GLAD" << std::endl;
exit(-1);
}

// Setup ImGui context
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();

io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;


ImGui_ImplGlfw_InitForOpenGL(m_Window, true);
ImGui_ImplOpenGL3_Init("#version 330");

ImFontConfig config;
config.OversampleH = 3;
config.OversampleV = 3;


ImFont* mainFont = io.Fonts->AddFontFromFileTTF(
"Assets/Fonts/JetBrainsMono-2.304/fonts/ttf/JetBrainsMono-Regular.ttf",
17, &config);
io.FontDefault = mainFont;
terminal_log.set_min_log_level(ImTerm::message::severity::info);


spdlog::set_level(spdlog::level::trace);
spdlog::default_logger()->sinks().push_back(terminal_log.get_terminal_helper());

m_ShowingTerm = true;
}

void Application::run(){


terminal_log.addCallback([this]() {
refresh();
});

while (!glfwWindowShouldClose(m_Window)) {
glfwPollEvents();
refresh();
}
}

void Application::refresh(){
int display_w, display_h;
glfwGetFramebufferSize(m_Window, &display_w, &display_h);
// 1. Poll events and clear the frame
glfwPollEvents();

glViewport(0, 0, display_w, display_h);
glClearColor(0.45f, 0.55f, 0.60f, 1.00f);
glClear(GL_COLOR_BUFFER_BIT);

// 2. Start the ImGui frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
ImGuiStyle& style = ImGui::GetStyle();
ImVec2 windowPadding = style.WindowPadding; // Store original padding
ImVec2 itemSpacing = style.ItemSpacing; // Store original item spacing
ImVec2 framePadding = style.FramePadding; // Store original frame padding

style.WindowPadding = ImVec2(0.0f, 0.0f); // Set padding to zero for this window
style.ItemSpacing = ImVec2(0.0f, 0.0f); // Optional: reduce spacing between items
style.FramePadding = ImVec2(0.0f, 0.0f); // Optional: reduce frame padding
//Render imgui

// Window flags for the fullscreen window
ImGuiWindowFlags window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking;
window_flags |= ImGuiWindowFlags_NoTitleBar;
window_flags |= ImGuiWindowFlags_NoCollapse;
window_flags |= ImGuiWindowFlags_NoResize;
window_flags |= ImGuiWindowFlags_NoMove;
window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus;
window_flags |= ImGuiWindowFlags_NoNavFocus;
window_flags |= ImGuiWindowFlags_NoBackground; ; // Disables the close button


// Make it fullscreen
const ImGuiViewport* viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(viewport->Pos);
ImGui::SetNextWindowSize(viewport->Size);
ImGui::SetNextWindowViewport(viewport->ID);

// Begin the parent window
ImGui::Begin("DockSpace Demo", nullptr, window_flags);

// Restore original style after you're done with the fullscreen window
style.FramePadding.x = framePadding.x;
style.WindowPadding.x = windowPadding.x;
style.ItemSpacing.x = itemSpacing.x;

// Custom taskbar (menu bar)
if (ImGui::BeginMenuBar()) {
if (ImGui::BeginMenu("File")) {
if (ImGui::MenuItem("New")) {
// Handle "New" action here
}
if (ImGui::MenuItem("Open")) {
// Handle "Open" action here
}
if (ImGui::MenuItem("Save")) {
// Handle "Save" action here
}
if (ImGui::MenuItem("Exit")) {
glfwSetWindowShouldClose(m_Window, true); // Close the application
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Edit")) {
if (ImGui::MenuItem("Undo")) {
// Handle "Undo" action here
}
// ... add other Edit options as needed ...
ImGui::EndMenu();
}
// ... add other menus as needed ...
ImGui::EndMenuBar();
}

// DockSpace
ImGuiID dockspace_id = ImGui::GetID("MyDockSpace");
ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), ImGuiDockNodeFlags_None);

// Example child window (You can create multiple windows like this)
if (ImGui::Begin("Child Window", nullptr, ImGuiWindowFlags_NoCollapse)) {
ImGui::Text("Hello from the Child Window!");
}
ImGui::End();

ImGui::ShowDemoWindow();
ImGui::ShowDebugLogWindow();
ImGui::ShowMetricsWindow();
ImGui::ShowStackToolWindow();


// End the parent window
ImGui::End();


ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); // <-- This is crucial

// 4. Swap the buffers
glfwSwapBuffers(m_Window);

if (m_ShowingTerm) {

if (cmd_struct.should_close) {
glfwSetWindowShouldClose(m_Window, true);
}
m_ShowingTerm = terminal_log.show();
}
}
38 changes: 38 additions & 0 deletions example/Application.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once
#include <iostream>
#include <spdlog/spdlog.h>

#include <imgui.h>

#include <imgui_internal.h>

#include "backends/imgui_impl_glfw.h"
#include "backends/imgui_impl_opengl3.h"

#include <GLAD/glad.h>
#include <GLFW/glfw3.h>

//Terminal
#include "imterm/terminal.hpp"
#include "terminal_commands.hpp"

class Application {
public:
Application();

~Application();

void refresh();
void refreshFromTerminal();
private:
void init();
void run();

GLFWwindow *m_Window = nullptr;
unsigned long m_FrameCount = 0ul;
bool m_Initialized = false;
bool m_ShowingTerm = true;

static const int c_WindowWidth = 800;
static const int c_WindowHeight = 600;
};
10 changes: 10 additions & 0 deletions example/Assets/Fonts/JetBrainsMono-2.304/AUTHORS.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This is the official list of project authors for copyright purposes.
# This file is distinct from the CONTRIBUTORS.txt file.
# See the latter for an explanation.
#
# Names should be added to this file as:
# Name or Organization <email address>

JetBrains <>
Philipp Nurullin <[email protected]>
Konstantin Bulenkov <[email protected]>
Loading