Skip to content

Commit e831c08

Browse files
committed
Basic docs
1 parent 78c142d commit e831c08

File tree

13 files changed

+594
-16
lines changed

13 files changed

+594
-16
lines changed

README.md

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,16 @@ A class for creating input fields. It extends the `Text` class and adds input-sp
3333
### Button
3434
A class for creating buttons. It extends the `Element` class and adds button-specific attributes and methods.
3535

36-
## Creating Custom Elements
37-
You can create custom UI elements by extending the base `Element` class. Here is an example of a custom element:
38-
39-
```python
40-
class CustomElement(pygameui.Element):
41-
def __init__(self, position, width, height, color):
42-
super().__init__(position, width, height, color)
43-
44-
def draw(self, surface):
45-
super().draw(surface)
46-
# Add custom drawing code here
47-
48-
def update(self):
49-
super().update()
50-
# Add custom update code here
51-
```
36+
## Learn more in the docs!
37+
- [Getting Started](docs/getting-started.md)
38+
- [Components Guide](docs/components/index.md)
39+
- [Basic Tutorial](docs/tutorials/basic.md)
40+
- [Animation Guide](docs/features/animation.md)
41+
42+
43+
## Quick Links
44+
- [Examples](docs/examples/index.md)
45+
- [Gallery](docs/examples/gallery.md)
46+
47+
## Getting Help
48+
- [GitHub Issues](https://github.com/trymbf/pygameui/issues)
29.6 KB
Binary file not shown.

docs/components/button.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Button
2+
3+
Buttons provide clickable interface elements with hover effects.
4+
5+
## Basic Usage
6+
7+
```python
8+
button = pygameui.Button(
9+
position=(100, 100),
10+
content="Click Me",
11+
width=200,
12+
height=50,
13+
color=(255, 255, 255),
14+
hover_color=(200, 200, 200),
15+
click_color=(150, 150, 150),
16+
text_color=(0, 0, 0),
17+
centered=True
18+
)
19+
```
20+
21+
## Properties
22+
23+
```python
24+
position: tuple[int, int],
25+
width: int = 200,
26+
height: int = 50,
27+
border_radius: int = 10,
28+
content: str = "Click me.",
29+
color: tuple[int, int, int] = (255, 255, 255),
30+
hover_color: tuple[int, int, int] = (200, 200, 200),
31+
click_color: tuple[int, int, int] = (150, 150, 150),
32+
text_color: tuple[int, int, int] = (100, 100, 100),
33+
text_hover_color: tuple[int, int, int] = (0, 0, 0),
34+
text_click_color: tuple[int, int, int] = (0, 0, 0),
35+
font_size: int = 20,
36+
font_family: str = "Arial",
37+
centered: bool = False
38+
```
39+
40+
- `position`: Tuple of (x, y) coordinates
41+
- `width`: Width of the button
42+
- `height`: Height of the button
43+
- `border_radius`: Radius for rounded corners
44+
- `content`: Text displayed on the button
45+
- `color`: Default button backgroundcolor
46+
- `hover_color`: Backgroundcolor when the button is hovered over
47+
- `click_color`: Backgroundcolor when the button is clicked
48+
- `text_color`: Color of the text when not hovered
49+
- `text_hover_color`: Color of the text when hovered over
50+
- `text_click_color`: Color of the text when clicked
51+
- `font_size`: Size of the text font
52+
- `font_family`: Font family for the text
53+
- `centered`: If True, the button is centered on the provided position
54+
55+
### Button States
56+
- Normal: Default appearance
57+
- Hover: When mouse is over the button
58+
- Click: When button is being pressed

docs/components/element.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Element Class
2+
3+
The Element class is the foundation of all UI components in PygameUI.
4+
5+
## Basic Usage
6+
7+
```python
8+
element = pygameui.Element(
9+
position=(100, 100),
10+
width=200,
11+
height=100,
12+
color=(255, 255, 255),
13+
border_radius=10,
14+
centered=False
15+
)
16+
```
17+
18+
## Properties
19+
```python
20+
position: tuple[int, int],
21+
width: int,
22+
height:int,
23+
color: tuple[int, int, int] = (255, 255, 255),
24+
border_radius: int = 0,
25+
centered: bool = False
26+
```
27+
28+
- `position`: Tuple of (x, y) coordinates
29+
- `width`: Width of the element
30+
- `height`: Height of the element
31+
- `color`: RGB tuple for element color
32+
- `border_radius`: Radius for rounded corners
33+
- `centered`: If True, the element is centered on the provided position
34+
35+
## Methods
36+
37+
### Position Control
38+
```python
39+
# Set new position
40+
element.set_position((200, 200))
41+
42+
# Get current position
43+
pos = element.get_position()
44+
45+
# Center the element
46+
element.centered = True
47+
```
48+
49+
### Display Control
50+
```python
51+
# Hide element
52+
element.set_display(False)
53+
54+
# Show element
55+
element.set_display(True)
56+
57+
# Toggle visibility
58+
element.toggle_display()
59+
```
60+
61+
### Mouse Interaction
62+
```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+
```

docs/components/image.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Image Element
2+
3+
The Image class allows you to display images in your UI.
4+
5+
## Basic Usage
6+
7+
```python
8+
image = pygameui.Image(
9+
position=(100, 100),
10+
image_path="path/to/image.png",
11+
width=200, # Optional
12+
height=150, # Optional
13+
scale=1, # Optional
14+
centered=True
15+
)
16+
```
17+
18+
## Properties
19+
```python
20+
position: tuple[int, int],
21+
image_path: str,
22+
width: int = 0,
23+
height: int = 0,
24+
scale:int = 1,
25+
centered: bool = False
26+
```
27+
28+
- `position`: Tuple of (x, y) coordinates
29+
- `image_path`: Path to the image file
30+
- `width`: Width of the image (optional, 0 for auto, overrides scale)
31+
- `height`: Height of the image (optional, 0 for auto, overrides scale)
32+
- `scale`: Scale factor for the image (optional, default is 1)
33+
- `centered`: If True, the image is centered on the provided position
34+
35+
## Supported Formats
36+
37+
- PNG (recommended)
38+
- JPEG
39+
- GIF (first frame only)
40+
- BMP
41+
42+
## Image Scaling
43+
44+
Three ways to control image size:
45+
1. Original size (no parameters)
46+
2. Scale factor (`scale` parameter)
47+
3. Exact dimensions (`width` and `height` parameters)
48+
49+
## Performance Tips
50+
51+
```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+
)
59+
```
60+
61+
## Best Practices
62+
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: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Components Guide
2+
3+
**Next:** [Animation Guide](../animation.md) | **Previous:** [Basic Tutorial](../tutorials/basic.md)
4+
5+
## Available Components
6+
7+
1. [Element](element.md) - Base component
8+
- Foundation for all UI elements
9+
- Positioning and display control
10+
- Mouse interaction handling
11+
12+
2. [Text](text.md) - Text display
13+
- Custom fonts and sizes
14+
- Color control
15+
- Dynamic content updates
16+
17+
3. [Button](button.md) - Interactive buttons
18+
- Click handling
19+
- Hover effects
20+
- Custom styling
21+
22+
4. [Input](input.md) - Text input fields
23+
- Text filtering
24+
- Cursor control
25+
- Custom borders
26+
27+
5. [Image](image.md) - Image display
28+
- Multiple formats
29+
- 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: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Input Field
2+
3+
Text input fields for user data entry.
4+
5+
## Basic Usage
6+
```python
7+
input_field = pygameui.Input(
8+
position=(100, 100),
9+
width=200,
10+
height=50,
11+
hint="Enter text...",
12+
font_size=20
13+
)
14+
```
15+
16+
## Properties
17+
```python
18+
position: tuple [int, int],
19+
width: int = 200,
20+
height: int = 50,
21+
passive_text_color: tuple[int, int, int] = (150, 150, 150),
22+
active_text_color: tuple[int, int, int] = (255, 255, 255),
23+
passive_border_color: tuple[int, int, int] = (100, 100, 100),
24+
active_border_color: tuple[int, int, int] = (200, 200, 200),
25+
border_radius: int = 0,
26+
border_width: int = 2,
27+
font_size: int = 20,
28+
font_family: str = "Arial",
29+
hint: str = "",
30+
centered: bool = False
31+
```
32+
33+
- `position`: Tuple of (x, y) coordinates
34+
- `width`: Width of the input field
35+
- `height`: Height of the input field
36+
- `passive_text_color`: Color of the text when not focused
37+
- `active_text_color`: Color of the text when focused
38+
- `passive_border_color`: Color of the border when not focused
39+
- `active_border_color`: Color of the border when focused
40+
- `border_radius`: Radius for rounded corners
41+
- `border_width`: Width of the border
42+
- `font_size`: Size of the text font
43+
- `font_family`: Font family for the text
44+
- `hint`: Placeholder text when the field is empty
45+
- `centered`: If True, the element is centered on the provided position
46+
47+
### Input Features
48+
- Text filtering
49+
- Custom borders
50+
- Active/inactive states
51+
- Cursor navigation
52+
- Text selection
53+
54+
### Input Filtering
55+
```python
56+
# Only allow numbers
57+
input_field.set_filter("0123456789", exclude_mode=False)
58+
59+
# Exclude special characters
60+
input_field.set_filter("@#$%^&*()", exclude_mode=True)
61+
```

0 commit comments

Comments
 (0)