Comments (14)
@jvcleave
IsPosHoveringAnyWindow()
happens to be broken (and was always broken depending on the call timing), and anyway it isn't what you want to use, I think you need to use io.WantCaptureMouse
for that purpose.
io.WantCaptureMouse will handle more use cases and behaviors, should as clicking on a drag/slider widget and moving the mouse outside the imgui window (you still want to be capturing mouse in this case).
from ofximgui.
I would like to check if the mouse is inside a specific widget, like a text input.
You can use IsItemHovered()...
from ofximgui.
Any way you could provide a small app just so we have a base to talk around?
from ofximgui.
ok, I see what you are saying - here is what I am playing with
#include "ofMain.h"
#include "ofxImGui.h"
class ofApp : public ofBaseApp{
public:
ofEasyCam easyCam;
ofxImGui gui;
float floatValue;
ofColor backgroundColor;
void setup()
{
//
easyCam.setDistance(100);
gui.setup();
floatValue = 0.0f;
backgroundColor = ofColor(114, 144, 154);
}
void update()
{
}
void draw()
{
ofSetBackgroundColor(backgroundColor);
ofPushStyle();
ofEnableDepthTest();
easyCam.begin();
ofNoFill();
ofDrawBox(30);
easyCam.end();
ofPopStyle();
ofDisableDepthTest();
gui.begin();
ImGui::Text("Hello, world!");
ImGui::SliderFloat("Float", &floatValue, 0.0f, 1.0f);
//this will change the app background color
ImGui::ColorEdit3("Background Color", (float*)&backgroundColor);
gui.end();
}
void keyPressed(int key)
{
}
void keyReleased(int key)
{
}
void mouseMoved(int x, int y )
{
}
void mouseDragged(int x, int y, int button)
{
}
void mousePressed(int x, int y, int button)
{
}
void mouseReleased(int x, int y, int button)
{
}
};
//========================================================================
int main( ){
ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context
// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
ofRunApp(new ofApp());
}
from ofximgui.
yes sorry, that's exactly what I meant. This is a problem I've always had with guis in OF :) not sure if it can be addressed without structural changes to the way events are handled in the core?
from ofximgui.
This seems to work ok
void draw()
{
ofSetBackgroundColor(backgroundColor);
ofPushStyle();
ofEnableDepthTest();
bool isHovering = ImGui::IsPosHoveringAnyWindow(ofVec2f(ofGetMouseX(), ofGetMouseY()));
ofLogVerbose() << "isHovering: " << isHovering;
if(isHovering)
{
easyCam.disableMouseInput();
}else
{
easyCam.enableMouseInput();
}
easyCam.begin();
ofNoFill();
ofDrawBox(30);
easyCam.end();
ofPopStyle();
ofDisableDepthTest();
gui.begin();
ImGui::Text("Hello, world!");
ImGui::SliderFloat("Float", &floatValue, 0.0f, 1.0f);
//this will change the app background color
ImGui::ColorEdit3("Background Color", (float*)&backgroundColor);
gui.end();
}
from ofximgui.
oh wow that's smart thanks. still need a more generic solution. e.g. when typing in a text field, the key events are still sent to the ofApp::keyPressed. So would need to add a similar check for key events. but this is great!
from ofximgui.
Cool - The hover check may actually still apply with textfields as well. If not there is probably a focus check
from ofximgui.
yup this is cool and works, thx
from ofximgui.
hey @ocornut ,
(not sure if It's better to write into your ImGui repo...)
I would like to check if the mouse is inside a specific widget, like a text input.
How can I do this?
For the moment I am checking if the mouse it's inside any ImGui window doing this:
// draw()
mouseOverGui = ImGuiDraw();
mouseOverGui = ofxImGui::IsMouseOverGui();
if (mouseOverGui != mouseOverGui_PRE)// changed
{
mouseOverGui_PRE = mouseOverGui;
ofLog() << "mouseOverGui: " << (mouseOverGui ? " Going InSide" : " Going outSide");
}
//-----------
// ImGuiDraw()
std::string _text = "type here";
char tab2[32];
strncpy(tab2, _text.c_str(), sizeof(tab2));
tab2[sizeof(tab2) - 1] = 0;
if (ImGui::InputText("", tab2, IM_ARRAYSIZE(tab2)))
{
ofLog() << "InputText:" << ofToString(tab2);
_text = ofToString(tab2);
}
from ofximgui.
bool ofxImGui::IsMouseOverGui()
{
return ImGui::IsWindowHovered(ImGuiHoveredFlags_AnyWindow);
}
I see this:
// Flags for ImGui::IsItemHovered(), ImGui::IsWindowHovered()
// Note: if you are trying to check whether your mouse should be dispatched to imgui or to your app, you should use the 'io.WantCaptureMouse' boolean for that. Please read the FAQ!
// Note: windows with the ImGuiWindowFlags_NoInputs flag are ignored by IsWindowHovered() calls.
enum ImGuiHoveredFlags_
{
ImGuiHoveredFlags_None = 0, // Return true if directly over the item/window, not obstructed by another window, not obstructed by an active popup or modal blocking inputs under them.
ImGuiHoveredFlags_ChildWindows = 1 << 0, // IsWindowHovered() only: Return true if any children of the window is hovered
ImGuiHoveredFlags_RootWindow = 1 << 1, // IsWindowHovered() only: Test from root window (top most parent of the current hierarchy)
ImGuiHoveredFlags_AnyWindow = 1 << 2, // IsWindowHovered() only: Return true if any window is hovered
ImGuiHoveredFlags_AllowWhenBlockedByPopup = 1 << 3, // Return true even if a popup window is normally blocking access to this item/window
//ImGuiHoveredFlags_AllowWhenBlockedByModal = 1 << 4, // Return true even if a modal popup window is normally blocking access to this item/window. FIXME-TODO: Unavailable yet.
ImGuiHoveredFlags_AllowWhenBlockedByActiveItem = 1 << 5, // Return true even if an active item is blocking access to this item/window. Useful for Drag and Drop patterns.
ImGuiHoveredFlags_AllowWhenOverlapped = 1 << 6, // Return true even if the position is obstructed or overlapped by another window
ImGuiHoveredFlags_AllowWhenDisabled = 1 << 7, // Return true even if the item is disabled
ImGuiHoveredFlags_RectOnly = ImGuiHoveredFlags_AllowWhenBlockedByPopup | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem | ImGuiHoveredFlags_AllowWhenOverlapped,
ImGuiHoveredFlags_RootAndChildWindows = ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows
};
from ofximgui.
sorry,
but where must be placed?
I tried inside and / or after the InputText
but is not appearing...
if (ImGui::InputText("", tab2, IM_ARRAYSIZE(tab2)))
{
//if (ImGui::IsItemHovered())
// ImGui::SetTooltip("I am a tooltip");
textInput_temp = ofToString(tab2);
}
if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("I am a tooltip");
}
from ofximgui.
from ofximgui.
solved. Thanks.
if (ImGui::InputText("", tab, IM_ARRAYSIZE(tab)))
{
textInput_New = ofToString(tab);
ofLog() << "textInput_New:" << textInput_New;
}
bool b = bTextInputActive;
bTextInputActive = ImGui::IsItemActive();
if (bTextInputActive != b) // hover into textInput changed
ofLog() << "TextInput : " << (bTextInputActive?"ACTIVE":"DISABLED");
from ofximgui.
Related Issues (20)
- No gui on Android HOT 2
- UTF-8 rendering fails with garbled characters. I need your help! Thank you! HOT 2
- input latin characters HOT 2
- ofxImGuiLoggerChannel.h HOT 2
- Merging forks : ImGuiContext and more HOT 8
- EGl window rk boards HOT 10
- ofxImGui upgrade HOT 8
- arb textures HOT 1
- imgui_stdlib.h and imgui_stdlib.cpp should be included in project files HOT 1
- Closing a window within a window? HOT 3
- imgui_impl_glfw_context_support.h missing from develop branch.
- develop brach broken HOT 5
- ofxImGui::Gui::exit() released context, can't Gui::setup() again HOT 2
- OF 0.12 compatibility
- Drawing ofFbo's texture as ImGui::Image(); HOT 3
- adding imGui as submodule? HOT 1
- how can we add the color picker expanded by default? HOT 2
- it's possible to use more than one instance of ofxImGui (inside classes) in the same ofApp? HOT 3
- Unknown type name 'ofVec2f'
- I make oF window borderless(not fullscreen),the screen display has an offset(mouse also)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ofximgui.