cecd34301 Delay load DPI-related functions bfc172f70 Added exception to some unimplemented functions 7c8d469bc Added item modifications functions 847d0e6d9 Improved keyboard navigation 8c4270e0f Dropdown can now be closed by re-selecting it 91402c31e Fix dropdown positioning in x11 and win32 02da8cdc0 Added ListView::GetPreferredWidth, ListView::GetPreferredHeight, ListView::GetMinHeight 04bf153d9 Added event subscriber system 1ce55e5da Added Dropdown Known issues: does not hide when parent widget's visibility changes git-subtree-dir: libraries/ZWidget git-subtree-split: cecd34301d369400227eb0f27bad2ab41ad756d2
69 lines
1.5 KiB
C++
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;
|
|
};
|