add sizable trait
This commit is contained in:
@@ -12,9 +12,9 @@ use gpui::{
|
||||
SharedString, StatefulInteractiveElement as _, Styled as _, TextAlign, TextRun, UTF16Selection,
|
||||
Window, canvas, div, fill, point, 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};
|
||||
|
||||
/// Input layout information for hit testing and caret positioning.
|
||||
struct InputLayout {
|
||||
@@ -374,6 +374,7 @@ pub struct Input {
|
||||
id: ElementId,
|
||||
state: Entity<InputState>,
|
||||
placeholder: SharedString,
|
||||
size: Size,
|
||||
disabled: bool,
|
||||
a11y_label: Option<SharedString>,
|
||||
}
|
||||
@@ -388,6 +389,7 @@ impl Input {
|
||||
id: id.into(),
|
||||
state,
|
||||
placeholder: SharedString::default(),
|
||||
size: Size::default(),
|
||||
disabled: false,
|
||||
a11y_label: None,
|
||||
}
|
||||
@@ -418,11 +420,18 @@ impl Input {
|
||||
}
|
||||
}
|
||||
|
||||
impl Sizable for Input {
|
||||
fn apply_size(&mut self, size: Size) {
|
||||
self.size = size;
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for Input {
|
||||
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
let colors = theme.colors;
|
||||
let radius = theme.radius;
|
||||
let metrics = theme.sizes.resolve(self.size);
|
||||
let focus_handle = self.state.read(cx).focus_handle.clone();
|
||||
let layout_cell = self.state.read(cx).layout.clone();
|
||||
|
||||
@@ -447,19 +456,19 @@ impl RenderOnce for Input {
|
||||
|
||||
h_flex()
|
||||
.id(self.id.clone())
|
||||
.role(Role::TextInput)
|
||||
.aria_label(fallback_label)
|
||||
.relative()
|
||||
.overflow_hidden()
|
||||
.w_full()
|
||||
.h_7()
|
||||
.px_2()
|
||||
.h(metrics.input_height)
|
||||
.px(metrics.padding_x / 2.0)
|
||||
.rounded(radius.control)
|
||||
.border_1()
|
||||
.border_color(colors.border)
|
||||
.bg(colors.input)
|
||||
.text_sm()
|
||||
.text_size(metrics.text_size)
|
||||
.text_color(colors.foreground)
|
||||
.role(Role::TextInput)
|
||||
.aria_label(fallback_label)
|
||||
.when(self.disabled, |input| input.opacity(0.5))
|
||||
.when(!self.disabled, |input| {
|
||||
input.track_focus(&focus_handle).tab_stop(true)
|
||||
@@ -506,6 +515,7 @@ impl RenderOnce for Input {
|
||||
let layout_cell = layout_cell.clone();
|
||||
let focus = focus_handle.clone();
|
||||
let dragging = paint_dragging;
|
||||
let padding = metrics.padding_x / 2.0;
|
||||
let disabled = self.disabled;
|
||||
// `line` comes from the prepaint closure above.
|
||||
move |bounds, line, window, cx| {
|
||||
@@ -519,7 +529,6 @@ impl RenderOnce for Input {
|
||||
)
|
||||
};
|
||||
|
||||
let padding = px(8.);
|
||||
let selection = state.read(cx).selection();
|
||||
let caret_x = line.x_for_index(selection.end);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user