@@ -141,12 +141,15 @@ end
141141-- Column
142142--
143143
144+ local DEFAULT_DATA_WIDTH = 4
145+ local DEFAULT_COL_OVERSCAN = 14
146+
144147Column = defclass (Column , widgets .Panel )
145148Column .ATTRS {
146149 label = DEFAULT_NIL ,
147150 group = ' ' ,
148151 label_inset = 0 ,
149- data_width = 4 ,
152+ data_width = DEFAULT_DATA_WIDTH ,
150153 hidden = DEFAULT_NIL ,
151154 shared = DEFAULT_NIL ,
152155 data_fn = DEFAULT_NIL ,
@@ -161,7 +164,7 @@ local CH_UP = string.char(30)
161164local CH_DN = string.char (31 )
162165
163166function Column :init ()
164- self .frame = utils .assign ({t = 0 , b = 0 , l = 0 , w = 14 }, self .frame or {})
167+ self .frame = utils .assign ({t = 0 , b = 0 , l = 0 , w = DEFAULT_COL_OVERSCAN }, self .frame or {})
165168
166169 local function show_menu ()
167170 self .subviews .col_menu :show ()
@@ -767,7 +770,27 @@ function Spreadsheet:jump_to_group(group)
767770end
768771
769772function Spreadsheet :jump_to_col (idx )
773+ idx = math.min (idx , # self .cols .subviews )
774+ idx = math.max (idx , 1 )
770775 self .left_col = idx
776+ if self .cols .subviews [idx ].hidden then
777+ local found = false
778+ for shifted_idx = self .left_col - 1 ,1 ,- 1 do
779+ if not self .cols .subviews [shifted_idx ].hidden then
780+ self .left_col = shifted_idx
781+ found = true
782+ break
783+ end
784+ end
785+ if not found then
786+ for shifted_idx = self .left_col + 1 ,# self .cols .subviews do
787+ if not self .cols .subviews [shifted_idx ].hidden then
788+ self .left_col = shifted_idx
789+ break
790+ end
791+ end
792+ end
793+ end
771794 self :updateLayout ()
772795end
773796
@@ -868,7 +891,11 @@ function Spreadsheet:render(dc)
868891 if self .shared .refresh_headers then
869892 self :update_headers ()
870893 end
871- self :updateLayout ()
894+ if self .cols .subviews [self .left_col ].hidden then
895+ self :jump_to_col (self .left_col )
896+ else
897+ self :updateLayout ()
898+ end
872899 end
873900 local page_top = self .namelist .page_top
874901 local selected = self .namelist :getSelected ()
@@ -881,23 +908,16 @@ function Spreadsheet:render(dc)
881908end
882909
883910function Spreadsheet :get_num_visible_cols ()
884- local count = 0
885- for _ ,col in ipairs (self .cols .subviews ) do
886- if col .visible then
887- count = count + 1
888- end
889- end
890- return count
911+ local rect = self .frame_rect
912+ if not rect then return 1 end
913+ local other_width = self .subviews .name .data_width + (DEFAULT_COL_OVERSCAN - DEFAULT_DATA_WIDTH )
914+ local width = rect .width - other_width
915+ return width // (DEFAULT_DATA_WIDTH + 1 )
891916end
892917
893918function Spreadsheet :onInput (keys )
894919 if keys .KEYBOARD_CURSOR_LEFT then
895- for idx = self .left_col - 1 ,1 ,- 1 do
896- if not self .cols .subviews [idx ].hidden then
897- self :jump_to_col (idx )
898- break
899- end
900- end
920+ self :jump_to_col (self .left_col - 1 )
901921 elseif keys .KEYBOARD_CURSOR_LEFT_FAST then
902922 local remaining = self :get_num_visible_cols ()
903923 local target_col = self .left_col
@@ -1253,14 +1273,14 @@ ManipulatorOverlay.ATTRS{
12531273 default_pos = {x = 50 , y =- 6 },
12541274 default_enabled = true ,
12551275 viewscreens = ' dwarfmode/Info/CREATURES/CITIZEN' ,
1256- frame = {w = 34 , h = 1 },
1276+ frame = {w = 35 , h = 1 },
12571277}
12581278
12591279function ManipulatorOverlay :init ()
12601280 self :addviews {
12611281 widgets .TextButton {
12621282 frame = {t = 0 , l = 0 },
1263- label = ' DFHack citizen interface ' ,
1283+ label = ' DFHack citizen management ' ,
12641284 key = ' CUSTOM_CTRL_N' ,
12651285 on_activate = function () dfhack .run_script (' gui/manipulator' ) end ,
12661286 },
0 commit comments