mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06: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())
|
if (!parent())
|
||||||
return;
|
return;
|
||||||
for (auto& object : parent()->children()) {
|
for_each_child_widget([&] (auto& child) {
|
||||||
if (!object->is_widget())
|
if (!child.is_radio_button())
|
||||||
continue;
|
return IterationDecision::Continue;
|
||||||
if (!static_cast<GWidget*>(object)->is_radio_button())
|
return callback(static_cast<GRadioButton&>(child));
|
||||||
continue;
|
});
|
||||||
callback(*static_cast<GRadioButton*>(object));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GRadioButton::click()
|
void GRadioButton::click()
|
||||||
|
@ -71,6 +69,7 @@ void GRadioButton::click()
|
||||||
for_each_in_group([this] (auto& button) {
|
for_each_in_group([this] (auto& button) {
|
||||||
if (&button != this)
|
if (&button != this)
|
||||||
button.set_checked(false);
|
button.set_checked(false);
|
||||||
|
return IterationDecision::Continue;
|
||||||
});
|
});
|
||||||
set_checked(true);
|
set_checked(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,17 +40,15 @@ void GSplitter::mousedown_event(GMouseEvent& event)
|
||||||
GWidget* first_resizee { nullptr };
|
GWidget* first_resizee { nullptr };
|
||||||
GWidget* second_resizee { nullptr };
|
GWidget* second_resizee { nullptr };
|
||||||
int fudge = layout()->spacing();
|
int fudge = layout()->spacing();
|
||||||
for (auto* child : children()) {
|
for_each_child_widget([&] (auto& child) {
|
||||||
if (!child->is_widget())
|
int child_start = m_orientation == Orientation::Horizontal ? child.relative_rect().left() : child.relative_rect().top();
|
||||||
continue;
|
int child_end = m_orientation == Orientation::Horizontal ? child.relative_rect().right() : child.relative_rect().bottom();
|
||||||
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();
|
|
||||||
if (x_or_y > child_end && (x_or_y - fudge) <= child_end)
|
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)
|
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);
|
ASSERT(first_resizee && second_resizee);
|
||||||
m_first_resizee = first_resizee->make_weak_ptr();
|
m_first_resizee = first_resizee->make_weak_ptr();
|
||||||
m_second_resizee = second_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) {
|
} else if (event.type() == GEvent::ChildRemoved) {
|
||||||
if (m_active_widget == &child) {
|
if (m_active_widget == &child) {
|
||||||
GWidget* new_active_widget = nullptr;
|
GWidget* new_active_widget = nullptr;
|
||||||
for (auto* new_child : children()) {
|
for_each_child_widget([&] (auto& new_child) {
|
||||||
if (new_child->is_widget()) {
|
new_active_widget = &new_child;
|
||||||
new_active_widget = static_cast<GWidget*>(new_child);
|
return IterationDecision::Abort;
|
||||||
break;
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
set_active_widget(new_active_widget);
|
set_active_widget(new_active_widget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,15 +116,15 @@ void GWidget::handle_paint_event(GPaintEvent& event)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
paint_event(event);
|
paint_event(event);
|
||||||
for (auto* ch : children()) {
|
for_each_child_widget([&] (auto& child) {
|
||||||
auto* child = (GWidget*)ch;
|
if (!child.is_visible())
|
||||||
if (!child->is_visible())
|
return IterationDecision::Continue;
|
||||||
continue;
|
if (child.relative_rect().intersects(event.rect())) {
|
||||||
if (child->relative_rect().intersects(event.rect())) {
|
GPaintEvent local_event(event.rect().intersected(child.relative_rect()).translated(-child.relative_position()));
|
||||||
GPaintEvent local_event(event.rect().intersected(child->relative_rect()).translated(-child->relative_position()));
|
child.event(local_event);
|
||||||
child->event(local_event);
|
|
||||||
}
|
}
|
||||||
}
|
return IterationDecision::Continue;
|
||||||
|
});
|
||||||
second_paint_event(event);
|
second_paint_event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -185,6 +185,16 @@ public:
|
||||||
void register_local_shortcut_action(Badge<GAction>, GAction&);
|
void register_local_shortcut_action(Badge<GAction>, GAction&);
|
||||||
void unregister_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; }
|
virtual bool is_radio_button() const { return false; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -526,16 +526,14 @@ Vector<GWidget*> GWindow::focusable_widgets() const
|
||||||
Function<void(GWidget&)> collect_focusable_widgets = [&] (GWidget& widget) {
|
Function<void(GWidget&)> collect_focusable_widgets = [&] (GWidget& widget) {
|
||||||
if (widget.accepts_focus())
|
if (widget.accepts_focus())
|
||||||
collected_widgets.append(&widget);
|
collected_widgets.append(&widget);
|
||||||
for (auto& child : widget.children()) {
|
widget.for_each_child_widget([&] (auto& child) {
|
||||||
if (!child->is_widget())
|
if (!child.is_visible())
|
||||||
continue;
|
return IterationDecision::Continue;
|
||||||
auto& child_widget = *static_cast<GWidget*>(child);
|
if (!child.is_enabled())
|
||||||
if (!child_widget.is_visible())
|
return IterationDecision::Continue;
|
||||||
continue;
|
collect_focusable_widgets(child);
|
||||||
if (!child_widget.is_enabled())
|
return IterationDecision::Continue;
|
||||||
continue;
|
});
|
||||||
collect_focusable_widgets(child_widget);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
collect_focusable_widgets(*m_main_widget);
|
collect_focusable_widgets(*m_main_widget);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue