-
-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Selected ImGui::Button & Change Color #777
Comments
Hello, |
When i push a button, i would like that this button changing the Color. For example: And i would like that only this one button color is changing. charenc is just my encryption. |
PushStyleCol() / Button() / PopStyleCol() is probably what you want.
??? |
fixed! Thank you very much. |
is there a button callback function to do something when the button is pressed? |
Callbacks are the opposite of how dear imgui works. Every button return true when pressed. Check out the demo code. |
Thnx a lot for your reply, I have done as you asked me to do, the demo code is a great reference. |
Please specify exactly which example, which OS and which version. Thank you. |
Example: example_freeglut_opengl2 |
@FullStackDevoloper This is fixed as part of #2430 |
I don't really understand how it works...
i want the button to be a color and when i press it to change the color and then again back to the default color, how should i do that? |
Hello. This snippet can help you. color is your default color of type ImVec4.
|
I'm also having this problem. @Solisuom I think what @PINKColorful is looking for is the press event, rather than the click event. That is, for the button to be coloured during press-and-hold, rather than after it has been releasaed. At the moment, it seems I found that you can achieve this using the enum SmartButtonState {
None = 0,
Hovered,
Pressed,
Released,
DoubleClicked // Not yet implemented
};
static SmartButtonState SmartButton(const char* label, ImVec2 size = {0, 0}) {
bool released = ImGui::Button(label, size);
// Order of these are important
if (released) return SmartButtonState::Released;
if (ImGui::IsItemActive()) return SmartButtonState::Pressed;
if (ImGui::IsItemHovered()) return SmartButtonState::Hovered;
return SmartButtonState::None;
} The important bits being to color not just the button itself, but also when it's hovered and pressed, else your custom color would get overridden by those. You may want to give those a different color too, to indicate whether hovering is happening or not. Used like this. void drawButtons() {
ImGui::Begin("Buttons", nullptr);
{
static const auto size = ImVec2(150, 40);
static const ImVec4 pressColor { 0.5f, 0, 0, 1.0f };
static const ImVec4 releaseColor { 0, 0.5f, 0, 1.0f };
static ImVec4 currentColor = releaseColor;
ImGui::PushStyleColor(ImGuiCol_Button, currentColor);
ImGui::PushStyleColor(ImGuiCol_ButtonActive, currentColor);
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, currentColor);
auto state = SmartButton("Press Me", size);
ImGui::PopStyleColor(3);
if (state == SmartButtonState::Pressed) {
currentColor = pressColor;
}
else if (state == SmartButtonState::Released) {
currentColor = releaseColor;
}
ImGui::SameLine();
if (SmartButton("Green", size) == SmartButtonState::Released) {
printf("Clicked\n");
}
ImGui::SameLine();
SmartButton("Blue", size);
}
ImGui::End();
} With 3 caveats.
Here's an example of (2) and (3). You could probably leverage |
To create custom behavior with regards to coloring the button, you can copy the contents of Otherwise for anything else as you pointed you can use the |
Hello,
I don't know if it's a Issue or a coding issue by myself.
Following this Code:
ImGui::Begin(charenc("test"), &Vars.Menu.Opened, ImVec2(1000, 720), 0.8f, ImGuiWindowFlags_ShowBorders | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_ShowBorders);
{
if (Vars.Menu.openmethod == 0)
{
etc...
My openmethod is declared as int.
When i push the button "test1" is this button in my opinion active, why is this button color not changed as defined in:
style.Colors[ImGuiCol_Button] = ImVec4(0.85f, 0.85f, 0.85f, 1.f);
style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.85f, 0.85f, 0.85f, 1.f);
style.Colors[ImGuiCol_ButtonActive] = ImVec4(1.00f, 0.00f, 0.00f, 1.f);
Is there any option to change the button only from test 1 when i clicked on him?
All other buttons should be still in normal color.
Warm regards.
The text was updated successfully, but these errors were encountered: