From 25f99d28b404157fb91e02fec8effdb8fd609f9e Mon Sep 17 00:00:00 2001 From: Egor00f Date: Tue, 5 Nov 2024 17:43:55 +0000 Subject: [PATCH] It's working(HelloWorld example before second press button)! but falling & some comments fixes --- .devcontainer/devcontainer.json | 7 +- .devcontainer/postCreateCommand.sh | 7 ++ Readme.md | 3 +- examples/CheckBox/Checkbox.cpp | 15 ++-- examples/HelloWorld/HelloWorld.cpp | 14 +-- examples/MousePosition/mousePosition.cpp | 15 ++-- .../UI/buttons/ButtonsIDController.hpp | 18 ++-- include/kolibriLib/UI/buttons/baseButton.hpp | 1 + include/kolibriLib/UI/buttons/buttonsBase.hpp | 4 +- include/kolibriLib/system/os.hpp | 12 +-- src/KolibriLib/UI/buttons/BaseButton.cpp | 87 +++++++++++-------- src/KolibriLib/UI/buttons/Button.cpp | 6 +- .../UI/buttons/ButtonsIDController.cpp | 57 ++++++++---- src/KolibriLib/checkbox.cpp | 2 +- src/KolibriLib/os.cpp | 9 +- src/KolibriLib/textlabel.cpp | 14 +-- src/KolibriLib/window.cpp | 33 ++++--- 17 files changed, 180 insertions(+), 124 deletions(-) create mode 100644 .devcontainer/postCreateCommand.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index d76253c..bf262d4 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -23,12 +23,7 @@ } }, - "postCreateCommand": - { - "Install programs": "apt update && apt install fasm p7zip-full wget cmake", - "Install toolchain": "cd /workspaces && git clone https://github.com/Egor00f/kolibrios-gcc-toolchain.git && kolibrios-gcc-toolchain/./install", - "Clone kolibrios repo": "cd /workspaces && git clone https://git.kolibrios.org/KolibriOS/kolibrios.git" - } + "postCreateCommand": "bash .devcontainer/postCreateCommand.sh" } \ No newline at end of file diff --git a/.devcontainer/postCreateCommand.sh b/.devcontainer/postCreateCommand.sh new file mode 100644 index 0000000..6ecfa27 --- /dev/null +++ b/.devcontainer/postCreateCommand.sh @@ -0,0 +1,7 @@ +apt update +apt install fasm p7zip-full wget cmake + +git clone https://github.com/Egor00f/kolibrios-gcc-toolchain.git +kolibrios-gcc-toolchain/./install +cd .. +git clone https://git.kolibrios.org/KolibriOS/kolibrios.git diff --git a/Readme.md b/Readme.md index 1bec919..d380e91 100644 --- a/Readme.md +++ b/Readme.md @@ -47,12 +47,13 @@ kolibrios-gcc-toolchain/./install Остальные зависимости: ``` apt update -apt install fasm cmake make +apt install fasm cmake ``` ### Сама сборка Сборка: + ``` mkdir build cd build diff --git a/examples/CheckBox/Checkbox.cpp b/examples/CheckBox/Checkbox.cpp index b5f46e6..75f6f9c 100644 --- a/examples/CheckBox/Checkbox.cpp +++ b/examples/CheckBox/Checkbox.cpp @@ -6,22 +6,22 @@ int main() { Window window("Checkbox example"); - auto frame = window.AddElement(Frame( + std::shared_ptr frame(window.AddElement(Frame( UDim(0.2f, 0.2f), - UDim(0.6f, 0.4f))); + UDim(0.6f, 0.4f)))); frame->SetColor(Globals::SystemColors.work_area); - auto checkbox = window.AddElement(CheckBox( + std::shared_ptr checkbox(window.AddElement(CheckBox( UDim(0.1f, 0.25f), UDim(0.2f, 0.5f) - )); + ))); checkbox->SetParent(frame); - auto textLabel = window.AddElement(TextLabel( + std::shared_ptr textLabel(window.AddElement(TextLabel( UDim(0.3f, 0.0f), UDim(0.7f, 1.0f), "<- checkbox" - )); + ))); textLabel->SetParent(frame); window.RenderAllElements(); @@ -51,6 +51,5 @@ int main() } } - return 0; -} \ No newline at end of file +} diff --git a/examples/HelloWorld/HelloWorld.cpp b/examples/HelloWorld/HelloWorld.cpp index d7f76d3..9f8f003 100644 --- a/examples/HelloWorld/HelloWorld.cpp +++ b/examples/HelloWorld/HelloWorld.cpp @@ -14,16 +14,18 @@ int main() ); // Добавление текстовой метки - TextLabel* label = wndw->AddElement(TextLabel( + std::shared_ptr label(wndw->AddElement(TextLabel( UDim(0.0f, 0, 0.0f, 0), // Координаты текстовой метки (самый левый верхний угол окна) UDim(0.6f, 0, 1.0f, 0), // Рамер текстовой метки (3/5 ширины окна и в полную высоту окна) "Hello World", {32, 36} // Размер символов 32x36 ) - ); + )); // Добавление кнопки - TextButton* button = wndw->AddElement(TextButton(UDim(0.6f, 0, 0.4f, 0), UDim(0.2f, 0, 0.2f, 0))); + std::shared_ptr button(wndw->AddElement(TextButton(UDim(0.6f, 0, 0.4f, 0), UDim(0.2f, 0, 0.2f, 0)))); + + logger << microlog::LogLevel::Info << "Button ID: " << button->GetId() << std::endl; // Отрисовка всех элементов, чтоб они были видны wndw->RenderAllElements(); @@ -40,12 +42,12 @@ int main() case Event::Button: // Была нажата какая-то кнопка - if(static_cast(wndw->GetPressedButton().get()) == static_cast(button)) + if(wndw->GetPressedButton().get() == static_cast(button.get())) { - logger << "You Press Button"; + logger << "You Press Button" << std::endl; OS::Notify("You Press Buttons"); - label->SetTextColor(Color(rand())); + label->SetTextColor(Color(std::rand())); } break; diff --git a/examples/MousePosition/mousePosition.cpp b/examples/MousePosition/mousePosition.cpp index 1a60e53..63626db 100644 --- a/examples/MousePosition/mousePosition.cpp +++ b/examples/MousePosition/mousePosition.cpp @@ -2,8 +2,8 @@ using namespace KolibriLib; -TextLabel *MousePosAbs; -TextLabel *MousePosRelative; +std::shared_ptr MousePosAbs; +std::shared_ptr MousePosRelative; void update() { @@ -24,17 +24,16 @@ int main() Window wnd("Mouse Pos"); - MousePosAbs = wnd.AddElement(TextLabel( + MousePosAbs.reset(wnd.AddElement(TextLabel( UDim(0.2f, 0.2f), UDim(0.6f, 0.2f), - "idk")); + "idk"))); MousePosAbs->SetAlign(TextLabel::Align::Left); - - MousePosRelative = wnd.AddElement(TextLabel( + MousePosRelative.reset(wnd.AddElement(TextLabel( UDim(0.2f, 0.4f), UDim(0.6f, 0.2f), - "idk")); + "idk"))); wnd.RenderAllElements(); @@ -73,4 +72,4 @@ int main() } return 0; -} \ No newline at end of file +} diff --git a/include/kolibriLib/UI/buttons/ButtonsIDController.hpp b/include/kolibriLib/UI/buttons/ButtonsIDController.hpp index 7361ae4..4ab1db6 100644 --- a/include/kolibriLib/UI/buttons/ButtonsIDController.hpp +++ b/include/kolibriLib/UI/buttons/ButtonsIDController.hpp @@ -31,7 +31,12 @@ namespace KolibriLib /** * @brief Указатели на кнопки, использующие этот ID */ - std::vector> pointers; + std::vector pointers; + + /** + * @brief Конструктор по умолчанию + */ + node() = default; /** * @brief Конструктор @@ -44,7 +49,7 @@ namespace KolibriLib * @param Id IS кнопки * @param p указатель на кнопку */ - node(ButtonID Id, std::shared_ptr p); + node(ButtonID Id, BaseButton* p); node &operator=(const node &) = default; @@ -81,21 +86,22 @@ namespace KolibriLib * @return ID кнопки, который не занят * @todo Надо оптимизировать алгоритм поиска, а то он кривой и медленный */ - ButtonID GetFreeButtonID(std::shared_ptr ptr); + ButtonID GetFreeButtonID(BaseButton* ptr); /** * @brief Занять ID кнопки * @param id ID кнопки * @param ptr указатель на кнопку */ - void TakeUpButtonID(const ButtonID &id, std::shared_ptr ptr); + void TakeUpButtonID(const ButtonID &id, BaseButton* ptr); /** * @brief Освободить ID * @param id ID который нужно освободить + * @param ptr указатель на кнопку, которая занимала этот ID * @todo Надо оптимизировать алгоритм поиска, а то он кривой и медленный */ - void FreeButtonID(const ButtonID &id); + void FreeButtonID(const ButtonID &id, BaseButton* ptr); /** * @brief Получить список всех занятых ID кнопок @@ -116,7 +122,7 @@ namespace KolibriLib * @param ID ID кнопки * @return указатель на ту самую кнопку */ - std::vector> GetPointerToButton(const ButtonID &ID) const; + std::vector GetPointerToButton(const ButtonID &ID) const; /** * @brief Убрать лишнее diff --git a/include/kolibriLib/UI/buttons/baseButton.hpp b/include/kolibriLib/UI/buttons/baseButton.hpp index 3b1cd74..09a2f2c 100644 --- a/include/kolibriLib/UI/buttons/baseButton.hpp +++ b/include/kolibriLib/UI/buttons/baseButton.hpp @@ -80,6 +80,7 @@ namespace KolibriLib mutable bool _status = false; private: + /** * @brief Тип кнопки * @details false - системная кнопка, true кастомная diff --git a/include/kolibriLib/UI/buttons/buttonsBase.hpp b/include/kolibriLib/UI/buttons/buttonsBase.hpp index 1809d69..c20309f 100644 --- a/include/kolibriLib/UI/buttons/buttonsBase.hpp +++ b/include/kolibriLib/UI/buttons/buttonsBase.hpp @@ -144,9 +144,9 @@ namespace KolibriLib * \param id id кнопки * \param color цвет */ - inline void DefineButton(const Coord &coord, const Size &size, const ButtonID &id, Colors::Color color = Globals::SystemColors.work_button) + inline void DefineButton(const Coord &coord, const Size &size, ButtonID id, Colors::Color color = Globals::SystemColors.work_button) { - assert((id == ButtonIDNotSet || id >= ButtonIDEnd) && "Wrong button id!"); + assert((id != ButtonIDNotSet || id < ButtonIDEnd)); _ksys_define_button( static_cast(coord.x), diff --git a/include/kolibriLib/system/os.hpp b/include/kolibriLib/system/os.hpp index 95c8148..ac71d06 100644 --- a/include/kolibriLib/system/os.hpp +++ b/include/kolibriLib/system/os.hpp @@ -38,7 +38,7 @@ namespace KolibriLib /// @brief Активность мыши Mouse = KSYS_EVENT_MOUSE, - /// @brief Программу открыли в дебагере + /// @brief Программу открыли в отладчике Debug = KSYS_EVENT_DEBUG, /// @brief Выход @@ -229,10 +229,11 @@ namespace KolibriLib * \brief Запустить программу * \param AppName Полное имя исполняемого файла * \param args аргументы. Максимум 256 символов - * @param ec ошибка файловой системы - * @param debug режим дебага + * @param ec код ошибки файловой системы + * @param debug Запустить в режиме отладки * \return PID запущенной программы * @return -1 если произошла ошибка + * @note Если процесс запускается как отлаживаемый, он создаётся в замороженном состоянии */ Thread::PID Exec(const filesystem::Path &AppName, const std::string &args, filesystem::FilesystemErrors &ec, bool debug = false) noexcept; @@ -240,10 +241,11 @@ namespace KolibriLib * @brief Запустить программу * @param AppName Полное имя исполняемого файла * @param args аргументы. Максимум 256 символов - * @param debug режим дебага + * @param debug Запустить в режиме отладки * \return PID запущенной программы * @return -1 если произошла ошибка - * @throw Код ошибки файловой системы + * @throw Код ошибки файловой системы (filesystem::FilesystemErrors) + * @note Если процесс запускается как отлаживаемый, он создаётся в замороженном состоянии */ Thread::PID Exec(const filesystem::Path &AppName, const std::string &args, bool debug = false); diff --git a/src/KolibriLib/UI/buttons/BaseButton.cpp b/src/KolibriLib/UI/buttons/BaseButton.cpp index 17d20fa..f815348 100644 --- a/src/KolibriLib/UI/buttons/BaseButton.cpp +++ b/src/KolibriLib/UI/buttons/BaseButton.cpp @@ -7,29 +7,33 @@ using namespace buttons; BaseButton::BaseButton() { - #ifndef NO_LOGS +#ifndef NO_LOGS +#ifdef VERBOSE logger << microlog::LogLevel::Debug << "BaseButton constructor" << std::endl; - #endif +#endif +#endif if (KolibriLib::Globals::DefaultButtonsIDController != nullptr) { _ButtonsIDController = KolibriLib::Globals::DefaultButtonsIDController; - std::shared_ptr s_ptr(this); - - _id = KolibriLib::Globals::DefaultButtonsIDController->GetFreeButtonID(s_ptr); + _id = KolibriLib::Globals::DefaultButtonsIDController->GetFreeButtonID(this); } - #ifndef NO_LOGS +#ifndef NO_LOGS +#ifdef VERBOSE logger << microlog::LogLevel::Debug << "BaseButton constructor: done" << std::endl; - #endif +#endif +#endif } BaseButton::BaseButton(ButtonID id) { - #ifndef NO_LOGS +#ifndef NO_LOGS +#ifdef VERBOSE logger << microlog::LogLevel::Debug << "BaseButton constructor" << std::endl; - #endif +#endif +#endif if (KolibriLib::Globals::DefaultButtonsIDController != nullptr) { @@ -37,37 +41,47 @@ BaseButton::BaseButton(ButtonID id) SetId(id); } - #ifndef NO_LOGS +#ifndef NO_LOGS +#ifdef VERBOSE logger << microlog::LogLevel::Debug << "BaseButton constructor: done" << std::endl; - #endif +#endif +#endif } KolibriLib::UI::buttons::BaseButton::BaseButton(const BaseButton &button) : _ButtonsIDController(button._ButtonsIDController), _type(button._type) { - #ifndef NO_LOGS +#ifndef NO_LOGS +#ifdef VERBOSE logger << microlog::LogLevel::Debug << "BaseButton constructor(copy)" << std::endl; - #endif +#endif +#endif SetId(button._id); - #ifndef NO_LOGS +#ifndef NO_LOGS +#ifdef VERBOSE logger << microlog::LogLevel::Debug << "BaseButton constructor: done" << std::endl; - #endif +#endif +#endif } buttons::BaseButton::~BaseButton() { - #ifndef NO_LOGS +#ifndef NO_LOGS +#ifdef VERBOSE logger << microlog::LogLevel::Debug << "BaseButton destructor" << std::endl; - #endif +#endif +#endif Deactivate(); - #ifndef NO_LOGS +#ifndef NO_LOGS +#ifdef VERBOSE logger << microlog::LogLevel::Debug << "BaseButton destructor: done" << std::endl; - #endif +#endif +#endif } void BaseButton::BaseButton::Deactivate() @@ -76,16 +90,16 @@ void BaseButton::BaseButton::Deactivate() { if (_ButtonsIDController != nullptr) { - _ButtonsIDController->FreeButtonID(_id); + _ButtonsIDController->FreeButtonID(_id, this); } _id = buttons::ButtonIDNotSet; } else { - #ifndef NO_LOGS +#ifndef NO_LOGS logger << microlog::LogLevel::Warning << "BaseButton already not active" << std::endl; - #endif +#endif } } @@ -97,21 +111,23 @@ void BaseButton::BaseButton::Activate() } else { - #ifndef NO_LOGS +#ifndef NO_LOGS logger << microlog::LogLevel::Warning << "BaseButton already active" << std::endl; - #endif +#endif } } bool KolibriLib::UI::buttons::BaseButton::IsActive() const { - #ifdef DEBUG +#ifdef DEBUG +#ifdef VERBOSE logger << microlog::LogLevel::Debug << "Button is "; - if(_id == ButtonIDNotSet) + if (_id == ButtonIDNotSet) logger << "not"; logger << " active" << std::endl; - #endif +#endif +#endif return _id != ButtonIDNotSet; } @@ -128,33 +144,30 @@ buttons::ButtonID buttons::BaseButton::GetId() const void KolibriLib::UI::buttons::BaseButton::SetId(const ButtonID &NewID) { - #ifndef NO_LOGS +#ifndef NO_LOGS logger << microlog::LogLevel::Debug << "SetId(ButtonID)" << std::endl; - #endif +#endif _id = NewID; if (_ButtonsIDController != nullptr) { - std::shared_ptr s_ptr(this); - _ButtonsIDController->TakeUpButtonID(NewID, s_ptr); + _ButtonsIDController->TakeUpButtonID(NewID, this); } } void KolibriLib::UI::buttons::BaseButton::SetId() { - #ifndef NO_LOGS +#ifndef NO_LOGS logger << microlog::LogLevel::Debug << "SetId()" << std::endl; - #endif +#endif - if (_ButtonsIDController != nullptr) { if (IsActive()) - _ButtonsIDController->FreeButtonID(_id); + _ButtonsIDController->FreeButtonID(_id, this); - std::shared_ptr s_ptr(this); - _id = _ButtonsIDController->GetFreeButtonID(s_ptr); + _id = _ButtonsIDController->GetFreeButtonID(this); } else { diff --git a/src/KolibriLib/UI/buttons/Button.cpp b/src/KolibriLib/UI/buttons/Button.cpp index 47e61da..6adcddf 100644 --- a/src/KolibriLib/UI/buttons/Button.cpp +++ b/src/KolibriLib/UI/buttons/Button.cpp @@ -9,7 +9,8 @@ using namespace buttons; */ Button::Button() - : UIElement() + : UIElement(), + BaseButton() { #ifdef VERBOSE logger << microlog::LogLevel::Debug << "Button constructor" << std::endl; @@ -17,7 +18,8 @@ Button::Button() } Button::Button(UDim coord, UDim size, unsigned Margin, Colors::Color backGroundColor) - : UIElement(coord, size, backGroundColor, Margin) + : UIElement(coord, size, backGroundColor, Margin), + BaseButton() { #ifdef VERBOSE logger << microlog::LogLevel::Debug << "Button constructor" << std::endl; diff --git a/src/KolibriLib/UI/buttons/ButtonsIDController.cpp b/src/KolibriLib/UI/buttons/ButtonsIDController.cpp index 51eeb23..13807a2 100644 --- a/src/KolibriLib/UI/buttons/ButtonsIDController.cpp +++ b/src/KolibriLib/UI/buttons/ButtonsIDController.cpp @@ -7,7 +7,7 @@ using namespace buttons; UI::buttons::ButtonsIDController *Globals::DefaultButtonsIDController = nullptr; -ButtonID buttons::ButtonsIDController::GetFreeButtonID(std::weak_ptr ptr) +ButtonID buttons::ButtonsIDController::GetFreeButtonID(BaseButton *ptr) { #ifndef NO_LOGS logger << microlog::LogLevel::Debug << "ButtonsController::GetFreeButtonID"; @@ -26,7 +26,7 @@ ButtonID buttons::ButtonsIDController::GetFreeButtonID(std::weak_ptr { for (ButtonID i = _top; i < ButtonIDEnd; i.value++) { - for (auto j : _ButtonsIdList) + for (const node& j : _ButtonsIdList) { if (j.id != i) { @@ -34,7 +34,7 @@ ButtonID buttons::ButtonsIDController::GetFreeButtonID(std::weak_ptr #ifndef NO_LOGS #ifdef VERBOSE - logger << ": OK"; + logger << ": id is " << i; #endif logger << std::endl; #endif @@ -52,19 +52,31 @@ ButtonID buttons::ButtonsIDController::GetFreeButtonID(std::weak_ptr return ret; } -void buttons::ButtonsIDController::FreeButtonID(const ButtonID &id) +void buttons::ButtonsIDController::FreeButtonID(const ButtonID &id, BaseButton *ptr) { - if (id.CheckIsValid()) - { #ifndef NO_LOGS - logger << microlog::LogLevel::Debug << "ButtonsController::FreeButtonID"; + logger << microlog::LogLevel::Debug << "ButtonsController::FreeButtonID, ID: " << id; #endif + if (id.CheckIsValid()) + { for (std::size_t i = 0; i < _ButtonsIdList.size(); i++) { if (_ButtonsIdList[i].id == id) { - _ButtonsIdList.erase(std::next(_ButtonsIdList.begin(), i)); + if (_ButtonsIdList[i].pointers.size() > 1) + { + auto iter = std::find(_ButtonsIdList[i].pointers.begin(), _ButtonsIdList[i].pointers.end(), ptr); + + if (iter != _ButtonsIdList[i].pointers.end()) + { + _ButtonsIdList[i].pointers.erase(iter); + } + } + else // Если в ID заняла только 1 кнопка(или никто не занял), то можно удалить ноду с эти ID + { + _ButtonsIdList.erase(_ButtonsIdList.begin() + i); + } #ifndef NO_LOGS #ifdef VERBOSE @@ -96,9 +108,13 @@ const ButtonsIDController::List &buttons::ButtonsIDController::GetButtonsIDList( return _ButtonsIdList; } -std::vector> KolibriLib::UI::buttons::ButtonsIDController::GetPointerToButton(const ButtonID &ID) const +std::vector KolibriLib::UI::buttons::ButtonsIDController::GetPointerToButton(const ButtonID &ID) const { - std::vector> ret; +#ifndef NO_LOGS + logger << microlog::LogLevel::Debug << "ButtonsController::GetPointerToButton, ID: " << ID << std::endl; +#endif + + std::vector ret; std::find_if(_ButtonsIdList.begin(), _ButtonsIdList.end(), [&ID, &ret](const ButtonsIDController::node &n) @@ -119,7 +135,7 @@ ButtonIDList KolibriLib::UI::buttons::ButtonsIDController::ListToButtonIDList(co ButtonIDList ret; ret.reserve(list.size()); - for (ButtonsIDController::node i : list) + for (const ButtonsIDController::node& i : list) { ret.push_back(i.id); } @@ -127,28 +143,35 @@ ButtonIDList KolibriLib::UI::buttons::ButtonsIDController::ListToButtonIDList(co return ret; } -void KolibriLib::UI::buttons::ButtonsIDController::TakeUpButtonID(const ButtonID &id, std::weak_ptr ptr) +void KolibriLib::UI::buttons::ButtonsIDController::TakeUpButtonID(const ButtonID &id, BaseButton *ptr) { #ifndef NO_LOGS - logger << microlog::LogLevel::Debug << "TakeUpButtonID" << std::endl; + logger << microlog::LogLevel::Debug << "ButtonsIDController::TakeUpButtonID, ID: " << id << std::endl; #endif - for (auto i : _ButtonsIdList) + for (node& i : _ButtonsIdList) { if (i.id == id) { +#ifndef NO_LOGS + logger << microlog::LogLevel::Debug << "Add to exist node" << std::endl; +#endif i.pointers.push_back(ptr); return; } } +#ifndef NO_LOGS + logger << microlog::LogLevel::Debug << "Create new node" << std::endl; +#endif + _ButtonsIdList.push_back(node(id, ptr)); } void KolibriLib::UI::buttons::ButtonsIDController::Sort() { std::sort(_ButtonsIdList.begin(), _ButtonsIdList.end(), - [](node a, node b) + [](const node &a, const node &b) { return a.id > b.id; }); @@ -163,7 +186,7 @@ KolibriLib::UI::buttons::ButtonsIDController::node::node(ButtonID Id) { } -KolibriLib::UI::buttons::ButtonsIDController::node::node(ButtonID Id, std::weak_ptr p) +KolibriLib::UI::buttons::ButtonsIDController::node::node(ButtonID Id, BaseButton *p) : id(Id), pointers({p}) { @@ -177,4 +200,4 @@ bool KolibriLib::UI::buttons::ButtonsIDController::node::operator==(const node & bool KolibriLib::UI::buttons::ButtonsIDController::node::operator!=(const node &val) const { return id != val.id; -} \ No newline at end of file +} diff --git a/src/KolibriLib/checkbox.cpp b/src/KolibriLib/checkbox.cpp index 2c58962..f14cc65 100644 --- a/src/KolibriLib/checkbox.cpp +++ b/src/KolibriLib/checkbox.cpp @@ -142,4 +142,4 @@ bool KolibriLib::UI::CheckBox::operator!=(const CheckBox &c) const return static_cast(*this) != static_cast(c) || (_BorderColor != c._BorderColor) || (_style != c._style); -} \ No newline at end of file +} diff --git a/src/KolibriLib/os.cpp b/src/KolibriLib/os.cpp index e571389..c3e2542 100644 --- a/src/KolibriLib/os.cpp +++ b/src/KolibriLib/os.cpp @@ -1,7 +1,6 @@ #include #include #include -#include using namespace KolibriLib; using namespace OS; @@ -10,14 +9,14 @@ Thread::PID KolibriLib::OS::Exec(const filesystem::Path &AppName, const std::str { int ret = _ksys_exec(AppName.c_str(), const_cast(args.c_str()), debug); - if (ret < 0) + if (ret > 0) { ec = filesystem::FilesystemErrors::Successfully; return ret; } - else + else if(ret < 0) { - ec = static_cast(ret); + ec = static_cast(-ret); return -1; } } @@ -76,7 +75,7 @@ CoreVersion KolibriLib::OS::GetCoreVersion() /* === CoreVersion === - Opearators + Operators */ bool KolibriLib::OS::CoreVersion::operator==(const CoreVersion &ver) const diff --git a/src/KolibriLib/textlabel.cpp b/src/KolibriLib/textlabel.cpp index 10120e0..96e84f4 100644 --- a/src/KolibriLib/textlabel.cpp +++ b/src/KolibriLib/textlabel.cpp @@ -8,13 +8,13 @@ using namespace text; Constructors */ -TextLabel::TextLabel(const UDim &coord, const UDim &size, const std::string &text, const Size &CharSize, bool TextScale, Colors::Color TextColor, unsigned Margin) +TextLabel::TextLabel(const UDim &coord, const UDim &size, const std::string &text, const Size &CharSize, bool TextScale, Colors::Color TextColor, unsigned Margin) : Txt(text, TextColor), UIElement(coord, size, Globals::SystemColors.work_area, Margin) { - #ifdef VERBOSE +#ifdef VERBOSE logger << microlog::LogLevel::Debug << "TextLabel constructor" << std::endl; - #endif +#endif SetTextSize(CharSize); // SetFont(Fonts::Font(Fonts::DefaultFont.font_file, FontSize)); @@ -24,18 +24,18 @@ KolibriLib::UI::text::TextLabel::TextLabel(const UDim &coord, const UDim &size, : Txt(text), UIElement(coord, size, Globals::SystemColors.work_area) { - #ifdef VERBOSE +#ifdef VERBOSE logger << microlog::LogLevel::Debug << "TextLabel constructor" << std::endl; - #endif +#endif } TextLabel::TextLabel(const TextLabel ©) : Txt(copy), UIElement(copy) { - #ifdef VERBOSE +#ifdef VERBOSE logger << microlog::LogLevel::Debug << "TextLabel constructor(copy)" << std::endl; - #endif +#endif } /* diff --git a/src/KolibriLib/window.cpp b/src/KolibriLib/window.cpp index a16b649..d5aa8d7 100644 --- a/src/KolibriLib/window.cpp +++ b/src/KolibriLib/window.cpp @@ -281,6 +281,9 @@ OS::Event Window::Handler() { UI::buttons::ButtonID PressedButton = UI::buttons::GetPressedButton(); +#ifdef VERBOSE + logger << microlog::LogLevel::Debug << "Pressed Button ID: " << PressedButton << std::endl; +#endif if (PressedButton == UI::buttons::CloseButton) // Если нажата кнопка X { @@ -288,29 +291,33 @@ OS::Event Window::Handler() } else { - for (auto it : _Elements) + for (auto& it : _Elements) { it->OnButtonEvent(PressedButton); } } - std::shared_ptr s_ptr; - if (PressedButton.value != 1) { - try + + auto buttons = _buttonsController.GetPointerToButton(PressedButton); + + if (buttons.size() > 0) { - s_ptr = _buttonsController.GetPointerToButton(PressedButton).at(0).lock(); + for (auto i : buttons) + { + if (i != nullptr) + { + std::shared_ptrs_ptr(i); + _PressedButton = s_ptr; + break; + } + } } - catch (...) + else { - -#ifndef NO_LOGS - logger << microlog::LogLevel::Error << "Error Get s_ptr" << std::endl; -#endif + logger << microlog::LogLevel::Error << "Array of pointer to buttons is empty" << std::endl; } - - _PressedButton = s_ptr; } } @@ -450,4 +457,4 @@ void KolibriLib::window::Window::Update() const OS::Event KolibriLib::window::Window::GetLastEvent() const { return _lastEvent; -} \ No newline at end of file +}