EiffelVision 2 HowTo's

by Ian King (modified: 2008 Jun 21)

    Contents
  1. How do I set the size of an EV_PIXMAP?
  2. How do I have multi-line text in an EV_GRID?
  3. How do I prevent my widget from losing focus when tabbing?
  4. How do I have contextual menus coexist alongside pick and drop?

How do I set the size of an EV_PIXMAP?

An EV_PIXMAP widget is a little different than other widgets in the sense that setting its minimum size will not change the size of the drawable canvas held within. In order to set the size of the pixmap, you have to call 'set_size'. This will resize the static image data to the required size, you can then call 'set_minimum_size' to the same as the image size then the pixmap will not shrink beyond the image data.

-- Set the image size. my_pixmap.set_size (200, 200) -- Set the minimum size of the widget to match the image size. my_pixmap.set_minimum_size (200, 200)

How do I have multi-line text in an EV_GRID?

An EV_GRID defaults to a fixed row height implementation for optimization purposes. To allow a multi-line label item you have to set the pixel height of the row in to which the label item is placed, like as follows. create l_grid l_grid.disable_row_height_fixed create l_label_item.make_with_text ("Multi%NLined%NText") l_grid.set_item (1, 1, l_label_item) l_label_item.row.set_height (l_label_item.text_height)

How do I prevent my widget from losing focus when tabbing?

Each widget has a way of disabling the default key processing (ie: for tabbing, key events, dialog actions) via 'set_default_key_processing_handler

With this routine you can pass a predicate agent (boolean function) that takes an EV_KEY as its first open argument, this will override all default key processing for that widget if the agent returns False.

-- Prevent 'text_field' from having the focus lost when pressing tab create text_field text_field.set_default_key_processing_agent ( agent (a_key: EV_KEY): BOOLEAN do -- If Tab key then return False -- to prevent loss of focus when Tab key is pressed Result := a_key.code /= {EV_KEY_CONSTANTS}.key_tab end )

How do I have contextual menus coexist alongside pick and drop?

Here is some sample code that can be copied over {MAIN_WINDOW}.build_main_container of a default Vision2 wizard application. It demonstrates how to set up a simple pebble transportation of a string from a source button to a target button via a context menu by right clicking with the control key depressed, otherwise a default pick and drop will take place. Through the use of a context menu handler agent, we can easily populate a list related to the currently picked pebble passed to the agent based on the source of the transport, which is also passed.

build_main_container is -- Create and populate `main_container'. require main_container_not_yet_created: main_container = Void local source_button, target_button: EV_BUTTON do create main_container create source_button.make_with_text ("Source") source_button.set_pebble ("Pebble") -- Set up the configurable pick and drop menu source_button.set_configurable_target_menu_mode source_button.set_configurable_target_menu_handler (agent context_menu_handler) create target_button.make_with_text ("Target") -- Allow target button to be a recipient of a string pebble. target_button.drop_actions.extend (agent print) main_container.extend (source_button) main_container.extend (target_button) ensure main_container_created: main_container /= Void end context_menu_handler (a_menu: EV_MENU; a_target_list: ARRAYED_LIST [EV_PND_TARGET_DATA]; a_source: EV_PICK_AND_DROPABLE; a_pebble: ANY) is -- Context menu do if (create {EV_ENVIRONMENT}).application.ctrl_pressed then -- If the Ctrl button is pressed it will populate the context menu with a single item, -- this will show the context menu instead of defaulting to normal Pick and Drop -- There is also an option to revert back to the normal pick and drop by clicking on the -- the first menu item in the context menu. a_menu.extend (create {EV_MENU_ITEM}.make_with_text ("Print")) end end