lifecycle update

This commit is contained in:
Jorijn van der Graaf 2025-11-14 18:40:13 +01:00
commit 0b7a43efbd
14 changed files with 950 additions and 490 deletions

View file

@ -25,40 +25,16 @@ import :BindingsImport;
import :EventTypes;
namespace Crafter {
export class HtmlElementView {
export class HtmlElementPtr {
public:
void* ptr;
std::vector<std::int32_t> clickHandlers;
std::vector<std::int32_t> mouseOverHandlers;
std::vector<std::int32_t> mouseOutHandlers;
std::vector<std::int32_t> mouseMoveHandlers;
std::vector<std::int32_t> mouseDownHandlers;
std::vector<std::int32_t> mouseUpHandlers;
std::vector<std::int32_t> focusHandlers;
std::vector<std::int32_t> blurHandlers;
std::vector<std::int32_t> keyDownHandlers;
std::vector<std::int32_t> keyUpHandlers;
std::vector<std::int32_t> keyPressHandlers;
std::vector<std::int32_t> changeHandlers;
std::vector<std::int32_t> submitHandlers;
std::vector<std::int32_t> inputHandlers;
std::vector<std::int32_t> resizeHandlers;
std::vector<std::int32_t> scrollHandlers;
std::vector<std::int32_t> contextMenuHandlers;
std::vector<std::int32_t> dragStartHandlers;
std::vector<std::int32_t> dragEndHandlers;
std::vector<std::int32_t> dropHandlers;
std::vector<std::int32_t> dragOverHandlers;
std::vector<std::int32_t> dragEnterHandlers;
std::vector<std::int32_t> dragLeaveHandlers;
std::vector<std::int32_t> wheelHandlers;
HtmlElementView(const std::string_view id);
HtmlElementView(const std::string_view id, const std::string_view html);
HtmlElementView(HtmlElementView&&);
HtmlElementView(const HtmlElementView&) = delete;
HtmlElementView& operator=(const HtmlElementView&) = delete;
~HtmlElementView();
std::int32_t ptr;
HtmlElementPtr(const std::string_view id);
HtmlElementPtr(const std::string_view id, const std::string_view html);
HtmlElementPtr(HtmlElementPtr&&);
HtmlElementPtr(const HtmlElementPtr&) = delete;
HtmlElementPtr& operator=(const HtmlElementPtr&) = delete;
~HtmlElementPtr();
void SetInnerHTML(const std::string_view html);
void SetStyle(const std::string_view style);
void SetProperty(const std::string_view property, const std::string_view value);
@ -67,7 +43,6 @@ namespace Crafter {
void ToggleClass(const std::string_view className);
bool HasClass(const std::string_view className);
// Value property accessors
std::string GetValue();
void SetValue(const std::string_view value);
@ -144,13 +119,117 @@ namespace Crafter {
void RemoveWheelListener(std::int32_t id);
};
export class HtmlElementView : public HtmlElementPtr {
public:
HtmlElementView(const std::string_view id);
HtmlElementView(const std::string_view id, const std::string_view html);
HtmlElementView(HtmlElementView&&);
~HtmlElementView();
std::int32_t AddClickListener(std::function<void(Crafter::MouseEvent)> callback);
void RemoveClickListener(std::int32_t id);
std::int32_t AddMouseOverListener(std::function<void(Crafter::MouseEvent)> callback);
void RemoveMouseOverListener(std::int32_t id);
std::int32_t AddMouseOutListener(std::function<void(Crafter::MouseEvent)> callback);
void RemoveMouseOutListener(std::int32_t id);
std::int32_t AddMouseMoveListener(std::function<void(Crafter::MouseEvent)> callback);
void RemoveMouseMoveListener(std::int32_t id);
std::int32_t AddMouseDownListener(std::function<void(Crafter::MouseEvent)> callback);
void RemoveMouseDownListener(std::int32_t id);
std::int32_t AddMouseUpListener(std::function<void(Crafter::MouseEvent)> callback);
void RemoveMouseUpListener(std::int32_t id);
std::int32_t AddFocusListener(std::function<void(Crafter::FocusEvent)> callback);
void RemoveFocusListener(std::int32_t id);
std::int32_t AddBlurListener(std::function<void(Crafter::FocusEvent)> callback);
void RemoveBlurListener(std::int32_t id);
std::int32_t AddKeyDownListener(std::function<void(KeyboardEvent)> callback);
void RemoveKeyDownListener(std::int32_t id);
std::int32_t AddKeyUpListener(std::function<void(KeyboardEvent)> callback);
void RemoveKeyUpListener(std::int32_t id);
std::int32_t AddKeyPressListener(std::function<void(KeyboardEvent)> callback);
void RemoveKeyPressListener(std::int32_t id);
std::int32_t AddChangeListener(std::function<void(ChangeEvent)> callback);
void RemoveChangeListener(std::int32_t id);
std::int32_t AddSubmitListener(std::function<void(void)> callback);
void RemoveSubmitListener(std::int32_t id);
std::int32_t AddInputListener(std::function<void(InputEvent)> callback);
void RemoveInputListener(std::int32_t id);
std::int32_t AddResizeListener(std::function<void(ResizeEvent)> callback);
void RemoveResizeListener(std::int32_t id);
std::int32_t AddScrollListener(std::function<void(ScrollEvent)> callback);
void RemoveScrollListener(std::int32_t id);
std::int32_t AddContextMenuListener(std::function<void(MouseEvent)> callback);
void RemoveContextMenuListener(std::int32_t id);
std::int32_t AddDragStartListener(std::function<void(MouseEvent)> callback);
void RemoveDragStartListener(std::int32_t id);
std::int32_t AddDragEndListener(std::function<void(MouseEvent)> callback);
void RemoveDragEndListener(std::int32_t id);
std::int32_t AddDropListener(std::function<void(MouseEvent)> callback);
void RemoveDropListener(std::int32_t id);
std::int32_t AddDragOverListener(std::function<void(MouseEvent)> callback);
void RemoveDragOverListener(std::int32_t id);
std::int32_t AddDragEnterListener(std::function<void(MouseEvent)> callback);
void RemoveDragEnterListener(std::int32_t id);
std::int32_t AddDragLeaveListener(std::function<void(MouseEvent)> callback);
void RemoveDragLeaveListener(std::int32_t id);
std::int32_t AddWheelListener(std::function<void(WheelEvent)> callback);
void RemoveWheelListener(std::int32_t id);
private:
std::vector<std::int32_t> clickHandlers;
std::vector<std::int32_t> mouseOverHandlers;
std::vector<std::int32_t> mouseOutHandlers;
std::vector<std::int32_t> mouseMoveHandlers;
std::vector<std::int32_t> mouseDownHandlers;
std::vector<std::int32_t> mouseUpHandlers;
std::vector<std::int32_t> focusHandlers;
std::vector<std::int32_t> blurHandlers;
std::vector<std::int32_t> keyDownHandlers;
std::vector<std::int32_t> keyUpHandlers;
std::vector<std::int32_t> keyPressHandlers;
std::vector<std::int32_t> changeHandlers;
std::vector<std::int32_t> submitHandlers;
std::vector<std::int32_t> inputHandlers;
std::vector<std::int32_t> resizeHandlers;
std::vector<std::int32_t> scrollHandlers;
std::vector<std::int32_t> contextMenuHandlers;
std::vector<std::int32_t> dragStartHandlers;
std::vector<std::int32_t> dragEndHandlers;
std::vector<std::int32_t> dropHandlers;
std::vector<std::int32_t> dragOverHandlers;
std::vector<std::int32_t> dragEnterHandlers;
std::vector<std::int32_t> dragLeaveHandlers;
std::vector<std::int32_t> wheelHandlers;
};
export class HtmlElement : public HtmlElementView {
public:
HtmlElement(const std::string_view id);
HtmlElement(const std::string_view id, const std::string_view html);
HtmlElement(HtmlElement&&);
HtmlElement(const HtmlElement&) = delete;
HtmlElement& operator=(const HtmlElement&) = delete;
~HtmlElement();
};
}