Jelajahi Sumber

Tooltip clean up

rsredsq 10 tahun lalu
induk
melakukan
57792031fb

+ 13 - 5
Source/Atomic/UI/UI.cpp

@@ -540,16 +540,16 @@ void UI::HandleUpdate(StringHash eventType, VariantMap& eventData)
         return;
     }
     
-    mouseStayedTime += eventData[Update::P_TIMESTEP].GetFloat();
+    tooltipHoverTime_ += eventData[Update::P_TIMESTEP].GetFloat();
 
-    if (mouseStayedTime >= 0.5f)
+    if (tooltipHoverTime_ >= 0.5f)
     {
         UIWidget* hoveredWidget = GetHoveredWidget();
-        if (hoveredWidget && !tooltip_ && (hoveredWidget->GetShorten() || hoveredWidget->GetTooltip().Length() > 0))
+        if (hoveredWidget && !tooltip_ && (hoveredWidget->GetShortened() || hoveredWidget->GetTooltip().Length() > 0))
         {
-            tooltip_ = new UIPopupWindow(context_, hoveredWidget, "tooltip");
+            tooltip_ = new UIPopupWindow(context_, true, hoveredWidget, "tooltip");
             UILayout* tooltipLayout = new UILayout(context_, UI_AXIS_Y, true);
-            if (hoveredWidget->GetShorten())
+            if (hoveredWidget->GetShortened())
             {
                 UIEditField* fullTextField = new UIEditField(context_, true);
                 fullTextField->SetAdaptToContentSize(true);
@@ -645,6 +645,14 @@ UIWidget* UI::WrapWidget(tb::TBWidget* widget)
 
     // this is order dependent as we're using IsOfType which also works if a base class
 
+    if (widget->IsOfType<TBPopupWindow>())
+    {
+        UIPopupWindow* popupWindow = new UIPopupWindow(context_, false);
+        popupWindow->SetWidget(widget);
+        widgetWrap_[widget] = popupWindow;
+        return popupWindow;
+    }
+
     if (widget->IsOfType<TBDimmer>())
     {
         UIDimmer* dimmer = new UIDimmer(context_, false);

+ 1 - 1
Source/Atomic/UI/UI.h

@@ -158,7 +158,7 @@ private:
     bool consoleVisible_;
     bool exitRequested_;
     
-    float mouseStayedTime;
+    float tooltipHoverTime_;
 
     // Events
     void HandleScreenMode(StringHash eventType, VariantMap& eventData);

+ 1 - 1
Source/Atomic/UI/UIInput.cpp

@@ -139,7 +139,7 @@ void UI::HandleMouseMove(StringHash eventType, VariantMap& eventData)
 
     rootWidget_->InvokePointerMove(px, py, tb::TB_MODIFIER_NONE, false);
 
-    mouseStayedTime = 0;
+    tooltipHoverTime_ = 0;
 }
 
 

+ 27 - 22
Source/Atomic/UI/UIPopupWindow.cpp

@@ -33,41 +33,46 @@ using namespace tb;
 namespace Atomic
 {
 
-    UIPopupWindow::UIPopupWindow(Context* context, UIWidget* target, const String& id) : UIWidget(context, false)
+UIPopupWindow::UIPopupWindow(Context* context, bool createWidget, UIWidget* target, const String& id) : UIWidget(context, false)
+{
+    if (createWidget)
     {
+        //if we should create widget, then target shouldn't be null
+        assert(target);
         widget_ = new TBPopupWindow(target->GetInternalWidget());
         widget_->SetID(TBIDC(id.CString()));
         widget_->SetDelegate(this);
         GetSubsystem<UI>()->WrapWidget(this, widget_);
     }
+}
 
-    UIPopupWindow::~UIPopupWindow()
-    {
-    }
+UIPopupWindow::~UIPopupWindow()
+{
+}
 
-    void UIPopupWindow::Show(int x, int y)
+void UIPopupWindow::Show(int x, int y)
+{
+    if (x != -1 && y != -1)
     {
-        if (x != -1 && y != -1)
-        {
-            ((TBPopupWindow*)widget_)->Show(TBPopupAlignment(TBPoint(x, y)));
-        }
-        else
-        {
-            ((TBPopupWindow*)widget_)->Show(TBPopupAlignment());
-        }
+        ((TBPopupWindow*)widget_)->Show(TBPopupAlignment(TBPoint(x, y)));
     }
-
-    bool UIPopupWindow::OnEvent(const tb::TBWidgetEvent &ev)
+    else
     {
-        return false;
+        ((TBPopupWindow*)widget_)->Show(TBPopupAlignment());
     }
+}
 
-    void UIPopupWindow::Close()
-    {
-        if (!widget_)
-            return;
+bool UIPopupWindow::OnEvent(const tb::TBWidgetEvent &ev)
+{
+    return false;
+}
 
-        ((TBPopupWindow*)widget_)->Close();
-    }
+void UIPopupWindow::Close()
+{
+    if (!widget_)
+        return;
+
+    ((TBPopupWindow*)widget_)->Close();
+}
 
 }

+ 2 - 2
Source/Atomic/UI/UIPopupWindow.h

@@ -31,9 +31,9 @@ class UIPopupWindow: public UIWidget
 {
     OBJECT(UIPopupWindow)
 
-    public:
+public:
 
-    UIPopupWindow(Context* context, UIWidget* target, const String& id = String::EMPTY);
+    UIPopupWindow(Context* context, bool createWidget, UIWidget* target = nullptr, const String& id = String::EMPTY);
     virtual ~UIPopupWindow();
 
     void Show(int x = -1, int y = -1);

+ 4 - 4
Source/Atomic/UI/UIWidget.cpp

@@ -825,20 +825,20 @@ void UIWidget::InvokeShortcut(const String& shortcut)
     widget_->OnEvent(ev);
 }
 
-bool UIWidget::GetShorten()
+bool UIWidget::GetShortened()
 {
     if (!widget_)
         return false;
 
-    return widget_->GetShorten();
+    return widget_->GetShortened();
 }
 
-void UIWidget::SetShorten(bool shorten)
+void UIWidget::GetShortened(bool shortened)
 {
     if (!widget_)
         return;
 
-    widget_->SetShorten(shorten);
+    widget_->SetShortened(shortened);
 }
 
 String UIWidget::GetTooltip()

+ 2 - 2
Source/Atomic/UI/UIWidget.h

@@ -262,9 +262,9 @@ class UIWidget : public Object, public tb::TBWidgetDelegate
 
     void InvokeShortcut(const String& shortcut);
 
-    bool GetShorten();
+    bool GetShortened();
 
-    void SetShorten(bool shorten);
+    void GetShortened(bool shortened);
 
     String GetTooltip();
 

+ 1 - 0
Source/AtomicJS/Javascript/JSUI.cpp

@@ -82,6 +82,7 @@ JSUI::JSUI(Context* context) : Object(context),
     uiTypes_["UISeparator"] = true;
     uiTypes_["UIDimmer"] = true;
     uiTypes_["UISelectDropdown"] = true;
+    uiTypes_["UIPopupWindow"] = true;
 
 }
 

+ 1 - 1
Source/ThirdParty/TurboBadger/tb_widgets.cpp

@@ -75,7 +75,7 @@ TBWidget::TBWidget()
 	, m_packed_init(0)
     , needCapturing_(true)
     , captured_(false)
-    , shorten_(false)
+    , shortened_(false)
 {
 #ifdef TB_RUNTIME_DEBUG_INFO
 	last_measure_time = 0;

+ 3 - 3
Source/ThirdParty/TurboBadger/tb_widgets.h

@@ -999,9 +999,9 @@ public:
 
     TBWidget *GetWidgetByTouchId(unsigned touchId);
 
-    bool GetShorten() { return shorten_; }
+    bool GetShortened() { return shortened_; }
 
-    void SetShorten(bool shorten) { shorten_ = shorten; }
+    void SetShortened(bool shortened) { shortened_ = shortened; }
 
     TBStr GetTooltip() { TBStr str; str.Set(tooltip_); return str; }
 
@@ -1032,7 +1032,7 @@ private:
     bool needCapturing_; //if ours widget need capturing
     bool captured_; //if ours widget is currently captured
     unsigned touchId_;
-    bool shorten_;
+    bool shortened_;
     TBStr tooltip_;
 	union {
 		struct {

+ 2 - 2
Source/ThirdParty/TurboBadger/tb_widgets_common.cpp

@@ -43,7 +43,7 @@ void TBWidgetString::Paint(TBWidget *widget, const TBRect &rect, const TBColor &
 
     if (string_w <= rect.w)
     {
-        widget->SetShorten(false);
+        widget->SetShortened(false);
 		font->DrawString(x, y, color, m_text);
     }
 	else
@@ -55,7 +55,7 @@ void TBWidgetString::Paint(TBWidget *widget, const TBRect &rect, const TBColor &
 		// Some fonts seem to render ellipsis a lot uglier than three dots.
 		const char *end = "...";
 
-        widget->SetShorten(true);
+        widget->SetShortened(true);
 
 		int endw = font->GetStringWidth(end);
 		int startw = 0;