Skip to content

Commit e00139d

Browse files
committed
Add more rendering options to ui container and a active check for visitors.
1 parent 039ed01 commit e00139d

File tree

2 files changed

+78
-13
lines changed

2 files changed

+78
-13
lines changed

packages/rendering/include/rendering/ui/UIContainer.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ namespace l::ui {
162162

163163
class UIVisitor {
164164
public:
165+
virtual bool Active(const InputState&) {
166+
return true;
167+
}
165168
virtual bool Visit(UIContainer&, const InputState&, const ContainerArea&) {
166169
return false;
167170
}
@@ -213,6 +216,14 @@ namespace l::ui {
213216
float GetScale();
214217
void DebugLog();
215218

219+
const UIRenderData& GetRenderData() const {
220+
return mArea.mRender;
221+
}
222+
223+
const UILayoutData& GetLayoutData() const {
224+
return mArea.mLayout;
225+
}
226+
216227
friend UIVisitor;
217228
protected:
218229
std::string mName;
@@ -225,11 +236,13 @@ namespace l::ui {
225236

226237
class UIZoom : public UIVisitor {
227238
public:
239+
virtual bool Active(const InputState& input);
228240
virtual bool Visit(UIContainer& container, const InputState& input, const ContainerArea& parent);
229241
};
230242

231243
class UIDrag : public UIVisitor {
232244
public:
245+
virtual bool Active(const InputState& input);
233246
virtual bool Visit(UIContainer& container, const InputState& input, const ContainerArea& parent);
234247
protected:
235248
bool mDragging = false;
@@ -238,6 +251,7 @@ namespace l::ui {
238251

239252
class UIMove : public UIVisitor {
240253
public:
254+
virtual bool Active(const InputState& input);
241255
virtual bool Visit(UIContainer& container, const InputState& input, const ContainerArea& parent);
242256
protected:
243257
bool mMoving = false;

packages/rendering/source/common/ui/UIContainer.cpp

Lines changed: 64 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ namespace l::ui {
3737

3838
bool UIContainer::Accept(UIVisitor& visitor, const InputState& input, uint32_t flags) {
3939
ContainerArea current;
40-
return Accept(visitor, input, current, flags);
40+
if (visitor.Active(input)) {
41+
return Accept(visitor, input, current, flags);
42+
}
43+
return false;
4144
}
4245

4346
bool UIContainer::Accept(UIVisitor& visitor, const InputState& input, const ContainerArea& parent, uint32_t flags) {
@@ -159,6 +162,9 @@ namespace l::ui {
159162
}
160163

161164

165+
bool UIZoom::Active(const InputState& input) {
166+
return input.mScroll != 0;
167+
}
162168

163169
bool UIZoom::Visit(UIContainer& container, const InputState& input, const ContainerArea& parent) {
164170
if (input.mScroll != 0.0f) {
@@ -184,6 +190,10 @@ namespace l::ui {
184190
return false;
185191
}
186192

193+
bool UIDrag::Active(const InputState& input) {
194+
return input.mStarted && !mDragging || mDragging;
195+
}
196+
187197
bool UIDrag::Visit(UIContainer& container, const InputState& input, const ContainerArea& parent) {
188198
if (input.mStarted && !mDragging) {
189199
if (input.GetLocalPos().x >= 0.0f && input.GetLocalPos().y >= 0.0f) {
@@ -205,6 +215,10 @@ namespace l::ui {
205215
return false;
206216
}
207217

218+
bool UIMove::Active(const InputState& input) {
219+
return input.mStarted && !mMoving || mMoving;
220+
}
221+
208222
bool UIMove::Visit(UIContainer& container, const InputState& input, const ContainerArea& parent) {
209223
if (input.mStarted && !mMoving) {
210224
if (Overlap(input.GetLocalPos(), container.GetPosition(), container.GetPositionAtSize(), parent)) {
@@ -270,25 +284,62 @@ namespace l::ui {
270284
container.DebugLog();
271285
}
272286

287+
ImU32 color = container.GetRenderData().mColor;
273288
ImVec2 pTopLeft = container.GetPosition();
289+
ImVec2 pCenter = container.GetPositionAtCenter();
274290
ImVec2 pLowRight = container.GetPositionAtSize();
275-
291+
ImVec2 pSize = container.GetSize();
276292
ImVec2 p1 = parent.Transform(pTopLeft, input.mRootPos);
293+
ImVec2 p12 = parent.Transform(pCenter, input.mRootPos);
277294
ImVec2 p2 = parent.Transform(pLowRight, input.mRootPos);
278295

279-
ImVec4 colf = ImVec4(1.0f, 0.4f, 0.4f, 1.0f);
280-
const ImU32 col = ImColor(colf);
281-
282-
mDrawList->AddRect(p1, p2, col, 2.0f, ImDrawFlags_RoundCornersAll, 2.0f);
296+
switch (container.GetRenderData().mType) {
297+
case l::ui::UIRenderType::Rect:
298+
mDrawList->AddRect(p1, p2, color, 2.0f, ImDrawFlags_RoundCornersAll, 2.0f);
299+
break;
300+
case l::ui::UIRenderType::RectFilled:
301+
mDrawList->AddRectFilled(p1, p2, color, 2.0f, ImDrawFlags_RoundCornersAll);
302+
break;
303+
case l::ui::UIRenderType::Triangle:
304+
break;
305+
case l::ui::UIRenderType::TriangleFilled:
306+
break;
307+
case l::ui::UIRenderType::Circle:
308+
mDrawList->AddCircle(p1, pSize.x, color, 15, 2.0f);
309+
break;
310+
case l::ui::UIRenderType::CircleFilled:
311+
mDrawList->AddCircleFilled(p1, pSize.x, color, 15);
312+
break;
313+
case l::ui::UIRenderType::Polygon:
314+
break;
315+
case l::ui::UIRenderType::PolygonFilled:
316+
break;
317+
case l::ui::UIRenderType::Spline:
318+
break;
319+
case l::ui::UIRenderType::Text:
320+
break;
321+
case l::ui::UIRenderType::Texture:
322+
break;
323+
}
283324

284-
if (container.HasConfigFlag(ui::UIContainer_ResizeFlag)) {
285-
ImVec2 p3 = parent.Transform(pLowRight, ImVec2(input.mRootPos.x - 3.0f, input.mRootPos.y - 3.0f));
286-
ImVec2 p4 = parent.Transform(pLowRight, ImVec2(input.mRootPos.x + 3.0f, input.mRootPos.y + 3.0f));
287-
if (container.HasNotification(ui::UIContainer_ResizeFlag)) {
288-
p3 = parent.Transform(pLowRight, ImVec2(input.mRootPos.x - 5.0f, input.mRootPos.y - 5.0f));
289-
p4 = parent.Transform(pLowRight, ImVec2(input.mRootPos.x + 5.0f, input.mRootPos.y + 5.0f));
325+
switch (container.GetRenderData().mType) {
326+
case l::ui::UIRenderType::Rect:
327+
case l::ui::UIRenderType::RectFilled:
328+
case l::ui::UIRenderType::Texture:
329+
mDrawList->AddRect(p1, p2, color, 2.0f, ImDrawFlags_RoundCornersAll, 2.0f);
330+
331+
if (container.HasConfigFlag(ui::UIContainer_ResizeFlag)) {
332+
ImVec2 p3 = parent.Transform(pLowRight, ImVec2(input.mRootPos.x - 3.0f, input.mRootPos.y - 3.0f));
333+
ImVec2 p4 = parent.Transform(pLowRight, ImVec2(input.mRootPos.x + 3.0f, input.mRootPos.y + 3.0f));
334+
if (container.HasNotification(ui::UIContainer_ResizeFlag)) {
335+
p3 = parent.Transform(pLowRight, ImVec2(input.mRootPos.x - 5.0f, input.mRootPos.y - 5.0f));
336+
p4 = parent.Transform(pLowRight, ImVec2(input.mRootPos.x + 5.0f, input.mRootPos.y + 5.0f));
337+
}
338+
mDrawList->AddRectFilled(p3, p4, color);
290339
}
291-
mDrawList->AddRectFilled(p3, p4, col);
340+
break;
341+
default:
342+
break;
292343
}
293344

294345
return false;

0 commit comments

Comments
 (0)