z_mirror/TaskList

git clone https://git.raiguard.me/z_mirror/TaskList

raiguardMostly hook up task details GUI (#7)fa77a7d

task-details-gui
4.2 KiB137 linesraw
1local constants = require("constants")
2
3local templates = {}
4
5--- @param name string
6--- @param visible boolean|nil
7function templates.checkboxes_flow(name, visible)
8  return {
9    type = "flow",
10    direction = "vertical",
11    ref = { name .. "_flow" },
12    { type = "flow", name = "incompleted", direction = "vertical", visible = false },
13    { type = "flow", name = "completed", direction = "vertical", visible = false },
14    visible = visible,
15  }
16end
17
18--- @param sprite string
19--- @param tooltip LocalisedString|nil
20--- @param action table|nil
21--- @param ref table|nil
22function templates.frame_action_button(sprite, tooltip, action, ref)
23  return {
24    type = "sprite-button",
25    style = "frame_action_button",
26    sprite = sprite .. "_white",
27    hovered_sprite = sprite .. "_black",
28    clicked_sprite = sprite .. "_black",
29    tooltip = tooltip,
30    ref = ref,
31    actions = {
32      on_click = action,
33    },
34  }
35end
36
37--- @param Task Task
38--- @param gui_ident string|GuiIdent
39--- @param index number|nil
40--- @param completed boolean
41function templates.task_item(Task, gui_ident, index, completed)
42  return {
43    type = "flow",
44    name = Task.id,
45    direction = "vertical",
46    index = index or nil,
47    {
48      type = "flow",
49      style_mods = { vertical_align = "center" },
50      {
51        type = "checkbox",
52        style_mods = { horizontally_stretchable = true, horizontally_squashable = true },
53        caption = Task.title,
54        state = completed,
55        actions = {
56          on_checked_state_changed = { gui = gui_ident, action = "toggle_task_completed", task_id = Task.id },
57        },
58      },
59      {
60        type = "label",
61        style = "info_label",
62        caption = Task.assignee and Task.assignee.name or nil,
63        visible = Task.assignee and true or false,
64      },
65      {
66        type = "sprite",
67        style = "flib_indicator",
68        sprite = "flib_indicator_" .. constants.task_status[Task.status].color,
69        tooltip = constants.task_status[Task.status].label,
70        actions = {
71          on_click = { gui = gui_ident, action = "cycle_task_status", task_id = Task.id },
72        },
73      },
74      {
75        type = "sprite-button",
76        style = "mini_button_aligned_to_text_vertically_when_centered",
77        sprite = "utility/rename_icon_small_black",
78        tooltip = { "gui.tlst-edit-task" },
79        mouse_button_filter = { "left", "middle" },
80        actions = {
81          on_click = {
82            gui = gui_ident,
83            action = "edit_task",
84            task_id = Task.id,
85            parent_task_id = Task.owner.object_name == "Task" and Task.owner.id or nil,
86          },
87        },
88      },
89      {
90        type = "sprite-button",
91        style = "mini_button_aligned_to_text_vertically_when_centered",
92        sprite = "tlst_arrow_right",
93        tooltip = { "gui.tlst-expand-tooltip" },
94        mouse_button_filter = { "left", "middle" },
95        actions = {
96          on_click = { gui = gui_ident, transform = "handle_expand_click", task_id = Task.id },
97        },
98      },
99    },
100    {
101      type = "flow",
102      name = "details_flow",
103      style_mods = { left_margin = 22 },
104      direction = "vertical",
105      visible = false,
106      {
107        type = "label",
108        style_mods = { font_color = constants.description_color, single_line = false },
109        caption = Task.description,
110        visible = #Task.description > 0,
111      },
112      {
113        type = "flow",
114        name = "subtasks_flow",
115        direction = "vertical",
116        { type = "flow", name = "incompleted", direction = "vertical", visible = false },
117        { type = "flow", name = "completed", direction = "vertical", visible = false },
118        {
119          type = "flow",
120          style_mods = { padding = 0, margin = 0, horizontal_spacing = 8 },
121          {
122            type = "sprite-button",
123            style = "mini_button_aligned_to_text_vertically",
124            sprite = "utility/add",
125            tooltip = { "gui.tlst-add-subtask" },
126            actions = {
127              on_click = { gui = gui_ident, action = "edit_task", parent_task_id = Task.id },
128            },
129          },
130          { type = "label", caption = { "gui.tlst-add-subtask" } },
131        },
132      },
133    },
134  }
135end
136
137return templates