Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::marker::PhantomData;
- use gpui::{
- App, Application, Context, Menu, MenuItem, Window,
- WindowOptions, actions, div, prelude::*, rgb, Global
- };
- pub struct Theme {
- primary: u32,
- secondary: u32,
- }
- impl From<(u32, u32)> for Theme {
- fn from(tup: (u32, u32)) -> Theme {
- Theme { primary: tup.0, secondary: tup.1 }
- }
- }
- pub const SPOTIFY_THEME: Theme = Theme {
- primary: 0x1cd061,
- secondary: 0x121212,
- };
- pub const FIREFOX_THEME: Theme = Theme {
- primary: 0xff5933,
- secondary: 0x421c5f,
- };
- pub const BLUEY_THEME: Theme = Theme {
- primary: 0xf2d787,
- secondary: 0x9acbec,
- };
- pub const SPICY_THEME: Theme = Theme {
- primary: 0x1b1b1b,
- secondary: 0xffa31a,
- };
- pub struct SetMenus;
- pub struct ActiveTheme {
- active_theme: Theme,
- }
- impl Global for ActiveTheme {}
- //what does this macro do exactly
- actions!(set_menus, [Quit]);
- actions!(set_menus, [SpotifyTheme]);
- actions!(set_menus, [FirefoxTheme]);
- actions!(set_menus, [BlueyTheme]);
- actions!(set_menus, [SpicyTheme]);
- impl Render for SetMenus {
- fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
- div()
- .flex()
- .bg(rgb(cx.global::<ActiveTheme>().active_theme.primary))
- .size_full()
- .justify_center()
- .items_center()
- .text_xl()
- .text_color(rgb(cx.global::<ActiveTheme>().active_theme.secondary))
- .child("Set Menus Example")
- }
- }
- fn main() {
- Application::new().run(|cx: &mut App| {
- cx.set_global::<ActiveTheme>(ActiveTheme { active_theme: SPOTIFY_THEME });
- //??? idk what this does exactly
- cx.activate(true);
- cx.on_action(|_: &Quit, cx: &mut App| cx.quit());
- cx.on_action(|_: &FirefoxTheme, cx: &mut App| {
- cx.set_global::<ActiveTheme>(ActiveTheme { active_theme: FIREFOX_THEME });
- cx.notify();
- });
- cx.on_action(|_: &BlueyTheme, cx: &mut App| {
- cx.set_global::<ActiveTheme>(ActiveTheme { active_theme: BLUEY_THEME });
- cx.notify();
- });
- cx.on_action(|_: &SpotifyTheme, cx: &mut App| {
- cx.set_global::<ActiveTheme>(ActiveTheme { active_theme: SPOTIFY_THEME });
- cx.notify();
- });
- cx.on_action(|_: &SpicyTheme, cx: &mut App| {
- cx.set_global::<ActiveTheme>(ActiveTheme { active_theme: SPICY_THEME });
- cx.notify();
- });
- cx.set_menus(vec![
- Menu {
- name: "main".into(),
- items: vec![
- MenuItem::action("Quit", Quit),
- ]},
- Menu {
- name: "themes!!!".into(),
- items: vec![
- MenuItem::action("Spotify theme", SpotifyTheme),
- MenuItem::action("Firefox theme", FirefoxTheme),
- MenuItem::action("Bluey theme", BlueyTheme),
- MenuItem::action("Spicy theme", SpicyTheme),
- ],
- },
- ]);
- let set_menus = cx.new(|_| {SetMenus});
- cx.open_window(WindowOptions::default(), |_, _cx| { set_menus }).unwrap();
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment