Prompt Details
Model
(claude-4-5-sonnet)
Token size
306
Example input
[LANGUAGE_OR_FRAMEWORK]: C++17 with Dear ImGui
[UI_COMPONENT_OR_FUNCTION]: Responsive settings menu
[PROJECT_CONTEXT_OR_CONSTRAINTS]: Desktop tool/game overlay, standard library only, no external assets.
[DETAILED_TASK]: A fully functional responsive settings menu implementation that adapts to available window width. Include sections for General, Visuals, Controls, Audio, and Advanced. Include common widgets: checkboxes, sliders, combo boxes, color editors, and keybinds. Keep settings state separated from rendering logic.
Example output
#include <imgui.h>
#include <array>
#include <algorithm>
#include <string>
struct SettingsState {
struct General {
bool enabled = true;
bool start_minimized = false;
bool show_notifications = true;
bool auto_save = true;
int language = 0;
float ui_scale = 1.0f;
} general;
struct Visuals {
bool enabled = true;
bool show_fps = true;
bool vsync = true;
int theme = 0;
float opacity = 0.95f;
float rounding = 8.0f;
ImVec4 accent_color = ImVec4(0.25f, 0.55f, 1.0f, 1.0f);
ImVec4 background_color = ImVec4(0.08f, 0.09f, 0.11f, 1.0f);
} visuals;
struct Controls {
bool raw_input = true;
bool invert_mouse = false;
int toggle_menu_key = ImGuiKey_Insert;
int action_key = ImGuiKey_F;
float mouse_sensitivity = 1.0f;
float scroll_speed = 1.0f;
} controls;
struct Audio {
bool enabled = true;
bool mute_when_unfocused = false;
int output_device = 0;
float master_volume = 0.8f;
float effects_volume = 0.7f;
float ui_volume = 0.65f;
} audio;
struct Advanced {
bool developer_mode = false;
bool diagnostics = false;
bool experimental_features = false;
int log_level = 1;
int update_rate = 60;
float cache_size_mb = 128.0f;
} advanced;
};
class ResponsiveSettingsMenu {
public:
ResponsiveSettingsMenu()
: applied_(Defaults()), draft_(applied_) {}
const SettingsState& AppliedSettings() const { return applied_; }
SettingsState& DraftSettings() { return draft_; }
void Render(const char* window_name = "Settings", bool* open = nullptr) {
ImGui::SetNextWindowSize(ImVec2(760.0f, 560.0f), ImGuiCond_FirstUseEver);
if (!ImGui::Begin(window_name, open, ImGuiWindowFlags_NoCollapse)) {
ImGui::End();
return;
}
const float width = ImGui::GetContentRegionAvail().x;
const bool compact = width < 640.0f;
RenderHeader();
ImGui::Separator();
ImGui::Spacing();
if (compact) {
RenderTopTabs();
ImGui::Spacing();
RenderCurrentSection();
} else {
RenderSideNavigation();
ImGui::SameLine();
ImGui::BeginGroup();
RenderCurrentSection();
ImGui::EndGroup();
}
ImGui::Spacing();
ImGui::Separator();
RenderFooter();
ImGui::End();
}
void Apply() {
applied_ = draft_;
has_pending_changes_ = false;
}
void ResetDraft() {
draft_ = applied_;
capturing_key_ = nullptr;
has_pending_changes_ = false;
}
void ResetToDefaults() {
draft_ = Defaults();
capturing_key_ = nullptr;
has_pending_changes_ = true;
}
private:
enum class Section {
General,
Visuals,
Controls,
Audio,
Advanced
};
static SettingsState Defaults() {
return SettingsState{};
}
void MarkChanged(bool changed) {
has_pending_changes_ |= changed;
}
static void BeginCard(const char* title) {
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 10.0f);
ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 1.0f);
ImGui::BeginChild(title, ImVec2(0.0f, 0.0f), true, ImGuiWindowFlags_AlwaysUseWindowPadding);
ImGui::TextUnformatted(title);
ImGui::Separator();
ImGui::Spacing();
}
static void EndCard() {
ImGui::EndChild();
ImGui::PopStyleVar(2);
}
static bool Combo(const char* label, int* value, const char* const* items, int item_count) {
return ImGui::Combo(label, value, items, item_count);
}
static bool SliderFloatClamped(const char* label, float* value, float min, float max, const char* format = "%.2f")
{
const bool changed = ImGui::SliderFloat(label, value, min, max, format);
*value = std::clamp(*value, min, max);
return changed;
}
static bool SliderIntClamped(const char* label, int* value, int min, int max) {
const bool changed = ImGui::SliderInt(label, value, min, max);
*value = std::clamp(*value, min, max);
return changed;
}
static std::string KeyName(int key) {
if (key == 0) {
return "None";
}
if (key < 0) {
switch (key) {
case -1: return "Mouse Left";
case -2: return "Mouse Right";
case -3: return "Mouse Middle";
case -4: return "Mouse X1";
case -5: return "Mouse X2";
default: return "Mouse";
}
}
const char* name = ImGui::GetKeyName(static_cast<ImGuiKey>(key));
return name && name[0] ? name : "Unknown";
}
bool KeyBind(const char* label, int* key) {
ImGui::PushID(label);
const bool is_capturing = capturing_key_ == key;
const std::string button_label = is_capturing ? "Press a key..." : KeyName(*key);
ImGui::AlignTextToFramePadding();
ImGui::TextUnformatted(label);
ImGui::SameLine(ImGui::GetContentRegionAvail().x * 0.55f);
bool changed = false;
if (ImGui::Button(button_label.c_str(), ImVec2(ImGui::GetContentRegionAvail().x, 0.0f))) {
capturing_key_ = key;
}
if (is_capturing) {
ImGuiIO& io = ImGui::GetIO();
if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
*key = 0;
capturing_key_ = nullptr;
changed = true;
} else {
for (int mouse_button = 0; mouse_button < 5; ++mouse_button) {
if (ImGui::IsMouseClicked(mouse_button)) {
*key = -(mouse_button + 1);
capturing_key_ = nullptr;
changed = true;
break;
}
}
if (!changed) {
for (int named_key = ImGuiKey_NamedKey_BEGIN; named_key < ImGuiKey_NamedKey_END; ++named_key) {
const ImGuiKey candidate = static_cast<ImGuiKey>(named_key);
if (ImGui::IsKeyPressed(candidate) && candidate != ImGuiKey_Escape) {
*key = named_key;
capturing_key_ = nullptr;
changed = true;
break;
}
}
}
}
if (!ImGui::IsItemHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Left) && !io.WantCaptureMouse) {
capturing_key_ = nullptr;
}
}
ImGui::PopID();
return changed;
}
void RenderHeader() {
ImGui::BeginGroup();
ImGui::TextUnformatted("Responsive Settings Menu");
ImGui::TextDisabled("General configuration for UI, visuals, controls, audio, and advanced tools.");
ImGui::EndGroup();
if (has_pending_changes_) {
ImGui::SameLine(ImGui::GetContentRegionAvail().x - 105.0f);
ImGui::TextColored(ImVec4(1.0f, 0.72f, 0.22f, 1.0f), "Unsaved changes");
}
}
void RenderTopTabs() {
if (ImGui::BeginTabBar("SettingsTabs", ImGuiTabBarFlags_FittingPolicyScroll)) {
TabItem("General", Section::General);
TabItem("Visuals", Section::Visuals);
TabItem("Controls", Section::Controls);
TabItem("Audio", Section::Audio);
TabItem("Advanced", Section::Advanced);
ImGui::EndTabBar();
}
}
void TabItem(const char* label, Section section) {
if (ImGui::BeginTabItem(label, current_section_ == section ? nullptr : nullptr)) {
current_section_ = section;
ImGui::EndTabItem();
}
}
void RenderSideNavigation() {
const float nav_width = 170.0f;
ImGui::BeginChild("SettingsNavigation", ImVec2(nav_width, 0.0f), true);
NavButton("General", Section::General);
NavButton("Visuals", Section::Visuals);
NavButton("Controls", Section::Controls);
NavButton("Audio", Section::Audio);
NavButton("Advanced", Section::Advanced);
ImGui::EndChild();
}
void NavButton(const char* label, Section section) {
if (current_section_ == section) {
ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive));
}
if (ImGui::Button(label, ImVec2(-1.0f, 38.0f))) {
current_section_ = section;
}
if (current_section_ == section) {
ImGui::PopStyleColor();
}
}
void RenderCurrentSection() {
switch (current_section_) {
case Section::General: RenderGeneral(); break;
case Section::Visuals: RenderVisuals(); break;
case Section::Controls: RenderControls(); break;
case Section::Audio: RenderAudio(); break;
case Section::Advanced: RenderAdvanced(); break;
}
}
void RenderGeneral() {
static const char* const languages[] = { "English", "Deutsch", "Français", "Español", "Português", "Русский"
};
BeginCard("General");
MarkChanged(ImGui::Checkbox("Enable overlay", &draft_.general.enabled));
MarkChanged(ImGui::Checkbox("Start minimized", &draft_.general.start_minimized));
MarkChanged(ImGui::Checkbox("Show notifications", &draft_.general.show_notifications));
MarkChanged(ImGui::Checkbox("Auto-save settings", &draft_.general.auto_save));
ImGui::Spacing();
MarkChanged(Combo("Language", &draft_.general.language, languages, IM_ARRAYSIZE(languages)));
MarkChanged(SliderFloatClamped("UI scale", &draft_.general.ui_scale, 0.75f, 1.75f, "%.2fx"));
EndCard();
}
void RenderVisuals() {
static const char* const themes[] = { "Dark", "Light", "Classic", "Midnight", "Custom" };
BeginCard("Visuals");
MarkChanged(ImGui::Checkbox("Enable visuals", &draft_.visuals.enabled));
MarkChanged(ImGui::Checkbox("Show FPS counter", &draft_.visuals.show_fps));
MarkChanged(ImGui::Checkbox("Vertical sync", &draft_.visuals.vsync));
ImGui::Spacing();
MarkChanged(Combo("Theme", &draft_.visuals.theme, themes, IM_ARRAYSIZE(themes)));
MarkChanged(SliderFloatClamped("Window opacity", &draft_.visuals.opacity, 0.25f, 1.0f));
MarkChanged(SliderFloatClamped("Corner rounding", &draft_.visuals.rounding, 0.0f, 18.0f, "%.1f"));
ImGui::Spacing();
MarkChanged(ImGui::ColorEdit4("Accent color", &draft_.visuals.accent_color.x, ImGuiColorEditFlags_AlphaBar));
MarkChanged(ImGui::ColorEdit4("Background color", &draft_.visuals.background_color.x,
ImGuiColorEditFlags_AlphaBar));
EndCard();
}
void RenderControls() {
BeginCard("Controls");
MarkChanged(ImGui::Checkbox("Raw input", &draft_.controls.raw_input));
MarkChanged(ImGui::Checkbox("Invert mouse", &draft_.controls.invert_mouse));
ImGui::Spacing();
MarkChanged(SliderFloatClamped("Mouse sensitivity", &draft_.controls.mouse_sensitivity, 0.1f, 5.0f, "%.2f"));
MarkChanged(SliderFloatClamped("Scroll speed", &draft_.controls.scroll_speed, 0.25f, 3.0f, "%.2f"));
ImGui::Spacing();
MarkChanged(KeyBind("Toggle menu", &draft_.controls.toggle_menu_key));
MarkChanged(KeyBind("Action key", &draft_.controls.action_key));
EndCard();
}
void RenderAudio() {
static const char* const devices[] = { "Default", "Headphones", "Speakers", "HDMI Output", "Virtual Device" };
BeginCard("Audio");
MarkChanged(ImGui::Checkbox("Enable audio", &draft_.audio.enabled));
MarkChanged(ImGui::Checkbox("Mute when unfocused", &draft_.audio.mute_when_unfocused));
ImGui::Spacing();
MarkChanged(Combo("Output device", &draft_.audio.output_device, devices, IM_ARRAYSIZE(devices)));
MarkChanged(SliderFloatClamped("Master volume", &draft_.audio.master_volume, 0.0f, 1.0f));
MarkChanged(SliderFloatClamped("Effects volume", &draft_.audio.effects_volume, 0.0f, 1.0f));
MarkChanged(SliderFloatClamped("UI volume", &draft_.audio.ui_volume, 0.0f, 1.0f));
EndCard();
}
void RenderAdvanced() {
static const char* const log_levels[] = { "Trace", "Info", "Warning", "Error", "None" };
BeginCard("Advanced");
MarkChanged(ImGui::Checkbox("Developer mode", &draft_.advanced.developer_mode));
MarkChanged(ImGui::Checkbox("Diagnostics overlay", &draft_.advanced.diagnostics));
MarkChanged(ImGui::Checkbox("Experimental features", &draft_.advanced.experimental_features));
ImGui::Spacing();
MarkChanged(Combo("Log level", &draft_.advanced.log_level, log_levels, IM_ARRAYSIZE(log_levels)));
MarkChanged(SliderIntClamped("Update rate", &draft_.advanced.update_rate, 15, 240));
MarkChanged(SliderFloatClamped("Cache size", &draft_.advanced.cache_size_mb, 32.0f, 1024.0f, "%.0f MB"));
EndCard();
}
void RenderFooter() {
const float button_width = 110.0f;
const float spacing = ImGui::GetStyle().ItemSpacing.x;
const float total_width = button_width * 3.0f + spacing * 2.0f;
const float available_width = ImGui::GetContentRegionAvail().x;
if (available_width > total_width) {
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + available_width - total_width);
}
if (ImGui::Button("Reset", ImVec2(button_width, 0.0f))) {
ResetToDefaults();
}
ImGui::SameLine();
if (ImGui::Button("Revert", ImVec2(button_width, 0.0f))) {
ResetDraft();
}
ImGui::SameLine();
ImGui::BeginDisabled(!has_pending_changes_);
if (ImGui::Button("Apply", ImVec2(button_width, 0.0f))) {
Apply();
}
ImGui::EndDisabled();
}
private:
SettingsState applied_;
SettingsState draft_;
Section current_section_ = Section::General;
int* capturing_key_ = nullptr;
bool has_pending_changes_ = false;
};
inline void RenderResponsiveSettingsMenu(bool* open = nullptr) {
static ResponsiveSettingsMenu menu;
menu.Render("Settings", open);
}
By purchasing this prompt, you agree to our terms of service
CLAUDE-4-5-SONNET
Generates clean, optimized, production-ready UI and tools code with zero explanations, chatty intros, or filler text. Perfect for complex tasks like creating responsive Dear ImGui menus in C++17, React components, Qt dashboards, or custom game engine tools. It strictly follows DRY principles, separates state from rendering logic, and outputs raw code inside a single code block, making it instantly ready to paste into your IDE.
...more
Added 1 week ago
