Skip to content

Commit

Permalink
use imgui-docking wip
Browse files Browse the repository at this point in the history
  • Loading branch information
floooh committed Dec 9, 2024
1 parent 8ab44a8 commit 6f73988
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
2 changes: 1 addition & 1 deletion ext/sokol/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fips_begin_lib(sokol)
fips_files(sokol.cc)
fips_deps(imgui)
fips_deps(imgui-docking)
if (FIPS_OSX)
fips_files(sokol.m)
if (FIPS_IOS)
Expand Down
2 changes: 1 addition & 1 deletion ext/texteditor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fips_begin_lib(texteditor)
fips_files(TextEditor.cpp TextEditor.h)
fips_deps(imgui)
fips_deps(imgui-docking)
fips_end_lib()
target_include_directories(texteditor INTERFACE .)
if (FIPS_CLANG)
Expand Down
2 changes: 1 addition & 1 deletion src/gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void gfx_init(const gfx_desc_t* desc) {
gfx.seg_max_x = desc->seg_max_x;
gfx.seg_max_y = desc->seg_max_y;
gfx.aspect = 1.0f;
gfx.scale = 7.0f;
gfx.scale = 6.0f;
gfx.offset = (float2_t) { -0.05f, 0.0f };
gfx.palette = gfx_default_palette;
for (int i = 0; i < MAX_LAYERS; i++) {
Expand Down
47 changes: 33 additions & 14 deletions src/ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// ui.cc
//------------------------------------------------------------------------------
#include "imgui.h"
#include "imgui_internal.h"
#include "res/fonts.h"
#include "res/iconsfontawesome4_c.h"
#include "res/markdown.h"
Expand Down Expand Up @@ -227,6 +228,7 @@ static struct {
sgimgui_t sgimgui;
} ui;

static void ui_handle_docking(void);
static void ui_menu(void);
static void ui_picking(void);
static void ui_floating_controls(void);
Expand Down Expand Up @@ -310,6 +312,7 @@ void ui_init() {

// setup ImGui font with custom icons
auto& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
io.Fonts->AddFontDefault();
static const ImWchar icons_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 };
ImFontConfig icons_config;
Expand Down Expand Up @@ -636,6 +639,7 @@ void ui_frame() {
assert(ui.valid);
ui.link_hovered = false;
simgui_new_frame({ sapp_width(), sapp_height(), sapp_frame_duration(), sapp_dpi_scale() });
ui_handle_docking();
ui_menu();
ui_floating_controls();
ui_picking();
Expand Down Expand Up @@ -666,6 +670,25 @@ void ui_draw() {
simgui_render();
}

static void ui_handle_docking(void) {
const ImGuiViewport* viewport = ImGui::GetMainViewport();
const ImGuiID dspace_id = ImGui::GetID("main_dockspace");
if (ImGui::DockBuilderGetNode(dspace_id) == nullptr) {
ImGui::DockBuilderRemoveNode(dspace_id);
ImGui::DockBuilderAddNode(dspace_id, ImGuiDockNodeFlags_CentralNode);
ImGui::DockBuilderSetNodeSize(dspace_id, viewport->WorkSize);

ImGuiID dock_id_left, dock_id_right, dock_id_down, dock_id_up;
ImGui::DockBuilderSplitNode(dspace_id, ImGuiDir_Down, 0.25f, &dock_id_down, &dock_id_up);
ImGui::DockBuilderSplitNode(dock_id_up, ImGuiDir_Right, 0.25f, &dock_id_right, &dock_id_left);
ImGui::DockBuilderSetNodeSize(dock_id_right, { 270, viewport->WorkSize.y });
ImGui::DockBuilderDockWindow("CPU Controls", dock_id_right);
ImGui::DockBuilderDockWindow("Trace Log", dock_id_down);
ImGui::DockBuilderFinish(dspace_id);
}
ImGui::DockSpaceOverViewport(dspace_id, viewport, ImGuiDockNodeFlags_NoDockingOverCentralNode | ImGuiDockNodeFlags_PassthruCentralNode);
}

static void ui_menu(void) {
ui.menu.open_source_hovered = false;
ui.menu.save_source_hovered = false;
Expand Down Expand Up @@ -833,7 +856,14 @@ static void ui_menu(void) {
static void ui_floating_controls(void) {
if (ui.window_open.floating_controls) {
ImGui::SetNextWindowPos({ 10, 20 }, ImGuiCond_Once);
if (ImGui::Begin("##floating", &ui.window_open.floating_controls, ImGuiWindowFlags_NoDecoration|ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoBackground)) {
const ImGuiWindowFlags flags =
ImGuiWindowFlags_NoDocking |
ImGuiWindowFlags_NoDecoration |
ImGuiWindowFlags_AlwaysAutoResize |
ImGuiWindowFlags_NoBackground |
ImGuiWindowFlags_NoBringToFrontOnFocus |
ImGuiWindowFlags_NoFocusOnAppearing;
if (ImGui::Begin("##floating", &ui.window_open.floating_controls, flags)) {
if (ImGui::SliderInt("Layers", &ui.menu.layer_slider, 0, MAX_LAYERS)) {
int i = 0;
for (; i < ui.menu.layer_slider; i++) {
Expand Down Expand Up @@ -1239,16 +1269,8 @@ static void ui_cassette_deck_controls(void) {

static void ui_controls(void) {
if (ui.window_open.cpu_controls) {
ImGui::SetNextWindowPos({ ImGui::GetIO().DisplaySize.x - 300, 50 }, ImGuiCond_Once);
ImGui::SetNextWindowSize({ 270, 480 }, ImGuiCond_Once);
#if defined(CHIP_6502)
const char* cpu_name = "MOS 6502";
#elif defined(CHIP_Z80)
const char* cpu_name = "Zilog Z80";
#elif defined(CHIP_2A03)
const char* cpu_name = "Ricoh 2A03";
#endif
if (ImGui::Begin(cpu_name, &ui.window_open.cpu_controls, ImGuiWindowFlags_NoScrollbar)) {
ImGui::SetNextWindowSize({ 270, 120 }, ImGuiCond_Once);
if (ImGui::Begin("CPU Controls", &ui.window_open.cpu_controls, ImGuiWindowFlags_NoScrollbar)) {
/* cassette deck controls */
ui_cassette_deck_controls();
ImGui::Separator();
Expand Down Expand Up @@ -1472,10 +1494,7 @@ static void ui_tracelog(void) {
ui.trace.diff_view_active = false;
return;
}
const float disp_w = ImGui::GetIO().DisplaySize.x;
const float disp_h = ImGui::GetIO().DisplaySize.y;
const float footer_h = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing();
ImGui::SetNextWindowPos({ disp_w / 2, disp_h - 150 }, ImGuiCond_Once, { 0.5f, 0.0f });
ImGui::SetNextWindowSize({ 600, 128 }, ImGuiCond_Once);
bool any_hovered = false;
if (ImGui::Begin("Trace Log", &ui.window_open.tracelog, ImGuiWindowFlags_None)) {
Expand Down

0 comments on commit 6f73988

Please sign in to comment.