Fixed file picker and scroll area clipping region
This commit is contained in:
parent
b95adcf0f0
commit
10217e97f4
12 changed files with 69 additions and 23 deletions
|
|
@ -20,6 +20,10 @@ namespace GUIStuff {
|
|||
boundingBox = std::nullopt;
|
||||
}
|
||||
|
||||
void Element::set_parent_clipping_region(const std::optional<SCollision::AABB<float>>& bb) {
|
||||
parentClippingRegion = bb;
|
||||
}
|
||||
|
||||
const std::optional<SCollision::AABB<float>>& Element::get_bb() const {
|
||||
return boundingBox;
|
||||
}
|
||||
|
|
@ -27,7 +31,8 @@ namespace GUIStuff {
|
|||
bool Element::collides_with_point(const Vector2f& p) const {
|
||||
if(!boundingBox.has_value())
|
||||
return false;
|
||||
return SCollision::collide(p, boundingBox.value());
|
||||
bool inClippingRegion = !parentClippingRegion.has_value() || SCollision::collide(p, parentClippingRegion.value());
|
||||
return inClippingRegion && SCollision::collide(p, boundingBox.value());
|
||||
}
|
||||
|
||||
SCollision::AABB<float> Element::get_bb_from_command(Clay_RenderCommand* command) {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ namespace GUIStuff {
|
|||
virtual bool collides_with_point(const Vector2f& p) const;
|
||||
|
||||
void set_bounding_box_from_elem_data(const Clay_ElementData& elemData);
|
||||
void set_parent_clipping_region(const std::optional<SCollision::AABB<float>>& bb);
|
||||
const std::optional<SCollision::AABB<float>>& get_bb() const;
|
||||
virtual ~Element() = default;
|
||||
|
||||
|
|
@ -27,6 +28,7 @@ namespace GUIStuff {
|
|||
protected:
|
||||
static SCollision::AABB<float> get_bb_from_command(Clay_RenderCommand* command);
|
||||
std::optional<SCollision::AABB<float>> boundingBox;
|
||||
std::optional<SCollision::AABB<float>> parentClippingRegion;
|
||||
|
||||
GUIManager& gui;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ bool SelectableButton::input_mouse_button_callback(const InputManager::MouseButt
|
|||
isHovering = mouseHovering;
|
||||
isHeld = isHovering && button.button == InputManager::MouseButton::LEFT && button.down;
|
||||
if(isHeld) {
|
||||
gui.set_post_callback_func([&]{onClick();});
|
||||
gui.set_post_callback_func([&]{ if(onClick) onClick(); });
|
||||
gui.set_to_layout();
|
||||
}
|
||||
else if(isHovering != oldIsHovering || isHeld != oldIsHeld)
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@ template <typename T> class TextBox : public Element {
|
|||
virtual void input_key_callback(const InputManager::KeyCallbackArgs& key) override;
|
||||
~TextBox();
|
||||
private:
|
||||
void init_textbox(UpdateInputData& io, bool forceTextUpdate);
|
||||
void init_textbox(UpdateInputData& io);
|
||||
void reset_textbox_text();
|
||||
bool update_data();
|
||||
|
||||
std::optional<T> oldData;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,10 @@ template <typename T> TextBox<T>::TextBox(GUIManager& gui): Element(gui) {}
|
|||
template <typename T> void TextBox<T>::layout(const Clay_ElementId& id, const TextBoxData<T>& userInfo) {
|
||||
auto& io = gui.io;
|
||||
this->userInfo = userInfo;
|
||||
init_textbox(io, false);
|
||||
init_textbox(io);
|
||||
if(!oldData.has_value() || oldData.value() != *userInfo.data)
|
||||
reset_textbox_text();
|
||||
|
||||
CLAY(id, {
|
||||
.layout = {
|
||||
.sizing = {.width = CLAY_SIZING_GROW(static_cast<float>(io.fontSize * 2)), .height = CLAY_SIZING_FIXED(static_cast<float>(io.fontSize * 1.25f))}
|
||||
|
|
@ -73,7 +76,7 @@ template <typename T> bool TextBox<T>::input_mouse_button_callback(const InputMa
|
|||
gui.io.input->remove_rich_text_box_input(textbox);
|
||||
if(update_data())
|
||||
gui.set_post_callback_func_high_priority(userInfo.onEdit);
|
||||
init_textbox(gui.io, true);
|
||||
reset_textbox_text();
|
||||
isSelected = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -96,12 +99,12 @@ template <typename T> void TextBox<T>::input_key_callback(const InputManager::Ke
|
|||
gui.set_post_callback_func_high_priority([&, success] {
|
||||
if(success && userInfo.onEdit) userInfo.onEdit();
|
||||
if(userInfo.onEnter) userInfo.onEnter();
|
||||
init_textbox(gui.io, true);
|
||||
reset_textbox_text();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T> void TextBox<T>::init_textbox(UpdateInputData& io, bool forceTextUpdate) {
|
||||
template <typename T> void TextBox<T>::init_textbox(UpdateInputData& io) {
|
||||
if(!textbox) {
|
||||
textbox = std::make_shared<RichText::TextBox>();
|
||||
textbox->set_width(std::numeric_limits<float>::max());
|
||||
|
|
@ -111,11 +114,6 @@ template <typename T> void TextBox<T>::init_textbox(UpdateInputData& io, bool fo
|
|||
rect = std::make_shared<SCollision::AABB<float>>();
|
||||
}
|
||||
|
||||
if(forceTextUpdate || !oldData.has_value() || oldData.value() != *userInfo.data) {
|
||||
textbox->clear_text();
|
||||
cur->pos = cur->selectionBeginPos = cur->selectionEndPos = textbox->insert({0, 0}, userInfo.toStr(*userInfo.data));
|
||||
}
|
||||
|
||||
textbox->onUserTextEdit = [&] {
|
||||
if(userInfo.immutable)
|
||||
cur->pos = cur->selectionBeginPos = cur->selectionEndPos = textbox->insert({0, 0}, userInfo.toStr(*userInfo.data));
|
||||
|
|
@ -126,6 +124,11 @@ template <typename T> void TextBox<T>::init_textbox(UpdateInputData& io, bool fo
|
|||
};
|
||||
}
|
||||
|
||||
template <typename T> void TextBox<T>::reset_textbox_text() {
|
||||
textbox->set_string(userInfo.toStr(*userInfo.data));
|
||||
cur->pos = cur->selectionBeginPos = cur->selectionEndPos = {0, 0};
|
||||
}
|
||||
|
||||
template <typename T> bool TextBox<T>::update_data() {
|
||||
std::optional<T> dataToAssign = userInfo.fromStr(textbox->get_string());
|
||||
if(dataToAssign.has_value()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue