You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/components/element.md
+59-24Lines changed: 59 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,37 +34,72 @@ centered: bool = False
34
34
35
35
## Methods
36
36
37
-
### Position Control
37
+
### Basic methods
38
38
```python
39
-
# Set new position
40
-
element.set_position((200, 200))
41
-
42
-
# Get current position
43
-
pos =element.get_position()
39
+
draw(surface: pygame.Surface) ->None
40
+
update() ->None
41
+
```
42
+
-`draw`: Draws the element on the provided surface.
43
+
-`update`: Updates the element's state. This method should be called every frame to ensure animations and events are processed.
44
44
45
-
# Center the element
46
-
element.centered =True
45
+
### Setters
46
+
```python
47
+
set_position(position: tuple[int,int]) ->None
48
+
set_framerate(framerate: int) ->None
49
+
set_display(display: bool) ->None
50
+
set_color(color: tuple[int, int, int]) ->None
51
+
set_border_radius(radius: int) ->None
52
+
set_animate(state: bool) ->None
47
53
```
48
54
49
-
### Display Control
55
+
-`set_position`: Set the position of the element
56
+
-`set_framerate`: Set the framerate for the elements animations
57
+
-`set_display`: If set True, the element is drawn when element.draw is called
58
+
-`set_color`: Set the color of the element
59
+
-`set_border_radius`: Set the border radius of the element
60
+
-`set_animate`: If set True, the elements set animations are will be preformed when the element is updated
61
+
62
+
### Getters
50
63
```python
51
-
# Hide element
52
-
element.set_display(False)
64
+
get_position() -> tuple[int, int]
65
+
get_display() ->bool
66
+
get_animation_state() ->bool
67
+
```
68
+
69
+
-`get_position`: Get the current position of the element, if the element is centered, the returned position is the center of the element
70
+
-`get_display`: Get the display state of the element
71
+
-`get_animation_state`: Get the animation state of the element, if the element is being animated, the returned value is True, otherwise False
53
72
54
-
# Show element
55
-
element.set_display(True)
56
73
57
-
# Toggle visibility
58
-
element.toggle_display()
74
+
### Animations
75
+
76
+
```python
77
+
flow(
78
+
start_position: tuple[int, int],
79
+
end_position: tuple[int, int],
80
+
time: int,
81
+
loop: bool=False
82
+
) ->None
83
+
84
+
jump(
85
+
start_position: tuple[int, int],
86
+
end_position: tuple[int, int],
87
+
time: int,
88
+
loop: bool=False,
89
+
ratio: float=1
90
+
) ->None
59
91
```
92
+
-`flow`: Moves the element from start_position to end_position over a specified time. If loop is True, the animation will repeat.
60
93
61
-
### Mouse Interaction
94
+
-`jump`: Teleports the element from start_position to end_position over a specified time. If loop is True, the animation will repeat.
95
+
96
+
### Mouse and Click Events
62
97
```python
63
-
# Check if mouse is over element
64
-
if element.is_hovered():
65
-
print("Mouse over!")
66
-
67
-
# Check if element is clicked
68
-
if element.is_clicked():
69
-
print("Clicked!")
70
-
```
98
+
is_hovered() ->bool
99
+
is_clicked(button: int=1) ->bool
100
+
was_clicked() ->bool
101
+
```
102
+
103
+
-`is_hovered`: Check if the mouse is hovering over the element. Returns True if hovered, False otherwise.
104
+
-`is_clicked`: Check if the element is hovered and the provided mouse button is down. Returns True if clicked, False otherwise. The default button is 1 (left mouse button).
105
+
-`was_clicked`: Check if the element was clicked in the last frame. Returns True if clicked, False otherwise.
Copy file name to clipboardExpand all lines: docs/components/input.md
+31-13Lines changed: 31 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,18 +44,36 @@ centered: bool = False
44
44
-`hint`: Placeholder text when the field is empty
45
45
-`centered`: If True, the element is centered on the provided position
46
46
47
-
### Input Features
48
-
- Text filtering
49
-
- Custom borders
50
-
- Active/inactive states
51
-
- Cursor navigation
52
-
- Text selection
53
-
54
-
### Input Filtering
47
+
## Methods
48
+
All methods inherited from the [Element](element.md) class.
49
+
50
+
(Some methods may not be applicable to the Image class, but are included for consistency.)
51
+
52
+
### Basic methods
53
+
```python
54
+
draw(surface: pygame.Surface) ->None
55
+
update(events: list) ->None
56
+
```
57
+
58
+
-`draw`: Draws the input field on the provided surface.
59
+
-`update`: Updates the input field and processes events. The `events` parameter should be the list of events from `pygame.event.get()`, se [Basic structure](../getting-started.md#Basic-Structure). This method should be called every frame to ensure animations and events are processed.
-`set_max_length`: Set the maximum length of the input field.
70
+
-`set_filter`: Set a filter for the input field. The `filter` parameter can be a string of characters. If `only_allow_filter` is set to False, only characters in the filter will be allowed. If set to True, all characters except those in the filter will be allowed.
71
+
-`set_hint`: Set the hint text for the input field.
72
+
-`set_value`: Set the current value of the input field.
0 commit comments