-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject.sh
More file actions
66 lines (58 loc) · 1.63 KB
/
object.sh
File metadata and controls
66 lines (58 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Interface of component
declare -A _global_obj
# $1 - variable name
# $2 - component class name
# Registers current component in global list, so other components can use this component, without knowing its type
function register_object() {
if [ -n "${_global_obj["$1"]}" ]; then
echo "component:[$1] already exists, exiting"
exit
fi
is_function_exists "$2.draw"
is_function_exists "$2.delete"
is_function_exists "$2.get_minimal_size"
is_function_exists "$2.set_style"
_global_obj["$1"]=$2
}
# $1 - variable name
function unregister_object() {
unset _global_obj["$1"]
}
# $1 - object name
# Creates new component
function object.new() {
echo "Called abstract function object.new, exiting"
exit
}
# $1 - object name
# Deletes components
function object.delete() {
local comp_class=${_global_obj["$1"]}
local func="$comp_class.delete"
$func $1
}
# $1 - object name
# $2 - layout
# Draws components within given layout
function object.draw() {
local func="${_global_obj["$1"]}.draw"
$func $1 $2
}
# $1 - object name
# $2 - layout within object will calculate its size
# $3 - variable name for x size
# $4 - variable name for y size
# Calculates minimal size inside given layout
function object.get_minimal_size() {
local comp_class=${_global_obj["$1"]}
local func="$comp_class.get_minimal_size"
$func $1 $2 $3 $4
}
# $1 - object name
# $2, $3, ... - names of properties to enable, see SYMBOL_MODIFIERS for more style.set_style
# Sets style for object
function object.set_style() {
local comp_class=${_global_obj["$1"]}
local func="$comp_class.set_style"
$func $1 $2
}