Search code examples
abapsap-guidynpro

Set width of toolbar button defined in cl_gui_toolbar


I've got a toolbar defined with class cl_gui_toolbar which is displayed in a container (which got created via class cl_gui_custom_container). I've added some buttons and button groups into it.

Now my user wants one of those button groups to be bigger, because the user might not recognize that the button is there. Is there any method to set the width of the button-group?

Here is my current code:

METHOD init_toolbar.

    DATA: lt_buttons_data TYPE ttb_button,
          ls_button_data TYPE LINE OF ttb_button.

    go_toolbar_container = NEW cl_gui_custom_container( container_name = 'TOOLBAR_1000' ).
    go_toolbar = NEW cl_gui_toolbar( parent = go_toolbar_container ).

" Some other buttons
" ...
" ...

  CLEAR ls_button_data.
  CLEAR lt_buttons_data.

  ls_button_data-function =  'DBFILTER'.
  ls_button_data-icon =      '@EX@'.
  ls_button_data-quickinfo = 'Quickinfo'.
  ls_button_data-text =      'SmallText'.
  ls_button_data-butn_type = cntb_btype_menu.
  APPEND ls_button_data TO lt_buttons_data.

  go_toolbar->add_button_group( data_table = lt_buttons_data ).

  CLEAR ct_expand.
  ct_expand = NEW cl_ctmenu( ).

  ct_expand->add_function( fcode = '1' text = '1' checked = abap_false ).
  ct_expand->add_function( fcode = '2' text = '2' checked = abap_false ).
  ct_expand->add_function( fcode = '3' text = '3' checked = abap_false ).

  CLEAR wa_ctxmenu.
  wa_ctxmenu-function = 'DBFILTER'.
  wa_ctxmenu-ctmenu = ct_expand.
  APPEND wa_ctxmenu TO table_ctxmenu.
  go_toolbar->assign_static_ctxmenu_table( table_ctxmenu = table_ctxmenu ).

ENDMETHOD.

Do you know a way how to set the width of this button-group?

PS: I just got the info, that the text of the button ( e. g. "smallText" ) can be replaced if a longer text, if there is no other way .


Solution

  • It's not possible to customize the width of a button in class CL_GUI_TOOLBAR as a number of pixels.

    As a workaround:

    • Enter a longer text. Maybe enter "non-breaking spaces" at the end of your text. This is the Unicode character U+00A0 (CL_ABAP_CONV_IN_CE=>UCCP( '00A0' )).
    • Instead of CL_GUI_TOOLBAR, use the class CL_GUI_HTML_VIEWER to define the buttons with HTML code and CSS styles. But I doubt it's worth spending time for that.