Eerste opzet
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
||||
6314
Cargo.lock
generated
Normal file
6314
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
10
Cargo.toml
Normal file
10
Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "slint-demo"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
slint = { version = "1", features = ["backend-linuxkms", "compat-1-2"] }
|
||||
|
||||
[build-dependencies]
|
||||
slint-build = "1"
|
||||
59
README.md
Normal file
59
README.md
Normal file
@@ -0,0 +1,59 @@
|
||||
# Slint Linux KMS Demo
|
||||
|
||||
1920×480 scherm met een donkergrijze titelbalk en een regenbooggradiënt van 50px verticale balken.
|
||||
|
||||
## Vereisten
|
||||
|
||||
### Systeembibliotheken
|
||||
|
||||
| Package | Arch Linux / CachyOS | Debian / Ubuntu |
|
||||
|-----------------|---------------------------------|-----------------------------------|
|
||||
| `seatd` | `sudo pacman -S seatd` | `sudo apt install libseat-dev` |
|
||||
| `libdrm` | `sudo pacman -S libdrm` | `sudo apt install libdrm-dev` |
|
||||
| `mesa` (GBM) | `sudo pacman -S mesa` | `sudo apt install libgbm-dev` |
|
||||
| `libinput` | `sudo pacman -S libinput` | `sudo apt install libinput-dev` |
|
||||
|
||||
**Seatd** moet draaien voor session management. Start en enable het:
|
||||
|
||||
```bash
|
||||
sudo systemctl enable --now seatd
|
||||
```
|
||||
|
||||
Voeg je gebruiker toe aan de `seat` groep:
|
||||
|
||||
```bash
|
||||
sudo usermod -aG seat $USER
|
||||
```
|
||||
|
||||
Herstart of log opnieuw in om de groep actief te maken.
|
||||
|
||||
### Rust
|
||||
|
||||
```bash
|
||||
rustup update stable
|
||||
```
|
||||
|
||||
## Draaien
|
||||
|
||||
Uitvoeren op een **lege TTY** (Ctrl+Alt+F2..F6), niet in X11/Wayland:
|
||||
|
||||
```bash
|
||||
cargo run
|
||||
```
|
||||
|
||||
Of expliciet de KMS backend kiezen:
|
||||
|
||||
```bash
|
||||
SLINT_BACKEND=linuxkms cargo run
|
||||
```
|
||||
|
||||
Stoppen met `Ctrl+C` of `Q`.
|
||||
|
||||
## Projectstructuur
|
||||
|
||||
```
|
||||
├── Cargo.toml
|
||||
├── build.rs
|
||||
├── ui/demo.slint # Slint UI definitie
|
||||
└── src/main.rs # Rust entry-point
|
||||
```
|
||||
3
build.rs
Normal file
3
build.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
slint_build::compile("ui/demo.slint").unwrap();
|
||||
}
|
||||
43
src/main.rs
Normal file
43
src/main.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use std::rc::Rc;
|
||||
use slint::{Color, VecModel};
|
||||
|
||||
slint::include_modules!();
|
||||
|
||||
fn hsl_to_rgb(hue: f32, sat: f32, light: f32) -> (u8, u8, u8) {
|
||||
let c = (1.0 - (2.0 * light - 1.0).abs()) * sat;
|
||||
let x = c * (1.0 - ((hue / 60.0) % 2.0 - 1.0).abs());
|
||||
let m = light - c / 2.0;
|
||||
|
||||
let (r, g, b) = match (hue as u32) % 360 {
|
||||
h if h < 60 => (c, x, 0.0),
|
||||
h if h < 120 => (x, c, 0.0),
|
||||
h if h < 180 => (0.0, c, x),
|
||||
h if h < 240 => (0.0, x, c),
|
||||
h if h < 300 => (x, 0.0, c),
|
||||
_ => (c, 0.0, x),
|
||||
};
|
||||
|
||||
(
|
||||
((r + m) * 255.0) as u8,
|
||||
((g + m) * 255.0) as u8,
|
||||
((b + m) * 255.0) as u8,
|
||||
)
|
||||
}
|
||||
|
||||
fn main() -> Result<(), slint::PlatformError> {
|
||||
let demo = DemoWindow::new()?;
|
||||
|
||||
let colors: Vec<slint::Brush> = (0..38)
|
||||
.map(|i| {
|
||||
let hue = (i as f32 / 38.0) * 360.0;
|
||||
let (r, g, b) = hsl_to_rgb(hue, 0.85, 0.55);
|
||||
Color::from_rgb_u8(r, g, b).into()
|
||||
})
|
||||
.collect();
|
||||
|
||||
let model: Rc<VecModel<slint::Brush>> = Rc::new(VecModel::from(colors));
|
||||
demo.set_bar_colors(model.into());
|
||||
demo.set_window_title("DEMO Slint".into());
|
||||
|
||||
demo.run()
|
||||
}
|
||||
33
ui/demo.slint
Normal file
33
ui/demo.slint
Normal file
@@ -0,0 +1,33 @@
|
||||
export component DemoWindow inherits Window {
|
||||
width: 1920px;
|
||||
height: 480px;
|
||||
|
||||
in property <[brush]> bar-colors;
|
||||
in property <string> window-title;
|
||||
|
||||
VerticalLayout {
|
||||
Rectangle {
|
||||
height: 60px;
|
||||
background: #2d2d2d;
|
||||
|
||||
Text {
|
||||
text: window-title;
|
||||
color: #ffffff;
|
||||
font-size: 28px;
|
||||
font-weight: 700;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
}
|
||||
|
||||
HorizontalLayout {
|
||||
alignment: start;
|
||||
spacing: 0px;
|
||||
|
||||
for color in bar-colors: Rectangle {
|
||||
width: 50px;
|
||||
background: color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user