aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic-extension/classes/GUIListBox.hpp
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2024-03-04 23:49:37 +0100
committer GitHub <noreply@github.com>2024-03-04 23:49:37 +0100
commit521f7d3d156f42535fb7574fb36f2726e9d13885 (patch)
tree8c319b540020aaf382592c9b513a27e9fcaaa603 /extension/src/openvic-extension/classes/GUIListBox.hpp
parent9e305db5e5090a1a24979c480d64eebfe2de65da (diff)
parent9ee1940ac3d15aa4c0a87b84d1c4ab8958184f63 (diff)
Merge pull request #210 from OpenVicProject/gui-listbox
Add GUIListBox + UI improvements
Diffstat (limited to 'extension/src/openvic-extension/classes/GUIListBox.hpp')
-rw-r--r--extension/src/openvic-extension/classes/GUIListBox.hpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/extension/src/openvic-extension/classes/GUIListBox.hpp b/extension/src/openvic-extension/classes/GUIListBox.hpp
new file mode 100644
index 0000000..9d49840
--- /dev/null
+++ b/extension/src/openvic-extension/classes/GUIListBox.hpp
@@ -0,0 +1,58 @@
+#pragma once
+
+#include <godot_cpp/classes/container.hpp>
+
+#include <openvic-simulation/interface/GUI.hpp>
+
+#include "openvic-extension/classes/GUIScrollbar.hpp"
+
+namespace OpenVic {
+ class GUIListBox : public godot::Container {
+ GDCLASS(GUIListBox, godot::Container)
+
+ GUI::ListBox const* PROPERTY(gui_listbox);
+
+ GUIScrollbar* scrollbar;
+
+ struct child_data_t {
+ Control* child;
+ real_t start_pos, height;
+ };
+
+ std::vector<child_data_t> children_data;
+
+ /* The children_data index of the topmost visible child element. */
+ int32_t PROPERTY(scroll_index);
+ int32_t PROPERTY(max_scroll_index);
+
+ godot::Error _calculate_child_arrangement();
+ godot::Error _update_child_positions();
+
+ protected:
+ static void _bind_methods();
+
+ void _notification(int what);
+
+ public:
+ GUIListBox();
+
+ godot::Vector2 _get_minimum_size() const override;
+ void _gui_input(godot::Ref<godot::InputEvent> const& event) override;
+
+ /* Reset gui_listbox to nullptr, and remove all child elements. */
+ void clear();
+
+ /* Remove all child elements except for the scrollbar. */
+ void clear_children();
+
+ void set_scroll_index(int32_t new_scroll_index);
+
+ /* Set the GUI::ListBox. This does not affect any existing child elements. */
+ godot::Error set_gui_listbox(GUI::ListBox const* new_gui_listbox);
+
+ /* Return the name of the GUI::ListBox, or an empty String if it's null. */
+ godot::String get_gui_listbox_name() const;
+
+ GUIScrollbar* get_scrollbar() const;
+ };
+}