1 /*
2  *  Copyright (C) 2005-2018 Team Kodi
3  *  This file is part of Kodi - https://kodi.tv
4  *
5  *  SPDX-License-Identifier: GPL-2.0-or-later
6  *  See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "../../c-api/gui/controls/label.h"
12 #include "../Window.h"
13 
14 #ifdef __cplusplus
15 
16 namespace kodi
17 {
18 namespace gui
19 {
20 namespace controls
21 {
22 
23 //==============================================================================
24 /// @defgroup cpp_kodi_gui_windows_controls_CLabel Control Label
25 /// @ingroup cpp_kodi_gui_windows_controls
26 /// @brief @cpp_class{ kodi::gui::controls::CLabel }
27 /// **Window control used to show some lines of text**\n
28 /// The label control is used for displaying text in Kodi. You can choose
29 /// the font, size, colour, location and contents of the text to be displayed.
30 ///
31 /// It has the header @ref Label.h "#include <kodi/gui/controls/Label.h>"
32 /// be included to enjoy it.
33 ///
34 /// Here you find the needed skin part for a @ref Label_Control "label control".
35 ///
36 /// @note The call of the control is only possible from the corresponding
37 /// window as its class and identification number is required.
38 ///
39 class ATTRIBUTE_HIDDEN CLabel : public CAddonGUIControlBase
40 {
41 public:
42   //============================================================================
43   /// @ingroup cpp_kodi_gui_windows_controls_CLabel
44   /// @brief Construct a new control.
45   ///
46   /// @param[in] window Related window control class
47   /// @param[in] controlId Used skin xml control id
48   ///
CLabel(CWindow * window,int controlId)49   CLabel(CWindow* window, int controlId) : CAddonGUIControlBase(window)
50   {
51     m_controlHandle = m_interface->kodi_gui->window->get_control_label(
52         m_interface->kodiBase, m_Window->GetControlHandle(), controlId);
53     if (!m_controlHandle)
54       kodi::Log(ADDON_LOG_FATAL,
55                 "kodi::gui::controls::CLabel can't create control class from Kodi !!!");
56   }
57   //----------------------------------------------------------------------------
58 
59   //============================================================================
60   /// @ingroup cpp_kodi_gui_windows_controls_CLabel
61   /// @brief Destructor.
62   ///
63   ~CLabel() override = default;
64   //----------------------------------------------------------------------------
65 
66   //============================================================================
67   /// @ingroup cpp_kodi_gui_windows_controls_CLabel
68   /// @brief Set the control on window to visible.
69   ///
70   /// @param[in] visible If true visible, otherwise hidden
71   ///
SetVisible(bool visible)72   void SetVisible(bool visible)
73   {
74     m_interface->kodi_gui->control_label->set_visible(m_interface->kodiBase, m_controlHandle,
75                                                       visible);
76   }
77   //----------------------------------------------------------------------------
78 
79   //============================================================================
80   /// @ingroup cpp_kodi_gui_windows_controls_CLabel
81   /// @brief To set the text string on label.
82   ///
83   /// @param[in] text Text to show
84   ///
SetLabel(const std::string & text)85   void SetLabel(const std::string& text)
86   {
87     m_interface->kodi_gui->control_label->set_label(m_interface->kodiBase, m_controlHandle,
88                                                     text.c_str());
89   }
90   //----------------------------------------------------------------------------
91 
92   //============================================================================
93   /// @ingroup cpp_kodi_gui_windows_controls_CLabel
94   /// @brief Get the used text from control.
95   ///
96   /// @return Used text on label control
97   ///
GetLabel()98   std::string GetLabel() const
99   {
100     std::string label;
101     char* ret =
102         m_interface->kodi_gui->control_label->get_label(m_interface->kodiBase, m_controlHandle);
103     if (ret != nullptr)
104     {
105       if (std::strlen(ret))
106         label = ret;
107       m_interface->free_string(m_interface->kodiBase, ret);
108     }
109     return label;
110   }
111   //----------------------------------------------------------------------------
112 };
113 
114 } /* namespace controls */
115 } /* namespace gui */
116 } /* namespace kodi */
117 
118 #endif /* __cplusplus */
119