Fix to work with new GPUI.

This commit is contained in:
Jason Lee 2024-07-31 10:12:26 +08:00
parent 06008524dd
commit c94e9feae2
3 changed files with 33 additions and 31 deletions

View file

@ -278,11 +278,13 @@ impl Render for StoryWorkspace {
.gap_2() .gap_2()
.child( .child(
Button::new("theme-mode", cx) Button::new("theme-mode", cx)
.when_else( .map(|this| {
cx.theme().mode.is_dark(), if cx.theme().mode.is_dark() {
|this| this.icon(IconName::Moon), this.icon(IconName::Sun)
|this| this.icon(IconName::Sun), } else {
) this.icon(IconName::Moon)
}
})
.size(Size::Small) .size(Size::Small)
.style(ButtonStyle::Ghost) .style(ButtonStyle::Ghost)
.on_click(move |_, cx| { .on_click(move |_, cx| {

View file

@ -1,7 +1,7 @@
use gpui::{ use gpui::{
div, prelude::FluentBuilder as _, AnyElement, Context, EventEmitter, FocusHandle, div, prelude::FluentBuilder, AnyElement, Context, EventEmitter, FocusHandle, FocusableView,
FocusableView, InteractiveElement, IntoElement, KeyDownEvent, Model, MouseButton, InteractiveElement, IntoElement, KeyDownEvent, Model, MouseButton, MouseDownEvent,
MouseDownEvent, ParentElement as _, Render, SharedString, Styled as _, ViewContext, ParentElement as _, Render, SharedString, Styled as _, ViewContext,
}; };
use crate::{h_flex, theme::ActiveTheme, v_flex}; use crate::{h_flex, theme::ActiveTheme, v_flex};
@ -174,17 +174,13 @@ impl Render for OtpInput {
.h_8() .h_8()
.text_lg() .text_lg()
.on_mouse_down(MouseButton::Left, cx.listener(Self::on_input_mouse_down)) .on_mouse_down(MouseButton::Left, cx.listener(Self::on_input_mouse_down))
.when_some_else( .map(|this| match c {
c, Some(c) => this.child(if self.masked {
|this, c| {
this.child(if self.masked {
SharedString::from("") SharedString::from("")
} else { } else {
SharedString::from(c.to_string()) SharedString::from(c.to_string())
}) }),
}, None => this.when(is_input_focused && blink_show, |this| {
|this| {
this.when(is_input_focused && blink_show, |this| {
this.child( this.child(
div() div()
.h_4() .h_4()
@ -192,9 +188,8 @@ impl Render for OtpInput {
.border_l_3() .border_l_3()
.border_color(crate::blue_500()), .border_color(crate::blue_500()),
) )
}),
}) })
},
)
.into_any_element(), .into_any_element(),
); );
} }

View file

@ -5,6 +5,8 @@ use gpui::{
Interactivity, IntoElement, IsZero, Pixels, SharedString, Size, StyleRefinement, Styled, Interactivity, IntoElement, IsZero, Pixels, SharedString, Size, StyleRefinement, Styled,
WindowContext, WindowContext,
}; };
use image::Frame;
use smallvec::SmallVec;
use image::ImageBuffer; use image::ImageBuffer;
@ -124,7 +126,10 @@ impl Asset for Image {
pixel.swap(0, 2); pixel.swap(0, 2);
} }
Ok(Arc::new(ImageData::new(buffer))) Ok(Arc::new(ImageData::new(SmallVec::from_elem(
Frame::new(buffer),
1,
))))
} }
} }
} }
@ -257,7 +262,7 @@ impl Element for SvgImg {
origin: new_origin, origin: new_origin,
}; };
match cx.paint_image(img_bounds, px(0.).into(), data, false) { match cx.paint_image(img_bounds, px(0.).into(), data, 0, false) {
Ok(_) => {} Ok(_) => {}
Err(err) => eprintln!("failed to paint svg image: {:?}", err), Err(err) => eprintln!("failed to paint svg image: {:?}", err),
} }