docs
Docs
C++ API
C API
Search API
Ctrl K
2.0
2.0
latest
1.4
Ultralight C++ API
2.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
ActionInfo.h
Go to the documentation of this file.
1
///
2
/// Copyright (C) 2026 Ultralight, Inc. All rights reserved.
3
/// A license is required for commercial use. https://ultralig.ht
4
///
5
#pragma once
6
#include <Ultralight/CAPI/CAPI_DOMData.h>
7
8
#include <cstdint>
9
#include <string_view>
10
11
namespace
ultralight
{
12
namespace
dom
{
13
namespace
data
{
14
15
///
16
/// Details of a delivered action (its name and the list row it fired from).
17
///
18
/// Take one as the second parameter of a generic action handler:
19
///
20
/// ```
21
/// binding.OnAction<"roster.kick">([&](dd::Value payload, dd::ActionInfo info) {
22
/// if (info.has_row())
23
/// KickPlayer(info.row_int_key());
24
/// });
25
/// ```
26
///
27
/// An action fired from `ul-on:*` markup never has a payload, and it doesn't say which View's
28
/// page fired it.
29
///
30
class
ActionInfo
{
31
public
:
32
///
33
/// Get the action's name.
34
///
35
/// @return Returns the name from the schema. For a row action this is its name in the row
36
/// type's schema (eg, `kick` for `roster.kick`).
37
///
38
const
char
*
name
()
const
{
return
name_; }
39
40
///
41
/// Whether or not the action fired from a list row.
42
///
43
bool
has_row
()
const
{
return
has_row_; }
44
45
///
46
/// Whether or not the row's key is a string (see row_string_key()).
47
///
48
bool
row_key_is_string
()
const
{
return
row_is_string_; }
49
50
///
51
/// Get the row's integer key.
52
///
53
/// @return Returns the key (for a list without keys, the row's position when the page fired
54
/// the action), or 0 when the key is a string or there's no row.
55
///
56
int64_t
row_int_key
()
const
{
return
int_key_; }
57
58
///
59
/// Get the row's string key.
60
///
61
/// @return Returns the key, or an empty view when the key isn't a string or there's no row.
62
///
63
/// @note The view is valid only during the handler call. Copy it to keep it.
64
///
65
std::string_view
row_string_key
()
const
{
return
string_key_; }
66
67
/// \cond INTERNAL
68
ActionInfo
(
const
char
*
name
,
const
ULDOMDataActionSource* source) : name_(
name
) {
69
if
(source) {
70
has_row_ =
true
;
71
row_is_string_ = source->is_string_key;
72
int_key_ = source->int_key;
73
if
(source->is_string_key && source->string_key)
74
string_key_ = std::string_view(source->string_key, source->string_key_length);
75
}
76
}
77
/// \endcond
78
79
private
:
80
const
char
* name_ =
""
;
81
bool
has_row_ =
false
;
82
bool
row_is_string_ =
false
;
83
int64_t int_key_ = 0;
84
std::string_view string_key_;
85
};
86
87
}
// namespace data
88
}
// namespace dom
89
}
// namespace ultralight
ultralight::dom::data::ActionInfo
Details of a delivered action (its name and the list row it fired from).
Definition
ActionInfo.h:30
ultralight::dom::data::ActionInfo::has_row
bool has_row() const
Whether or not the action fired from a list row.
Definition
ActionInfo.h:43
ultralight::dom::data::ActionInfo::row_int_key
int64_t row_int_key() const
Get the row's integer key.
Definition
ActionInfo.h:56
ultralight::dom::data::ActionInfo::name
const char * name() const
Get the action's name.
Definition
ActionInfo.h:38
ultralight::dom::data::ActionInfo::row_string_key
std::string_view row_string_key() const
Get the row's string key.
Definition
ActionInfo.h:65
ultralight::dom::data::ActionInfo::row_key_is_string
bool row_key_is_string() const
Whether or not the row's key is a string (see row_string_key()).
Definition
ActionInfo.h:48
ultralight::dom::data
Data-binding API that connects native C++ data to HTML and CSS markup.
Definition
ActionInfo.h:13
ultralight::dom
Direct C++ access to modify page elements and handle events.
ultralight
Root namespace for every public Ultralight type, function, and enumeration.
Ultralight
dom
data
ActionInfo.h
Docs
C++ API
C API
Version
2.0
2.0
latest
1.4