aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic-extension/classes
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2024-08-01 21:35:11 +0200
committer GitHub <noreply@github.com>2024-08-01 21:35:11 +0200
commit8431914a6971cbacfb20bba13a4113d9ac4d5153 (patch)
tree71c1fa0482ab845b18a577a0d7503e40d49225f2 /extension/src/openvic-extension/classes
parente2cb2f5bd746d3928b4554252c69943df2ed5a3d (diff)
parent70f3c3cf6f9c1563d95ffb8c25bf8cd2bb7a1ad0 (diff)
Merge pull request #246 from OpenVicProject/search-panel
Search panel + text edit box UI generation
Diffstat (limited to 'extension/src/openvic-extension/classes')
-rw-r--r--extension/src/openvic-extension/classes/GUIListBox.cpp22
-rw-r--r--extension/src/openvic-extension/classes/GUINode.cpp3
-rw-r--r--extension/src/openvic-extension/classes/GUINode.hpp3
3 files changed, 18 insertions, 10 deletions
diff --git a/extension/src/openvic-extension/classes/GUIListBox.cpp b/extension/src/openvic-extension/classes/GUIListBox.cpp
index c153870..e3bea86 100644
--- a/extension/src/openvic-extension/classes/GUIListBox.cpp
+++ b/extension/src/openvic-extension/classes/GUIListBox.cpp
@@ -9,6 +9,7 @@
using namespace OpenVic;
using namespace godot;
+using namespace OpenVic::Utilities::literals;
using OpenVic::Utilities::std_view_to_godot_string;
@@ -24,14 +25,14 @@ Error GUIListBox::_calculate_max_scroll_index(bool signal) {
if (fixed_item_count <= 0) {
max_scroll_index = 0;
fixed_visible_items = 0;
- } else if (fixed_item_height <= 0.0f) {
+ } else if (fixed_item_height <= 0.0_real) {
max_scroll_index = fixed_item_count - 1;
fixed_visible_items = max_scroll_index;
} else {
const real_t max_height = get_size().height;
fixed_visible_items = max_height / fixed_item_height;
- max_scroll_index = fixed_item_count - std::max(fixed_visible_items, 1);
+ max_scroll_index = std::max(fixed_item_count - std::max(fixed_visible_items, 1), 0);
}
} else {
const int32_t child_count = get_child_count();
@@ -41,7 +42,7 @@ Error GUIListBox::_calculate_max_scroll_index(bool signal) {
} else {
const real_t max_height = get_size().height;
- real_t height_under_max_scroll_index = 0.0f;
+ real_t height_under_max_scroll_index = 0.0_real;
max_scroll_index = child_count;
@@ -75,8 +76,9 @@ Error GUIListBox::_calculate_max_scroll_index(bool signal) {
Error GUIListBox::_update_child_positions() {
const int32_t child_count = get_child_count();
const real_t max_height = get_size().height;
+ const Vector2 offset = gui_listbox != nullptr ? Utilities::to_godot_fvec2(gui_listbox->get_items_offset()) : Vector2 {};
- real_t height = 0.0f;
+ real_t height = 0.0_real;
const int32_t child_scroll_index = fixed ? 0 : scroll_index;
@@ -87,7 +89,7 @@ Error GUIListBox::_update_child_positions() {
if (index < child_scroll_index) {
child->hide();
} else {
- child->set_position({ 0.0f, height });
+ child->set_position(offset + Vector2 { 0.0_real, height });
height += child->get_size().height; /* Spacing is ignored */
@@ -130,7 +132,7 @@ void GUIListBox::_notification(int what) {
GUIListBox::GUIListBox()
: gui_listbox { nullptr }, scrollbar { nullptr }, scroll_index { 0 }, max_scroll_index { 0 },
- fixed { false }, fixed_item_count { 0 }, fixed_visible_items { 0 }, fixed_item_height { 0.0f } {}
+ fixed { false }, fixed_item_count { 0 }, fixed_visible_items { 0 }, fixed_item_height { 0.0_real } {}
Vector2 GUIListBox::_get_minimum_size() const {
if (gui_listbox != nullptr) {
@@ -177,7 +179,7 @@ void GUIListBox::clear() {
fixed = false;
fixed_item_count = 0;
fixed_visible_items = 0;
- fixed_item_height = 0.0f;
+ fixed_item_height = 0.0_real;
clear_children();
if (scrollbar != nullptr) {
@@ -233,7 +235,7 @@ Error GUIListBox::unset_fixed(bool signal) {
fixed = false;
fixed_item_count = 0;
- fixed_item_height = 0.0f;
+ fixed_item_height = 0.0_real;
return _calculate_max_scroll_index(signal);
}
@@ -273,7 +275,9 @@ Error GUIListBox::set_gui_listbox(GUI::ListBox const* new_gui_listbox) {
add_child(scrollbar, false, INTERNAL_MODE_FRONT);
const Size2 size = Utilities::to_godot_fvec2(gui_listbox->get_size());
- scrollbar->set_position({ size.width, 0.0f });
+ Vector2 position = Utilities::to_godot_fvec2(gui_listbox->get_scrollbar_offset());
+ position.x += size.width;
+ scrollbar->set_position(position);
scrollbar->set_length_override(size.height);
static const StringName set_scroll_index_func_name = "set_scroll_index";
diff --git a/extension/src/openvic-extension/classes/GUINode.cpp b/extension/src/openvic-extension/classes/GUINode.cpp
index d8ab6c1..bd8197b 100644
--- a/extension/src/openvic-extension/classes/GUINode.cpp
+++ b/extension/src/openvic-extension/classes/GUINode.cpp
@@ -46,7 +46,8 @@ using namespace OpenVic;
F(TextureRect, texture_rect) \
F(GUIOverlappingElementsBox, gui_overlapping_elements_box) \
F(GUIScrollbar, gui_scrollbar) \
- F(GUIListBox, gui_listbox)
+ F(GUIListBox, gui_listbox) \
+ F(LineEdit, line_edit)
#define APPLY_TO_TEXTURE_TYPES(F) \
F(GFXSpriteTexture, gfx_sprite_texture) \
diff --git a/extension/src/openvic-extension/classes/GUINode.hpp b/extension/src/openvic-extension/classes/GUINode.hpp
index 27ce780..f8eb62c 100644
--- a/extension/src/openvic-extension/classes/GUINode.hpp
+++ b/extension/src/openvic-extension/classes/GUINode.hpp
@@ -6,6 +6,7 @@
#include <godot_cpp/classes/image.hpp>
#include <godot_cpp/classes/input_event.hpp>
#include <godot_cpp/classes/label.hpp>
+#include <godot_cpp/classes/line_edit.hpp>
#include <godot_cpp/classes/node.hpp>
#include <godot_cpp/classes/panel.hpp>
#include <godot_cpp/classes/ref.hpp>
@@ -58,6 +59,7 @@ namespace OpenVic {
static GUIOverlappingElementsBox* get_gui_overlapping_elements_box_from_node(godot::Node* node);
static GUIScrollbar* get_gui_scrollbar_from_node(godot::Node* node);
static GUIListBox* get_gui_listbox_from_node(godot::Node* node);
+ static godot::LineEdit* get_line_edit_from_node(godot::Node* node);
godot::Button* get_button_from_nodepath(godot::NodePath const& path) const;
godot::Label* get_label_from_nodepath(godot::NodePath const& path) const;
@@ -67,6 +69,7 @@ namespace OpenVic {
GUIOverlappingElementsBox* get_gui_overlapping_elements_box_from_nodepath(godot::NodePath const& path) const;
GUIScrollbar* get_gui_scrollbar_from_nodepath(godot::NodePath const& path) const;
GUIListBox* get_gui_listbox_from_nodepath(godot::NodePath const& path) const;
+ godot::LineEdit* get_line_edit_from_nodepath(godot::NodePath const& path) const;
/* Helper functions to get textures from TextureRects and Buttons. */
static godot::Ref<godot::Texture2D> get_texture_from_node(godot::Node* node);