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()
.child(
Button::new("theme-mode", cx)
.when_else(
cx.theme().mode.is_dark(),
|this| this.icon(IconName::Moon),
|this| this.icon(IconName::Sun),
)
.map(|this| {
if cx.theme().mode.is_dark() {
this.icon(IconName::Sun)
} else {
this.icon(IconName::Moon)
}
})
.size(Size::Small)
.style(ButtonStyle::Ghost)
.on_click(move |_, cx| {

View file

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

View file

@ -5,6 +5,8 @@ use gpui::{
Interactivity, IntoElement, IsZero, Pixels, SharedString, Size, StyleRefinement, Styled,
WindowContext,
};
use image::Frame;
use smallvec::SmallVec;
use image::ImageBuffer;
@ -124,7 +126,10 @@ impl Asset for Image {
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,
};
match cx.paint_image(img_bounds, px(0.).into(), data, false) {
match cx.paint_image(img_bounds, px(0.).into(), data, 0, false) {
Ok(_) => {}
Err(err) => eprintln!("failed to paint svg image: {:?}", err),
}