Client Upload Part 2

RD Core / Commit #5

Commit Client Upload Part 2

Alex Alex committed 19/10/2026 00:06 main Patch
1,244 files +271,215 -0
A RD_Client/src/framework/ui/uimanager.h +99-0 View file
@@ -0,0 +1,99 @@
1+/*
2+ * Copyright (c) 2010-2017 OTClient <https://github.com/edubart/otclient>
3+ *
4+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5+ * of this software and associated documentation files (the "Software"), to deal
6+ * in the Software without restriction, including without limitation the rights
7+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+ * copies of the Software, and to permit persons to whom the Software is
9+ * furnished to do so, subject to the following conditions:
10+ *
11+ * The above copyright notice and this permission notice shall be included in
12+ * all copies or substantial portions of the Software.
13+ *
14+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+ * THE SOFTWARE.
21+ */
22+
23+#ifndef UIMANAGER_H
24+#define UIMANAGER_H
25+
26+#include "declarations.h"
27+#include "uiwidget.h"
28+#include <framework/core/inputevent.h>
29+#include <framework/otml/declarations.h>
30+
31+//@bindsingleton g_ui
32+class UIManager
33+{
34+public:
35+ void init();
36+ void terminate();
37+
38+ void render(Fw::DrawPane drawPane);
39+ void resize(const Size& size);
40+ void inputEvent(const InputEvent& event);
41+
42+ void updatePressedWidget(const Fw::MouseButton button, const UIWidgetPtr& newPressedWidget, const Point& clickedPos = Point(), bool fireClicks = true);
43+ bool updateDraggingWidget(const UIWidgetPtr& draggingWidget, const Point& clickedPos = Point());
44+ void updateHoveredWidget(bool now = false);
45+
46+ void clearStyles();
47+ bool importStyle(std::string file);
48+ bool importStyleFromString(std::string data);
49+ void importStyleFromOTML(const OTMLNodePtr& styleNode);
50+ OTMLNodePtr getStyle(const std::string& styleName);
51+ std::string getStyleClass(const std::string& styleName);
52+
53+ UIWidgetPtr loadUIFromString(const std::string& data, const UIWidgetPtr& parent);
54+ UIWidgetPtr loadUI(std::string file, const UIWidgetPtr& parent);
55+ UIWidgetPtr displayUI(const std::string& file) { return loadUI(file, m_rootWidget); }
56+ UIWidgetPtr createWidget(const std::string& styleName, const UIWidgetPtr& parent);
57+ UIWidgetPtr createWidgetFromOTML(const OTMLNodePtr& widgetNode, const UIWidgetPtr& parent);
58+
59+ void setMouseReceiver(const UIWidgetPtr& widget) { m_mouseReceiver = widget; }
60+ void setKeyboardReceiver(const UIWidgetPtr& widget) { m_keyboardReceiver = widget; }
61+ void setDebugBoxesDrawing(bool enabled) { m_drawDebugBoxes = enabled; }
62+ void resetMouseReceiver() { m_mouseReceiver = m_rootWidget; }
63+ void resetKeyboardReceiver() { m_keyboardReceiver = m_rootWidget; }
64+ UIWidgetPtr getMouseReceiver() { return m_mouseReceiver; }
65+ UIWidgetPtr getKeyboardReceiver() { return m_keyboardReceiver; }
66+ UIWidgetPtr getDraggingWidget() { return m_draggingWidget; }
67+ UIWidgetPtr getHoveredWidget() { return m_hoveredWidget; }
68+ UIWidgetPtr getPressedWidget() { return m_pressedWidget[Fw::MouseLeftButton]; }
69+ UIWidgetPtr getRootWidget() { return m_rootWidget; }
70+ bool isMouseGrabbed() { return m_mouseReceiver != m_rootWidget; }
71+ bool isKeyboardGrabbed() { return m_keyboardReceiver != m_rootWidget; }
72+
73+ bool isDrawingDebugBoxes() { return m_drawDebugBoxes; }
74+
75+protected:
76+ void onWidgetAppear(const UIWidgetPtr& widget);
77+ void onWidgetDisappear(const UIWidgetPtr& widget);
78+ void onWidgetDestroy(const UIWidgetPtr& widget);
79+
80+ friend class UIWidget;
81+
82+private:
83+ UIWidgetPtr m_rootWidget;
84+ UIWidgetPtr m_mouseReceiver;
85+ UIWidgetPtr m_keyboardReceiver;
86+ UIWidgetPtr m_draggingWidget;
87+ UIWidgetPtr m_hoveredWidget;
88+ UIWidgetPtr m_pressedWidget[Fw::MouseButtonLast + 1] = { nullptr };
89+ stdext::boolean<false> m_hoverUpdateScheduled;
90+ stdext::boolean<false> m_drawDebugBoxes;
91+ std::unordered_map<std::string, OTMLNodePtr> m_styles;
92+ UIWidgetList m_destroyedWidgets;
93+ ScheduledEventPtr m_checkEvent;
94+ stdext::timer m_moveTimer;
95+};
96+
97+extern UIManager g_ui;
98+
99+#endif
A RD_Client/src/framework/ui/uitextedit.h +155-0 View file
@@ -0,0 +1,155 @@
1+/*
2+ * Copyright (c) 2010-2017 OTClient <https://github.com/edubart/otclient>
3+ *
4+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5+ * of this software and associated documentation files (the "Software"), to deal
6+ * in the Software without restriction, including without limitation the rights
7+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+ * copies of the Software, and to permit persons to whom the Software is
9+ * furnished to do so, subject to the following conditions:
10+ *
11+ * The above copyright notice and this permission notice shall be included in
12+ * all copies or substantial portions of the Software.
13+ *
14+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+ * THE SOFTWARE.
21+ */
22+
23+#ifndef UITEXTEDIT_H
24+#define UITEXTEDIT_H
25+
26+#include "uiwidget.h"
27+
28+// @bindclass
29+class UITextEdit : public UIWidget
30+{
31+public:
32+ UITextEdit();
33+
34+ void drawSelf(Fw::DrawPane drawPane);
35+
36+private:
37+ void update(bool focusCursor = false);
38+
39+public:
40+ void setCursorPos(int pos);
41+ void setSelection(int start, int end);
42+ void setCursorVisible(bool enable) { m_cursorVisible = enable; }
43+ void setTextHidden(bool hidden);
44+ void setValidCharacters(const std::string validCharacters) { m_validCharacters = validCharacters; }
45+ void setShiftNavigation(bool enable) { m_shiftNavigation = enable; }
46+ void setMultiline(bool enable) { m_multiline = enable; }
47+ void setMaxLength(uint maxLength) { m_maxLength = maxLength; }
48+ void setTextVirtualOffset(const Point& offset);
49+ void setEditable(bool editable) { m_editable = editable; }
50+ void setSelectable(bool selectable) { m_selectable = selectable; }
51+ void setSelectionColor(const Color& color) { m_selectionColor = color; }
52+ void setSelectionBackgroundColor(const Color& color) { m_selectionBackgroundColor = color; }
53+ void setAutoScroll(bool autoScroll) { m_autoScroll = autoScroll; }
54+ void setAutoSubmit(bool autoSubmit) { m_autoSubmit = autoSubmit; }
55+
56+ void setPlaceholder(std::string placeholder) { m_placeholder = placeholder; }
57+ void setPlaceholderColor(const Color& color) { m_placeholderColor = color; }
58+ void setPlaceholderAlign(Fw::AlignmentFlag align) { m_placeholderAlign = align; }
59+ void setPlaceholderFont(const std::string& fontName);
60+
61+ void moveCursorHorizontally(bool right);
62+ void moveCursorVertically(bool up);
63+ void appendText(std::string text);
64+ void appendCharacter(char c);
65+ void removeCharacter(bool right);
66+ void blinkCursor();
67+
68+ void del(bool right = false);
69+ void paste(const std::string& text);
70+ std::string copy();
71+ std::string cut();
72+ void selectAll() { setSelection(0, m_text.length()); }
73+ void clearSelection() { setSelection(0, 0); }
74+
75+ void wrapText();
76+ std::string getDisplayedText();
77+ std::string getSelection();
78+ int getTextPos(Point pos);
79+ int getCursorPos() { return m_cursorPos; }
80+ Point getTextVirtualOffset() { return m_textVirtualOffset; }
81+ Size getTextVirtualSize() { return m_textVirtualSize; }
82+ Size getTextTotalSize() { return m_textTotalSize; }
83+ uint getMaxLength() { return m_maxLength; }
84+ int getSelectionStart() { return m_selectionStart; }
85+ int getSelectionEnd() { return m_selectionEnd; }
86+ Color getSelectionColor() { return m_selectionColor; }
87+ Color getSelectionBackgroundColor() { return m_selectionBackgroundColor; }
88+ bool hasSelection() { return m_selectionEnd - m_selectionStart > 0; }
89+ bool isCursorVisible() { return m_cursorVisible; }
90+ bool isTextHidden() { return m_textHidden; }
91+ bool isShiftNavigation() { return m_shiftNavigation; }
92+ bool isMultiline() { return m_multiline; }
93+ bool isEditable() { return m_editable; }
94+ bool isSelectable() { return m_selectable; }
95+ bool isAutoScrolling() { return m_autoScroll; }
96+
97+protected:
98+ void updateText();
99+
100+ virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
101+ virtual void onGeometryChange(const Rect& oldRect, const Rect& newRect);
102+ virtual void onFocusChange(bool focused, Fw::FocusReason reason);
103+ virtual bool onKeyText(const std::string& keyText);
104+ virtual bool onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeatTicks);
105+ virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button);
106+ virtual bool onMouseRelease(const Point& mousePos, Fw::MouseButton button);
107+ virtual bool onMouseMove(const Point& mousePos, const Point& mouseMoved);
108+ virtual bool onDoubleClick(const Point& mousePos);
109+ virtual void onTextAreaUpdate(const Point& vitualOffset, const Size& virtualSize, const Size& totalSize);
110+
111+private:
112+ void disableUpdates() { m_updatesEnabled = false; }
113+ void enableUpdates() { m_updatesEnabled = true; }
114+ void recacheGlyphs() { m_glyphsMustRecache = true; }
115+
116+ Rect m_drawArea;
117+ int m_cursorPos;
118+ Point m_textVirtualOffset;
119+ Size m_textVirtualSize;
120+ Size m_textTotalSize;
121+ ticks_t m_cursorTicks;
122+ bool m_textHidden;
123+ bool m_shiftNavigation;
124+ bool m_multiline;
125+ bool m_cursorInRange;
126+ bool m_cursorVisible;
127+ bool m_editable;
128+ std::string m_validCharacters;
129+ uint m_maxLength;
130+ bool m_updatesEnabled;
131+ bool m_autoScroll;
132+ bool m_autoSubmit;
133+
134+ bool m_selectable;
135+ int m_selectionReference;
136+ int m_selectionStart;
137+ int m_selectionEnd;
138+
139+ Color m_selectionColor;
140+ Color m_selectionBackgroundColor;
141+
142+ std::vector<Rect> m_glyphsCoords;
143+ std::vector<Rect> m_glyphsTexCoords;
144+
145+ CoordsBuffer m_glyphsTextCoordsBuffer;
146+ CoordsBuffer m_glyphsSelectCoordsBuffer;
147+ bool m_glyphsMustRecache;
148+
149+ std::string m_placeholder;
150+ Color m_placeholderColor;
151+ Fw::AlignmentFlag m_placeholderAlign;
152+ BitmapFontPtr m_placeholderFont;
153+};
154+
155+#endif
A RD_Client/src/framework/ui/uitranslator.cpp +115-0 View file
@@ -0,0 +1,115 @@
1+/*
2+ * Copyright (c) 2010-2017 OTClient <https://github.com/edubart/otclient>
3+ *
4+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5+ * of this software and associated documentation files (the "Software"), to deal
6+ * in the Software without restriction, including without limitation the rights
7+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+ * copies of the Software, and to permit persons to whom the Software is
9+ * furnished to do so, subject to the following conditions:
10+ *
11+ * The above copyright notice and this permission notice shall be included in
12+ * all copies or substantial portions of the Software.
13+ *
14+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+ * THE SOFTWARE.
21+ */
22+
23+#include "uitranslator.h"
24+#include <framework/stdext/string.h>
25+#include <boost/algorithm/string.hpp>
26+
27+Fw::AlignmentFlag Fw::translateAlignment(std::string aligment)
28+{
29+ boost::to_lower(aligment);
30+ boost::erase_all(aligment, " ");
31+ if(aligment == "topleft")
32+ return Fw::AlignTopLeft;
33+ else if(aligment == "topright")
34+ return Fw::AlignTopRight;
35+ else if(aligment == "bottomleft")
36+ return Fw::AlignBottomLeft;
37+ else if(aligment == "bottomright")
38+ return Fw::AlignBottomRight;
39+ else if(aligment == "left")
40+ return Fw::AlignLeftCenter;
41+ else if(aligment == "right")
42+ return Fw::AlignRightCenter;
43+ else if(aligment == "top")
44+ return Fw::AlignTopCenter;
45+ else if(aligment == "bottom")
46+ return Fw::AlignBottomCenter;
47+ else if(aligment == "center")
48+ return Fw::AlignCenter;
49+ return Fw::AlignNone;
50+}
51+
52+Fw::AnchorEdge Fw::translateAnchorEdge(std::string anchorEdge)
53+{
54+ boost::to_lower(anchorEdge);
55+ boost::erase_all(anchorEdge, " ");
56+ if(anchorEdge == "left")
57+ return Fw::AnchorLeft;
58+ else if(anchorEdge == "right")
59+ return Fw::AnchorRight;
60+ else if(anchorEdge == "top")
61+ return Fw::AnchorTop;
62+ else if(anchorEdge == "bottom")
63+ return Fw::AnchorBottom;
64+ else if(anchorEdge == "horizontalcenter")
65+ return Fw::AnchorHorizontalCenter;
66+ else if(anchorEdge == "verticalcenter")
67+ return Fw::AnchorVerticalCenter;
68+ return Fw::AnchorNone;
69+}
70+
71+Fw::WidgetState Fw::translateState(std::string state)
72+{
73+ boost::to_lower(state);
74+ boost::trim(state);
75+ if(state == "active")
76+ return Fw::ActiveState;
77+ else if(state == "focus")
78+ return Fw::FocusState;
79+ else if(state == "hover")
80+ return Fw::HoverState;
81+ else if(state == "pressed")
82+ return Fw::PressedState;
83+ else if(state == "checked")
84+ return Fw::CheckedState;
85+ else if(state == "disabled")
86+ return Fw::DisabledState;
87+ else if(state == "on")
88+ return Fw::OnState;
89+ else if(state == "first")
90+ return Fw::FirstState;
91+ else if(state == "middle")
92+ return Fw::MiddleState;
93+ else if(state == "last")
94+ return Fw::LastState;
95+ else if(state == "alternate")
96+ return Fw::AlternateState;
97+ else if(state == "dragging")
98+ return Fw::DraggingState;
99+ else if (state == "hidden")
100+ return Fw::HiddenState;
101+ else if (state == "mobile")
102+ return Fw::MobileState;
103+ return Fw::InvalidState;
104+}
105+
106+Fw::AutoFocusPolicy Fw::translateAutoFocusPolicy(std::string policy)
107+{
108+ boost::to_lower(policy);
109+ boost::trim(policy);
110+ if(policy == "first")
111+ return Fw::AutoFocusFirst;
112+ else if(policy == "last")
113+ return Fw::AutoFocusLast;
114+ return Fw::AutoFocusNone;
115+}
A RD_Client/src/framework/ui/uitranslator.h +38-0 View file
@@ -0,0 +1,38 @@
1+/*
2+ * Copyright (c) 2010-2017 OTClient <https://github.com/edubart/otclient>
3+ *
4+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5+ * of this software and associated documentation files (the "Software"), to deal
6+ * in the Software without restriction, including without limitation the rights
7+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+ * copies of the Software, and to permit persons to whom the Software is
9+ * furnished to do so, subject to the following conditions:
10+ *
11+ * The above copyright notice and this permission notice shall be included in
12+ * all copies or substantial portions of the Software.
13+ *
14+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+ * THE SOFTWARE.
21+ */
22+
23+#ifndef TRANSLATOR_H
24+#define TRANSLATOR_H
25+
26+#include "../const.h"
27+#include <string>
28+
29+namespace Fw {
30+
31+AlignmentFlag translateAlignment(std::string aligment);
32+AnchorEdge translateAnchorEdge(std::string anchorEdge);
33+WidgetState translateState(std::string state);
34+AutoFocusPolicy translateAutoFocusPolicy(std::string policy);
35+
36+};
37+
38+#endif
A RD_Client/src/framework/ui/uiverticallayout.cpp +102-0 View file
@@ -0,0 +1,102 @@
1+/*
2+ * Copyright (c) 2010-2017 OTClient <https://github.com/edubart/otclient>
3+ *
4+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5+ * of this software and associated documentation files (the "Software"), to deal
6+ * in the Software without restriction, including without limitation the rights
7+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+ * copies of the Software, and to permit persons to whom the Software is
9+ * furnished to do so, subject to the following conditions:
10+ *
11+ * The above copyright notice and this permission notice shall be included in
12+ * all copies or substantial portions of the Software.
13+ *
14+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+ * THE SOFTWARE.
21+ */
22+
23+#include "uiverticallayout.h"
24+#include "uiwidget.h"
25+#include <framework/core/eventdispatcher.h>
26+
27+void UIVerticalLayout::applyStyle(const OTMLNodePtr& styleNode)
28+{
29+ UIBoxLayout::applyStyle(styleNode);
30+
31+ for(const OTMLNodePtr& node : styleNode->children()) {
32+ if(node->tag() == "align-bottom")
33+ setAlignBottom(node->value<bool>());
34+ }
35+}
36+
37+bool UIVerticalLayout::internalUpdate()
38+{
39+ bool changed = false;
40+
41+ UIWidgetPtr parentWidget = getParentWidget();
42+ if(!parentWidget)
43+ return false;
44+
45+ UIWidgetList widgets = parentWidget->getChildren();
46+
47+ if(m_alignBottom)
48+ std::reverse(widgets.begin(), widgets.end());
49+
50+ Rect paddingRect = parentWidget->getPaddingRect();
51+ Point pos = (m_alignBottom) ? paddingRect .bottomLeft() : paddingRect.topLeft();
52+ int preferredHeight = 0;
53+ int gap;
54+
55+ for(const UIWidgetPtr& widget : widgets) {
56+ if(!widget->isExplicitlyVisible())
57+ continue;
58+
59+ Size size = widget->getSize();
60+
61+ gap = (m_alignBottom) ? -(widget->getMarginBottom()+widget->getHeight()) : widget->getMarginTop();
62+ pos.y += gap;
63+ preferredHeight += gap;
64+
65+ if(widget->isFixedSize()) {
66+ // center it
67+ if(widget->getTextAlign() & Fw::AlignLeft) {
68+ pos.x = paddingRect.left() + widget->getMarginLeft();
69+ } else if(widget->getTextAlign() & Fw::AlignLeft) {
70+ pos.x = paddingRect.bottom() - widget->getHeight() - widget->getMarginBottom();
71+ pos.x = std::max<int>(pos.x, paddingRect.left());
72+ } else {
73+ pos.x = paddingRect.left() + (paddingRect.width() - (widget->getMarginLeft() + widget->getWidth() + widget->getMarginRight()))/2;
74+ pos.x = std::max<int>(pos.x, paddingRect.left());
75+ }
76+ } else {
77+ // expand width
78+ size.setWidth(paddingRect.width() - (widget->getMarginLeft() + widget->getMarginRight()));
79+ pos.x = paddingRect.left() + (paddingRect.width() - size.width())/2;
80+ }
81+
82+ if(widget->setRect(Rect(pos - parentWidget->getVirtualOffset(), size)))
83+ changed = true;
84+
85+ gap = (m_alignBottom) ? -widget->getMarginTop() : (widget->getHeight() + widget->getMarginBottom());
86+ gap += m_spacing;
87+ pos.y += gap;
88+ preferredHeight += gap;
89+ }
90+
91+ preferredHeight -= m_spacing;
92+ preferredHeight += parentWidget->getPaddingTop() + parentWidget->getPaddingBottom();
93+
94+ if(m_fitChildren && preferredHeight != parentWidget->getHeight()) {
95+ // must set the preferred width later
96+ g_dispatcher.addEvent([=] {
97+ parentWidget->setHeight(preferredHeight);
98+ });
99+ }
100+
101+ return changed;
102+}
A RD_Client/src/framework/ui/uiverticallayout.h +47-0 View file
@@ -0,0 +1,47 @@
1+/*
2+ * Copyright (c) 2010-2017 OTClient <https://github.com/edubart/otclient>
3+ *
4+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5+ * of this software and associated documentation files (the "Software"), to deal
6+ * in the Software without restriction, including without limitation the rights
7+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+ * copies of the Software, and to permit persons to whom the Software is
9+ * furnished to do so, subject to the following conditions:
10+ *
11+ * The above copyright notice and this permission notice shall be included in
12+ * all copies or substantial portions of the Software.
13+ *
14+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+ * THE SOFTWARE.
21+ */
22+
23+#ifndef UIVERTICALLAYOUT_H
24+#define UIVERTICALLAYOUT_H
25+
26+#include "uiboxlayout.h"
27+
28+// @bindclass
29+class UIVerticalLayout : public UIBoxLayout
30+{
31+public:
32+ UIVerticalLayout(UIWidgetPtr parentWidget) : UIBoxLayout(parentWidget) { }
33+
34+ void applyStyle(const OTMLNodePtr& styleNode);
35+
36+ void setAlignBottom(bool aliginBottom) { m_alignBottom = aliginBottom; update(); }
37+ bool isAlignBottom() { return m_alignBottom; }
38+
39+ bool isUIVerticalLayout() { return true; }
40+
41+protected:
42+ bool internalUpdate();
43+
44+ stdext::boolean<false> m_alignBottom;
45+};
46+
47+#endif
Top