Vision 2 | ||
---|---|---|
<<< Previous | Next >>> |
![]() | Describe what a minimal application consists of. Create a standard application and attach a single frame window. Allow the application to close. |
The simplest application in Vision consists of an instance of EV_APPLICATION and a single window, typically an instance of EV_FRAME. The application object initializes the window and starts the event processing loop. Example 1 shows a minimal application class.
Example 1. Minimal Application
class APPLICATION inherit EV_APPLICATION (1) creation start feature -- Initialization start is -- Create the application, set up `main_window' -- and then launch the application. do default_create (2) create main_window main_window.show (3) launch (4) end feature {NONE} -- Implementation main_window: MAIN_WINDOW -- Main window. end -- class APPLICATION |
The corresponding MAIN_WINDOW class is shown in Example 2. The window initializes itself with a ...
Example 2. Minimal Application Window
class MAIN_WINDOW inherit EV_TITLED_WINDOW redefine initialize end feature -- Initialisation initialize is -- Initialize window. local environment: EV_ENVIRONMENT do Precursor {EV_TITLED_WINDOW} set_title ("Minimal Application") -- allow close using X button create environment close_request_actions.extend (agent (environment.application).destroy) end end -- class MAIN_WINDOW |
The widget created by this application is a single framed window with the title Minimal Application. The window contains no other widgets and is painted grey. You may notice that the size of the window differs depending on your computer platform. The source code did not explicitly set the initial size of the window and because of this, the underlying windowing system has used its own default size. On Windows, the window is sized so that the title bar and border are the only visible elements. On GTK, the central panel of the window is, in this case, sized to 200 by 200 pixels. This highlights that fact that a number of underlying windowing system differences and anomolies can surface even when using a library such as Vision 2. Differences such as this can be easily overcome. In this case, all we need to do is to give the window an initial size in the initialize routine using the set_size routine. Simple as these problems are to fix, you still need to test an application on all target platforms to discover them. The GTK version of this window is shown in Figure 1.
<<< Previous | Home | Next >>> |
Model | The EV_APPLICATION Interface |