fluix 0.1.20

A comprehensive UI component library for GPUI 0.2 - Modern, performant, and type-safe
Documentation
use fluix::*;
use gpui::*;

fn main() {
    env_logger::init();

    let app = Application::new().with_assets(fluix::Assets);

    app.run(move |cx| {
        let window_options = WindowOptions {
            window_bounds: Some(WindowBounds::Windowed(Bounds {
                origin: point(px(100.), px(100.)),
                size: size(px(900.), px(700.)),
            })),
            titlebar: Some(TitlebarOptions {
                title: Some("Select Alignment Demo".into()),
                appears_transparent: false,
                ..Default::default()
            }),
            ..Default::default()
        };

        cx.open_window(window_options, |window, cx| {
            cx.new(|cx| SelectAlignmentDemo::new(window, cx))
        })
        .unwrap();
    });
}

struct SelectAlignmentDemo {
    scroll_handle: ScrollHandle,
    left_down: Entity<Select>,
    right_down: Entity<Select>,
    center_down: Entity<Select>,
    left_up: Entity<Select>,
    right_up: Entity<Select>,
    center_up: Entity<Select>,
}

impl SelectAlignmentDemo {
    fn new(_window: &mut Window, cx: &mut Context<Self>) -> Self {
        let scroll_handle = ScrollHandle::new();

        let options = vec![
            SelectOption::new("react", "React"),
            SelectOption::new("vue", "Vue"),
            SelectOption::new("angular", "Angular"),
            SelectOption::new("svelte", "Svelte"),
        ];

        // Left aligned, expand down
        let left_down = cx.new(|cx| {
            Select::new(cx)
                .placeholder("Left aligned (default)")
                .align_left()
                .dropdown_direction(DropdownDirection::Down)
                .options(options.clone())
        });

        // Right aligned, expand down
        let right_down = cx.new(|cx| {
            Select::new(cx)
                .placeholder("Right aligned")
                .align_right()
                .dropdown_direction(DropdownDirection::Down)
                .options(options.clone())
        });

        // Center aligned, expand down
        let center_down = cx.new(|cx| {
            Select::new(cx)
                .placeholder("Center aligned")
                .align_center()
                .dropdown_direction(DropdownDirection::Down)
                .options(options.clone())
        });

        // Left aligned, expand up
        let left_up = cx.new(|cx| {
            Select::new(cx)
                .placeholder("Left + Up")
                .align_left()
                .dropdown_direction(DropdownDirection::Up)
                .options(options.clone())
        });

        // Right aligned, expand up
        let right_up = cx.new(|cx| {
            Select::new(cx)
                .placeholder("Right + Up")
                .align_right()
                .dropdown_direction(DropdownDirection::Up)
                .options(options.clone())
        });

        // Center aligned, expand up
        let center_up = cx.new(|cx| {
            Select::new(cx)
                .placeholder("Center + Up")
                .align_center()
                .dropdown_direction(DropdownDirection::Up)
                .options(options.clone())
        });

        Self {
            scroll_handle,
            left_down,
            right_down,
            center_down,
            left_up,
            right_up,
            center_up,
        }
    }
}

impl Render for SelectAlignmentDemo {
    fn render(&mut self, _: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
        div()
            .size_full()
            .overflow_hidden()
            .child(
                div()
                    .id("scroll-container")
                    .size_full()
                    .overflow_y_scroll()
                    .track_scroll(&self.scroll_handle)
                    .child(
                        div()
                            .flex()
                            .flex_col()
                            .bg(rgb(0xF5F5F5))
                            .p_8()
                            .gap_8()
                            .child(
                                div()
                                    .flex()
                                    .flex_col()
                                    .gap_2()
                                    .child(
                                        div()
                                            .text_2xl()
                                            .font_weight(FontWeight::BOLD)
                                            .text_color(rgb(0x111827))
                                            .child("Select Alignment Demo")
                                    )
                                    .child(
                                        div()
                                            .text_sm()
                                            .text_color(rgb(0x6B7280))
                                            .child("Dropdown menu alignment: left, right, or center")
                                    )
                            )
                            .child(
                                div()
                                    .flex()
                                    .flex_col()
                                    .w_full()
                                    .max_w(px(700.))
                                    .p_6()
                                    .bg(rgb(0xFFFFFF))
                                    .border_1()
                                    .border_color(rgb(0xE5E7EB))
                                    .rounded(px(12.))
                                    .gap_6()
                                    .child(
                                        div()
                                            .text_lg()
                                            .font_weight(FontWeight::SEMIBOLD)
                                            .text_color(rgb(0x111827))
                                            .child("Expand Down (Default)")
                                    )
                                    .child(
                                        div()
                                            .flex()
                                            .flex_col()
                                            .gap_4()
                                            .child(
                                                div()
                                                    .flex()
                                                    .flex_col()
                                                    .gap_2()
                                                    .child(
                                                        div()
                                                            .text_sm()
                                                            .font_weight(FontWeight::MEDIUM)
                                                            .text_color(rgb(0x374151))
                                                            .child("Left Aligned (Default)")
                                                    )
                                                    .child(self.left_down.clone())
                                                    .child(
                                                        div()
                                                            .text_xs()
                                                            .text_color(rgb(0x9CA3AF))
                                                            .child("Code: .align_left() or .dropdown_alignment(DropdownAlignment::Left)")
                                                    )
                                            )
                                            .child(
                                                div()
                                                    .flex()
                                                    .flex_col()
                                                    .gap_2()
                                                    .child(
                                                        div()
                                                            .text_sm()
                                                            .font_weight(FontWeight::MEDIUM)
                                                            .text_color(rgb(0x374151))
                                                            .child("Right Aligned")
                                                    )
                                                    .child(self.right_down.clone())
                                                    .child(
                                                        div()
                                                            .text_xs()
                                                            .text_color(rgb(0x9CA3AF))
                                                            .child("Code: .align_right() or .dropdown_alignment(DropdownAlignment::Right)")
                                                    )
                                            )
                                            .child(
                                                div()
                                                    .flex()
                                                    .flex_col()
                                                    .gap_2()
                                                    .child(
                                                        div()
                                                            .text_sm()
                                                            .font_weight(FontWeight::MEDIUM)
                                                            .text_color(rgb(0x374151))
                                                            .child("Center Aligned")
                                                    )
                                                    .child(self.center_down.clone())
                                                    .child(
                                                        div()
                                                            .text_xs()
                                                            .text_color(rgb(0x9CA3AF))
                                                            .child("Code: .align_center() or .dropdown_alignment(DropdownAlignment::Center)")
                                                    )
                                            )
                                    )
                            )
                            .child(
                                div()
                                    .flex()
                                    .flex_col()
                                    .w_full()
                                    .max_w(px(700.))
                                    .p_6()
                                    .bg(rgb(0xFFFFFF))
                                    .border_1()
                                    .border_color(rgb(0xE5E7EB))
                                    .rounded(px(12.))
                                    .gap_6()
                                    .child(
                                        div()
                                            .text_lg()
                                            .font_weight(FontWeight::SEMIBOLD)
                                            .text_color(rgb(0x111827))
                                            .child("Expand Up (Scroll down to see)")
                                    )
                                    .child(
                                        div()
                                            .flex()
                                            .flex_col()
                                            .gap_4()
                                            .child(
                                                div()
                                                    .flex()
                                                    .flex_col()
                                                    .gap_2()
                                                    .child(
                                                        div()
                                                            .text_sm()
                                                            .font_weight(FontWeight::MEDIUM)
                                                            .text_color(rgb(0x374151))
                                                            .child("Left + Up")
                                                    )
                                                    .child(self.left_up.clone())
                                                    .child(
                                                        div()
                                                            .text_xs()
                                                            .text_color(rgb(0x9CA3AF))
                                                            .child("Code: .align_left().dropdown_direction(DropdownDirection::Up)")
                                                    )
                                            )
                                            .child(
                                                div()
                                                    .flex()
                                                    .flex_col()
                                                    .gap_2()
                                                    .child(
                                                        div()
                                                            .text_sm()
                                                            .font_weight(FontWeight::MEDIUM)
                                                            .text_color(rgb(0x374151))
                                                            .child("Right + Up")
                                                    )
                                                    .child(self.right_up.clone())
                                                    .child(
                                                        div()
                                                            .text_xs()
                                                            .text_color(rgb(0x9CA3AF))
                                                            .child("Code: .align_right().dropdown_direction(DropdownDirection::Up)")
                                                    )
                                            )
                                            .child(
                                                div()
                                                    .flex()
                                                    .flex_col()
                                                    .gap_2()
                                                    .child(
                                                        div()
                                                            .text_sm()
                                                            .font_weight(FontWeight::MEDIUM)
                                                            .text_color(rgb(0x374151))
                                                            .child("Center + Up")
                                                    )
                                                    .child(self.center_up.clone())
                                                    .child(
                                                        div()
                                                            .text_xs()
                                                            .text_color(rgb(0x9CA3AF))
                                                            .child("Code: .align_center().dropdown_direction(DropdownDirection::Up)")
                                                    )
                                            )
                                    )
                            )
                            .child(
                                div()
                                    .p_4()
                                    .bg(rgb(0xDCFCE7))
                                    .border_1()
                                    .border_color(rgb(0x86EFAC))
                                    .rounded(px(8.))
                                    .child(
                                        div()
                                            .flex()
                                            .flex_col()
                                            .gap_2()
                                            .child(
                                                div()
                                                    .text_sm()
                                                    .font_weight(FontWeight::SEMIBOLD)
                                                    .text_color(rgb(0x166534))
                                                    .child("✨ Alignment Options")
                                            )
                                            .child(
                                                div()
                                                    .text_sm()
                                                    .text_color(rgb(0x15803D))
                                                    .child("• Left: Align dropdown to left edge (default)")
                                            )
                                            .child(
                                                div()
                                                    .text_sm()
                                                    .text_color(rgb(0x15803D))
                                                    .child("• Right: Align dropdown to right edge")
                                            )
                                            .child(
                                                div()
                                                    .text_sm()
                                                    .text_color(rgb(0x15803D))
                                                    .child("• Center: Center align dropdown")
                                            )
                                            .child(
                                                div()
                                                    .text_sm()
                                                    .text_color(rgb(0x15803D))
                                                    .child("• Combine with Up/Down direction for full control")
                                            )
                                    )
                            )
                    )
            )
    }
}