2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "my-control-impl.h"
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali-toolkit/devel-api/controls/control-devel.h>
25 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
26 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
27 #include <dali/devel-api/scripting/enum-helper.h>
30 using namespace Dali::Toolkit;
38 Dali::BaseHandle Create()
40 return Demo::MyControl::New();
43 // Required code for Property set up.
45 DALI_TYPE_REGISTRATION_BEGIN(MyControl, Dali::Toolkit::Control, Create);
47 DALI_PROPERTY_REGISTRATION(Demo, MyControl, "iconVisual", MAP, ICON_VISUAL)
49 DALI_TYPE_REGISTRATION_END();
51 // Add an enum to string conversion entry for the control's visuals. In this case just the icon visual.
52 // Enables Setting of the property using enums or strings.
53 DALI_ENUM_TO_STRING_TABLE_BEGIN(VISUAL_PROPERTIES)
54 {"iconVisual", Demo::MyControl::Property::ICON_VISUAL},
55 DALI_ENUM_TO_STRING_TABLE_END(VISUAL_PROPERTIES)
57 } // anonymous namespace
59 Internal::MyControl::MyControl()
60 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT))
64 Demo::MyControl Internal::MyControl::New()
66 IntrusivePtr<Internal::MyControl> impl = new Internal::MyControl();
67 Demo::MyControl handle = Demo::MyControl(*impl);
72 void MyControl::OnInitialize()
74 Dali::Actor self = Self();
75 self.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
78 void MyControl::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
80 Demo::MyControl myControl = Demo::MyControl::DownCast(Dali::BaseHandle(object));
84 MyControl& impl = GetImpl(myControl);
87 case Demo::MyControl::Property::ICON_VISUAL:
89 Toolkit::Visual::Base iconVisual;
90 Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get();
91 const Property::Map* map = value.GetMap();
92 if(map && !map->Empty())
94 iconVisual = visualFactory.CreateVisual(*map);
99 DevelControl::RegisterVisual(impl, index, iconVisual);
107 Property::Value MyControl::GetProperty(BaseObject* object, Property::Index propertyIndex)
109 Property::Value value;
111 Demo::MyControl myControl = Demo::MyControl::DownCast(Dali::BaseHandle(object));
115 switch(propertyIndex)
117 case Demo::MyControl::Property::ICON_VISUAL:
120 MyControl& impl = GetImpl(myControl);
121 Toolkit::Visual::Base visual = DevelControl::GetVisual(impl, propertyIndex);
124 visual.CreatePropertyMap(map); // Creates a Property map containing the Visual that ICON_VISUAL currently is. Can change if state changes.
137 } // namespace Internal