gpui-component/crates/story/examples/html.rs
Jason Lee 34ef0ff6d0
chore: Rename Dropdown to Select, TextInput to Input. (#1449)
## Break Change

- The `Dropdown` has been renamed to `Select`.
- The `TextInput` has been renamed to `Input`.

| Before | After |
| --- | --- |
| TextInput | Input |
| Dropdown | Select |
| DropdownItem | SelectItem |
| DropdownItemGroup | SelectGroup |
| DropdownState | SelectState |
| DropdownEvent | SelectEvent |
| DropdownDelegate | SelectDelegate |
| dropdown::ListEvent | ~~Removed~~ |

- Renamed `PopupMenuExt` to `DropdownMenu`.
- Removed pub mod `menu::popup_menu`, `menu::context_menu`, they are
moved into `menu` mod.
- Renamed `popup_menu` method to `dropdown_menu` for `DropdownMenu`,
`Panel`, `PanelView` and `DropdownButton`.

| Before | After |
| --- | --- |
| popup_menu::PopupMenuExt | menu::DropdownMenu |
| popup_menu | dropdown_menu |
| popup_menu_with_anchor | dropdown_menu_with_anchor |
2025-10-28 21:22:31 +08:00

95 lines
2.6 KiB
Rust

use gpui::*;
use gpui_component::{
highlighter::Language,
input::{Input, InputState, TabSize},
resizable::{ResizableState, h_resizable, resizable_panel},
text::TextView,
};
use story::Assets;
pub struct Example {
input_state: Entity<InputState>,
resizable_state: Entity<ResizableState>,
_subscribe: Subscription,
}
const EXAMPLE: &str = include_str!("./fixtures/test.html");
impl Example {
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
let input_state = cx.new(|cx| {
InputState::new(window, cx)
.code_editor(Language::Html)
.tab_size(TabSize {
tab_size: 4,
hard_tabs: false,
})
.default_value(EXAMPLE)
.placeholder("Enter your HTML here...")
});
let resizable_state = ResizableState::new(cx);
let _subscribe = cx.subscribe(
&input_state,
|_, _, _: &gpui_component::input::InputEvent, cx| {
cx.notify();
},
);
Self {
input_state,
resizable_state,
_subscribe,
}
}
fn view(window: &mut Window, cx: &mut App) -> Entity<Self> {
cx.new(|cx| Self::new(window, cx))
}
}
impl Render for Example {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
h_resizable("container", self.resizable_state.clone())
.child(
resizable_panel().child(
div()
.id("source")
.size_full()
.font_family("Menlo")
.text_size(px(13.))
.child(
Input::new(&self.input_state)
.h_full()
.appearance(false)
.focus_bordered(false),
),
),
)
.child(
resizable_panel().child(
TextView::html(
"preview",
self.input_state.read(cx).value().clone(),
window,
cx,
)
.p_5()
.scrollable()
.selectable(),
),
)
}
}
fn main() {
let app = Application::new().with_assets(Assets);
app.run(move |cx| {
story::init(cx);
cx.activate(true);
story::create_new_window("HTML Render (native)", Example::view, cx);
});
}