Skip to content

Commit d3f252d

Browse files
author
Chad Juliano
committed
Adding dims panel
1 parent 21b0111 commit d3f252d

13 files changed

+651
-170
lines changed

src/biw-main.sh

Lines changed: 91 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,13 @@
1313
# generate errors if unset vars are used.
1414
set -o nounset
1515

16-
# global panel geometry
17-
declare -ri BIW_MARGIN=10
18-
declare -ri BIW_PANEL_HEIGHT=20
19-
declare -ri BIW_PANEL_WIDTH=60
20-
2116
source ${BIW_HOME}/biw-util.sh
2217
source ${BIW_HOME}/biw-theme-mgr.sh
2318
source ${BIW_HOME}/biw-panel-hmenu.sh
2419
source ${BIW_HOME}/biw-panel-vmenu.sh
2520
source ${BIW_HOME}/biw-panel-browse.sh
2621
source ${BIW_HOME}/biw-panel-credits.sh
22+
source ${BIW_HOME}/biw-panel-slider.sh
2723

2824
declare -r BIW_VERSION=0.9
2925

@@ -56,6 +52,7 @@ declare -r BIW_MENU_BROWSE='File'
5652
declare -r BIW_MENU_THEME='Theme'
5753
declare -r BIW_MENU_HOTKEY='Hotkey'
5854
declare -r BIW_MENU_CREDITS='Credits'
55+
declare -r BIW_MENU_DIMENSIONS='Dims'
5956
declare -r BIW_MENU_CONFIG='Config'
6057
#declare -r BIW_MENU_DEFAULT='Default'
6158

@@ -69,11 +66,11 @@ declare -r BIW_MENU_CONFIG='Config'
6966
declare -A BIW_DISPATCH_MAP=(
7067
[$BIW_MENU_HISTORY]=fn_biw_controller_history
7168
[$BIW_MENU_BROWSE]=fn_biw_controller_browse
72-
[$BIW_MENU_CONFIG]=fn_biw_controller_hmenu_config
69+
[$BIW_MENU_CREDITS]=fn_biw_controller_credits
70+
[$BIW_MENU_CONFIG]=fn_biw_controller_cfg_hmenu
7371
[$BIW_MENU_THEME]=fn_biw_controller_cfg_theme
74-
[$BIW_MENU_HOTKEY]=fn_biw_controller_hotkey
75-
[$BIW_MENU_CREDITS]=fn_biw_controller_credits)
76-
72+
[$BIW_MENU_HOTKEY]=fn_biw_controller_cfg_hotkey
73+
[$BIW_MENU_DIMENSIONS]=fn_biw_controller_cfg_dims)
7774

7875
function fn_biw_controller_hmenu_top()
7976
{
@@ -91,7 +88,7 @@ function fn_biw_controller_hmenu_top()
9188
fn_util_dispatcher
9289
}
9390

94-
function fn_biw_controller_hmenu_config()
91+
function fn_biw_controller_cfg_hmenu()
9592
{
9693
# If we are at this point then it means:
9794
# 1. The user selected the "Config" entry in the H-Menu.
@@ -102,6 +99,7 @@ function fn_biw_controller_hmenu_config()
10299

103100
local -a _config_menu=(
104101
$BIW_MENU_THEME
102+
$BIW_MENU_DIMENSIONS
105103
$BIW_MENU_HOTKEY)
106104

107105
# Call the dispatcher that will handle actions
@@ -123,7 +121,7 @@ function fn_biw_controller_hmenu_config()
123121
# Controller: Hotkey configuration panel.
124122
##
125123

126-
function fn_biw_controller_hotkey()
124+
function fn_biw_controller_cfg_hotkey()
127125
{
128126
local -A _bind_selections=(
129127
['Arrow-Up']=$CSI_KEY_UP
@@ -143,7 +141,7 @@ function fn_biw_controller_hotkey()
143141
mapfile -t _key_descr_list < <(echo "${!_bind_selections[*]}" | sort)
144142

145143
fn_vmenu_init _key_descr_list[@]
146-
fn_biw_load_hotkey_idx
144+
fn_biw_cfg_hotkey_load
147145
vmenu_idx_selected=$?
148146

149147
fn_vmenu_set_message "Choose activation hotkey"
@@ -157,14 +155,14 @@ function fn_biw_controller_hotkey()
157155

158156
case "$_key" in
159157
$CSI_KEY_ENTER|$CSI_KEY_SPC)
160-
fn_biw_save_hotkey
158+
fn_biw_cfg_hotkey_save
161159
fn_vmenu_redraw
162160
;;
163161
esac
164162
done
165163
}
166164

167-
function fn_biw_load_hotkey_idx()
165+
function fn_biw_cfg_hotkey_load()
168166
{
169167
# create lookups
170168
local -A _bind_desc_lookup=()
@@ -194,7 +192,7 @@ function fn_biw_load_hotkey_idx()
194192
return $_selected_bind_idx
195193
}
196194

197-
function fn_biw_save_hotkey()
195+
function fn_biw_cfg_hotkey_save()
198196
{
199197
local _selected_bind_desc
200198
fn_vmenu_get_current_val '_selected_bind_desc'
@@ -250,11 +248,6 @@ function fn_biw_controller_history()
250248
while fn_util_process_key _key
251249
do
252250
fn_vmenu_actions "$_key"
253-
if [ $? == $UTIL_ACT_CHANGED ]
254-
then
255-
# vmenu handled the action so get next key
256-
continue
257-
fi
258251

259252
case "$_key" in
260253
$CSI_KEY_ENTER)
@@ -293,7 +286,7 @@ function fn_biw_controller_cfg_theme()
293286

294287
case "$_key" in
295288
$CSI_KEY_ENTER|$CSI_KEY_SPC)
296-
fn_theme_save
289+
fn_biw_cfg_theme_save
297290
fn_vmenu_redraw
298291
;;
299292
esac
@@ -302,7 +295,7 @@ function fn_biw_controller_cfg_theme()
302295
fn_theme_load
303296
}
304297

305-
function fn_theme_save()
298+
function fn_biw_cfg_theme_save()
306299
{
307300
local _saved_theme=${THEME_LIST[$theme_active_idx]}
308301
fn_settings_set_param $THEME_PARAM_NAME $_saved_theme
@@ -311,5 +304,81 @@ function fn_theme_save()
311304
fn_vmenu_set_message "Theme saved: ${_saved_theme}"
312305
}
313306

307+
##
308+
# Controller: Dimensions Configuration
309+
##
310+
311+
declare -i biw_dims_save_pending
312+
313+
function fn_biw_controller_cfg_dims()
314+
{
315+
biw_dims_save_pending=0
316+
317+
declare -a slider_ctl_width=(
318+
[$SLIDER_CTL_ATTR_LABEL]='Width'
319+
[$SLIDER_CTL_ATTR_MIN]=40
320+
[$SLIDER_CTL_ATTR_MAX]=80
321+
[$SLIDER_CTL_ATTR_VAL]=$biw_panel_col_size
322+
)
323+
324+
declare -a slider_ctl_height=(
325+
[$SLIDER_CTL_ATTR_LABEL]='Height'
326+
[$SLIDER_CTL_ATTR_MIN]=8
327+
[$SLIDER_CTL_ATTR_MAX]=40
328+
[$SLIDER_CTL_ATTR_VAL]=$biw_panel_row_size
329+
)
330+
331+
local -a _slider_list=(
332+
slider_ctl_width
333+
slider_ctl_height )
334+
335+
fn_slider_init '_slider_list[@]'
336+
fn_slider_redraw
337+
fn_util_draw_footer 'Set Panel Dimensions'
338+
339+
local _key
340+
341+
# we add a condition to fn_util_process_key so that it enable the hmenu
342+
# only when no slider controls are active.
343+
while fn_util_process_key _key '' $((slider_ctl_selected_idx >= 0))
344+
do
345+
fn_slider_actions "$_key"
346+
if [ $? == $UTIL_ACT_CHANGED ]
347+
then
348+
# action handled so get next key
349+
if((!biw_dims_save_pending))
350+
then
351+
fn_util_draw_footer 'Hit [Enter] or [Space] to save; [ESC] to cancel.'
352+
biw_dims_save_pending=1
353+
fi
354+
continue
355+
fi
356+
357+
case "$_key" in
358+
$CSI_KEY_ENTER|$CSI_KEY_SPC)
359+
fn_biw_cfg_dims_save
360+
;;
361+
esac
362+
done
363+
}
364+
365+
function fn_biw_cfg_dims_save()
366+
{
367+
if((!biw_dims_save_pending))
368+
then
369+
return
370+
fi
371+
372+
local -i _rows=${slider_ctl_height[$SLIDER_CTL_ATTR_VAL]}
373+
local -i _cols=${slider_ctl_width[$SLIDER_CTL_ATTR_VAL]}
374+
375+
fn_util_panel_set_dims $_rows $_cols
376+
377+
fn_slider_redraw
378+
fn_util_draw_footer 'Changes saved to settings file.'
379+
380+
biw_dims_save_pending=0
381+
}
382+
314383
# entry point
315384
fn_biw_main

src/biw-panel-browse.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ function fn_biw_controller_browse()
2424
while fn_util_process_key _key
2525
do
2626
fn_vmenu_actions "$_key"
27-
if [ $? == $UTIL_ACT_CHANGED ]
28-
then
29-
# vmenu handled the action so get next key
30-
continue
31-
fi
3227

3328
if [ "$_key" == $CSI_KEY_ENTER ]
3429
then

src/biw-panel-credits.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ declare -a cred_alpha_map
3535
function fn_cred_show()
3636
{
3737
# Panel geometry
38-
cred_height=$((BIW_PANEL_HEIGHT - HMENU_HEIGHT))
39-
cred_width=$BIW_PANEL_WIDTH
40-
cred_row_pos=$HMENU_HEIGHT
38+
cred_height=$((biw_panel_row_size - HMENU_ROW_SIZE))
39+
cred_width=$biw_panel_col_size
40+
cred_row_pos=$HMENU_ROW_SIZE
4141

4242
# geometry of drawing canvas
4343
cred_canvas_row_pos=$cred_row_pos
@@ -54,7 +54,7 @@ function fn_cred_show()
5454

5555
cred_color_map_size=${#cred_color_map[@]}
5656

57-
fn_utf8_box_panel
57+
fn_util_draw_box_panel $cred_row_pos
5858
fn_cred_load_data
5959
fn_util_debug_print
6060
fn_cred_print_data

src/biw-panel-hmenu.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
##
1111

1212
# Layout
13-
declare -ri HMENU_HEIGHT=1
13+
declare -ri HMENU_ROW_SIZE=1
1414
declare -ri HMENU_ITEM_WIDTH=10
1515

16-
declare -i hmenu_width
16+
declare -i hmenu_col_size
1717
declare -i hmenu_row_pos
1818

1919
# Indexes
@@ -36,7 +36,6 @@ function fn_hmenu_init()
3636
hmenu_idx_last=$((hmenu_data_size - 1))
3737

3838
# Layout
39-
hmenu_width=$BIW_PANEL_WIDTH
4039
hmenu_row_pos=0
4140
}
4241

@@ -58,6 +57,7 @@ function fn_hmenu_controller_sub()
5857
local _panel_msg
5958
mapfile -t _panel_msg <<-EOM
6059
60+
6161
${_old_selected_value} Menu Options:
6262
6363
[Down-Arrow]: Enter sub-menu
@@ -67,7 +67,7 @@ ${_old_selected_value} Menu Options:
6767
EOM
6868

6969
# fill the panel with an empty box
70-
fn_utf8_box_panel '_panel_msg[@]'
70+
fn_util_draw_box_panel $((hmenu_row_pos + 1)) '_panel_msg[@]'
7171

7272
# the user should use up and down keys to navigate
7373
local _key
@@ -161,6 +161,8 @@ function fn_hmenu_redraw()
161161
local -i _total_width=0
162162
local -i _print_width
163163

164+
hmenu_col_size=$biw_panel_col_size
165+
164166
for((_item_idx = 0; _item_idx < hmenu_data_size; _item_idx++))
165167
do
166168
fn_hmenu_draw_item $_item_idx
@@ -172,7 +174,7 @@ function fn_hmenu_redraw()
172174
fn_sgr_seq_start
173175
fn_theme_set_attr $THEME_SET_DEF_INACTIVE
174176
fn_sgr_op $SGR_ATTR_UNDERLINE
175-
fn_sgr_print_pad '' $((hmenu_width - _total_width))
177+
fn_sgr_print_pad '' $((hmenu_col_size - _total_width))
176178
fn_sgr_seq_flush
177179

178180
((hmenu_idx_redraws++))

0 commit comments

Comments
 (0)