GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_single_line_text_input_position_update.c Lines: 23 23 100.0 %
Date: 2026-03-06 19:21:09 Branches: 3 3 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
10
 **************************************************************************/
11
12
13
/**************************************************************************/
14
/**************************************************************************/
15
/**                                                                       */
16
/** GUIX Component                                                        */
17
/**                                                                       */
18
/**   Text Input Management (Single Line Text Input)                      */
19
/**                                                                       */
20
/**************************************************************************/
21
22
#define GX_SOURCE_CODE
23
24
25
/* Include necessary system files.  */
26
27
#include "gx_api.h"
28
#include "gx_system.h"
29
#include "gx_widget.h"
30
#include "gx_single_line_text_input.h"
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _gx_single_line_text_input_position_update          PORTABLE C      */
37
/*                                                           6.1          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Kenneth Maxwell, Microsoft Corporation                              */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function update the cursor position according to character     */
45
/*      insert index.                                                     */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    text_input                            Single-line text input widget */
50
/*                                            control block               */
51
/*                                                                        */
52
/*  OUTPUT                                                                */
53
/*                                                                        */
54
/*    Complete status                                                     */
55
/*                                                                        */
56
/*  CALLS                                                                 */
57
/*                                                                        */
58
/*    _gx_widget_font_get                   Get font by specified ID      */
59
/*    _gx_widget_border_width_get           Get widget border width       */
60
/*    _gx_widget_client_get                 Get widget client rectangle   */
61
/*    _gx_system_string_width_get           Get the width of a string     */
62
/*                                                                        */
63
/*  CALLED BY                                                             */
64
/*                                                                        */
65
/*    Application Code                                                    */
66
/*    GUIX Internal Code                                                  */
67
/*                                                                        */
68
/**************************************************************************/
69
13382
UINT _gx_single_line_text_input_position_update(GX_SINGLE_LINE_TEXT_INPUT *text_input)
70
{
71
GX_TEXT_INPUT_CURSOR *cursor_ptr;
72
UINT                  insert_pos;
73
GX_FONT              *gx_font;
74
GX_RECTANGLE          client;
75
GX_VALUE              width;
76
GX_VALUE              x_pos;
77
GX_STRING             string;
78
79
13382
    cursor_ptr = &text_input -> gx_single_line_text_input_cursor_instance;
80
13382
    insert_pos = text_input -> gx_single_line_text_input_insert_pos;
81
82
13382
    _gx_widget_font_get((GX_WIDGET *)text_input, text_input -> gx_prompt_font_id, &gx_font);
83
13382
    _gx_widget_border_width_get((GX_WIDGET *)text_input, &width);
84
13382
    _gx_widget_client_get((GX_WIDGET *)text_input, width, &client);
85
86
    /* Calculate distance from first character to character insert position.  */
87
13382
    string.gx_string_ptr = text_input -> gx_single_line_text_input_buffer;
88
13382
    string.gx_string_length = insert_pos;
89
13382
    _gx_system_string_width_get_ext(gx_font, &string, &width);
90
91
13382
    switch (text_input -> gx_widget_style & GX_STYLE_TEXT_ALIGNMENT_MASK)
92
    {
93
2056
    case GX_STYLE_TEXT_RIGHT:
94
2056
        x_pos = (GX_VALUE)(client.gx_rectangle_right - 1);
95
2056
        break;
96
97
4556
    case GX_STYLE_TEXT_CENTER:
98
4556
        x_pos = client.gx_rectangle_left;
99
4556
        x_pos = (GX_VALUE)(x_pos + 1 + ((client.gx_rectangle_right - client.gx_rectangle_left + 1) >> 1));
100
4556
        break;
101
102
6770
    case GX_STYLE_TEXT_LEFT:
103
    default:
104
6770
        x_pos = (GX_VALUE)(client.gx_rectangle_left + 1);
105
6770
        break;
106
    }
107
108
    /* Pick up draw start position.  */
109
13382
    x_pos = (GX_VALUE)(x_pos - text_input -> gx_single_line_text_input_xoffset);
110
111
    /* Update cursor position.  */
112
13382
    cursor_ptr -> gx_text_input_cursor_pos.gx_point_x = (GX_VALUE)(x_pos + width);
113
114
13382
    return GX_SUCCESS;
115
}
116