GWidget.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include <AK/Assertions.h>
  27. #include <AK/JsonObject.h>
  28. #include <LibDraw/GraphicsBitmap.h>
  29. #include <LibDraw/Palette.h>
  30. #include <LibGUI/GAction.h>
  31. #include <LibGUI/GApplication.h>
  32. #include <LibGUI/GButton.h>
  33. #include <LibGUI/GCheckBox.h>
  34. #include <LibGUI/GEvent.h>
  35. #include <LibGUI/GGroupBox.h>
  36. #include <LibGUI/GLabel.h>
  37. #include <LibGUI/GLayout.h>
  38. #include <LibGUI/GMenu.h>
  39. #include <LibGUI/GPainter.h>
  40. #include <LibGUI/GRadioButton.h>
  41. #include <LibGUI/GScrollBar.h>
  42. #include <LibGUI/GSlider.h>
  43. #include <LibGUI/GSpinBox.h>
  44. #include <LibGUI/GTextBox.h>
  45. #include <LibGUI/GWidget.h>
  46. #include <LibGUI/GWindow.h>
  47. #include <LibGUI/GWindowServerConnection.h>
  48. #include <unistd.h>
  49. REGISTER_GWIDGET(GButton)
  50. REGISTER_GWIDGET(GCheckBox)
  51. REGISTER_GWIDGET(GGroupBox)
  52. REGISTER_GWIDGET(GLabel)
  53. REGISTER_GWIDGET(GRadioButton)
  54. REGISTER_GWIDGET(GScrollBar)
  55. REGISTER_GWIDGET(GSlider)
  56. REGISTER_GWIDGET(GSpinBox)
  57. REGISTER_GWIDGET(GTextBox)
  58. REGISTER_GWIDGET(GWidget)
  59. static HashMap<String, GWidgetClassRegistration*>& widget_classes()
  60. {
  61. static HashMap<String, GWidgetClassRegistration*>* map;
  62. if (!map)
  63. map = new HashMap<String, GWidgetClassRegistration*>;
  64. return *map;
  65. }
  66. GWidgetClassRegistration::GWidgetClassRegistration(const String& class_name, Function<NonnullRefPtr<GWidget>(GWidget*)> factory)
  67. : m_class_name(class_name)
  68. , m_factory(move(factory))
  69. {
  70. widget_classes().set(class_name, this);
  71. }
  72. GWidgetClassRegistration::~GWidgetClassRegistration()
  73. {
  74. }
  75. void GWidgetClassRegistration::for_each(Function<void(const GWidgetClassRegistration&)> callback)
  76. {
  77. for (auto& it : widget_classes()) {
  78. callback(*it.value);
  79. }
  80. }
  81. const GWidgetClassRegistration* GWidgetClassRegistration::find(const String& class_name)
  82. {
  83. return widget_classes().get(class_name).value_or(nullptr);
  84. }
  85. GWidget::GWidget(GWidget* parent)
  86. : CObject(parent, true)
  87. , m_font(Font::default_font())
  88. , m_palette(GApplication::the().palette().impl())
  89. {
  90. }
  91. GWidget::~GWidget()
  92. {
  93. }
  94. void GWidget::child_event(CChildEvent& event)
  95. {
  96. if (event.type() == GEvent::ChildAdded) {
  97. if (event.child() && is<GWidget>(*event.child()) && layout()) {
  98. if (event.insertion_before_child() && event.insertion_before_child()->is_widget())
  99. layout()->insert_widget_before(to<GWidget>(*event.child()), to<GWidget>(*event.insertion_before_child()));
  100. else
  101. layout()->add_widget(to<GWidget>(*event.child()));
  102. }
  103. }
  104. if (event.type() == GEvent::ChildRemoved) {
  105. if (layout()) {
  106. if (event.child() && is<GWidget>(*event.child()))
  107. layout()->remove_widget(to<GWidget>(*event.child()));
  108. else
  109. invalidate_layout();
  110. }
  111. update();
  112. }
  113. return CObject::child_event(event);
  114. }
  115. void GWidget::set_relative_rect(const Rect& a_rect)
  116. {
  117. // Get rid of negative width/height values.
  118. Rect rect = {
  119. a_rect.x(),
  120. a_rect.y(),
  121. max(a_rect.width(), 0),
  122. max(a_rect.height(), 0)
  123. };
  124. if (rect == m_relative_rect)
  125. return;
  126. auto old_rect = m_relative_rect;
  127. bool size_changed = m_relative_rect.size() != rect.size();
  128. m_relative_rect = rect;
  129. if (size_changed) {
  130. GResizeEvent resize_event(m_relative_rect.size(), rect.size());
  131. event(resize_event);
  132. }
  133. if (auto* parent = parent_widget())
  134. parent->update(old_rect);
  135. update();
  136. }
  137. void GWidget::event(CEvent& event)
  138. {
  139. switch (event.type()) {
  140. case GEvent::Paint:
  141. return handle_paint_event(static_cast<GPaintEvent&>(event));
  142. case GEvent::Resize:
  143. return handle_resize_event(static_cast<GResizeEvent&>(event));
  144. case GEvent::FocusIn:
  145. return focusin_event(event);
  146. case GEvent::FocusOut:
  147. return focusout_event(event);
  148. case GEvent::Show:
  149. return show_event(static_cast<GShowEvent&>(event));
  150. case GEvent::Hide:
  151. return hide_event(static_cast<GHideEvent&>(event));
  152. case GEvent::KeyDown:
  153. return keydown_event(static_cast<GKeyEvent&>(event));
  154. case GEvent::KeyUp:
  155. return keyup_event(static_cast<GKeyEvent&>(event));
  156. case GEvent::MouseMove:
  157. return mousemove_event(static_cast<GMouseEvent&>(event));
  158. case GEvent::MouseDown:
  159. return handle_mousedown_event(static_cast<GMouseEvent&>(event));
  160. case GEvent::MouseDoubleClick:
  161. return handle_mousedoubleclick_event(static_cast<GMouseEvent&>(event));
  162. case GEvent::MouseUp:
  163. return handle_mouseup_event(static_cast<GMouseEvent&>(event));
  164. case GEvent::MouseWheel:
  165. return mousewheel_event(static_cast<GMouseEvent&>(event));
  166. case GEvent::Drop:
  167. return drop_event(static_cast<GDropEvent&>(event));
  168. case GEvent::Enter:
  169. return handle_enter_event(event);
  170. case GEvent::Leave:
  171. return handle_leave_event(event);
  172. case GEvent::EnabledChange:
  173. return change_event(static_cast<GEvent&>(event));
  174. default:
  175. return CObject::event(event);
  176. }
  177. }
  178. void GWidget::handle_paint_event(GPaintEvent& event)
  179. {
  180. ASSERT(is_visible());
  181. if (fill_with_background_color()) {
  182. GPainter painter(*this);
  183. painter.fill_rect(event.rect(), palette().color(background_role()));
  184. } else {
  185. #ifdef DEBUG_WIDGET_UNDERDRAW
  186. // FIXME: This is a bit broken.
  187. // If the widget is not opaque, let's not mess it up with debugging color.
  188. GPainter painter(*this);
  189. painter.fill_rect(rect(), Color::Red);
  190. #endif
  191. }
  192. paint_event(event);
  193. for_each_child_widget([&](auto& child) {
  194. if (!child.is_visible())
  195. return IterationDecision::Continue;
  196. if (child.relative_rect().intersects(event.rect())) {
  197. GPaintEvent local_event(event.rect().intersected(child.relative_rect()).translated(-child.relative_position()));
  198. child.dispatch_event(local_event, this);
  199. }
  200. return IterationDecision::Continue;
  201. });
  202. second_paint_event(event);
  203. }
  204. void GWidget::set_layout(OwnPtr<GLayout>&& layout)
  205. {
  206. if (m_layout)
  207. m_layout->notify_disowned({}, *this);
  208. m_layout = move(layout);
  209. if (m_layout) {
  210. m_layout->notify_adopted({}, *this);
  211. do_layout();
  212. } else {
  213. update();
  214. }
  215. }
  216. void GWidget::do_layout()
  217. {
  218. for_each_child_widget([&](auto& child) {
  219. child.do_layout();
  220. return IterationDecision::Continue;
  221. });
  222. custom_layout();
  223. if (!m_layout)
  224. return;
  225. m_layout->run(*this);
  226. update();
  227. }
  228. void GWidget::notify_layout_changed(Badge<GLayout>)
  229. {
  230. invalidate_layout();
  231. }
  232. void GWidget::handle_resize_event(GResizeEvent& event)
  233. {
  234. resize_event(event);
  235. do_layout();
  236. }
  237. void GWidget::handle_mouseup_event(GMouseEvent& event)
  238. {
  239. mouseup_event(event);
  240. }
  241. void GWidget::handle_mousedown_event(GMouseEvent& event)
  242. {
  243. if (accepts_focus())
  244. set_focus(true);
  245. mousedown_event(event);
  246. if (event.button() == GMouseButton::Right) {
  247. GContextMenuEvent c_event(event.position(), screen_relative_rect().location().translated(event.position()));
  248. context_menu_event(c_event);
  249. }
  250. }
  251. void GWidget::handle_mousedoubleclick_event(GMouseEvent& event)
  252. {
  253. doubleclick_event(event);
  254. }
  255. void GWidget::handle_enter_event(CEvent& event)
  256. {
  257. if (has_tooltip())
  258. GApplication::the().show_tooltip(m_tooltip, screen_relative_rect().center().translated(0, height() / 2));
  259. enter_event(event);
  260. }
  261. void GWidget::handle_leave_event(CEvent& event)
  262. {
  263. GApplication::the().hide_tooltip();
  264. leave_event(event);
  265. }
  266. void GWidget::click_event(GMouseEvent&)
  267. {
  268. }
  269. void GWidget::doubleclick_event(GMouseEvent&)
  270. {
  271. }
  272. void GWidget::resize_event(GResizeEvent&)
  273. {
  274. }
  275. void GWidget::paint_event(GPaintEvent&)
  276. {
  277. }
  278. void GWidget::second_paint_event(GPaintEvent&)
  279. {
  280. }
  281. void GWidget::show_event(GShowEvent&)
  282. {
  283. }
  284. void GWidget::hide_event(GHideEvent&)
  285. {
  286. }
  287. void GWidget::keydown_event(GKeyEvent& event)
  288. {
  289. if (!event.alt() && !event.ctrl() && !event.logo() && event.key() == KeyCode::Key_Tab) {
  290. if (event.shift())
  291. focus_previous_widget();
  292. else
  293. focus_next_widget();
  294. event.accept();
  295. return;
  296. }
  297. event.ignore();
  298. }
  299. void GWidget::keyup_event(GKeyEvent&)
  300. {
  301. }
  302. void GWidget::mousedown_event(GMouseEvent&)
  303. {
  304. }
  305. void GWidget::mouseup_event(GMouseEvent&)
  306. {
  307. }
  308. void GWidget::mousemove_event(GMouseEvent&)
  309. {
  310. }
  311. void GWidget::mousewheel_event(GMouseEvent&)
  312. {
  313. }
  314. void GWidget::context_menu_event(GContextMenuEvent&)
  315. {
  316. }
  317. void GWidget::focusin_event(CEvent&)
  318. {
  319. }
  320. void GWidget::focusout_event(CEvent&)
  321. {
  322. }
  323. void GWidget::enter_event(CEvent&)
  324. {
  325. }
  326. void GWidget::leave_event(CEvent&)
  327. {
  328. }
  329. void GWidget::change_event(GEvent&)
  330. {
  331. }
  332. void GWidget::drop_event(GDropEvent& event)
  333. {
  334. dbg() << class_name() << "{" << this << "} DROP position: " << event.position() << ", text: '" << event.text() << "'";
  335. event.ignore();
  336. }
  337. void GWidget::update()
  338. {
  339. if (rect().is_empty())
  340. return;
  341. update(rect());
  342. }
  343. void GWidget::update(const Rect& rect)
  344. {
  345. if (!is_visible())
  346. return;
  347. if (!updates_enabled())
  348. return;
  349. GWindow* window = m_window;
  350. GWidget* parent = parent_widget();
  351. while (parent) {
  352. if (!parent->updates_enabled())
  353. return;
  354. window = parent->m_window;
  355. parent = parent->parent_widget();
  356. }
  357. if (window)
  358. window->update(rect.translated(window_relative_rect().location()));
  359. }
  360. Rect GWidget::window_relative_rect() const
  361. {
  362. auto rect = relative_rect();
  363. for (auto* parent = parent_widget(); parent; parent = parent->parent_widget()) {
  364. rect.move_by(parent->relative_position());
  365. }
  366. return rect;
  367. }
  368. Rect GWidget::screen_relative_rect() const
  369. {
  370. return window_relative_rect().translated(window()->position());
  371. }
  372. GWidget* GWidget::child_at(const Point& point) const
  373. {
  374. for (int i = children().size() - 1; i >= 0; --i) {
  375. if (!is<GWidget>(children()[i]))
  376. continue;
  377. auto& child = to<GWidget>(children()[i]);
  378. if (!child.is_visible())
  379. continue;
  380. if (child.relative_rect().contains(point))
  381. return const_cast<GWidget*>(&child);
  382. }
  383. return nullptr;
  384. }
  385. GWidget::HitTestResult GWidget::hit_test(const Point& position, ShouldRespectGreediness should_respect_greediness)
  386. {
  387. if (should_respect_greediness == ShouldRespectGreediness::Yes && is_greedy_for_hits())
  388. return { this, position };
  389. if (auto* child = child_at(position))
  390. return child->hit_test(position - child->relative_position());
  391. return { this, position };
  392. }
  393. void GWidget::set_window(GWindow* window)
  394. {
  395. if (m_window == window)
  396. return;
  397. m_window = window;
  398. }
  399. bool GWidget::is_focused() const
  400. {
  401. auto* win = window();
  402. if (!win)
  403. return false;
  404. if (!win->is_active())
  405. return false;
  406. return win->focused_widget() == this;
  407. }
  408. void GWidget::set_focus(bool focus)
  409. {
  410. auto* win = window();
  411. if (!win)
  412. return;
  413. if (focus) {
  414. win->set_focused_widget(this);
  415. } else {
  416. if (win->focused_widget() == this)
  417. win->set_focused_widget(nullptr);
  418. }
  419. }
  420. void GWidget::set_font(const Font* font)
  421. {
  422. if (m_font.ptr() == font)
  423. return;
  424. if (!font)
  425. m_font = Font::default_font();
  426. else
  427. m_font = *font;
  428. did_change_font();
  429. update();
  430. }
  431. void GWidget::set_global_cursor_tracking(bool enabled)
  432. {
  433. auto* win = window();
  434. if (!win)
  435. return;
  436. win->set_global_cursor_tracking_widget(enabled ? this : nullptr);
  437. }
  438. bool GWidget::global_cursor_tracking() const
  439. {
  440. auto* win = window();
  441. if (!win)
  442. return false;
  443. return win->global_cursor_tracking_widget() == this;
  444. }
  445. void GWidget::set_preferred_size(const Size& size)
  446. {
  447. if (m_preferred_size == size)
  448. return;
  449. m_preferred_size = size;
  450. invalidate_layout();
  451. }
  452. void GWidget::set_size_policy(Orientation orientation, SizePolicy policy)
  453. {
  454. if (orientation == Orientation::Horizontal)
  455. set_size_policy(policy, m_vertical_size_policy);
  456. else
  457. set_size_policy(m_horizontal_size_policy, policy);
  458. }
  459. void GWidget::set_size_policy(SizePolicy horizontal_policy, SizePolicy vertical_policy)
  460. {
  461. if (m_horizontal_size_policy == horizontal_policy && m_vertical_size_policy == vertical_policy)
  462. return;
  463. m_horizontal_size_policy = horizontal_policy;
  464. m_vertical_size_policy = vertical_policy;
  465. invalidate_layout();
  466. }
  467. void GWidget::invalidate_layout()
  468. {
  469. if (window())
  470. window()->schedule_relayout();
  471. }
  472. void GWidget::set_visible(bool visible)
  473. {
  474. if (visible == m_visible)
  475. return;
  476. m_visible = visible;
  477. if (auto* parent = parent_widget())
  478. parent->invalidate_layout();
  479. if (m_visible)
  480. update();
  481. if (m_visible) {
  482. GShowEvent e;
  483. event(e);
  484. } else {
  485. GHideEvent e;
  486. event(e);
  487. }
  488. }
  489. bool GWidget::spans_entire_window_horizontally() const
  490. {
  491. auto* w = window();
  492. if (!w)
  493. return false;
  494. auto* main_widget = w->main_widget();
  495. if (!main_widget)
  496. return false;
  497. if (main_widget == this)
  498. return true;
  499. auto wrr = window_relative_rect();
  500. return wrr.left() == main_widget->rect().left() && wrr.right() == main_widget->rect().right();
  501. }
  502. void GWidget::set_enabled(bool enabled)
  503. {
  504. if (m_enabled == enabled)
  505. return;
  506. m_enabled = enabled;
  507. GEvent e(GEvent::EnabledChange);
  508. event(e);
  509. update();
  510. }
  511. void GWidget::move_to_front()
  512. {
  513. auto* parent = parent_widget();
  514. if (!parent)
  515. return;
  516. if (parent->children().size() == 1)
  517. return;
  518. parent->children().remove_first_matching([this](auto& entry) {
  519. return entry == this;
  520. });
  521. parent->children().append(*this);
  522. parent->update();
  523. }
  524. void GWidget::move_to_back()
  525. {
  526. auto* parent = parent_widget();
  527. if (!parent)
  528. return;
  529. if (parent->children().size() == 1)
  530. return;
  531. parent->children().remove_first_matching([this](auto& entry) {
  532. return entry == this;
  533. });
  534. parent->children().prepend(*this);
  535. parent->update();
  536. }
  537. bool GWidget::is_frontmost() const
  538. {
  539. auto* parent = parent_widget();
  540. if (!parent)
  541. return true;
  542. return &parent->children().last() == this;
  543. }
  544. bool GWidget::is_backmost() const
  545. {
  546. auto* parent = parent_widget();
  547. if (!parent)
  548. return true;
  549. return &parent->children().first() == this;
  550. }
  551. GAction* GWidget::action_for_key_event(const GKeyEvent& event)
  552. {
  553. auto it = m_local_shortcut_actions.find(GShortcut(event.modifiers(), (KeyCode)event.key()));
  554. if (it == m_local_shortcut_actions.end())
  555. return nullptr;
  556. return (*it).value;
  557. }
  558. void GWidget::register_local_shortcut_action(Badge<GAction>, GAction& action)
  559. {
  560. m_local_shortcut_actions.set(action.shortcut(), &action);
  561. }
  562. void GWidget::unregister_local_shortcut_action(Badge<GAction>, GAction& action)
  563. {
  564. m_local_shortcut_actions.remove(action.shortcut());
  565. }
  566. void GWidget::set_updates_enabled(bool enabled)
  567. {
  568. if (m_updates_enabled == enabled)
  569. return;
  570. m_updates_enabled = enabled;
  571. if (enabled)
  572. update();
  573. }
  574. void GWidget::focus_previous_widget()
  575. {
  576. auto focusable_widgets = window()->focusable_widgets();
  577. for (int i = focusable_widgets.size() - 1; i >= 0; --i) {
  578. if (focusable_widgets[i] != this)
  579. continue;
  580. if (i > 0)
  581. focusable_widgets[i - 1]->set_focus(true);
  582. else
  583. focusable_widgets.last()->set_focus(true);
  584. }
  585. }
  586. void GWidget::focus_next_widget()
  587. {
  588. auto focusable_widgets = window()->focusable_widgets();
  589. for (int i = 0; i < focusable_widgets.size(); ++i) {
  590. if (focusable_widgets[i] != this)
  591. continue;
  592. if (i < focusable_widgets.size() - 1)
  593. focusable_widgets[i + 1]->set_focus(true);
  594. else
  595. focusable_widgets.first()->set_focus(true);
  596. }
  597. }
  598. void GWidget::set_backcolor(const StringView& color_string)
  599. {
  600. auto color = Color::from_string(color_string);
  601. if (!color.has_value())
  602. return;
  603. set_background_color(color.value());
  604. }
  605. void GWidget::set_forecolor(const StringView& color_string)
  606. {
  607. auto color = Color::from_string(color_string);
  608. if (!color.has_value())
  609. return;
  610. set_foreground_color(color.value());
  611. }
  612. void GWidget::save_to(AK::JsonObject& json)
  613. {
  614. json.set("relative_rect", relative_rect().to_string());
  615. json.set("fill_with_background_color", fill_with_background_color());
  616. json.set("tooltip", tooltip());
  617. json.set("visible", is_visible());
  618. json.set("focused", is_focused());
  619. json.set("enabled", is_enabled());
  620. json.set("background_color", background_color().to_string());
  621. json.set("foreground_color", foreground_color().to_string());
  622. json.set("preferred_size", preferred_size().to_string());
  623. json.set("size_policy", String::format("[%s,%s]", to_string(horizontal_size_policy()), to_string(vertical_size_policy())));
  624. CObject::save_to(json);
  625. }
  626. Vector<GWidget*> GWidget::child_widgets() const
  627. {
  628. Vector<GWidget*> widgets;
  629. widgets.ensure_capacity(children().size());
  630. for (auto& child : const_cast<GWidget*>(this)->children()) {
  631. if (child.is_widget())
  632. widgets.append(static_cast<GWidget*>(&child));
  633. }
  634. return widgets;
  635. }
  636. void GWidget::set_palette(const Palette& palette)
  637. {
  638. m_palette = palette.impl();
  639. }