| Crates.io | egui_css |
| lib.rs | egui_css |
| version | 0.1.1 |
| created_at | 2025-01-11 02:25:28.586343+00 |
| updated_at | 2025-01-13 02:02:56.636741+00 |
| description | Use css to styling egui |
| homepage | https://github.com/SergioRibera/egui_css |
| repository | https://github.com/SergioRibera/egui_css |
| max_upload_size | |
| id | 1512033 |
| size | 147,150 |
egui_css is an extension for egui, a Rust-based immediate mode GUI library. This framework introduces a cascading style sheet (CSS) approach to styling, allowing developers to define styles declaratively for their egui applications.
https://github.com/user-attachments/assets/9d210ed1-4f1d-4f97-acbe-25f5689ee14b
:hover, :focus, or pseudo-elements. (implemented but not works 😔)The following CSS-like rules are supported:
width: Sets the width of an element.height: Sets the height of an element.min-width: Sets the minimum width of an element.min-height: Sets the minimum height of an element.max-width: Sets the maximum width of an element.max-height: Sets the maximum height of an element.border-color: Sets the border color.border: Sets the border width and color.border-width: Sets the width of the border.border-radius: Sets the rounding of corners.padding: Defines the padding around elements.padding-left: Sets the left padding.padding-top: Sets the top padding.padding-right: Sets the right padding.padding-bottom: Sets the bottom padding.margin: Defines the margin around elements.margin-left: Sets the left margin.margin-top: Sets the top margin.margin-right: Sets the right margin.margin-bottom: Sets the bottom margin.cursor: Defines the type of cursor to display.cursor-color: Sets the cursor color.color: Sets the text color.background-color: Sets the background color.box-shadow: Sets the shadow around elements.column-gap: Sets the gap between columns.row-gap: Sets the gap between rows.gap: Sets the gap between rows and columns.text-overflow: Defines how text overflows.transition: Sets the transition duration for animations. (no animate)The following properties are planned for future support:
display: Define how elements are displayed (e.g., block, inline).position: Control the positioning of elements.flex-direction: Define the main axis of flex container elements.flex-wrap: Allow wrapping of flex items.flex-grow: Define the grow factor for flex items.flex-shrink: Define the shrink factor for flex items.flex-basis: Define the initial size of a flex item.justify-content: Align flex items along the main axis.justify-self: Align individual items inside a container.align-self: Align a specific item inside a flex container.align-items: Align items inside a flex container.align-content: Align multiple lines inside a flex container.user-select: Control text selection behavior.z-index: Control the stack order of elements.aspect-ratio: Maintain a specific aspect ratio for elements.inset: Control positioning inside a container (e.g., top, left).outline: Define the outline of elements.font-size: Set the size of the font.font-family: Specify the font family.font-weight: Define the weight of the font.font-style: Define the style of the font (e.g., italic).line-height: Set the height of lines of text.cargo build tool.egui_css::change_style(egui_css::StyleSheet::from_css(
r#"
.header {
color: purple;
padding: 20px;
background-color: black;
height: 50px;
}
#counter {
color: green;
background-color: white;
padding: 20px;
margin: 20px;
}
#counter:hover {
color: purple;
}
.header:hover {
color: blue;
}
"#,
));
use egui_css::StyledWidgetExt;
ui.vertical(|ui| {
ui.add(Label::new("My egui Application").styled().class(".header"));
if ui
.add(Button::new("Increment").styled().css_id("counter"))
.clicked()
{
self.age += 1;
}
ui.add(
Label::new(format!("age {}", self.age))
.styled()
.class(".text-orange-700"),
);
ui.add(Label::new("No styled"));
})
Check out the examples in the examples/ directory of the repository for more advanced use cases, including:
Run the examples with:
cargo run -p egui_css --example simple
We welcome contributions! Whether you have ideas for new features, bug fixes, or documentation improvements, feel free to open an issue or submit a pull request.
Help us expand egui_css! If you're interested in contributing, here are some ways to get involved:
Join us in shaping the future of egui_css and making styling in egui applications more flexible and powerful!