add sizable trait
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
use gpui::{
|
||||
Entity, InteractiveElement as _, ParentElement as _, Render, Styled as _, TestAppContext,
|
||||
VisualTestContext, Window, div,
|
||||
};
|
||||
use gpui_native_core::button::{Button, ButtonVariant};
|
||||
use gpui_native_core::input::{Input, InputState};
|
||||
use gpui_native_theme::ActiveTheme as _;
|
||||
use gpui_native_theme::Theme;
|
||||
|
||||
struct Harness {
|
||||
state: Entity<InputState>,
|
||||
}
|
||||
|
||||
impl Render for Harness {
|
||||
fn render(
|
||||
&mut self,
|
||||
_window: &mut Window,
|
||||
_cx: &mut gpui::Context<Self>,
|
||||
) -> impl gpui::IntoElement {
|
||||
div()
|
||||
.flex()
|
||||
.flex_col()
|
||||
.gap_4()
|
||||
.child(
|
||||
div().debug_selector(|| "button-wrapper".to_string()).child(
|
||||
Button::new("cmp-button")
|
||||
.variant(ButtonVariant::Secondary)
|
||||
.label("Medium"),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.debug_selector(|| "input-wrapper".to_string())
|
||||
.child(Input::new("cmp-input", self.state.clone())),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// A medium input is exactly `input_height`, and sits taller than the
|
||||
/// medium button: native text fields are a touch taller than push buttons.
|
||||
#[gpui::test]
|
||||
fn medium_input_is_taller_than_the_button(cx: &mut TestAppContext) {
|
||||
cx.update(Theme::init);
|
||||
let state = cx.update(|cx| InputState::new_with_text("", cx));
|
||||
let state_for_window = state.clone();
|
||||
let window = cx.add_window(move |_, _| Harness {
|
||||
state: state_for_window,
|
||||
});
|
||||
let mut visual = VisualTestContext::from_window(window.into(), cx);
|
||||
visual.update(|window, cx| {
|
||||
window.draw(cx).clear(cx);
|
||||
});
|
||||
|
||||
let button = visual
|
||||
.debug_bounds("button-wrapper")
|
||||
.expect("button rendered");
|
||||
let input = visual
|
||||
.debug_bounds("input-wrapper")
|
||||
.expect("input rendered");
|
||||
|
||||
// The input's height is the theme table's (platform-stated) field height;
|
||||
// both bounds are snapped to device pixels, so allow half a pixel.
|
||||
let input_height = cx.update(|cx| cx.theme().sizes.medium.input_height);
|
||||
assert!(input.size.height > button.size.height);
|
||||
assert!((input.size.height - input_height).abs() <= gpui::px(0.5));
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
use gpui::{
|
||||
Entity, Modifiers, ParentElement as _, Render, Styled as _, TestAppContext,
|
||||
VisualTestContext, Window, div, point, px,
|
||||
Entity, Modifiers, ParentElement as _, Render, Styled as _, TestAppContext, VisualTestContext,
|
||||
Window, div, point, px,
|
||||
};
|
||||
use gpui_native_core::input::{Input, InputState};
|
||||
use gpui_native_theme::Theme;
|
||||
|
||||
Reference in New Issue
Block a user