YCLIMP
Yandex Command Line Interface Music Player
Loading...
Searching...
No Matches
ListDialogElement.tpp
1#pragma once
2
3#include "ListDialogElement.hpp"
4
5namespace
6{
7template <typename ElementPtr>
9typename ListDialogElement<ElementPtr>::LocalBounds CalculateLocalBounds(
10 const Recti& newBounds)
11{
13 auto& textBounds = lBounds.text;
14 auto& listBounds = lBounds.list;
15 auto& confirmBounds = lBounds.confirm;
16 textBounds.left = newBounds.left + 1;
17 textBounds.width = newBounds.width - 1;
18 listBounds.left = newBounds.left;
19 listBounds.width = newBounds.width;
20 confirmBounds.left = newBounds.left;
21 confirmBounds.width = newBounds.width;
22
23 // top text
24 textBounds.top = newBounds.top;
25 textBounds.height = 1;
26
27 // middle content
28 listBounds.top = newBounds.top + textBounds.height;
29 listBounds.height = newBounds.height - 1 - 1;
30
31 // bottom text
32 confirmBounds.top = listBounds.top + listBounds.height;
33 confirmBounds.height = 1;
34
35 return lBounds;
36}
37} // namespace
38
39template <typename ElementPtr>
41ListDialogElement<ElementPtr>::ListDialogElement(const Recti& bounds, std::string text,
42 std::vector<ElementPtr> elements, Type type, std::vector<std::string>&& options)
43 : DialogElement{bounds}
44 , mBounds{bounds}
45 , mLBounds{CalculateLocalBounds<ElementPtr>(bounds)}
46 , mHorizontalChoice{std::move(options), mLBounds.confirm}
47 , mText{std::move(text)}
48 , mFileSelector{mLBounds.list}
49 , mType{type}
50{
51 mFileSelector.Load(std::move(elements), true);
52}
53
54template <typename ElementPtr>
56void ListDialogElement<ElementPtr>::Draw() const
57{
58 if (IsFinished() == true)
59 return;
60
61 clearArea(mBounds);
62 printwMsgBox(mText, mLBounds.text);
63 mFileSelector.Draw();
64 mHorizontalChoice.Draw();
65}
66
67template <typename ElementPtr>
69void ListDialogElement<ElementPtr>::HandleResizeEvent(const Recti& newRect)
70{
71 if (IsFinished() == true)
72 return;
73
74 mBounds = newRect;
75 mLBounds = CalculateLocalBounds<ElementPtr>(newRect);
76 mFileSelector.HandleResize(mLBounds.list);
77 mHorizontalChoice.HandleResizeEvent(mLBounds.confirm);
78}
79
80template <typename ElementPtr>
82void ListDialogElement<ElementPtr>::HandleRawInput(int rawInputChar)
83{
84 if (IsFinished() == true)
85 return;
86}
87
88template <typename ElementPtr>
90void ListDialogElement<ElementPtr>::InputUp()
91{
92 if (IsFinished() == true)
93 return;
94
95 mFileSelector.SelectUp();
96}
97
98template <typename ElementPtr>
100void ListDialogElement<ElementPtr>::InputDown()
101{
102 if (IsFinished() == true)
103 return;
104
105 mFileSelector.SelectDown();
106}
107
108template <typename ElementPtr>
110void ListDialogElement<ElementPtr>::InputLeft()
111{
112 if (IsFinished() == true)
113 return;
114}
115
116template <typename ElementPtr>
118void ListDialogElement<ElementPtr>::InputRight()
119{
120 if (IsFinished() == true)
121 return;
122
123 if (mType == Type::ReadOnly)
124 return;
125
126 if (mType == Type::OneChoice)
127 {
128 mFileSelector.ClearAllLastingSelections();
129 }
130
131 mFileSelector.LastingSelectOnCurrent();
132}
133
134template <typename ElementPtr>
136void ListDialogElement<ElementPtr>::InputEnter()
137{
138 if (IsFinished() == true)
139 return;
140
141 mHorizontalChoice.ConfirmCurrentChoice();
142 SetFinished(std::string{mHorizontalChoice.GetFinalChoice()});
143
144 auto selected = mFileSelector.GetSelected();
145 if (selected.has_value())
146 {
147 SetData(mFileSelector.GetSelected().value()->name);
148 }
149}
150
151template <typename ElementPtr>
153void ListDialogElement<ElementPtr>::InputTab()
154{
155 if (IsFinished() == true)
156 return;
157
158 mHorizontalChoice.SelectNext();
159}
void printwMsgBox(const std::string &msg, const Recti &availableSpace)
Definition Utility.cpp:106
void clearArea(const Recti &rect)
clearArea - clears specified rect, rect itself is not included, only area inside rectangle without bo...
Definition Utility.cpp:74
The DialogElement class - Abstract class. Visual element designed to process some user input in a dia...
Definition DialogElement.hpp:50
Definition ElementSelector.hpp:28
Definition ListDialogElement.hpp:33