Separator
A thin horizontal or vertical rule.
Web replica of the native GPUI output
hyuskui
DocsComponentsGitHub
use gpui::{div, prelude::*, px};
use crate::ui::separator::Separator;
pub fn separator_demo() -> impl IntoElement {
div()
.flex()
.flex_col()
.gap_3()
.w(px(280.0))
.child(div().text_sm().child("hyuskui"))
.child(Separator::horizontal())
.child(
div()
.flex()
.h(px(20.0))
.gap_3()
.text_sm()
.child("Docs")
.child(Separator::vertical())
.child("Components")
.child(Separator::vertical())
.child("GitHub"),
)
}Installation
Add the component
$ cargo hyuskui add separatorOr copy it by hand: paste the source below into
src/ui/separator.rsand register it insrc/ui/mod.rs.Make sure the theme is installed
Every component reads colors from
crate::theme. If you have not runcargo hyuskui init, follow the installation guide first.
Usage
use crate::ui::separator::*;Source
This file is yours after install. Change the styles, add variants, or delete what you do not need.
use gpui::{div, prelude::*, px, App, Window};
use crate::theme::ActiveTheme;
#[derive(Clone, Copy, Default, PartialEq)]
pub enum Orientation {
#[default]
Horizontal,
Vertical,
}
#[derive(IntoElement, Default)]
pub struct Separator {
orientation: Orientation,
}
impl Separator {
pub fn horizontal() -> Self {
Self { orientation: Orientation::Horizontal }
}
pub fn vertical() -> Self {
Self { orientation: Orientation::Vertical }
}
}
impl RenderOnce for Separator {
fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
let line = div().flex_none().bg(cx.theme().border);
match self.orientation {
Orientation::Horizontal => line.w_full().h(px(1.0)),
Orientation::Vertical => line.h_full().w(px(1.0)),
}
}
}