Skip to content

Commit a9a2a34

Browse files
committed
Basic documentation up
still need exampels and rounting
1 parent 375ac6a commit a9a2a34

File tree

10 files changed

+282
-175
lines changed

10 files changed

+282
-175
lines changed
2.69 KB
Binary file not shown.

docs/components/button.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,30 @@ centered: bool = False
5151
- `font_size`: Size of the text font
5252
- `font_family`: Font family for the text
5353
- `centered`: If True, the button is centered on the provided position
54+
55+
## Methods
56+
All methods inherited from the [Element](element.md) class.
57+
58+
(Some methods may not be applicable to the Image class, but are included for consistency.)
59+
60+
### Setters
61+
```python
62+
set_label(label: str) -> None
63+
set_color(color: tuple[int, int, int]) -> None
64+
set_hover_color(color: tuple[int, int, int]) -> None
65+
set_click_color(color: tuple[int, int, int]) -> None
66+
set_text_color(color: tuple[int, int, int]) -> None
67+
set_text_hover_color(color: tuple[int, int, int]) -> None
68+
set_text_click_color(color: tuple[int, int, int]) -> None
69+
```
70+
71+
- `set_label`: Set the text displayed on the button
72+
- `set_color`: Set the default button background color
73+
- `set_hover_color`: Set the background color when the button is hovered over
74+
- `set_click_color`: Set the background color when the button is clicked
75+
- `set_text_color`: Set the color of the buttonlabel when not hovered
76+
- `set_text_hover_color`: Set the color of the buttonlabel when hovered over
77+
- `set_text_click_color`: Set the color of the buttonlabel when clicked
78+
79+
### Mouse and Click Events
80+
See the [Mouse and Click Events](element.md#mouse-and-click-events) section in the Element documentation.

docs/components/element.md

Lines changed: 59 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,37 +34,72 @@ centered: bool = False
3434

3535
## Methods
3636

37-
### Position Control
37+
### Basic methods
3838
```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.
4444

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
4753
```
4854

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
5063
```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
5372

54-
# Show element
55-
element.set_display(True)
5673

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
5991
```
92+
- `flow`: Moves the element from start_position to end_position over a specified time. If loop is True, the animation will repeat.
6093

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
6297
```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.

docs/components/image.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,26 @@ Three ways to control image size:
4646
2. Scale factor (`scale` parameter)
4747
3. Exact dimensions (`width` and `height` parameters)
4848

49-
## Performance Tips
49+
## Methods
5050

51+
All methods inherited from the [Element](element.md) class.
52+
53+
(Some methods may not be applicable to the Image class, but are included for consistency.)
54+
55+
### Setters
56+
```python
57+
set_image(image_path: str) -> None
58+
scale(scale: int) -> None
59+
```
60+
- `set_image`: Set a new image for the element
61+
- `scale`: Set a new scale for the image
62+
63+
### Getters
5164
```python
52-
# Efficient loading for multiple instances
53-
shared_image = pygame.image.load("sprite.png")
54-
for pos in positions:
55-
image = pygameui.Image(
56-
position=pos,
57-
image=shared_image
58-
)
65+
get_image() -> pygame.Surface
66+
get_scale() -> int
5967
```
6068

61-
## Best Practices
69+
- `get_image`: Get the current image of the element
70+
- `get_scale`: Get the current scale of the image
6271

63-
- Use appropriate image sizes
64-
- Convert images to PNG for transparency
65-
- Cache frequently used images
66-
- Consider memory usage with large images

docs/components/index.md

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Components Guide
22

3-
**Next:** [Animation Guide](../animation.md) | **Previous:** [Basic Tutorial](../tutorials/basic.md)
4-
53
## Available Components
64

75
1. [Element](element.md) - Base component
@@ -27,28 +25,3 @@
2725
5. [Image](image.md) - Image display
2826
- Multiple formats
2927
- Scaling options
30-
- Performance optimization
31-
32-
## Usage Examples
33-
34-
Each component page includes:
35-
- Basic implementation
36-
- Available properties
37-
- Common use cases
38-
- Performance tips
39-
40-
## Quick Reference
41-
42-
```python
43-
# Basic element creation pattern
44-
element = pygameui.ComponentName(
45-
position=(x, y),
46-
# ... other properties
47-
)
48-
49-
# Update and draw pattern
50-
element.update() # or element.update(events)
51-
element.draw(screen)
52-
```
53-
54-
**Next:** Learn about [Animation](../animation.md)

docs/components/input.md

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,36 @@ centered: bool = False
4444
- `hint`: Placeholder text when the field is empty
4545
- `centered`: If True, the element is centered on the provided position
4646

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.
60+
61+
### Setters
5562
```python
56-
# Only allow numbers
57-
input_field.set_filter("0123456789", exclude_mode=False)
63+
set_max_length(length: int) -> None
64+
set_filter(filter: str, only_allow_filter: bool = False) -> None
65+
set_hint(hint: str) -> None
66+
set_value(value: str) -> None
67+
```
68+
69+
- `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.
73+
74+
### Getters
75+
```python
76+
get_value() -> str
77+
```
5878

59-
# Exclude special characters
60-
input_field.set_filter("@#$%^&*()", exclude_mode=True)
61-
```
79+
- `get_value`: Get the current value of the input field.

docs/components/text.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ font_size: int = 20,
2424
font_family: str = "Arial",
2525
width: int = 0,
2626
height: int = 0,
27+
anti_aliasing: bool = True,
2728
centered: bool = False
2829
```
2930
- `position`: Tuple of (x, y) coordinates
@@ -33,19 +34,34 @@ centered: bool = False
3334
- `font_family`: Font family to use
3435
- `width`: Width of the text box (0 for auto)
3536
- `height`: Height of the text box (0 for auto)
37+
- `anti_aliasing`: If True, the text is anti-aliased meaning smoother edges
3638
- `centered`: If True, the text is centered on the provided position
3739

3840
## Methods
41+
All methods inherited from the [Element](element.md) class.
3942

40-
### Text Manipulation
43+
(Some methods may not be applicable to the Image class, but are included for consistency.)
44+
45+
### Setters
4146
```python
42-
# Change text content
43-
text.change_text("New text")
47+
set_content(content: str) -> None
48+
set_color(color: tuple[int, int, int]) -> None
49+
set_font_size(font_size: int) -> None
50+
set_font_family(font_family: str) -> None
51+
```
52+
53+
- `set_content`: Set the text content
54+
- `set_color`: Set the text color
55+
- `set_font_size`: Set the font size
56+
- `set_font_family`: Set the font family
4457

45-
# Change text color
46-
text.change_text_color((255, 0, 0))
58+
### Getters
59+
```python
60+
get_content() -> str
4761
```
4862

63+
- `get_content`: Get the current text content
64+
4965
## Font Support
5066

5167
Supported font families:

examples/login_screen.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767

6868
# Handle login attempt
6969
def attempt_login():
70-
username = username_input.get_text()
71-
password = password_input.get_text()
70+
username = username_input.get_value()
71+
password = password_input.get_value()
7272

7373
if username == "admin" and password == "password":
7474
status_msg.change_text("Login successful!")

0 commit comments

Comments
 (0)