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

Fixed backspace handling on MacOS and allow null view parameter to NewFrame #2818

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/imgui_impl_osx.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@

IMGUI_API bool ImGui_ImplOSX_Init();
IMGUI_API void ImGui_ImplOSX_Shutdown();
IMGUI_API void ImGui_ImplOSX_NewFrame(NSView *_Nonnull view);
IMGUI_API void ImGui_ImplOSX_NewFrame(NSView *_Nullable view);
IMGUI_API bool ImGui_ImplOSX_HandleEvent(NSEvent *_Nonnull event, NSView *_Nullable view);
11 changes: 7 additions & 4 deletions examples/imgui_impl_osx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,12 @@ void ImGui_ImplOSX_NewFrame(NSView* view)
{
// Setup display size
ImGuiIO& io = ImGui::GetIO();
const float dpi = [view.window backingScaleFactor];
io.DisplaySize = ImVec2((float)view.bounds.size.width, (float)view.bounds.size.height);
io.DisplayFramebufferScale = ImVec2(dpi, dpi);
if (view)
{
const float dpi = [view.window backingScaleFactor];
io.DisplaySize = ImVec2((float)view.bounds.size.width, (float)view.bounds.size.height);
io.DisplayFramebufferScale = ImVec2(dpi, dpi);
}

// Setup time step
if (g_Time == 0.0)
Expand Down Expand Up @@ -250,7 +253,7 @@ bool ImGui_ImplOSX_HandleEvent(NSEvent* event, NSView* view)
for (int i = 0; i < len; i++)
{
int c = [str characterAtIndex:i];
if (!io.KeyCtrl && !(c >= 0xF700 && c <= 0xFFFF))
if (!io.KeyCtrl && !((c >= 0xF700 && c <= 0xFFFF) || c == 127))
io.AddInputCharacter((unsigned int)c);

// We must reset in case we're pressing a sequence of special keys while keeping the command pressed
Expand Down