add sizable trait
This commit is contained in:
+13
-3
@@ -4,9 +4,9 @@ use gpui::{
|
||||
ParentElement as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _,
|
||||
Styled as _, Window, px,
|
||||
};
|
||||
use gpui_native_theme::ActiveTheme as _;
|
||||
use gpui_native_theme::{ActiveTheme as _, Size};
|
||||
|
||||
use crate::common::h_flex;
|
||||
use crate::common::{Sizable, h_flex};
|
||||
|
||||
/// The click handler. When set it replaces the default `href` opening.
|
||||
type ClickHandler = Box<dyn Fn(&ClickEvent, &mut Window, &mut App)>;
|
||||
@@ -17,6 +17,7 @@ pub struct Link {
|
||||
id: ElementId,
|
||||
label: Option<SharedString>,
|
||||
href: Option<SharedString>,
|
||||
size: Size,
|
||||
disabled: bool,
|
||||
a11y_label: Option<SharedString>,
|
||||
on_click: Option<ClickHandler>,
|
||||
@@ -32,6 +33,7 @@ impl Link {
|
||||
id: id.into(),
|
||||
label: None,
|
||||
href: None,
|
||||
size: Size::default(),
|
||||
disabled: false,
|
||||
a11y_label: None,
|
||||
on_click: None,
|
||||
@@ -81,18 +83,26 @@ impl Link {
|
||||
}
|
||||
}
|
||||
|
||||
impl Sizable for Link {
|
||||
fn apply_size(&mut self, size: Size) {
|
||||
self.size = size;
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for Link {
|
||||
fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
let colors = theme.colors;
|
||||
let ramps = theme.ramps;
|
||||
let metrics = theme.sizes.resolve(self.size);
|
||||
|
||||
let on_click = self.on_click;
|
||||
let href = self.href;
|
||||
let a11y_label = self.a11y_label.or_else(|| self.label.clone());
|
||||
|
||||
h_flex()
|
||||
.id(self.id)
|
||||
.text_sm()
|
||||
.text_size(metrics.text_size)
|
||||
.text_color(colors.accent)
|
||||
.underline()
|
||||
.role(Role::Link)
|
||||
|
||||
Reference in New Issue
Block a user