Repository navigation
|
I've looked at the helloworld example in the project, and I don't understand why it can't resize the window. At the same time, I checked the story project and used titlebar to create an application, which also cannot resize the window. I don't know where the problem is. use gpui::{
actions, div, prelude::*, px, rgb, size, App, Application, Bounds, Context, Corners, Hsla, MouseButton, Pixels, SharedString, Size, Window, WindowBounds, WindowKind, WindowOptions
};
use gpui_component::{self, TitleBar};
use rbeaver::Assets;
actions!(window, [Quit]);
struct MainWindow {
title: SharedString,
}
impl Render for MainWindow {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
div()
.flex_col()
.size_full()
.bg(rgb(0xffffff))
.on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
.child(
TitleBar::new()
.child(div().flex().items_center().child(self.title.clone()))
.child(
div()
.flex()
.items_center()
.child(div().ml_auto().w(px(12.)).h_full()),
),
)
.child(
div()
.flex_1()
.overflow_hidden()
.flex()
.size_full()
.gap_3()
.bg(rgb(0x505050))
.justify_center()
.items_center()
.shadow_lg()
.border_1()
.border_color(rgb(0x0000ff))
.text_xl()
.text_color(rgb(0xffffff))
.child("Hello, World!"),
)
}
}
fn main() {
Application::new().with_assets(Assets).run(|cx: &mut App| {
gpui_component::init(cx);
let mut window_size = size(px(1600.0), px(1200.0));
if let Some(display) = cx.primary_display() {
let display_size = display.bounds().size;
window_size.width = window_size.width.min(display_size.width * 0.85);
window_size.height = window_size.height.min(display_size.height * 0.85);
}
let window_bounds = Bounds::centered(None, window_size, cx);
let options = WindowOptions {
window_bounds: Some(WindowBounds::Windowed(window_bounds)),
titlebar: Some(TitleBar::title_bar_options()),
window_min_size: Some(gpui::Size {
width: px(480.),
height: px(320.),
}),
kind: WindowKind::Normal,
#[cfg(target_os = "linux")]
window_background: gpui::WindowBackgroundAppearance::Transparent,
#[cfg(target_os = "linux")]
window_decorations: Some(gpui::WindowDecorations::Client),
..Default::default()
};
cx.open_window(options, |_, cx| {
cx.new(|_| MainWindow {
title: "RBeaver".into(),
})
})
.unwrap();
});
} |
Answered by
huacnlee
Sep 17, 2025
Replies: 1 comment 1 reply
|
You must use And GPUI Component required the root element must to use the |
1 reply
Answer selected by
amwps290
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You must use
Rootfor your root element on window. There have special window resizing feature provider from this.And GPUI Component required the root element must to use the
Root.https://github.com/huacnlee/gpui-app/blob/8a3ef51ea1532c4d3a207db25a6e21d8dda6707f/crates/hello_world/src/main.rs#L63
https://github.com/huacnlee/gpui-app/blob/8a3ef51ea1532c4d3a207db25a6e21d8dda6707f/crates/ui/src/root.rs#L379-L388