z_mirror/TaskList
git clone https://git.raiguard.me/z_mirror/TaskList
d03b0d7
trunk
1local constants =require ( "constants" ) 2 3local templates ={} 4 5--- @param name string 6--- @param visible boolean|nil 7function templates . checkboxes_flow ( name , visible ) 8return { 9type ="flow" , 10direction ="vertical" , 11ref ={ name .. "_flow" } , 12{ type ="flow" , name ="incompleted" , direction ="vertical" , visible =false } , 13{ type ="flow" , name ="completed" , direction ="vertical" , visible =false } , 14visible =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 ) 23return { 24type ="sprite-button" , 25style ="frame_action_button" , 26sprite =sprite , 27tooltip =tooltip , 28ref =ref , 29actions ={ 30on_click =action , 31} , 32} 33end 34 35-- XXX: See https://forums.factorio.com/100896 36local toplevel_width =452 37local nesting_offset =22 38--- @param Task Task 39--- @return number 40local function get_task_description_width ( Task ) 41local nesting_level =0 42repeat 43Task =Task . owner --[[@as Task?]] 44nesting_level =nesting_level + 1 45until Task . object_name ~= "Task" 46 47return toplevel_width - ( nesting_offset * nesting_level ) 48end 49 50--- @param Task Task 51--- @param index number|nil 52--- @param completed boolean 53function templates . task_item ( Task , index , completed ) 54return { 55type ="flow" , 56name =Task . id , 57direction ="vertical" , 58index =index or nil , 59{ 60type ="flow" , 61style ="tlst_task_item_flow" , 62{ 63type ="checkbox" , 64style_mods ={ horizontally_stretchable =true , horizontally_squashable =true } , 65caption =Task . title , 66state =completed , 67actions ={ 68on_checked_state_changed ={ gui ="tasks" , action ="toggle_task_completed" , task_id =Task . id } , 69} , 70} , 71{ 72type ="label" , 73style ="info_label" , 74caption =Task . assignee and Task . assignee . name or nil , 75visible =Task . assignee and true or false , 76} , 77{ 78type ="sprite" , 79style ="flib_indicator" , 80sprite ="flib_indicator_" .. constants . task_status [ Task . status ]. color , 81tooltip =constants . task_status [ Task . status ]. label , 82actions ={ 83on_click ={ gui ="tasks" , action ="cycle_task_status" , task_id =Task . id } , 84} , 85} , 86{ 87type ="sprite-button" , 88style ="mini_button_aligned_to_text_vertically_when_centered" , 89sprite ="utility/rename_icon" , 90tooltip ={ "gui.tlst-edit-task" } , 91actions ={ 92on_click ={ 93gui ="tasks" , 94action ="edit_task" , 95task_id =Task . id , 96parent_task_id =Task . owner . object_name == "Task" and Task . owner . id or nil , 97} , 98} , 99} , 100{ 101type ="sprite-button" , 102style ="mini_button_aligned_to_text_vertically_when_centered" , 103sprite ="tlst_arrow_right" , 104tooltip ={ "gui.tlst-expand-tooltip" } , 105actions ={ 106on_click ={ gui ="tasks" , transform ="handle_expand_click" , task_id =Task . id } , 107} , 108} , 109} , 110{ 111type ="flow" , 112name ="details_flow" , 113style_mods ={ left_margin =22 } , 114direction ="vertical" , 115visible =false , 116{ 117type ="label" , 118style_mods ={ 119font_color =constants . description_color , 120single_line =false , 121width =get_task_description_width ( Task ), 122} , 123caption =Task . description , 124visible =# Task . description > 0 , 125} , 126{ 127type ="flow" , 128name ="subtasks_flow" , 129direction ="vertical" , 130{ type ="flow" , name ="incompleted" , direction ="vertical" , visible =false } , 131{ type ="flow" , name ="completed" , direction ="vertical" , visible =false } , 132{ 133type ="flow" , 134style ="tlst_task_item_flow" , 135{ 136type ="label" , 137style ="tlst_new_task_label" , 138caption ={ "gui.tlst-add-subtask" } , 139actions ={ 140on_click ={ gui ="tasks" , action ="edit_task" , parent_task_id =Task . id } , 141} , 142} , 143actions ={ 144on_click ={ gui ="tasks" , action ="edit_task" , parent_task_id =Task . id } , 145} , 146} , 147} , 148} , 149} 150end 151 152return templates