Readded chat box
This commit is contained in:
parent
99c2657434
commit
60af55d4db
19 changed files with 307 additions and 249 deletions
|
|
@ -6,6 +6,7 @@ namespace GUIStuff {
|
|||
gui(initGUI) {}
|
||||
|
||||
void Element::update() {}
|
||||
void Element::deselect() {}
|
||||
|
||||
void Element::input_paste_callback(const CustomEvents::PasteEventData& paste) { }
|
||||
void Element::input_text_key_callback(const InputManager::KeyCallbackArgs& key) { }
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ namespace GUIStuff {
|
|||
Element* parent = nullptr;
|
||||
|
||||
virtual void update();
|
||||
virtual void deselect();
|
||||
|
||||
virtual void input_paste_callback(const CustomEvents::PasteEventData& paste);
|
||||
virtual void input_text_key_callback(const InputManager::KeyCallbackArgs& key);
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ void SelectableButton::layout(const Clay_ElementId& id, const Data& d) {
|
|||
SkColor4f backgroundColorHighlight;
|
||||
SkColor4f backgroundColor;
|
||||
|
||||
instantResponse = d.instantResponse;
|
||||
onClick = [&, this, d] {
|
||||
if(d.onClickButton)
|
||||
d.onClickButton(this);
|
||||
|
|
@ -70,10 +71,16 @@ void SelectableButton::layout(const Clay_ElementId& id, const Data& d) {
|
|||
void SelectableButton::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) {
|
||||
bool oldIsHeld = isHeld;
|
||||
isHeld = mouseHovering && button.button == InputManager::MouseButton::LEFT && button.down;
|
||||
if(isHeld)
|
||||
if(isHeld) {
|
||||
if(instantResponse) {
|
||||
std::cout << "INSTANT" << std::endl;
|
||||
gui.set_post_callback_func(onClick);
|
||||
}
|
||||
gui.set_to_layout();
|
||||
}
|
||||
else if(mouseHovering && oldIsHeld && button.button == InputManager::MouseButton::LEFT && !button.down) {
|
||||
gui.set_post_callback_func(onClick);
|
||||
if(!instantResponse)
|
||||
gui.set_post_callback_func(onClick);
|
||||
gui.set_to_layout();
|
||||
}
|
||||
else if(mouseHovering != oldIsHovering || isHeld != oldIsHeld)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ class SelectableButton : public Element {
|
|||
struct Data {
|
||||
DrawType drawType = DrawType::TRANSPARENT_ALL;
|
||||
bool isSelected = false;
|
||||
bool instantResponse = false;
|
||||
std::function<void()> onClick;
|
||||
std::function<void(SelectableButton*)> onClickButton;
|
||||
std::function<void(const InnerContentCallbackParameters&)> innerContent;
|
||||
|
|
@ -32,6 +33,7 @@ class SelectableButton : public Element {
|
|||
virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) override;
|
||||
|
||||
private:
|
||||
bool instantResponse = false;
|
||||
bool isHeld = false;
|
||||
bool oldIsHovering = false;
|
||||
std::function<void()> onClick;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ template <typename T> struct TextBoxData {
|
|||
std::function<std::optional<T>(const std::string&)> fromStr;
|
||||
std::function<std::string(const T&)> toStr;
|
||||
bool singleLine = true;
|
||||
bool updateEveryEdit = true;
|
||||
bool immutable = false;
|
||||
InputManager::TextInputProperties textInputProps;
|
||||
std::function<void()> onEdit;
|
||||
|
|
@ -38,7 +37,9 @@ template <typename T> class TextBox : public Element {
|
|||
TextBox(GUIManager& gui);
|
||||
|
||||
void layout(const Clay_ElementId& id, const TextBoxData<T>& userInfo);
|
||||
virtual void update();
|
||||
void select();
|
||||
virtual void update() override;
|
||||
virtual void deselect() override;
|
||||
virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) override;
|
||||
virtual void input_paste_callback(const CustomEvents::PasteEventData& paste) override;
|
||||
virtual void input_text_key_callback(const InputManager::KeyCallbackArgs& key) override;
|
||||
|
|
|
|||
|
|
@ -71,6 +71,23 @@ template <typename T> void TextBox<T>::clay_draw(SkCanvas* canvas, UpdateInputDa
|
|||
canvas->restore();
|
||||
}
|
||||
|
||||
template <typename T> void TextBox<T>::select() {
|
||||
if(!is_selected()) {
|
||||
SCollision::AABB<float> rect = {(boundingBox.value().min + gui.io.windowPos) * gui.io.guiScaleMultiplier, (boundingBox.value().max + gui.io.windowPos) * gui.io.guiScaleMultiplier};
|
||||
unsigned id = gui.io.input->set_text_box_front(rect, userInfo.textInputProps);
|
||||
edit = TextEditData(id, textbox, cur);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T> void TextBox<T>::deselect() {
|
||||
if(is_selected()) {
|
||||
gui.io.input->remove_text_box(edit.value().textboxInputID);
|
||||
if(userInfo.onDeselect) userInfo.onDeselect();
|
||||
reset_textbox_text();
|
||||
edit = std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T> bool TextBox<T>::is_selected() const {
|
||||
return edit.has_value();
|
||||
}
|
||||
|
|
@ -101,7 +118,7 @@ template <typename T> void TextBox<T>::after_text_input_callback() {
|
|||
if(userInfo.immutable)
|
||||
cur->pos = cur->selectionBeginPos = cur->selectionEndPos = textbox->insert({0, 0}, userInfo.toStr(*userInfo.data));
|
||||
else {
|
||||
if(userInfo.updateEveryEdit && update_data() && userInfo.onEdit)
|
||||
if(update_data() && userInfo.onEdit)
|
||||
gui.set_post_callback_func_high_priority(userInfo.onEdit);
|
||||
}
|
||||
}
|
||||
|
|
@ -114,37 +131,22 @@ template <typename T> void TextBox<T>::input_text_callback(const InputManager::T
|
|||
}
|
||||
|
||||
template <typename T> void TextBox<T>::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) {
|
||||
auto& io = gui.io;
|
||||
|
||||
isHeld = false;
|
||||
|
||||
if(button.button == InputManager::MouseButton::LEFT && boundingBox.has_value()) {
|
||||
if(button.down) {
|
||||
if(mouseHovering) {
|
||||
if(!is_selected()) {
|
||||
SCollision::AABB<float> rect = {(boundingBox.value().min + io.windowPos) * io.guiScaleMultiplier, (boundingBox.value().max + io.windowPos) * io.guiScaleMultiplier};
|
||||
unsigned id = gui.io.input->set_text_box_front(rect, userInfo.textInputProps);
|
||||
edit = TextEditData(id, textbox, cur);
|
||||
select();
|
||||
gui.set_post_callback_func_high_priority([&] {
|
||||
if(userInfo.onSelect) userInfo.onSelect();
|
||||
});
|
||||
}
|
||||
isHeld = true;
|
||||
textbox->process_mouse_left_button(*cur, button.pos - boundingBox.value().min, button.clicks, isHeld, gui.io.input->key(InputManager::KEY_GENERIC_LSHIFT).held);
|
||||
}
|
||||
else if(is_selected()) {
|
||||
gui.io.input->remove_text_box(edit.value().textboxInputID);
|
||||
gui.set_post_callback_func_high_priority([&] {
|
||||
if(update_data())
|
||||
if(userInfo.onEdit) userInfo.onEdit();
|
||||
if(userInfo.onDeselect) userInfo.onDeselect();
|
||||
});
|
||||
reset_textbox_text();
|
||||
edit = std::nullopt;
|
||||
textbox->process_mouse_left_button(*cur, button.pos - boundingBox.value().min, button.clicks, true, gui.io.input->key(InputManager::KEY_GENERIC_LSHIFT).held);
|
||||
}
|
||||
else if(is_selected())
|
||||
deselect();
|
||||
}
|
||||
else {
|
||||
textbox->process_mouse_left_button(*cur, button.pos - boundingBox.value().min, 0, isHeld, gui.io.input->key(InputManager::KEY_GENERIC_LSHIFT).held);
|
||||
textbox->process_mouse_left_button(*cur, button.pos - boundingBox.value().min, 0, false, gui.io.input->key(InputManager::KEY_GENERIC_LSHIFT).held);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue