12 [
Attribute(
"1",
UIWidgets.CheckBox,
"When true and scroll input is detected, the component will try to find a new focused widget, or will reset focused widget to null if no suitable widget found")]
33#ifdef GAMEPAD_SCROLL_DEBUG
35 protected ref array<Widget> m_aDebugMarksPool;
36 protected ref array<Widget> m_aDebugMarksBusy;
46 super.HandlerAttached(w);
53 #ifdef GAMEPAD_SCROLL_DEBUG
54 m_aDebugMarksPool = {};
55 m_aDebugMarksBusy = {};
96 float tDelta = ftime / 1000.0;
104#ifdef GAMEPAD_SCROLL_DEBUG
105 DebugMarks_StartUpdate();
113 PlaceDebugMark(refPoint,
"-");
125 if (scrollContentRect.GetHeight() <= scrollRect.GetHeight())
133 if (vScrollInput != 0)
140#ifdef GAMEPAD_SCROLL_DEBUG
141 PlaceDebugMark(
"200 40 0",
string.Format(
"V Scroll Input: notNull: %1, value: %2", vScrollInput != 0, vScrollInput));
142 PlaceDebugMark(
"800 40 0",
string.Format(
"Current focus: %1",
GetGame().GetWorkspace().GetFocusedWidget()));
143 DebugMarks_EndUpdate();
148 if (scrollContentRect.GetWidth() <= scrollRect.GetWidth())
156 if (hScrollInput != 0)
163#ifdef GAMEPAD_SCROLL_DEBUG
164 PlaceDebugMark(
"200 40 0",
string.Format(
"H Scroll Input: notNull: %1, value: %2", hScrollInput != 0, hScrollInput));
165 PlaceDebugMark(
"800 40 0",
string.Format(
"Current focus: %1",
GetGame().GetWorkspace().GetFocusedWidget()));
166 DebugMarks_EndUpdate();
174 Widget scrollContent = wScroll.GetChildren();
179 float xScrollSize, yScrollSize;
180 wScroll.GetScreenSize(xScrollSize, yScrollSize);
182 float xContentSize, yContentSize;
183 scrollContent.GetScreenSize(xContentSize, yContentSize);
185 if (yContentSize <= yScrollSize || yContentSize == 0)
192 float xPosAbsCurrent, yPosAbsCurrent;
193 wScroll.GetSliderPosPixels(xPosAbsCurrent, yPosAbsCurrent);
197 wScroll.SetSliderPosPixels(0, yPosAbsNew);
203 Widget scrollContent = wScroll.GetChildren();
208 float xScrollSize, yScrollSize;
209 wScroll.GetScreenSize(xScrollSize, yScrollSize);
211 float xContentSize, yContentSize;
212 scrollContent.GetScreenSize(xContentSize, yContentSize);
214 if (xContentSize <= xScrollSize || xContentSize == 0)
221 float xPosAbsCurrent, yPosAbsCurrent;
222 wScroll.GetSliderPosPixels(xPosAbsCurrent, yPosAbsCurrent);
226 wScroll.SetSliderPosPixels(xPosAbsNew, 0);
232 return GetGame().GetInputManager().GetActionValue(
"MenuScrollHorizontal");
238 return GetGame().GetInputManager().GetActionValue(
"MenuScrollVertical");
244 float value =
GetGame().GetInputManager().GetActionValue(
"MouseWheel");
261 Widget currentFocus =
GetGame().GetWorkspace().GetFocusedWidget();
269 if (!scrollRect.HasInside(focusedWidgetRect))
270 GetGame().GetWorkspace().SetFocusedWidget(null);
284 array<Widget> allButtons = {};
288 array<Widget> widgetsInFrame = {};
289 foreach (
Widget w : allButtons)
292 if (scrollRect.HasInside(wRect))
293 widgetsInFrame.Insert(w);
296 if (widgetsInFrame.IsEmpty())
310 newFocus = widgetsInFrame[0];
312 foreach (
Widget w : widgetsInFrame)
316#ifdef GAMEPAD_SCROLL_DEBUG
318 vector wRectCenter = wRect.GetCenter();
319 PlaceDebugMark(wRectCenter,
string.Format(
"%1", m));
329 GetGame().GetWorkspace().SetFocusedWidget(newFocus);
336 float sliderX, sliderY;
337 wScroll.GetSliderPos(sliderX, sliderY);
340 refPoint[0] = scrollRect.p0[0];
341 refPoint[1] = scrollRect.p0[1] + sliderY * scrollRect.GetHeight();
346 Widget focusedWidget =
GetGame().GetWorkspace().GetFocusedWidget();
347 float xPos, yPos, width, height;
348 focusedWidget.GetScreenPos(xPos, yPos);
349 focusedWidget.GetScreenSize(width, height);
352 refPoint[0] = width * 0.5 + xPos - 1;
362 float sliderX, sliderY;
363 wScroll.GetSliderPos(sliderX, sliderY);
366 refPoint[0] = scrollRect.p0[0] + sliderX * scrollRect.GetWidth();
367 refPoint[1] = scrollRect.p0[1];
372 Widget focusedWidget =
GetGame().GetWorkspace().GetFocusedWidget();
373 float xPos, yPos, width, height;
374 focusedWidget.GetScreenPos(xPos, yPos);
375 focusedWidget.GetScreenSize(width, height);
378 refPoint[1] = height * 0.5 + yPos - 1;
389 vector wRectPoint = wRect.p0;
390 wRectPoint[1] = 0.5 * (wRect.p0[1] + wRect.p1[1]);
394 float dx = v0[0] - v1[0];
395 float dy = v0[1] - v1[1];
397 return 100 *
Math.AbsFloat(dy) +
Math.AbsFloat(dx);
410 w.GetScreenPos(posX, posY);
411 w.GetScreenSize(sizeX, sizeY);
429 if (wb.IsFocusable())
433 Widget child = w.GetChildren();
437 child = child.GetSibling();
479#ifdef GAMEPAD_SCROLL_DEBUG
482 protected void DebugMarks_StartUpdate()
485 foreach (
Widget w : m_aDebugMarksBusy)
487 m_aDebugMarksPool.Insert(w);
490 m_aDebugMarksBusy.Clear();
496 protected void PlaceDebugMark(vector pos,
string text)
498 WorkspaceWidget workspace =
GetGame().GetWorkspace();
501 if (!m_aDebugMarksPool.IsEmpty())
503 w = m_aDebugMarksPool[0];
504 m_aDebugMarksPool.Remove(0);
508 Widget workspaceRoot =
GetGame().GetWorkspace();
509 w = workspace.CreateWidgets(
"{79FC19F28E381C1E}UI/layouts/Menus/DebugTextMark.layout", workspaceRoot);
512 m_aDebugMarksBusy.Insert(w);
514 TextWidget wtext = TextWidget.Cast(w.FindWidget(
"Text"));
517 FrameSlot.SetPos(w, workspace.DPIUnscale(pos[0]), workspace.DPIUnscale(pos[1]));
521 protected void DebugMarks_EndUpdate()
524 foreach (Widget w : m_aDebugMarksPool)
ArmaReforgerScripted GetGame()
SCR_Rect2D ExpandAllDirections(float delta)
This rect will be expanded in all directions by given value.
SCR_FieldOfViewSettings Attribute