Skip to content

Commit

Permalink
LibGUI+Inspector: Highlight the currently remotely inspected widget
Browse files Browse the repository at this point in the history
This patch adds a magenta rectangle around the currently inspected
widget. This allows you to browse an app's widget tree somewhat
visually using the Inspector. :^)
  • Loading branch information
awesomekling committed Mar 5, 2020
1 parent d16f821 commit e23c5b7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions DevTools/Inspector/RemoteProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ void RemoteProcess::send_request(const JsonObject& request)
m_socket->write(serialized);
}

void RemoteProcess::set_inspected_object(uintptr_t address)
{
JsonObject request;
request.set("type", "SetInspectedObject");
request.set("address", address);
send_request(request);
}

void RemoteProcess::update()
{
m_socket->on_connected = [this] {
Expand Down
2 changes: 2 additions & 0 deletions DevTools/Inspector/RemoteProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class RemoteProcess {
RemoteObjectGraphModel& object_graph_model() { return *m_object_graph_model; }
const NonnullOwnPtrVector<RemoteObject>& roots() const { return m_roots; }

void set_inspected_object(uintptr_t);

Function<void()> on_update;

private:
Expand Down
1 change: 1 addition & 0 deletions DevTools/Inspector/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ int main(int argc, char** argv)
tree_view.on_activation = [&](auto& index) {
auto* remote_object = static_cast<RemoteObject*>(index.internal_data());
properties_table_view.set_model(remote_object->property_model());
remote_process.set_inspected_object(remote_object->json.get("address").to_number<uintptr_t>());
};

window->show();
Expand Down
15 changes: 15 additions & 0 deletions Libraries/LibGUI/Widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ void Widget::handle_paint_event(PaintEvent& event)
return IterationDecision::Continue;
});
second_paint_event(event);

if (is_being_inspected()) {
Painter painter(*this);
painter.draw_rect(rect(), Color::Magenta);
}
}

void Widget::set_layout(NonnullRefPtr<Layout> layout)
Expand Down Expand Up @@ -763,4 +768,14 @@ Gfx::Palette Widget::palette() const
return Gfx::Palette(*m_palette);
}

void Widget::did_begin_inspection()
{
update();
}

void Widget::did_end_inspection()
{
update();
}

}
3 changes: 3 additions & 0 deletions Libraries/LibGUI/Widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ class Widget : public Core::Object {
virtual void drag_move_event(DragEvent&);
virtual void drop_event(DropEvent&);

virtual void did_begin_inspection() override;
virtual void did_end_inspection() override;

private:
void handle_paint_event(PaintEvent&);
void handle_resize_event(ResizeEvent&);
Expand Down

0 comments on commit e23c5b7

Please sign in to comment.