Cross-platform C SDK logo

Cross-platform C SDK

Window

❮ Back
Next ❯
This page has been automatically translated using the Google Translate API services. We are working on improving texts. Thank you for your understanding and patience.

Functions

Window*window_create (...)
voidwindow_destroy (...)
voidwindow_panel (...)
voidwindow_OnClose (...)
voidwindow_OnMoved (...)
voidwindow_OnResize (...)
voidwindow_title (...)
voidwindow_show (...)
voidwindow_hide (...)
uint32_twindow_modal (...)
voidwindow_stop_modal (...)
voidwindow_hotkey (...)
voidwindow_next_tabstop (...)
voidwindow_previous_tabstop (...)
voidwindow_update (...)
voidwindow_origin (...)
voidwindow_size (...)
V2Dfwindow_get_origin (...)
S2Dfwindow_get_size (...)
S2Dfwindow_get_client_size (...)
voidwindow_defbutton (...)
voidwindow_cursor (...)

Window objects are the top-level containers within the user interface (Figure 1). They are made up of the title bar, where the close, maximize and minimize buttons are located, the interior zone and the frame. If the window supports resizing, said frame can be dragged with the mouse to change its size. The interior zone or client area of ​​the window is configured by means of a main Panel. In Hello World! you have a simple example of composing and displaying a window.


1. Window size

In principle, the size of the window is calculated automatically based on the Natural sizing of its main panel, but it can be altered at any time.

  • Use window_size to resize the main panel.
  • Use the ekWINDOW_MAX flag to include the maximize button in the title bar.
  • Use the ekWINDOW_MIN flag to include the minimize button in the title bar.
  • Use the ekWINDOW_RESIZE flag to create a window with resizable borders.

The change in the dimensions of the client area implies a re-location and re-sizing of the interior controls. This is handled automatically by Layout objects based on how their Cell expansion has been configured, which will propagate recursively through all sublayouts. In Die you have an example of resizing a window (Figure 2).

Shows how the excess is distributed among the controls when resizing the window.
Figure 2: Resizing the window in the demo Die.

2. Closing the window

Normally a window is closed by pressing the [X] button located to the right of the title bar. But sometimes it can be useful to also close it with the [ENTER] or [ESC] keys. Closing a window implies hiding it, but not destroying it. That is, we can show an already closed window again using window_show. In the case that the closing is conditioned to a state of the application, such as saving a file for example, we must assign a handler through window_OnClose and decide there whether to close it or not.

Destroying a window implicitly destroys all of its internal elements and controls.

3. Modal windows

They are those that, when launched, block the previous window (or parent) until it is closed (Figure 3). Being "modal" or not is not a characteristic of the window itself, but of the way it is launched. In Hello Modal Window! you have an example of use.

  • Use window_modal to display a window in modal mode.
  • Use window_stop_modal to hide it and stop the modal loop.
  • Various modal windows.
    Figure 3: Multiple modal windows.

After calling window_modal, the program stops at this point, waiting for the window to close, which can be done using [X], [ENTER], [ESC] or by calling window_stop_modal (Listing 2). The value returned by this function will be:

  • ekGUI_CLOSE_ESC (1). If the modal window was closed by pressing [ESC].
  • ekGUI_CLOSE_INTRO (2). If the modal window was closed by pressing [ENTER].
  • ekGUI_CLOSE_BUTTON (3). If the modal window was closed by pressing [X].
  • The value indicated in window_stop_modal.
  • Listing 2: Using modal windows.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    
    static void i_OnAcceptClick(Window *window, Event *e)
    {
        window_stop_modal(window, 300);
    }
    
    Window *window = i_create_window_with_accept_button();
    // The program will stop HERE until window is closed
    uint32_t ret = window_modal(window);
    
    if (ret == 1)
    {
        // Closed by ESC
    }
    else if (ret == 2)
    {
        // Closed by INTRO
    }
    else if (ret == 3)
    {
        // Closed by [X]
    }
    else if (ret == 300)
    {
        // Closed by window_stop_modal
    }
    
    window_destroy(&window);
    

4. Hotkeys

Normally, the keyboard focus will be fixed to some control inside the window like Edit, Button or View. But it is possible that we want to define global actions associated with a specific key.

hotkeys will take precedence over keyboard (Figure 4) focus. That is, if we have an action linked to the [F9] key, it will be executed when the key is pressed and the ekGUI_EVENT_KEYDOWN(F9) event will not be received by the control that has the focus.

Keyboard shortcut.
Figure 4: Processing a hotkey.

window_create ()

Create a new window.

Window*
window_create(const uint32_t flags);
flags

Combination of window_flag_t values.

Return

The window.


window_destroy ()

Destroy the window and all its contents.

