vkdoom_m/include/zwidget/widgets/dropdown/dropdown.h
Rachael Alexanderson 6356d87438 Squashed 'libraries/ZWidget/' changes from 02da8cdc0e..cecd34301d
cecd34301d Delay load DPI-related functions
bfc172f702 Added exception to some unimplemented functions
7c8d469bcb Added item modifications functions
847d0e6d9e Improved keyboard navigation
8c4270e0f8 Dropdown can now be closed by re-selecting it
91402c31ec Fix dropdown positioning in x11 and win32

git-subtree-dir: libraries/ZWidget
git-subtree-split: cecd34301d369400227eb0f27bad2ab41ad756d2
2025-08-13 17:17:30 -04:00

69 lines
1.5 KiB
C++

#pragma once
#include <string>
#include <vector>
#include <functional>
#include "../../core/widget.h"
#include "../../widgets/listview/listview.h"
class DropdownList : public ListView
{
public:
DropdownList(Widget* parent, Dropdown* owner);
protected:
void OnKeyDown(InputKey key) override;
Dropdown* owner;
};
class Dropdown : public Widget
{
public:
Dropdown(Widget* parent);
void AddItem(const std::string& text, int index = -1);
bool UpdateItem(const std::string& text, int index);
bool RemoveItem(int index = -1);
void ClearItems();
const std::string& GetItem(int index);
void SetMaxDisplayItems(int items);
void SetDropdownDirection(bool below);
int GetSelectedItem() const { return selectedItem; }
void SetSelectedItem(int index);
double GetPreferredHeight() const;
double GetPreferredWidth() const;
std::function<void(int)> OnChanged;
protected:
void OnPaint(Canvas* canvas) override;
bool OnMouseDown(const Point& pos, InputKey key) override;
void OnKeyDown(InputKey key) override;
void OnGeometryChanged() override;
void OnLostFocus() override;
void Notify(Widget* source, const WidgetEvent type) override;
private:
void ItemsChanged();
bool OpenDropdown();
bool CloseDropdown();
void OnDropdownActivated();
size_t GetDisplayItems();
std::vector<std::string> items;
int selectedItem = -1;
std::string text;
bool dropdownOpen = false;
Widget* dropdown = nullptr;
DropdownList* listView = nullptr;
int maxDisplayItems = 0;
bool dropdownDirection = true;
friend DropdownList;
};