dl
dl_ui_file_explorer.h
浏览该文件的文档.
1
12#pragma once
13
14#ifndef DL_DISABLE_RENDER
16#include "ui/dl_ui_background.h"
17#include "ui/dl_ui_panel.h"
18#include "ui/dl_ui_window.h"
19#include "ui/dl_ui_list_box.h"
20
21namespace dl::UI
22{
24class FileExplorer : public Window
25{
26public:
27
32 static FileExplorer* Create(UI::Text* txt_path, UI::ListBox* lst, UI::ListBox* lst_root)
33 {
34 FileExplorer* ret = new FileExplorer;
35 ret->_txtPath = txt_path;
36 ret->_lstPath = lst;
37 ret->_lstPathRoot = lst_root;
38 ret->_init();
39 return ret;
40 }
41
42 void SetOnlyFolder(bool only_folder)
43 {
44 _bOnlyFolder = only_folder;
45 }
46
47 void SetPathCurrent(std::string_view path)
48 {
49 _pathCurrent = path;
50 Refresh();
51 }
52 void SetTargetName(std::string_view name)
53 {
54 _targetName = name;
55 Refresh();
56 }
57
58 std::string GetPathCurrent() { return _pathCurrent; }
59
61 std::string GetPathSelect()
62 {
63 Value v = _lstPath->GetSelect();
64 if (v)
65 return GetPathCurrent() + v.ToString();
66 else
67 return GetPathCurrent();
68 }
69
70 void Refresh();
71
72 virtual void Update() override;
73
74
76private:
77 FileExplorer() :
78 _bOnlyFolder{ false }
79 {
80 _pathCurrent = File::PathPublic();
81 }
82 UI::Text* _txtPath;
83
84 UI::ListBox* _lstPath;
85 std::vector<std::string> _vecPath;
86 std::string _pathCurrent;
87
88 UI::ListBox* _lstPathRoot;
89 std::vector<std::string> _vecPathRoot;
90
91 bool _bOnlyFolder; // 只显示文件夹模式
92 std::string _targetName; // 目标文件名(带后缀,匹配才显示)
93
94 void _init()
95 {
96 _panel->Add(_txtPath);
97 _panel->Add(_lstPath);
98 _panel->Add(_lstPathRoot);
99
100 Refresh();
101 }
102};
103}
104
105#endif
std::string GetPathSelect()
当前选中的目录(没选中则返回GetPathCurrent)
void SetPathCurrent(std::string_view path)
设置当前目录
static FileExplorer * Create(UI::Text *txt_path, UI::ListBox *lst, UI::ListBox *lst_root)
创建窗口
virtual void Update() override
帧函数 @info 子类重载后,需要调用 Window::Update()
std::string GetPathCurrent()
当前显示的目录
void SetOnlyFolder(bool only_folder)
void SetTargetName(std::string_view name)
void Add(T *p)
添加一个Element
任意类型
std::string ToString() const
组件实例
作为绘图背景
UI之列表框
ui之panel
UI之窗口
std::string PathPublic()
返回公共路径 rw