Tizen Construct() Button 方法失败

Tizen Construct() Button method fails

本文关键字:方法 失败 Button Construct Tizen      更新时间:2023-10-16

谁能帮助解决Tizen按钮构造问题?

在按钮和应用程序的 Construct() 调用崩溃后,我收到以下日志消息。但是在这种情况下,Construct() 返回E_SUCCESS:

result Tizen::Graphics::_Text::TextObject::SetBounds(const Tizen::Graphics::FloatRectangle&)(1134) > [E_OUT_OF_RANGE] The given rectangle(width:-4.000000,height:12.000000) is out of range.

在下面的代码中:

MainSimpleButton::MainSimpleButton()
{
    result res = Construct(FloatRectangle(50, 50, 20, 20), String("Default button"));
    if (res != E_SUCCESS)
    {
        throw Exception("Failed Construct() button");
    }
}

以下是详细信息。我已经自定义了按钮类:

#ifndef MAINBUTTON_H_
#define MAINBUTTON_H_
#include <FApp.h>
#include <FUi.h>
#include <FGraphics.h>
class MainSimpleButton : public Tizen::Ui::Controls::Button {
public:
    MainSimpleButton(); // <------- This constructor is used
    MainSimpleButton(const Tizen::Graphics::Rectangle &rect, const Tizen::Base::String &text);
    MainSimpleButton(const Tizen::Graphics::FloatRectangle &rect, const Tizen::Base::String &text);
    virtual ~MainSimpleButton();
};
#endif /* MAINBUTTON_H_ */

通过以下简单实现:

MainSimpleButton::MainSimpleButton()
{
    result res = Construct(FloatRectangle(50, 50, 20, 20), String("Default button"));
    if (res != E_SUCCESS)
    {
        throw Exception("Failed Construct() button");
    }
}
MainSimpleButton::MainSimpleButton(const Rectangle &rect, const String &text)
{ // Similar to MainSimpleButton }
MainSimpleButton::MainSimpleButton(const FloatRectangle &rect, const String &text)
{ // Similar to MainSimpleButton }
MainSimpleButton::~MainSimpleButton() {}

添加此自定义 Button() 的实例在此处创建:

void MainForm::InitMainForm(unsigned long formStyle)
{
    if (Construct(formStyle) != E_SUCCESS) { throw Exception("MainForm Construct() failed"); }
    MainSimpleButton *btn1 = new MainSimpleButton(); // <----- This code
    if (AddControl(btn1) != E_SUCCESS)
    {
        throw Exception("MainForm AddControl() failed");
    }
}
一般来说,

这是一个Tizen框架问题。建议你有一个按钮的UI应用程序。应用程序结构如下:

UIApp : [ Frame : [ Form : [ Button ] ] ]

这个简单 UI 的初始化调用链将如下所示:

OnAppInitializing():
    new Frame() => Frame.Construct() =>
    AddFrame(frame):
        Frame.OnInitializing():
            new Form() => Form.Construct() =>
            AddControl(form):
                Form.OnInitializing():
                    new Button() => Button.Construct() =>
                    AddControl(button):
                        Button.OnInitializing()

原因是:对象构造函数什么都不做(因为 Tizen 不使用异常),真正的工作是由 Construct() 方法完成的。我们可以通过使用将使用构造函数和异常的自定义对象来获得相同的结果。

OnAppInitializing():
    new Frame():
        Frame.Construct()
        new Form():
            Form.Construct()
            new Button():
                Button.Construct()
            AddControl(button)
         AddControl(form)
     AddFrame(frame)

这就是我想做的。

从 Tizen 框架的角度来看,我们应该得到与每次AddFrame()/AddControl()函数调用之前相同的结果,我们有有效的链new Object() => Object.Construct() => AddControl(Object)

但问题可能是,当我在手机上得到相同的结果时,日志是不同的:

04-05 02:18:04.840 : ERROR / Tizen::Ui::Controls ( 16130 : 16130 ) : Tizen::Ui::Animations::_VisualElement* Tizen::Ui::Controls::_IndicatorManager::GetIndicatorVisualElement(Tizen::Ui::_Window*, Tizen::Ui::Controls::_IndicatorOrientation, Tizen::Ui::_Control*) const(132) > [E_SYSTEM] Unable to get Indicator
04-05 02:18:04.840 : ERROR / Tizen::Ui::Controls ( 16130 : 16130 ) : result Tizen::Ui::Controls::_Indicator::AddIndicatorObject(Tizen::Ui::_Control*, Tizen::Ui::_Window*)(373) > [E_SYSTEM] Indicator can not create the surface.
04-05 02:18:04.840 : ERROR / Tizen::Ui::Controls ( 16130 : 16130 ) : Tizen::Ui::Animations::_VisualElement* Tizen::Ui::Controls::_IndicatorManager::GetIndicatorVisualElement(Tizen::Ui::_Window*, Tizen::Ui::Controls::_IndicatorOrientation, Tizen::Ui::_Control*) const(132) > [E_SYSTEM] Unable to get Indicator
04-05 02:18:04.840 : ERROR / Tizen::Ui::Controls ( 16130 : 16130 ) : result Tizen::Ui::Controls::_Indicator::AddIndicatorObject(Tizen::Ui::_Control*, Tizen::Ui::_Window*)(373) > [E_SYSTEM] Indicator can not create the surface.
04-05 02:18:04.840 : ERROR / Tizen::Ui ( 16130 : 16130 ) : result Tizen::Ui::_Control::SetFocused(bool)(2634) > [E_INVALID_OPERATION] This control should have a parent or be attached to the main tree.

因此,我认为Tizen框架不能很好地支持我的方法。