Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
godot
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
community
godot
Commits
cb996d71
Unverified
Commit
cb996d71
authored
Apr 10, 2018
by
Rémi Verschelde
Committed by
GitHub
Apr 10, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #18095 from robfram/fix-lineedit-17113
LineEdit placeholder alignment, content margins, and overflow bugs
parents
fd32a981
53b51f68
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
4 deletions
+17
-4
line_edit.cpp
scene/gui/line_edit.cpp
+16
-4
line_edit.h
scene/gui/line_edit.h
+1
-0
No files found.
scene/gui/line_edit.cpp
View file @
cb996d71
...
...
@@ -602,6 +602,7 @@ void LineEdit::_notification(int p_what) {
}
int
x_ofs
=
0
;
int
cached_text_width
=
text
.
empty
()
?
cached_placeholder_width
:
cached_width
;
switch
(
align
)
{
...
...
@@ -615,15 +616,15 @@ void LineEdit::_notification(int p_what) {
if
(
window_pos
!=
0
)
x_ofs
=
style
->
get_offset
().
x
;
else
x_ofs
=
int
(
size
.
width
-
(
cached_width
))
/
2
;
x_ofs
=
MAX
(
style
->
get_margin
(
MARGIN_LEFT
),
int
(
size
.
width
-
(
cached_text_width
))
/
2
)
;
}
break
;
case
ALIGN_RIGHT
:
{
x_ofs
=
int
(
size
.
width
-
style
->
get_offset
().
x
-
(
cached_width
));
x_ofs
=
MAX
(
style
->
get_margin
(
MARGIN_LEFT
),
int
(
size
.
width
-
style
->
get_margin
(
MARGIN_RIGHT
)
-
(
cached_text_width
)
));
}
break
;
}
int
ofs_max
=
width
-
style
->
get_m
inimum_size
().
width
;
int
ofs_max
=
width
-
style
->
get_m
argin
(
MARGIN_RIGHT
)
;
int
char_ofs
=
window_pos
;
int
y_area
=
height
-
style
->
get_minimum_size
().
height
;
...
...
@@ -881,7 +882,7 @@ void LineEdit::set_cursor_at_pixel_pos(int p_x) {
}
break
;
case
ALIGN_RIGHT
:
{
pixel_ofs
=
int
(
size
.
width
-
style
->
get_
offset
().
x
-
(
cached_width
));
pixel_ofs
=
int
(
size
.
width
-
style
->
get_
margin
(
MARGIN_RIGHT
)
-
(
cached_width
));
}
break
;
}
...
...
@@ -1014,6 +1015,15 @@ String LineEdit::get_text() const {
void
LineEdit
::
set_placeholder
(
String
p_text
)
{
placeholder
=
tr
(
p_text
);
if
((
max_length
<=
0
)
||
(
placeholder
.
length
()
<=
max_length
))
{
Ref
<
Font
>
font
=
get_font
(
"font"
);
cached_placeholder_width
=
0
;
if
(
font
!=
NULL
)
{
for
(
int
i
=
0
;
i
<
placeholder
.
length
();
i
++
)
{
cached_placeholder_width
+=
font
->
get_char_size
(
placeholder
[
i
]).
width
;
}
}
}
update
();
}
...
...
@@ -1127,6 +1137,7 @@ void LineEdit::clear_internal() {
_clear_undo_stack
();
cached_width
=
0
;
cached_placeholder_width
=
0
;
cursor_pos
=
0
;
window_pos
=
0
;
undo_text
=
""
;
...
...
@@ -1468,6 +1479,7 @@ LineEdit::LineEdit() {
_create_undo_state
();
align
=
ALIGN_LEFT
;
cached_width
=
0
;
cached_placeholder_width
=
0
;
cursor_pos
=
0
;
window_pos
=
0
;
window_has_focus
=
true
;
...
...
scene/gui/line_edit.h
View file @
cb996d71
...
...
@@ -84,6 +84,7 @@ private:
int
max_length
;
// 0 for no maximum
int
cached_width
;
int
cached_placeholder_width
;
struct
Selection
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment