opuntiaOS - an operating system targeting x86 and ARMv7
1#include "AppListView.h"
2#include "IconView.h"
3#include <algorithm>
4#include <cstdlib>
5#include <libfoundation/EventLoop.h>
6#include <libfoundation/KeyboardMapping.h>
7#include <libg/Color.h>
8#include <libg/ImageLoaders/PNGLoader.h>
9#include <libui/App.h>
10#include <libui/Context.h>
11#include <unistd.h>
12
13static AppListView* this_view;
14
15AppListView::AppListView(UI::View* superview, const LG::Rect& frame)
16 : UI::View(superview, frame)
17{
18 auto& dock_stack_view = add_subview<UI::StackView>(bounds());
19 dock_stack_view.set_spacing(padding());
20 dock_stack_view.set_background_color(LG::Color::Opaque);
21 dock_stack_view.set_axis(UI::LayoutConstraints::Axis::Horizontal);
22 dock_stack_view.set_distribution(UI::StackView::Distribution::EqualCentering);
23 m_dock_stackview = &dock_stack_view;
24}
25
26AppListView::AppListView(UI::View* superview, UI::Window* window, const LG::Rect& frame)
27 : UI::View(superview, window, frame)
28{
29 auto& label = add_subview<UI::Label>(LG::Rect(16, 16, 16, 24));
30 label.set_text_color(LG::Color::DarkSystemText);
31 label.set_text("App List");
32 label.set_font(LG::Font::system_font(LG::Font::SystemTitleSize));
33 label.set_width(label.preferred_width());
34
35 auto& dock_stack_view = add_subview<UI::StackView>(LG::Rect(0, 50, bounds().width(), bounds().height()));
36 dock_stack_view.set_spacing(padding());
37 dock_stack_view.set_background_color(LG::Color::Opaque);
38 dock_stack_view.set_axis(UI::LayoutConstraints::Axis::Horizontal);
39 dock_stack_view.set_distribution(UI::StackView::Distribution::EqualCentering);
40 m_dock_stackview = &dock_stack_view;
41}
42
43void AppListView::display(const LG::Rect& rect)
44{
45 LG::Context ctx = UI::graphics_current_context();
46 ctx.add_clip(rect);
47
48 ctx.set_fill_color(background_color());
49 ctx.fill_rounded(bounds(), layer().corner_mask());
50}
51
52void AppListView::new_dock_entity(const std::string& exec_path, const std::string& icon_path, const std::string& bundle_id)
53{
54 LG::PNG::PNGLoader loader;
55
56 auto& icon_view = m_dock_stackview->add_arranged_subview<IconView>();
57 icon_view.add_constraint(UI::Constraint(icon_view, UI::Constraint::Attribute::Height, UI::Constraint::Relation::Equal, icon_view_size()));
58 icon_view.add_constraint(UI::Constraint(icon_view, UI::Constraint::Attribute::Width, UI::Constraint::Relation::Equal, icon_view_size()));
59 icon_view.entity().set_icon(loader.load_from_file(icon_path + "/48x48.png"));
60 icon_view.entity().set_path_to_exec(std::move(exec_path));
61 icon_view.entity().set_bundle_id(std::move(bundle_id));
62 m_icon_views.push_back(&icon_view);
63 set_needs_layout();
64}