Added CTA buttons to welcome experience
Co-authored-by: Nathan <nathan@zed.dev>
This commit is contained in:
parent
9dee2ca2be
commit
f89f33347d
5 changed files with 102 additions and 48 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -8024,6 +8024,7 @@ dependencies = [
|
||||||
"project",
|
"project",
|
||||||
"settings",
|
"settings",
|
||||||
"theme",
|
"theme",
|
||||||
|
"theme_selector",
|
||||||
"util",
|
"util",
|
||||||
"workspace",
|
"workspace",
|
||||||
]
|
]
|
||||||
|
|
|
@ -854,6 +854,7 @@ pub struct FeedbackStyle {
|
||||||
#[derive(Clone, Deserialize, Default)]
|
#[derive(Clone, Deserialize, Default)]
|
||||||
pub struct WelcomeStyle {
|
pub struct WelcomeStyle {
|
||||||
pub checkbox: CheckboxStyle,
|
pub checkbox: CheckboxStyle,
|
||||||
|
pub button: Interactive<ContainedText>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Deserialize, Default)]
|
#[derive(Clone, Deserialize, Default)]
|
||||||
|
|
|
@ -18,5 +18,6 @@ gpui = { path = "../gpui" }
|
||||||
project = { path = "../project" }
|
project = { path = "../project" }
|
||||||
settings = { path = "../settings" }
|
settings = { path = "../settings" }
|
||||||
theme = { path = "../theme" }
|
theme = { path = "../theme" }
|
||||||
|
theme_selector = { path = "../theme_selector" }
|
||||||
util = { path = "../util" }
|
util = { path = "../util" }
|
||||||
workspace = { path = "../workspace" }
|
workspace = { path = "../workspace" }
|
|
@ -1,12 +1,14 @@
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
color::Color,
|
color::Color,
|
||||||
elements::{Canvas, Empty, Flex, Label, MouseEventHandler, ParentElement, Stack, Svg},
|
elements::{Canvas, Empty, Flex, Label, MouseEventHandler, ParentElement, Stack, Svg},
|
||||||
geometry::rect::RectF,
|
geometry::rect::RectF,
|
||||||
Element, ElementBox, Entity, MouseRegion, MutableAppContext, RenderContext, Subscription, View,
|
Action, Element, ElementBox, Entity, MouseButton, MouseRegion, MutableAppContext,
|
||||||
ViewContext,
|
RenderContext, Subscription, View, ViewContext,
|
||||||
};
|
};
|
||||||
use settings::{settings_file::SettingsFile, Settings, SettingsFileContent};
|
use settings::{settings_file::SettingsFile, Settings, SettingsFileContent};
|
||||||
use theme::CheckboxStyle;
|
use theme::{CheckboxStyle, ContainedText, Interactive};
|
||||||
use workspace::{item::Item, Welcome, Workspace};
|
use workspace::{item::Item, Welcome, Workspace};
|
||||||
|
|
||||||
pub fn init(cx: &mut MutableAppContext) {
|
pub fn init(cx: &mut MutableAppContext) {
|
||||||
|
@ -86,6 +88,8 @@ impl View for WelcomePage {
|
||||||
theme.editor.hover_popover.prose.clone(),
|
theme.editor.hover_popover.prose.clone(),
|
||||||
)
|
)
|
||||||
.boxed(),
|
.boxed(),
|
||||||
|
self.render_cta_button(2, "Choose a theme", theme_selector::Toggle, cx),
|
||||||
|
self.render_cta_button(3, "Choose a keymap", theme_selector::Toggle, cx),
|
||||||
Flex::row()
|
Flex::row()
|
||||||
.with_children([
|
.with_children([
|
||||||
self.render_settings_checkbox::<Metrics>(
|
self.render_settings_checkbox::<Metrics>(
|
||||||
|
@ -141,6 +145,32 @@ impl WelcomePage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn render_cta_button<L, A>(
|
||||||
|
&self,
|
||||||
|
region_id: usize,
|
||||||
|
label: L,
|
||||||
|
action: A,
|
||||||
|
cx: &mut RenderContext<Self>,
|
||||||
|
) -> ElementBox
|
||||||
|
where
|
||||||
|
L: Into<Cow<'static, str>>,
|
||||||
|
A: 'static + Action + Clone,
|
||||||
|
{
|
||||||
|
let theme = cx.global::<Settings>().theme.clone();
|
||||||
|
MouseEventHandler::<A>::new(region_id, cx, |state, _| {
|
||||||
|
let style = theme.welcome.button.style_for(state, false);
|
||||||
|
Label::new(label, style.text.clone())
|
||||||
|
.contained()
|
||||||
|
.with_style(style.container)
|
||||||
|
.boxed()
|
||||||
|
})
|
||||||
|
.on_click(MouseButton::Left, move |_, cx| {
|
||||||
|
cx.dispatch_action(action.clone())
|
||||||
|
})
|
||||||
|
.aligned()
|
||||||
|
.boxed()
|
||||||
|
}
|
||||||
|
|
||||||
fn render_settings_checkbox<T: 'static>(
|
fn render_settings_checkbox<T: 'static>(
|
||||||
&self,
|
&self,
|
||||||
style: &CheckboxStyle,
|
style: &CheckboxStyle,
|
||||||
|
|
|
@ -1,55 +1,76 @@
|
||||||
|
|
||||||
import { ColorScheme } from "../themes/common/colorScheme";
|
import { ColorScheme } from "../themes/common/colorScheme";
|
||||||
import { border } from "./components";
|
import { border, background, text } from "./components";
|
||||||
|
|
||||||
|
|
||||||
export default function welcome(colorScheme: ColorScheme) {
|
export default function welcome(colorScheme: ColorScheme) {
|
||||||
let layer = colorScheme.highest;
|
let layer = colorScheme.highest;
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
let checkboxBase = {
|
let checkboxBase = {
|
||||||
cornerRadius: 4,
|
cornerRadius: 4,
|
||||||
padding: {
|
padding: {
|
||||||
left: 8,
|
left: 8,
|
||||||
right: 8,
|
right: 8,
|
||||||
top: 4,
|
top: 4,
|
||||||
bottom: 4,
|
bottom: 4,
|
||||||
},
|
},
|
||||||
shadow: colorScheme.popoverShadow,
|
shadow: colorScheme.popoverShadow,
|
||||||
border: border(layer),
|
border: border(layer),
|
||||||
margin: {
|
margin: {
|
||||||
left: -8,
|
left: -8,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
checkbox: {
|
button: {
|
||||||
width: 9,
|
background: background(layer),
|
||||||
height: 9,
|
border: border(layer),
|
||||||
default: {
|
cornerRadius: 6,
|
||||||
...checkboxBase,
|
margin: {
|
||||||
background: colorScheme.ramps.blue(0.5).hex(),
|
top: 1,
|
||||||
},
|
},
|
||||||
checked: {
|
padding: {
|
||||||
...checkboxBase,
|
top: 1,
|
||||||
background: colorScheme.ramps.red(0.5).hex(),
|
bottom: 1,
|
||||||
},
|
left: 7,
|
||||||
hovered: {
|
right: 7,
|
||||||
...checkboxBase,
|
},
|
||||||
background: colorScheme.ramps.blue(0.5).hex(),
|
...text(layer, "sans", "variant", { size: "xs" }),
|
||||||
|
hover: {
|
||||||
|
...text(layer, "sans", "hovered", { size: "xs" }),
|
||||||
|
background: background(layer, "hovered"),
|
||||||
|
border: border(layer, "hovered"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
checkbox: {
|
||||||
|
width: 9,
|
||||||
|
height: 9,
|
||||||
|
default: {
|
||||||
|
...checkboxBase,
|
||||||
|
background: colorScheme.ramps.blue(0.5).hex(),
|
||||||
|
},
|
||||||
|
checked: {
|
||||||
|
...checkboxBase,
|
||||||
|
background: colorScheme.ramps.red(0.5).hex(),
|
||||||
|
},
|
||||||
|
hovered: {
|
||||||
|
...checkboxBase,
|
||||||
|
background: colorScheme.ramps.blue(0.5).hex(),
|
||||||
|
|
||||||
border: {
|
border: {
|
||||||
color: colorScheme.ramps.green(0.5).hex(),
|
color: colorScheme.ramps.green(0.5).hex(),
|
||||||
width: 1,
|
width: 1,
|
||||||
}
|
|
||||||
},
|
|
||||||
hoveredAndChecked: {
|
|
||||||
...checkboxBase,
|
|
||||||
background: colorScheme.ramps.red(0.5).hex(),
|
|
||||||
border: {
|
|
||||||
color: colorScheme.ramps.green(0.5).hex(),
|
|
||||||
width: 1,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
hoveredAndChecked: {
|
||||||
|
...checkboxBase,
|
||||||
|
background: colorScheme.ramps.red(0.5).hex(),
|
||||||
|
border: {
|
||||||
|
color: colorScheme.ramps.green(0.5).hex(),
|
||||||
|
width: 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue