rosier 0.3.0

A fast picture and video viewer for large folders
//! The sponsor dialog: what sponsoring pays for, then a button that opens
//! GitHub Sponsors in the browser. Nothing is sent from the app itself.

use gpui::{AnyElement, Context, div, prelude::*, px};

use crate::app::Rosier;
use crate::assets::Icon;
use crate::i18n::t;
use crate::theme;
use crate::ui::{button, glass, glass_sheen, icon, primary_button};

pub const SPONSOR_URL: &str = "https://github.com/sponsors/nao1215";

/// GitHub Sponsors' heart.
const HEART: u32 = 0xdb61a2;

impl Rosier {
    pub(crate) fn open_sponsor_page(&mut self, cx: &mut Context<Self>) {
        cx.open_url(SPONSOR_URL);
        self.show_sponsor = false;
        cx.notify();
    }

    pub(crate) fn render_sponsor(&mut self, cx: &mut Context<Self>) -> AnyElement {
        div()
            .id("sponsor")
            .absolute()
            .top_0()
            .left_0()
            .size_full()
            .flex()
            .items_center()
            .justify_center()
            .bg(gpui::rgba(0x000000a8))
            .on_click(cx.listener(|this, _, _, cx| {
                this.show_sponsor = false;
                cx.notify();
            }))
            .child(
                glass(theme::R_PANEL)
                    .id("sponsor-dialog")
                    // Clicks inside the dialog do not close it.
                    .on_click(|_, _, cx| cx.stop_propagation())
                    .bg(gpui::rgba(0x18181cf0))
                    .w(px(432.0))
                    .p_6()
                    .flex()
                    .flex_col()
                    .gap_4()
                    .child(glass_sheen(theme::R_PANEL))
                    .child(
                        div()
                            .flex()
                            .flex_row()
                            .items_center()
                            .gap_2()
                            .child(icon(Icon::HeartFill, 20.0, gpui::rgb(HEART)))
                            .child(div().text_lg().child(t("sponsor.title"))),
                    )
                    .child(div().text_sm().text_color(theme::text_dim()).child(t("sponsor.body")))
                    .child(
                        div()
                            .pt_2()
                            .flex()
                            .flex_row()
                            .justify_end()
                            .gap_2()
                            .child(button("sponsor-close").child(t("sponsor.close")).on_click(cx.listener(
                                |this, _, _, cx| {
                                    this.show_sponsor = false;
                                    cx.notify();
                                },
                            )))
                            .child(
                                primary_button("sponsor-open", t("sponsor.open"))
                                    .on_click(cx.listener(|this, _, _, cx| this.open_sponsor_page(cx))),
                            ),
                    ),
            )
            .into_any_element()
    }
}