Begin to prototype many things.
This commit is contained in:
		
					parent
					
						
							
								42530ce824
							
						
					
				
			
			
				commit
				
					
						84450d25af
					
				
			
		
					 14 changed files with 176 additions and 9 deletions
				
			
		
							
								
								
									
										1
									
								
								src/controller.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								src/controller.cpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
#include "controller.hpp"
 | 
			
		||||
| 
						 | 
				
			
			@ -1,6 +1,7 @@
 | 
			
		|||
#include "gui/gui.hpp"
 | 
			
		||||
#include "gui/gui_data.hpp"
 | 
			
		||||
#include "imgui.h"
 | 
			
		||||
#include "imgui_stdlib.h"
 | 
			
		||||
#include "imgui_impl_glfw.h"
 | 
			
		||||
#include "imgui_impl_opengl3.h"
 | 
			
		||||
#include "imgui_impl_opengl3_loader.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -47,6 +48,44 @@ void gui::Gui::render_gui() {
 | 
			
		|||
 | 
			
		||||
		ImGui::Text("Hello world!");
 | 
			
		||||
		ImGui::Text("Average framerate: %.3f ms/frame (%.1f FPS)", 1000.f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
 | 
			
		||||
		{
 | 
			
		||||
			ImGui::BeginChild("left pane",
 | 
			
		||||
							  ImVec2(ImGui::GetWindowWidth() / 2, -ImGui::GetFrameHeightWithSpacing() -
 | 
			
		||||
																  ImGui::GetStyle().ItemSpacing.y * 4 -
 | 
			
		||||
																  ImGui::GetStyle().ChildBorderSize -
 | 
			
		||||
																  ImGui::GetStyle().FrameBorderSize),
 | 
			
		||||
							  true);
 | 
			
		||||
			ImGui::Text("Caractère");
 | 
			
		||||
			// Remove label
 | 
			
		||||
			ImGui::PushItemWidth(-1);
 | 
			
		||||
			ImGui::InputTextMultiline("Caractère", &data.billy.caractere);
 | 
			
		||||
			ImGui::PopItemWidth();
 | 
			
		||||
			ImGui::TreePop();
 | 
			
		||||
			ImGui::EndChild();
 | 
			
		||||
		}
 | 
			
		||||
		ImGui::SameLine();
 | 
			
		||||
 | 
			
		||||
		{
 | 
			
		||||
			ImGui::BeginChild("Right Pane",
 | 
			
		||||
							  ImVec2(0,
 | 
			
		||||
									 -ImGui::GetFrameHeightWithSpacing() -
 | 
			
		||||
									 ImGui::GetStyle().ItemSpacing.y * 4 -
 | 
			
		||||
									 ImGui::GetStyle().ChildBorderSize -
 | 
			
		||||
									 ImGui::GetStyle().FrameBorderSize),
 | 
			
		||||
							  true);
 | 
			
		||||
			ImGui::Text("Hello");
 | 
			
		||||
			ImGui::EndChild();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		{
 | 
			
		||||
			ImGui::BeginChild("Bottom pane", ImVec2(0, 0), true);
 | 
			
		||||
			ImGui::Text("Bottom pane");
 | 
			
		||||
			ImGui::Text("Bottom pane1");
 | 
			
		||||
			ImGui::Text("Bottom pane2");
 | 
			
		||||
			ImGui::Text("Bottom pane3");
 | 
			
		||||
			ImGui::Text("Bottom pane4");
 | 
			
		||||
			ImGui::EndChild();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		ImGui::End();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,14 +1,22 @@
 | 
			
		|||
#include "gui/menu/menu.hpp"
 | 
			
		||||
#include "imgui.h"
 | 
			
		||||
#include "gui/menu/menu_data.hpp"
 | 
			
		||||
#include <fstream>
 | 
			
		||||
#include <nlohmann/json.hpp>
 | 
			
		||||
 | 
			
		||||
void gui::menu::Menu::gui() const noexcept {
 | 
			
		||||
	if (ImGui::BeginMenuBar()) {
 | 
			
		||||
		if (ImGui::BeginMenu("File")) {
 | 
			
		||||
			if (ImGui::MenuItem("Save")) {
 | 
			
		||||
			if (ImGui::MenuItem("Open file")) {
 | 
			
		||||
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if (ImGui::MenuItem("Save")) {
 | 
			
		||||
				std::ofstream file{ data.save_path / data.filename };
 | 
			
		||||
				nlohmann::json j;
 | 
			
		||||
				j.emplace("character_sheet", data)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if (ImGui::MenuItem("Save as...")) {
 | 
			
		||||
 | 
			
		||||
			}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										76
									
								
								src/imgui/imgui_stdlib.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										76
									
								
								src/imgui/imgui_stdlib.cpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,76 @@
 | 
			
		|||
// dear imgui: wrappers for C++ standard library (STL) types (std::string, etc.)
 | 
			
		||||
// This is also an example of how you may wrap your own similar types.
 | 
			
		||||
 | 
			
		||||
// Compatibility:
 | 
			
		||||
// - std::string support is only guaranteed to work from C++11.
 | 
			
		||||
//   If you try to use it pre-C++11, please share your findings (w/ info about compiler/architecture)
 | 
			
		||||
 | 
			
		||||
// Changelog:
 | 
			
		||||
// - v0.10: Initial version. Added InputText() / InputTextMultiline() calls with std::string
 | 
			
		||||
 | 
			
		||||
#include "imgui.h"
 | 
			
		||||
#include "imgui_stdlib.h"
 | 
			
		||||
 | 
			
		||||
struct InputTextCallback_UserData
 | 
			
		||||
{
 | 
			
		||||
    std::string*            Str;
 | 
			
		||||
    ImGuiInputTextCallback  ChainCallback;
 | 
			
		||||
    void*                   ChainCallbackUserData;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static int InputTextCallback(ImGuiInputTextCallbackData* data)
 | 
			
		||||
{
 | 
			
		||||
    InputTextCallback_UserData* user_data = (InputTextCallback_UserData*)data->UserData;
 | 
			
		||||
    if (data->EventFlag == ImGuiInputTextFlags_CallbackResize)
 | 
			
		||||
    {
 | 
			
		||||
        // Resize string callback
 | 
			
		||||
        // If for some reason we refuse the new length (BufTextLen) and/or capacity (BufSize) we need to set them back to what we want.
 | 
			
		||||
        std::string* str = user_data->Str;
 | 
			
		||||
        IM_ASSERT(data->Buf == str->c_str());
 | 
			
		||||
        str->resize(data->BufTextLen);
 | 
			
		||||
        data->Buf = (char*)str->c_str();
 | 
			
		||||
    }
 | 
			
		||||
    else if (user_data->ChainCallback)
 | 
			
		||||
    {
 | 
			
		||||
        // Forward to user callback, if any
 | 
			
		||||
        data->UserData = user_data->ChainCallbackUserData;
 | 
			
		||||
        return user_data->ChainCallback(data);
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool ImGui::InputText(const char* label, std::string* str, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data)
 | 
			
		||||
{
 | 
			
		||||
    IM_ASSERT((flags & ImGuiInputTextFlags_CallbackResize) == 0);
 | 
			
		||||
    flags |= ImGuiInputTextFlags_CallbackResize;
 | 
			
		||||
 | 
			
		||||
    InputTextCallback_UserData cb_user_data;
 | 
			
		||||
    cb_user_data.Str = str;
 | 
			
		||||
    cb_user_data.ChainCallback = callback;
 | 
			
		||||
    cb_user_data.ChainCallbackUserData = user_data;
 | 
			
		||||
    return InputText(label, (char*)str->c_str(), str->capacity() + 1, flags, InputTextCallback, &cb_user_data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool ImGui::InputTextMultiline(const char* label, std::string* str, const ImVec2& size, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data)
 | 
			
		||||
{
 | 
			
		||||
    IM_ASSERT((flags & ImGuiInputTextFlags_CallbackResize) == 0);
 | 
			
		||||
    flags |= ImGuiInputTextFlags_CallbackResize;
 | 
			
		||||
 | 
			
		||||
    InputTextCallback_UserData cb_user_data;
 | 
			
		||||
    cb_user_data.Str = str;
 | 
			
		||||
    cb_user_data.ChainCallback = callback;
 | 
			
		||||
    cb_user_data.ChainCallbackUserData = user_data;
 | 
			
		||||
    return InputTextMultiline(label, (char*)str->c_str(), str->capacity() + 1, size, flags, InputTextCallback, &cb_user_data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool ImGui::InputTextWithHint(const char* label, const char* hint, std::string* str, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data)
 | 
			
		||||
{
 | 
			
		||||
    IM_ASSERT((flags & ImGuiInputTextFlags_CallbackResize) == 0);
 | 
			
		||||
    flags |= ImGuiInputTextFlags_CallbackResize;
 | 
			
		||||
 | 
			
		||||
    InputTextCallback_UserData cb_user_data;
 | 
			
		||||
    cb_user_data.Str = str;
 | 
			
		||||
    cb_user_data.ChainCallback = callback;
 | 
			
		||||
    cb_user_data.ChainCallbackUserData = user_data;
 | 
			
		||||
    return InputTextWithHint(label, hint, (char*)str->c_str(), str->capacity() + 1, flags, InputTextCallback, &cb_user_data);
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue