The Battle for Wesnoth  1.17.0-dev
Namespaces | Macros | Typedefs | Functions | Variables
lua_widget_attributes.cpp File Reference
#include "gui/core/canvas.hpp"
#include "gui/dialogs/drop_down_menu.hpp"
#include "gui/widgets/clickable_item.hpp"
#include "gui/widgets/styled_widget.hpp"
#include "gui/widgets/listbox.hpp"
#include "gui/widgets/multi_page.hpp"
#include "gui/widgets/multimenu_button.hpp"
#include "gui/widgets/progress_bar.hpp"
#include "gui/widgets/selectable_item.hpp"
#include "gui/widgets/slider.hpp"
#include "gui/widgets/stacked_widget.hpp"
#include "gui/widgets/text_box.hpp"
#include "gui/widgets/tree_view.hpp"
#include "gui/widgets/tree_view_node.hpp"
#include "gui/widgets/unit_preview_pane.hpp"
#include "gui/widgets/widget.hpp"
#include "gui/widgets/window.hpp"
#include "config.hpp"
#include "log.hpp"
#include "scripting/lua_common.hpp"
#include "scripting/lua_cpp_function.hpp"
#include "scripting/lua_kernel_base.hpp"
#include "scripting/lua_unit.hpp"
#include "scripting/lua_unit_type.hpp"
#include "scripting/push_check.hpp"
#include "scripting/lua_widget.hpp"
#include "scripting/lua_widget_attributes.hpp"
#include "serialization/string_utils.hpp"
#include "tstring.hpp"
#include "game_data.hpp"
#include "game_state.hpp"
#include <functional>
#include <boost/preprocessor/cat.hpp>
#include <map>
#include <utility>
#include <vector>
#include "lua/lauxlib.h"
#include "lua/lua.h"
Include dependency graph for lua_widget_attributes.cpp:

Go to the source code of this file.

Namespaces

 lua_widget
 

Macros

#define ERR_LUA   LOG_STREAM(err, log_scripting_lua)
 
#define WIDGET_GETTER4(name, value_type, widgt_type, id)
 
#define WIDGET_SETTER4(name, value_type, widgt_type, id)
 
#define WIDGET_GETTER(name, value_type, widgt_type)   WIDGET_GETTER4(name, value_type, widgt_type, __LINE__)
 
#define WIDGET_SETTER(name, value_type, widgt_type)   WIDGET_SETTER4(name, value_type, widgt_type, __LINE__)
 

Typedefs

using tgetters = std::map< std::string, std::vector< std::function< bool(lua_State *, gui2::widget &)> >>
 
using tsetters = std::map< std::string, std::vector< std::function< bool(lua_State *, int, gui2::widget &)> >>
 

Functions

static gui2::widgetfind_child_by_index (gui2::widget &w, int i)
 
static gui2::widgetfind_child_by_name (gui2::widget &w, const std::string &m)
 
 WIDGET_GETTER ("value_compat,selected_index", int, gui2::listbox)
 CLASSIC. More...
 
 WIDGET_SETTER ("value_compat,selected_index", int, gui2::listbox)
 
 WIDGET_GETTER ("value_compat,selected_index", int, gui2::multi_page)
 
 WIDGET_SETTER ("value_compat,selected_index", int, gui2::multi_page)
 
 WIDGET_GETTER ("value_compat,selected_index", int, gui2::stacked_widget)
 
 WIDGET_SETTER ("value_compat,selected_index", int, gui2::stacked_widget)
 
 WIDGET_GETTER ("selected_index", int, gui2::selectable_item)
 
 WIDGET_SETTER ("selected_index", int, gui2::selectable_item)
 
 WIDGET_GETTER ("value_compat,selected", bool, gui2::selectable_item)
 
 WIDGET_SETTER ("value_compat,selected", bool, gui2::selectable_item)
 
 WIDGET_GETTER ("value_compat,text", std::string, gui2::text_box)
 
 WIDGET_SETTER ("value_compat,text", std::string, gui2::text_box)
 
 WIDGET_GETTER ("value_compat,value", int, gui2::slider)
 
 WIDGET_SETTER ("value_compat,value", int, gui2::slider)
 
 WIDGET_GETTER ("max_value", int, gui2::slider)
 
 WIDGET_SETTER ("max_value", int, gui2::slider)
 
 WIDGET_GETTER ("min_value", int, gui2::slider)
 
 WIDGET_SETTER ("min_value", int, gui2::slider)
 
 WIDGET_GETTER ("value_compat,percentage", int, gui2::progress_bar)
 
 WIDGET_SETTER ("value_compat,percentage", int, gui2::progress_bar)
 
 WIDGET_GETTER ("value_compat,selected_item_path", std::vector< int >, gui2::tree_view)
 
 WIDGET_GETTER ("path", std::vector< int >, gui2::tree_view_node)
 
 WIDGET_SETTER ("value_compat,unfolded", bool, gui2::tree_view_node)
 
 WIDGET_SETTER ("value_compat,unit", lua_index_raw, gui2::unit_preview_pane)
 
 WIDGET_GETTER ("item_count", int, gui2::multi_page)
 
 WIDGET_GETTER ("item_count", int, gui2::listbox)
 
 WIDGET_SETTER ("use_markup", bool, gui2::styled_widget)
 
 WIDGET_SETTER ("marked_up_text", t_string, gui2::styled_widget)
 
 WIDGET_SETTER ("enabled", bool, gui2::styled_widget)
 
 WIDGET_SETTER ("tooltip", t_string, gui2::styled_widget)
 
 WIDGET_SETTER ("callback", lua_index_raw, gui2::widget)
 
 WIDGET_SETTER ("visible", lua_index_raw, gui2::styled_widget)
 
 WIDGET_SETTER ("value_compat,label", t_string, gui2::styled_widget)
 
 WIDGET_GETTER ("type", std::string, gui2::widget)
 
int lua_widget::impl_widget_get (lua_State *L)
 
int lua_widget::impl_widget_set (lua_State *L)
 

Variables

static lg::log_domain log_scripting_lua ("scripting/lua")
 
static tgetters getters
 
static tsetters setters
 

Macro Definition Documentation

◆ ERR_LUA

#define ERR_LUA   LOG_STREAM(err, log_scripting_lua)

◆ WIDGET_GETTER

#define WIDGET_GETTER (   name,
  value_type,
  widgt_type 
)    WIDGET_GETTER4(name, value_type, widgt_type, __LINE__)
Parameters
namestring comma seperated list
value_typethe type of the attribute, for example int or std::string
widgt_typethe type of the widget, for example gui2::listbox

Definition at line 162 of file lua_widget_attributes.cpp.

◆ WIDGET_GETTER4

#define WIDGET_GETTER4 (   name,
  value_type,
  widgt_type,
  id 
)
Value:
/* use a class member for L to surpress unused parameter wanring */ \
struct BOOST_PP_CAT(getter_, id) { value_type do_it(widgt_type& w); lua_State* L; }; \
struct BOOST_PP_CAT(getter_adder_, id) { \
BOOST_PP_CAT(getter_adder_, id) () \
{ \
utils::split_foreach(name, ',', 0, [](std::string_view name_part){\
getters[std::string(name_part)].push_back([](lua_State* L, gui2::widget& w) { \
if(widgt_type* pw = dynamic_cast<widgt_type*>(&w)) { \
lua_push(L, BOOST_PP_CAT(getter_, id){L}.do_it(*pw)); \
return true; \
} \
return false; \
}); \
}); \
} \
}; \
static BOOST_PP_CAT(getter_adder_, id) BOOST_PP_CAT(getter_adder_instance_, id) ; \
value_type BOOST_PP_CAT(getter_, id)::do_it(widgt_type& w)
Base class for all widgets.
Definition: widget.hpp:49
int w
void split_foreach(std::string_view s, char sep, const int flags, const F &f)

Definition at line 116 of file lua_widget_attributes.cpp.

◆ WIDGET_SETTER

#define WIDGET_SETTER (   name,
  value_type,
  widgt_type 
)    WIDGET_SETTER4(name, value_type, widgt_type, __LINE__)

Definition at line 164 of file lua_widget_attributes.cpp.

Referenced by WIDGET_GETTER().

◆ WIDGET_SETTER4

#define WIDGET_SETTER4 (   name,
  value_type,
  widgt_type,
  id 
)
Value:
struct BOOST_PP_CAT(setter_, id) { void do_it(widgt_type& w, const value_type& value); lua_State* L; }; \
struct BOOST_PP_CAT(setter_adder_, id) { \
BOOST_PP_CAT(setter_adder_, id) ()\
{ \
utils::split_foreach(name, ',', 0, [](std::string_view name_part){\
setters[std::string(name_part)].push_back([](lua_State* L, int idx, gui2::widget& w) { \
if(widgt_type* pw = dynamic_cast<widgt_type*>(&w)) { \
BOOST_PP_CAT(setter_, id){L}.do_it(*pw, lua_check<value_type>(L, idx)); \
return true; \
} \
return false; \
}); \
}); \
} \
}; \
static BOOST_PP_CAT(setter_adder_, id) BOOST_PP_CAT(setter_adder_instance_, id); \
void BOOST_PP_CAT(setter_, id)::do_it(widgt_type& w, const value_type& value)
Base class for all widgets.
Definition: widget.hpp:49
std::string id
Text to match against addon_info.tags()
Definition: manager.cpp:215
int w
void split_foreach(std::string_view s, char sep, const int flags, const F &f)

Definition at line 137 of file lua_widget_attributes.cpp.

Typedef Documentation

◆ tgetters

using tgetters = std::map<std::string, std::vector<std::function<bool(lua_State*, gui2::widget&)> >>

Definition at line 110 of file lua_widget_attributes.cpp.

◆ tsetters

using tsetters = std::map<std::string, std::vector<std::function<bool(lua_State*, int, gui2::widget&)> >>

Definition at line 113 of file lua_widget_attributes.cpp.

Function Documentation

◆ find_child_by_index()

static gui2::widget* find_child_by_index ( gui2::widget w,
int  i 
)
static

◆ find_child_by_name()

static gui2::widget* find_child_by_name ( gui2::widget w,
const std::string &  m 
)
static

Definition at line 105 of file lua_widget_attributes.cpp.

References gui2::widget::find().

Referenced by lua_widget::impl_widget_get().

◆ WIDGET_GETTER() [1/15]

WIDGET_GETTER ( value_compat,
selected_index"  ,
int  ,
gui2::listbox   
)

CLASSIC.

Definition at line 169 of file lua_widget_attributes.cpp.

References w.

◆ WIDGET_GETTER() [2/15]

WIDGET_GETTER ( value_compat,
selected_index"  ,
int  ,
gui2::multi_page   
)

Definition at line 179 of file lua_widget_attributes.cpp.

References w.

◆ WIDGET_GETTER() [3/15]

WIDGET_GETTER ( value_compat,
selected_index"  ,
int  ,
gui2::stacked_widget   
)

Definition at line 189 of file lua_widget_attributes.cpp.

References w.

◆ WIDGET_GETTER() [4/15]

WIDGET_GETTER ( "selected_index"  ,
int  ,
gui2::selectable_item   
)

Definition at line 199 of file lua_widget_attributes.cpp.

References w.

◆ WIDGET_GETTER() [5/15]

WIDGET_GETTER ( value_compat,
selected"  ,
bool  ,
gui2::selectable_item   
)

Definition at line 212 of file lua_widget_attributes.cpp.

References w.

◆ WIDGET_GETTER() [6/15]

WIDGET_GETTER ( value_compat,
text"  ,
std::string  ,
gui2::text_box   
)

Definition at line 225 of file lua_widget_attributes.cpp.

References w.

◆ WIDGET_GETTER() [7/15]

WIDGET_GETTER ( value_compat,
value"  ,
int  ,
gui2::slider   
)

Definition at line 235 of file lua_widget_attributes.cpp.

References w.

◆ WIDGET_GETTER() [8/15]

WIDGET_GETTER ( "max_value"  ,
int  ,
gui2::slider   
)

Definition at line 245 of file lua_widget_attributes.cpp.

References w.

◆ WIDGET_GETTER() [9/15]

WIDGET_GETTER ( "min_value"  ,
int  ,
gui2::slider   
)

Definition at line 255 of file lua_widget_attributes.cpp.

References w.

◆ WIDGET_GETTER() [10/15]

WIDGET_GETTER ( value_compat,
percentage"  ,
int  ,
gui2::progress_bar   
)

Definition at line 265 of file lua_widget_attributes.cpp.

References w.

◆ WIDGET_GETTER() [11/15]

WIDGET_GETTER ( value_compat,
selected_item_path"  ,
std::vector< int >  ,
gui2::tree_view   
)

Definition at line 275 of file lua_widget_attributes.cpp.

References a, and w.

◆ WIDGET_GETTER() [12/15]

WIDGET_GETTER ( "path"  ,
std::vector< int >  ,
gui2::tree_view_node   
)

Definition at line 282 of file lua_widget_attributes.cpp.

References a, and w.

◆ WIDGET_GETTER() [13/15]

WIDGET_GETTER ( "item_count"  ,
int  ,
gui2::multi_page   
)

Definition at line 309 of file lua_widget_attributes.cpp.

References w.

◆ WIDGET_GETTER() [14/15]

WIDGET_GETTER ( "item_count"  ,
int  ,
gui2::listbox   
)

Definition at line 314 of file lua_widget_attributes.cpp.

References w.

◆ WIDGET_GETTER() [15/15]

WIDGET_GETTER ( "type"  ,
std::string  ,
gui2::widget   
)

◆ WIDGET_SETTER() [1/19]

