按钮
void draw();
void onButtonClick(void*);
int btnNum;
void Demo::draw(){
ImVec2 d_linesize(80, 30);
ImVec2 d_paddingsize(5, 10);
ImGui::PushStyleColor(ImGuiCol_Button, { 0.5f, 0.2f,0.2f,1.0f });
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, { 0.0f, 0.5f, 0.5f, 1.0f });
ImGui::PushStyleColor(ImGuiCol_ButtonActive, { 0.5f, 0.0f, 0.5f, 1.0f });
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 10.0f);
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, d_paddingsize);
ImGui::PushID("myButton");
if(ImGui::Button("Button_4", d_linesize)) {
onButtonClick(this);
}
ImGui::PopID();
ImGui::PopStyleColor(3);
ImGui::PopStyleVar(2);
}
void Demo::onButtonClick(void* userdata) {
cout << "我被点击了" << btnNum << endl;
btnNum += 1;
}
图片按钮
void draw();
void onImgButtonClick(void*);
GLuint img1;
ofTexture image;
ofxImGui::Gui gui;
bool flag;
void Demo::draw(){
img1 = gui.loadTexture(image, "ground.jpg");//导入图片
ImVec2 buttonSize(108, 24);//设置图片宽高
ImTextureID textureID = (ImTextureID)img1;//添加图片的唯一ID
ImVec4 buttonColor(1.0f, 1.0f, 1.0f, 0.5f);
ImGui::ImageButton(textureID, buttonSize, ImVec2(0, 0), ImVec2(1, 1), 0);
bool pressed = ImGui::IsItemClicked(); // 定义是否点击变量
if(presswd) {
flag = !flag;
}
if(flag){
ImGui::Button("按钮", ImVec2(108, 24));
}
}
void Demo::onImgButtonClick(void* userdata) {
cout << "成功" << endl;
flag = !flag;
}