mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 05:58:11 +00:00
LibGUI: Add GWidget::for_each_child_widget(callback).
This commit is contained in:
parent
906fde8f8c
commit
723ba91f74
6 changed files with 43 additions and 40 deletions
|
@ -55,13 +55,11 @@ void GRadioButton::for_each_in_group(Callback callback)
|
|||
{
|
||||
if (!parent())
|
||||
return;
|
||||
for (auto& object : parent()->children()) {
|
||||
if (!object->is_widget())
|
||||
continue;
|
||||
if (!static_cast<GWidget*>(object)->is_radio_button())
|
||||
continue;
|
||||
callback(*static_cast<GRadioButton*>(object));
|
||||
}
|
||||
for_each_child_widget([&] (auto& child) {
|
||||
if (!child.is_radio_button())
|
||||
return IterationDecision::Continue;
|
||||
return callback(static_cast<GRadioButton&>(child));
|
||||
});
|
||||
}
|
||||
|
||||
void GRadioButton::click()
|
||||
|
@ -71,6 +69,7 @@ void GRadioButton::click()
|
|||
for_each_in_group([this] (auto& button) {
|
||||
if (&button != this)
|
||||
button.set_checked(false);
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
set_checked(true);
|
||||
}
|
||||
|
|
|
@ -40,17 +40,15 @@ void GSplitter::mousedown_event(GMouseEvent& event)
|
|||
GWidget* first_resizee { nullptr };
|
||||
GWidget* second_resizee { nullptr };
|
||||
int fudge = layout()->spacing();
|
||||
for (auto* child : children()) {
|
||||
if (!child->is_widget())
|
||||
continue;
|
||||
auto& child_widget = *static_cast<GWidget*>(child);
|
||||
int child_start = m_orientation == Orientation::Horizontal ? child_widget.relative_rect().left() : child_widget.relative_rect().top();
|
||||
int child_end = m_orientation == Orientation::Horizontal ? child_widget.relative_rect().right() : child_widget.relative_rect().bottom();
|
||||
for_each_child_widget([&] (auto& child) {
|
||||
int child_start = m_orientation == Orientation::Horizontal ? child.relative_rect().left() : child.relative_rect().top();
|
||||
int child_end = m_orientation == Orientation::Horizontal ? child.relative_rect().right() : child.relative_rect().bottom();
|
||||
if (x_or_y > child_end && (x_or_y - fudge) <= child_end)
|
||||
first_resizee = &child_widget;
|
||||
first_resizee = &child;
|
||||
if (x_or_y < child_start && (x_or_y + fudge) >= child_start)
|
||||
second_resizee = &child_widget;
|
||||
}
|
||||
second_resizee = &child;
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
ASSERT(first_resizee && second_resizee);
|
||||
m_first_resizee = first_resizee->make_weak_ptr();
|
||||
m_second_resizee = second_resizee->make_weak_ptr();
|
||||
|
|
|
@ -61,12 +61,10 @@ void GTabWidget::child_event(CChildEvent& event)
|
|||
} else if (event.type() == GEvent::ChildRemoved) {
|
||||
if (m_active_widget == &child) {
|
||||
GWidget* new_active_widget = nullptr;
|
||||
for (auto* new_child : children()) {
|
||||
if (new_child->is_widget()) {
|
||||
new_active_widget = static_cast<GWidget*>(new_child);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for_each_child_widget([&] (auto& new_child) {
|
||||
new_active_widget = &new_child;
|
||||
return IterationDecision::Abort;
|
||||
});
|
||||
set_active_widget(new_active_widget);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,15 +116,15 @@ void GWidget::handle_paint_event(GPaintEvent& event)
|
|||
#endif
|
||||
}
|
||||
paint_event(event);
|
||||
for (auto* ch : children()) {
|
||||
auto* child = (GWidget*)ch;
|
||||
if (!child->is_visible())
|
||||
continue;
|
||||
if (child->relative_rect().intersects(event.rect())) {
|
||||
GPaintEvent local_event(event.rect().intersected(child->relative_rect()).translated(-child->relative_position()));
|
||||
child->event(local_event);
|
||||
}
|
||||
for_each_child_widget([&] (auto& child) {
|
||||
if (!child.is_visible())
|
||||
return IterationDecision::Continue;
|
||||
if (child.relative_rect().intersects(event.rect())) {
|
||||
GPaintEvent local_event(event.rect().intersected(child.relative_rect()).translated(-child.relative_position()));
|
||||
child.event(local_event);
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
second_paint_event(event);
|
||||
}
|
||||
|
||||
|
|
|
@ -185,6 +185,16 @@ public:
|
|||
void register_local_shortcut_action(Badge<GAction>, GAction&);
|
||||
void unregister_local_shortcut_action(Badge<GAction>, GAction&);
|
||||
|
||||
template<typename Callback>
|
||||
void for_each_child_widget(Callback callback)
|
||||
{
|
||||
for_each_child([&] (auto& child) {
|
||||
if (child.is_widget())
|
||||
return callback(static_cast<GWidget&>(child));
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
}
|
||||
|
||||
virtual bool is_radio_button() const { return false; }
|
||||
|
||||
private:
|
||||
|
|
|
@ -526,16 +526,14 @@ Vector<GWidget*> GWindow::focusable_widgets() const
|
|||
Function<void(GWidget&)> collect_focusable_widgets = [&] (GWidget& widget) {
|
||||
if (widget.accepts_focus())
|
||||
collected_widgets.append(&widget);
|
||||
for (auto& child : widget.children()) {
|
||||
if (!child->is_widget())
|
||||
continue;
|
||||
auto& child_widget = *static_cast<GWidget*>(child);
|
||||
if (!child_widget.is_visible())
|
||||
continue;
|
||||
if (!child_widget.is_enabled())
|
||||
continue;
|
||||
collect_focusable_widgets(child_widget);
|
||||
}
|
||||
widget.for_each_child_widget([&] (auto& child) {
|
||||
if (!child.is_visible())
|
||||
return IterationDecision::Continue;
|
||||
if (!child.is_enabled())
|
||||
return IterationDecision::Continue;
|
||||
collect_focusable_widgets(child);
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
};
|
||||
|
||||
collect_focusable_widgets(*m_main_widget);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue