🎯 **PRODUCTION-READY UI ARCHITECTURE** - Data-agnostic IUI interface with type-safe enums for performance - Revolutionary hybrid sizing: percentage targets + absolute pixel constraints - Hierarchical windowing: Parent → Dock → Split → Tab → Window structure - Complete ImGuiUI implementation with all DataType content renderers 🔧 **DEVELOPMENT INFRASTRUCTURE** - AddressSanitizer + GDB debugging workflow for instant crash detection - Cross-platform pipeline: Linux development → Windows .exe automation - Debug mode default with comprehensive sanitizer coverage 📊 **TECHNICAL ACHIEVEMENTS** - Fixed JSON type mixing and buffer overflow crashes with precise debugging - Mathematical hybrid sizing formula: clamp(percentage_target, min_px, max_px) - Professional layout system: economic topbar + companies panel + strategic map - Interactive callback system with request/response architecture 🚀 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
175 lines
6.7 KiB
C++
175 lines
6.7 KiB
C++
#include "core/include/warfactory/IUI_Enums.h"
|
|
#include "core/include/warfactory/ImGuiUI.h"
|
|
|
|
using namespace warfactory;
|
|
|
|
int main() {
|
|
// Create ImGuiUI instance
|
|
ImGuiUI ui;
|
|
|
|
// Initialize with basic config
|
|
ui.initialize({
|
|
{"title", "ImGuiUI Test - Hybrid Sizing System"},
|
|
{"window_size", {{"width", 1400}, {"height", 900}}}
|
|
});
|
|
|
|
ui.info("Testing ImGuiUI implementation with hybrid sizing system");
|
|
|
|
// Test 1: Responsive sidebar - 20% but min 250px
|
|
ui.createDock("sidebar", DockType::TABBED, DockPosition::LEFT, {
|
|
{"size", {{"width", "20%"}}}, // Target 20% = 280px
|
|
{"min_size", {{"width", 250}}}, // Minimum 250px
|
|
{"max_size", {{"width", 400}}}, // Maximum 400px
|
|
{"resizable", true},
|
|
{"collapsible", true}
|
|
});
|
|
|
|
ui.success("Created responsive sidebar: Target 20%, min 250px, max 400px");
|
|
|
|
// Test 2: Bottom console - 25% height with hybrid constraints
|
|
ui.createDock("console", DockType::DOCK, DockPosition::BOTTOM, {
|
|
{"size", {{"height", "25%"}}}, // Target 25% = 225px
|
|
{"min_size", {{"height", 120}}}, // Minimum 4 lines
|
|
{"max_size", {{"height", "35%"}}}, // Max 35% = 315px
|
|
{"resizable", true}
|
|
});
|
|
|
|
ui.success("Created bottom console: Target 25%, min 120px, max 35%");
|
|
|
|
// Test 3: Economy window in sidebar
|
|
ui.showData(DataType::ECONOMY, {
|
|
{"content", {
|
|
{"prices", {{"steel_plate", 5.2}, {"iron_ore", 1.1}, {"copper_ore", 0.8}}},
|
|
{"trends", {{"steel_plate", "+2.1%"}, {"iron_ore", "-0.5%"}, {"copper_ore", "+1.2%"}}},
|
|
{"market_status", "stable"}
|
|
}},
|
|
{"window", {
|
|
{"id", "economy_main"},
|
|
{"title", "💰 Economy Dashboard"},
|
|
{"parent", "sidebar"},
|
|
{"dock", "tab"},
|
|
{"size", {{"width", "90%"}, {"height", 300}}}, // 90% of sidebar, 300px height
|
|
{"min_size", {{"width", 200}, {"height", 250}}}, // Readable minimum
|
|
{"max_size", {{"width", "95%"}, {"height", 400}}} // Max 95% sidebar, 400px
|
|
}}
|
|
});
|
|
|
|
ui.info("Created economy window: 90% of sidebar width x 300px height");
|
|
|
|
// Test 4: Map window
|
|
ui.showData(DataType::MAP, {
|
|
{"content", {
|
|
{"current_chunk", {{"x", 0}, {"y", 0}}},
|
|
{"tiles", {{"iron", 25}, {"copper", 15}, {"coal", 10}}}
|
|
}},
|
|
{"window", {
|
|
{"id", "map_main"},
|
|
{"title", "🗺️ Global Map"},
|
|
{"size", {{"width", "50%"}, {"height", "60%"}}}, // 50% x 60% of screen
|
|
{"min_size", {{"width", 400}, {"height", 300}}}, // Minimum for visibility
|
|
{"max_size", {{"width", 800}, {"height", 600}}} // Don't dominate
|
|
}}
|
|
});
|
|
|
|
ui.info("Created map window: 50% x 60% of screen with 400x300-800x600 constraints");
|
|
|
|
// Test 5: Settings dialog - floating with hybrid sizing
|
|
ui.showData(DataType::SETTINGS, {
|
|
{"content", {
|
|
{"graphics", {{"resolution", "1400x900"}, {"fullscreen", false}, {"vsync", true}}},
|
|
{"audio", {{"master_volume", 0.8}, {"effects_volume", 0.7}}},
|
|
{"controls", {{"mouse_sensitivity", 1.2}}}
|
|
}},
|
|
{"window", {
|
|
{"id", "settings_dialog"},
|
|
{"title", "⚙️ Settings"},
|
|
{"floating", true},
|
|
{"size", {{"width", "30%"}, {"height", "40%"}}}, // 30% x 40% of screen
|
|
{"min_size", {{"width", 400}, {"height", 300}}}, // Usable dialog size
|
|
{"max_size", {{"width", 600}, {"height", 500}}} // Don't dominate
|
|
}}
|
|
});
|
|
|
|
ui.info("Created settings dialog: Floating 30% x 40% with 400x300-600x500 constraints");
|
|
|
|
// Set up callbacks for testing
|
|
ui.onRequest(RequestType::GET_PRICES, [&](const json& req) {
|
|
ui.info("📈 Price update requested - would fetch from backend");
|
|
|
|
// Simulate price update
|
|
ui.showData(DataType::ECONOMY, {
|
|
{"content", {
|
|
{"prices", {{"steel_plate", 5.7}, {"iron_ore", 1.0}, {"copper_ore", 0.9}}},
|
|
{"trends", {{"steel_plate", "+9.6%"}, {"iron_ore", "-9.1%"}, {"copper_ore", "+12.5%"}}},
|
|
{"market_status", "volatile"}
|
|
}},
|
|
{"window", {
|
|
{"id", "economy_main"}
|
|
}}
|
|
});
|
|
});
|
|
|
|
ui.onRequest(RequestType::GET_CHUNK, [&](const json& req) {
|
|
ui.info("🗺️ Map chunk requested: " + req.dump());
|
|
|
|
// Simulate chunk update
|
|
ui.showData(DataType::MAP, {
|
|
{"content", {
|
|
{"current_chunk", {{"x", 1}, {"y", 0}}},
|
|
{"tiles", {{"iron", 30}, {"copper", 8}, {"stone", 12}}}
|
|
}},
|
|
{"window", {
|
|
{"id", "map_main"}
|
|
}}
|
|
});
|
|
});
|
|
|
|
ui.onRequestCustom("console_command", [&](const json& req) {
|
|
std::string command = req.value("command", "");
|
|
ui.info("💻 Console command: " + command);
|
|
|
|
if (command == "test_resize") {
|
|
ui.info("🔄 Testing window resize behavior...");
|
|
// All percentage-based sizes would recalculate automatically
|
|
} else if (command == "show_performance") {
|
|
ui.showData(DataType::PERFORMANCE, {
|
|
{"content", {
|
|
{"fps", 60},
|
|
{"frame_time", "16.7ms"},
|
|
{"memory_usage", "156MB"},
|
|
{"entities", 2847}
|
|
}},
|
|
{"window", {
|
|
{"id", "performance_monitor"},
|
|
{"title", "📊 Performance Monitor"},
|
|
{"size", {{"width", 300}, {"height", "25%"}}}, // 300px x 25% height
|
|
{"min_size", {{"width", 250}, {"height", 200}}},
|
|
{"floating", true}
|
|
}}
|
|
});
|
|
}
|
|
});
|
|
|
|
ui.success("All callbacks configured - UI ready for testing!");
|
|
ui.info("Commands: 'test_resize', 'show_performance'");
|
|
ui.info("Try resizing the window to see responsive percentage behavior");
|
|
|
|
// Main loop
|
|
int frame = 0;
|
|
while (ui.update()) {
|
|
frame++;
|
|
|
|
// Test automatic percentage recalculation every 5 seconds
|
|
if (frame == 300) { // 5s at 60fps
|
|
ui.debug("🔄 Simulating window resize - percentages recalculate automatically");
|
|
}
|
|
|
|
if (frame % 3600 == 0) { // Every 60 seconds
|
|
ui.info("Frame " + std::to_string(frame) + " - Hybrid sizing system operational");
|
|
}
|
|
}
|
|
|
|
ui.info("Shutting down ImGuiUI test");
|
|
ui.shutdown();
|
|
return 0;
|
|
} |