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

Push/Pop TweakedTheme - Change theme per window #111

Closed
colesnicov opened this issue May 25, 2024 · 2 comments
Closed

Push/Pop TweakedTheme - Change theme per window #111

colesnicov opened this issue May 25, 2024 · 2 comments
Labels

Comments

@colesnicov
Copy link

Hello. Could you implement ImGuiTheme::Push(ImGuiTweakedTheme ...)/ImGuiTheme::Pop methods for ImGuiTheme? I would like to be able to apply a theme to only one window, or to one element or group of elements..

@pthom
Copy link
Owner

pthom commented May 26, 2024

Hello,

This is actually a good idea. I just added this feature.

See f5c6f82 (inside Hello ImGui)

And pthom/imgui_bundle@90298ce (inside ImGui Bundle)

image

@pthom pthom changed the title Push/Pop TweakedTheme REQUEST Push/Pop TweakedTheme - Change theme per window May 26, 2024
@pthom pthom added the faq label May 26, 2024
@colesnicov
Copy link
Author

I modified part of the code from imgui demo.cpp.
Specifically from the 'Style Editor':

static void Push(ImGuiStyle *_style_from) {
//	Main
	ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, _style_from->WindowPadding);
	ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, _style_from->FramePadding);
	ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, _style_from->ItemSpacing);
	ImGui::PushStyleVar(ImGuiStyleVar_ItemInnerSpacing, _style_from->ItemInnerSpacing);
	ImGui::PushStyleVar(ImGuiStyleVar_IndentSpacing, _style_from->IndentSpacing);
	ImGui::PushStyleVar(ImGuiStyleVar_ScrollbarSize, _style_from->ScrollbarSize);
	ImGui::PushStyleVar(ImGuiStyleVar_GrabMinSize, _style_from->GrabMinSize);
//	Borders
	ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, _style_from->WindowBorderSize);
	ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, _style_from->ChildBorderSize);
	ImGui::PushStyleVar(ImGuiStyleVar_PopupBorderSize, _style_from->PopupBorderSize);
	ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, _style_from->FrameBorderSize);
	ImGui::PushStyleVar(ImGuiStyleVar_TabBorderSize, _style_from->TabBorderSize);
	ImGui::PushStyleVar(ImGuiStyleVar_TabBarBorderSize, _style_from->TabBarBorderSize);
//	Rounding
	ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, _style_from->WindowRounding);
	ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, _style_from->ChildRounding);
	ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, _style_from->FrameRounding);
	ImGui::PushStyleVar(ImGuiStyleVar_PopupRounding, _style_from->PopupRounding);
	ImGui::PushStyleVar(ImGuiStyleVar_ScrollbarRounding, _style_from->ScrollbarRounding);
	ImGui::PushStyleVar(ImGuiStyleVar_GrabRounding, _style_from->GrabRounding);
	ImGui::PushStyleVar(ImGuiStyleVar_TabRounding, _style_from->TabRounding);
//	Tables
	ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, _style_from->CellPadding);
	ImGui::PushStyleVar(ImGuiStyleVar_TableAngledHeadersAngle,
			_style_from->TableAngledHeadersAngle);
//	Widgets
	ImGui::PushStyleVar(ImGuiStyleVar_WindowTitleAlign, _style_from->WindowTitleAlign);
	ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, _style_from->ButtonTextAlign);
	ImGui::PushStyleVar(ImGuiStyleVar_SelectableTextAlign, _style_from->SelectableTextAlign);
	ImGui::PushStyleVar(ImGuiStyleVar_SeparatorTextBorderSize,
			_style_from->SeparatorTextBorderSize);
	ImGui::PushStyleVar(ImGuiStyleVar_SeparatorTextAlign, _style_from->SeparatorTextAlign);
	ImGui::PushStyleVar(ImGuiStyleVar_SeparatorTextPadding, _style_from->SeparatorTextPadding);

//	Rendering
	ImGui::PushStyleVar(ImGuiStyleVar_Alpha, _style_from->Alpha);
	ImGui::PushStyleVar(ImGuiStyleVar_DisabledAlpha, _style_from->DisabledAlpha);

	//	Colors
	for (int i = 0; i < ImGuiCol_COUNT; i++) {
		ImGui::PushStyleColor(i, _style_from->Colors[i]);
	}
}

and

void Pop() {
	ImGui::PopStyleVar(ImGuiStyleVar_COUNT - 2);
	ImGui::PopStyleColor(ImGuiCol_COUNT);
}

Not all variables are set, some are global to the entire application. For example ImGuiStyleVar_TaouchExtraPadding and ImGuiStyleVar_AntiAliasedLines or Docking...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants