botserver/docs/src/chapter-05-gbtheme/README.md

155 lines
4.2 KiB
Markdown
Raw Normal View History

2025-11-23 20:12:09 -03:00
# Chapter 05: gbtheme CSS Theming
2025-11-23 09:19:06 -03:00
2025-11-23 20:12:09 -03:00
The `.gbtheme` package provides CSS-based styling for your bot's user interface. Themes control colors, fonts, layouts, and visual effects across all .gbui templates.
2025-11-23 09:19:06 -03:00
2025-11-23 13:46:55 -03:00
## Quick Start
2025-11-23 09:19:06 -03:00
2025-11-24 09:49:25 -03:00
To theme your bot, create a `.gbtheme` folder in your bot package and add a CSS file:
2025-11-23 09:19:06 -03:00
```
2025-11-23 13:46:55 -03:00
mybot.gbai/
└── mybot.gbtheme/
2025-11-24 09:49:25 -03:00
└── default.css # Your theme file
2025-11-23 09:19:06 -03:00
```
2025-11-24 09:49:25 -03:00
The theme loads automatically when the bot starts.
2025-11-23 09:19:06 -03:00
2025-11-23 13:46:55 -03:00
## How Themes Work
2025-11-23 09:19:06 -03:00
2025-11-24 09:49:25 -03:00
Themes are standard CSS files that override the default styles. The system loads them in this order:
1. System default styles
2. Your theme CSS file
3. Any inline style overrides
## Available Theme Files
You can create multiple theme files for different purposes:
- `default.css` - Main theme (loaded automatically)
- `dark.css` - Dark mode variant
- `print.css` - Print-friendly styles
- Custom theme names for special occasions
## Theme Elements to Style
### Core Components
- `.chat-container` - Main chat window
- `.message` - All messages
- `.message-user` - User messages
- `.message-bot` - Bot responses
- `.chat-input` - Input field
- `.send-button` - Send button
### UI Elements
- `.sidebar` - Side navigation
- `.header` - Top bar
- `.footer` - Bottom bar
- `.card` - Content cards
- `.button` - All buttons
- `.dialog` - Modal dialogs
### States and Interactions
- `.typing-indicator` - Typing animation
- `.loading` - Loading states
- `.error` - Error messages
- `.success` - Success messages
- `:hover` - Hover effects
- `:focus` - Focus states
2025-11-23 09:19:06 -03:00
2025-11-23 13:46:55 -03:00
## Switching Themes
2025-11-23 09:19:06 -03:00
2025-11-24 09:49:25 -03:00
Use the `CHANGE THEME` command in your BASIC scripts:
2025-11-23 09:19:06 -03:00
2025-11-23 13:46:55 -03:00
```basic
2025-11-24 09:49:25 -03:00
' Switch to dark theme
CHANGE THEME "dark"
2025-11-23 09:19:06 -03:00
2025-11-23 13:46:55 -03:00
' Back to default
CHANGE THEME "default"
```
2025-11-23 09:19:06 -03:00
2025-11-24 09:49:25 -03:00
## Theme Best Practices
2025-11-23 09:19:06 -03:00
2025-11-24 09:49:25 -03:00
1. **Start Simple**: Begin with colors and fonts, add complexity gradually
2. **Test Responsiveness**: Ensure your theme works on mobile devices
3. **Maintain Readability**: Keep sufficient contrast between text and backgrounds
4. **Use CSS Variables**: Define colors once, reuse throughout
5. **Test Dark Mode**: Many users prefer dark interfaces
2025-11-23 09:19:06 -03:00
2025-11-24 09:49:25 -03:00
## Pre-built Themes
2025-11-23 09:19:06 -03:00
2025-11-24 09:49:25 -03:00
BotServer includes example themes you can use as starting points:
2025-11-23 09:19:06 -03:00
2025-11-24 09:49:25 -03:00
- **default** - Clean, modern interface
- **3dbevel** - Retro Windows 95 style
- **minimal** - Simplified, distraction-free
- **corporate** - Professional business look
- **playful** - Colorful, fun design
2025-11-23 09:19:06 -03:00
2025-11-24 09:49:25 -03:00
## File Structure
2025-11-23 09:19:06 -03:00
2025-11-24 09:49:25 -03:00
Keep your theme files organized:
2025-11-23 09:19:06 -03:00
2025-11-24 09:49:25 -03:00
```
mybot.gbtheme/
├── default.css # Main theme
├── dark.css # Dark variant
├── mobile.css # Mobile-specific styles
└── assets/ # Images, fonts
├── logo.png
└── fonts/
```
2025-11-23 09:19:06 -03:00
2025-11-23 13:46:55 -03:00
## Loading Order
2025-11-23 09:19:06 -03:00
2025-11-24 09:49:25 -03:00
Themes are applied in a specific order to ensure proper cascading:
1. Base system styles (always loaded)
2. Theme file specified in config or `default.css`
3. Media queries for responsive design
4. User preference overrides (if any)
## Dynamic Theme Changes
Themes can be changed at runtime without restarting:
```basic
' Change theme based on time of day
hour = HOUR(NOW())
IF hour >= 18 OR hour < 6 THEN
CHANGE THEME "dark"
ELSE
CHANGE THEME "default"
END IF
```
## Troubleshooting
### Theme Not Loading
- Check file is named correctly (e.g., `default.css`)
- Verify `.gbtheme` folder is in the right location
- Restart the bot after adding new theme files
### Styles Not Applying
- Check CSS syntax is valid
- Use browser developer tools to inspect elements
- Verify selectors match the HTML structure
- Clear browser cache if changes aren't visible
### Performance Issues
- Minimize complex animations
- Optimize image sizes
- Avoid too many web fonts
- Use CSS transforms instead of position changes
## Summary
2025-11-23 09:19:06 -03:00
2025-11-24 09:49:25 -03:00
The `.gbtheme` system keeps styling simple and separate from bot logic. Just drop a CSS file in the `.gbtheme` folder and your bot gets a new look. Focus on the essentials - colors, fonts, and spacing - and let the default styles handle the rest.
2025-11-23 20:12:09 -03:00
## See Also
- [Chapter 4: .gbui Interface](../chapter-04-gbui/README.md) - User interface templates
2025-11-24 09:49:25 -03:00
- [Chapter 2: Packages](../chapter-02/README.md) - Package structure
- [Chapter 6: BASIC Dialogs](../chapter-06-gbdialog/README.md) - Using CHANGE THEME command
- [Chapter 8: Configuration](../chapter-08-config/README.md) - Theme configuration options