void
window_destroy(Window **window);
window

The window. Will be set to NULL after destruction.

Remarks

Panels, layouts and components will be recursively destroyed.


window_panel ()

Associate the main panel with a window.

void
window_panel(Window *window,
             Panel *panel);
window

The window.

panel

Main panel, which integrates all the content of the window (views, controls, etc).

Remarks

The size of the window will be adjusted based on the Natural sizing of the main panel.


window_OnClose ()

Set an event handler for the window closing.

void
window_OnClose(Window *window,
               Listener *listener);
window

The window.

listener

Callback function to be called before closing a window.

Remarks

See Closing the window.


window_OnMoved ()

Set an event handler for moving the window on the desktop.

void
window_OnMoved(Window *window,
               Listener *listener);
window

The window.

listener

Callback function to be called as the title bar is dragged and the window moves across the desktop.

Remarks

See GUI Events.


window_OnResize ()

Set an event handler for window resizing.

void
window_OnResize(Window *window,
                Listener *listener);
window

The window.

listener

Callback function to be called as the outer edges of the window are dragged to resize.

Remarks

The resizing and relocation of elements is done automatically based on the main Layout, so it is not usually necessary for the application to respond to this event. See GUI Events.


window_title ()

Set the text that will display the window in the title bar.

void
window_title(Window *window,
             const char_t *text);
window

The window.

text

UTF8 C-string terminated in null character '\0'.


window_show ()

Show the window. By default windows are created hidden. You have to show them explicitly.

void
window_show(Window *window);
window

The window.


window_hide ()

Hide the window.

void
window_hide(Window *window);
window

The window.


window_modal ()

Launch a window in modal mode.

uint32_t
window_modal(Window *window,
             Window *parent);
window

The window.

parent

The parent window.

Return

Value returned by window_stop_modal.

Remarks

parent stop receiving events until you call window_stop_modal.


window_stop_modal ()

Ends the modal cycle of a window.

void
window_stop_modal(Window *window,
                  const uint32_t return_value);
window

The window previously launched with window_modal.

return_value

Value to be returned window_modal.


window_hotkey ()

Sets an action associated with pressing a key.

void
window_hotkey(Window *window,
              const vkey_t key,
              const uint32_t modifiers);
window

The window.

key

The key.

modifiers

Modifiers. 0 or combination of mkey_t.

Remarks

See Hotkeys.


window_next_tabstop ()

Moves keyboard focus to the next control in the tab-list. It has the same effect as pressing [TAB].

void
window_next_tabstop(Window *window);
window

The window.

Remarks

Equivalent to layout_next_tabstop. See Tabstops.


window_previous_tabstop ()

Moves the keyboard focus to the previous control in the tab-list. This has the same effect as pressing [SHIFT]+[TAB].

void
window_previous_tabstop(Window *window);
window

The window.

Remarks

Equivalent to layout_previous_tabstop. See Tabstops.


window_update ()

Recalculate the position and size of the controls after modifying any Layout.

void
window_update(Window *window);
window

The window.


window_origin ()

Move the window to specific desktop coordinates.

void
window_origin(Window *window,
              const V2Df origin);
window

The window.

origin

Position (x,y) of the upper-left corner of the window.


window_size ()

Set the size of the client area of the window.

void
window_size(Window *window,
            const S2Df size);
window

The window.

size

Main panel size.

Remarks

The final size will depend on the window frame and desktop theme settings. This measure only refers to the interior area.


window_get_origin ()

Get the window position.

V2Df
window_get_origin(const Window *window);
window

The window.

Return

Position (x,y) from the upper-left corner of the window.


window_get_size ()

Get the total dimensions of the window.

S2Df
window_get_size(const Window *window);
window

The window.

Return

Window size.

Remarks

The frame and title bar are taken into account.


window_get_client_size ()

Get the dimensions of the client area of the window.

S2Df
window_get_client_size(const Window *window);
window

The window.

Return

Main panel size.


window_defbutton ()

Set the default window button. It will be activated when pressed [Intro].

void
window_defbutton(Window *window,
                 Button *button);
window

The window.

button

The button.


window_cursor ()

Change the mouse cursor.

void
window_cursor(Window *window,
              const gui_cursor_t cursor,
              const Image *image,
              const real32_t hot_x,
              const real32_t hot_y);
window

The window.

cursor

Identifier of the new cursor.

image

Custom image. Only valid in ekGUI_CURSOR_USER.

hot_x

The x coordinate of the click point. Only valid in ekGUI_CURSOR_USER.

hot_y

The y coordinate of the click point. Only valid in ekGUI_CURSOR_USER.

Remarks

hot_x, hot_y indicate the "sensitive" point within the image, which will indicate the exact position of the mouse.

❮ Back
Next ❯