WIDGET_SETTER ( value_compat,
selected_index"  ,
int  ,
gui2::listbox   
)

Definition at line 174 of file lua_widget_attributes.cpp.

References w.

◆ WIDGET_SETTER() [2/19]

WIDGET_SETTER ( value_compat,
selected_index"  ,
int  ,
gui2::multi_page   
)

Definition at line 184 of file lua_widget_attributes.cpp.

References w.

◆ WIDGET_SETTER() [3/19]

WIDGET_SETTER ( value_compat,
selected_index"  ,
int  ,
gui2::stacked_widget   
)

Definition at line 194 of file lua_widget_attributes.cpp.

References w.

◆ WIDGET_SETTER() [4/19]

WIDGET_SETTER ( "selected_index"  ,
int  ,
gui2::selectable_item   
)

Definition at line 204 of file lua_widget_attributes.cpp.

References w.

◆ WIDGET_SETTER() [5/19]

WIDGET_SETTER ( value_compat,
selected"  ,
bool  ,
gui2::selectable_item   
)

Definition at line 220 of file lua_widget_attributes.cpp.

References w.

◆ WIDGET_SETTER() [6/19]

WIDGET_SETTER ( value_compat,
text"  ,
std::string  ,
gui2::text_box   
)

Definition at line 230 of file lua_widget_attributes.cpp.

References w.

◆ WIDGET_SETTER() [7/19]

WIDGET_SETTER ( value_compat,
value"  ,
int  ,
gui2::slider   
)

Definition at line 240 of file lua_widget_attributes.cpp.

References w.

◆ WIDGET_SETTER() [8/19]

WIDGET_SETTER ( "max_value"  ,
int  ,
gui2::slider   
)

Definition at line 250 of file lua_widget_attributes.cpp.

References w.

◆ WIDGET_SETTER() [9/19]

WIDGET_SETTER ( "min_value"  ,
int  ,
gui2::slider   
)

Definition at line 260 of file lua_widget_attributes.cpp.

References w.

◆ WIDGET_SETTER() [10/19]

WIDGET_SETTER ( value_compat,
percentage"  ,
int  ,
gui2::progress_bar   
)

Definition at line 270 of file lua_widget_attributes.cpp.

References w.

◆ WIDGET_SETTER() [11/19]

WIDGET_SETTER ( value_compat,
unfolded"  ,
bool  ,
gui2::tree_view_node   
)

Definition at line 289 of file lua_widget_attributes.cpp.

References w.

◆ WIDGET_SETTER() [12/19]

WIDGET_SETTER ( value_compat,
unit ,
lua_index_raw  ,
gui2::unit_preview_pane   
)

Definition at line 298 of file lua_widget_attributes.cpp.

References luaW_tounit(), luaW_tounittype(), luaW_type_error(), and w.

◆ WIDGET_SETTER() [13/19]

WIDGET_SETTER ( "use_markup"  ,
bool  ,
gui2::styled_widget   
)

Definition at line 319 of file lua_widget_attributes.cpp.

References w.

◆ WIDGET_SETTER() [14/19]

WIDGET_SETTER ( "marked_up_text"  ,
t_string  ,
gui2::styled_widget   
)

Definition at line 328 of file lua_widget_attributes.cpp.

References w.

◆ WIDGET_SETTER() [15/19]

WIDGET_SETTER ( "enabled"  ,
bool  ,
gui2::styled_widget   
)

Definition at line 334 of file lua_widget_attributes.cpp.

References w.

◆ WIDGET_SETTER() [16/19]

WIDGET_SETTER ( "tooltip"  ,
t_string  ,
gui2::styled_widget   
)

Definition at line 339 of file lua_widget_attributes.cpp.

References w.

◆ WIDGET_SETTER() [17/19]

WIDGET_SETTER ( "callback"  ,
lua_index_raw  ,
gui2::widget   
)

◆ WIDGET_SETTER() [18/19]

WIDGET_SETTER ( "visible"  ,
lua_index_raw  ,
gui2::styled_widget   
)

◆ WIDGET_SETTER() [19/19]

WIDGET_SETTER ( value_compat,
label ,
t_string  ,
gui2::styled_widget   
)

Definition at line 399 of file lua_widget_attributes.cpp.

References gui2::window::invalidate_layout(), and w.

Variable Documentation

◆ getters

tgetters getters
static

Definition at line 111 of file lua_widget_attributes.cpp.

Referenced by lua_widget::impl_widget_get().

◆ log_scripting_lua

lg::log_domain log_scripting_lua("scripting/lua")
static

◆ setters

tsetters setters
static

Definition at line 114 of file lua_widget_attributes.cpp.

Referenced by lua_widget::impl_widget_set().