gpui: Fix text-align
with nowrap mode (#24116)
Release Notes: - N/A ------ - Continue #24090 to fix text align for when used `whitespace_nowrap`. - Fix wrapped line length calculation. And add example ``` cargo run -p gpui --example text_layout ``` <img width="760" alt="image" src="https://github.com/user-attachments/assets/a087c300-0e0e-4a80-98c6-90161a9b0905" /> --------- Co-authored-by: Owen Law <owenlaw222@gmail.com>
This commit is contained in:
parent
e689c8c01b
commit
c5913899d9
4 changed files with 83 additions and 16 deletions
64
crates/gpui/examples/text_layout.rs
Normal file
64
crates/gpui/examples/text_layout.rs
Normal file
|
@ -0,0 +1,64 @@
|
|||
use gpui::{
|
||||
div, prelude::*, px, size, App, Application, Bounds, Context, Window, WindowBounds,
|
||||
WindowOptions,
|
||||
};
|
||||
|
||||
struct HelloWorld {}
|
||||
|
||||
impl Render for HelloWorld {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
div()
|
||||
.bg(gpui::white())
|
||||
.flex()
|
||||
.flex_col()
|
||||
.gap_3()
|
||||
.p_4()
|
||||
.size_full()
|
||||
.child(div().child("Text left"))
|
||||
.child(div().text_center().child("Text center"))
|
||||
.child(div().text_right().child("Text right"))
|
||||
.child(
|
||||
div()
|
||||
.flex()
|
||||
.gap_2()
|
||||
.justify_between()
|
||||
.child(
|
||||
div()
|
||||
.w(px(400.))
|
||||
.border_1()
|
||||
.border_color(gpui::blue())
|
||||
.p_1()
|
||||
.whitespace_nowrap()
|
||||
.overflow_hidden()
|
||||
.text_center()
|
||||
.child("A long non-wrapping text align center"),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.w_32()
|
||||
.border_1()
|
||||
.border_color(gpui::blue())
|
||||
.p_1()
|
||||
.whitespace_nowrap()
|
||||
.overflow_hidden()
|
||||
.text_right()
|
||||
.child("100%"),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
Application::new().run(|cx: &mut App| {
|
||||
let bounds = Bounds::centered(None, size(px(800.0), px(600.0)), cx);
|
||||
cx.open_window(
|
||||
WindowOptions {
|
||||
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
||||
..Default::default()
|
||||
},
|
||||
|_, cx| cx.new(|_| HelloWorld {}),
|
||||
)
|
||||
.unwrap();
|
||||
cx.activate(true);
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue