Description
div on_hover() and on_click not trigger
and the webside: https://longbridge.github.io/gpui-component/docs/components/button
click Options button and select any one ,the page will stuck。
Environment
- Platform: Manjaro 26 ,niri
Steps to Reproduce
this is my code :
use gpui::{InteractiveElement, ParentElement, Render, StatefulInteractiveElement, Styled, div};
use gpui_component::{
IconName, StyledExt, avatar::Avatar, black, button::Button, white, yellow_100,list
};
pub struct Sider{
pub hover_id:String,
}
impl Sider {
pub fn new()->Self{
Self { hover_id: String::new() }
}
}
impl Render for Sider {
fn render(
&mut self,
_: &mut gpui::Window,
cx: &mut gpui::Context,
) -> impl gpui::IntoElement {
//println!("Sider render called, hover_id = {}", self.hover_id);
div()
.child(
div().child(
div()
.flex()
.items_center()
.p_2()
.child(
Avatar::new().name("Zenghaifeng"), //.src("https://tdesign.gtimg.com/site/avatar.jpg"),
)
.child(div().pl_2().child("Zenghaifeng")),
),
)
.child(
div()
.flex()
.p_2()
.gap_1()
.child(
Button::new("home")
.icon(IconName::Battery)
.w_1_2(),
)
.child(Button::new("like").icon(IconName::Heart).w_1_2()),
)
.child(
div()
.flex()
.p_2()
.gap_1()
.child(
Button::new("popula")
.icon(IconName::Palette)
.w_1_2(),
)
.child(Button::new("plus").icon(IconName::Plus).w_1_2()),
)
.child(
div().v_flex().p_2().size_full().child(
div().flex_col().gap_2()
.size_full()
.child(div().id("like_button").h_10().w_full().rounded_md().cursor_pointer().bg(if self.hover_id == "like_button" {black()}else {yellow_100()})
.on_hover(cx.listener(move |this,hovered,_window,cx|{
if *hovered {
println!("hoverd");
this.hover_id="like_button".to_string();
}else{
println!("not hoverd");
this.hover_id=String::new();
}
cx.notify();
})).on_click(move |_,_,_| println!("like_button licked")).child("lick"))
.child(div().child("aa"))
.child(div().child("bb"))
.child(div().child("cc"))
)
)
}
}
Description
div on_hover() and on_click not trigger
and the webside: https://longbridge.github.io/gpui-component/docs/components/button
click Options button and select any one ,the page will stuck。
Environment
Steps to Reproduce
this is my code :
use gpui::{InteractiveElement, ParentElement, Render, StatefulInteractiveElement, Styled, div};
use gpui_component::{
IconName, StyledExt, avatar::Avatar, black, button::Button, white, yellow_100,list
};
pub struct Sider{
pub hover_id:String,
}
impl Sider {
pub fn new()->Self{
Self { hover_id: String::new() }
}
}
impl Render for Sider {
fn render(
&mut self,
_: &mut gpui::Window,
cx: &mut gpui::Context,
) -> impl gpui::IntoElement {
//println!("Sider render called, hover_id = {}", self.hover_id);
div()
.child(
div().child(
div()
.flex()
.items_center()
.p_2()
.child(
Avatar::new().name("Zenghaifeng"), //.src("https://tdesign.gtimg.com/site/avatar.jpg"),
)
.child(div().pl_2().child("Zenghaifeng")),
),
)
.child(
div()
.flex()
.p_2()
.gap_1()
.child(
Button::new("home")
.icon(IconName::Battery)
.w_1_2(),
)
.child(Button::new("like").icon(IconName::Heart).w_1_2()),
)
.child(
div()
.flex()
.p_2()
.gap_1()
.child(
Button::new("popula")
.icon(IconName::Palette)
.w_1_2(),
)
.child(Button::new("plus").icon(IconName::Plus).w_1_2()),
)
.child(
div().v_flex().p_2().size_full().child(
div().flex_col().gap_2()
.size_full()
.child(div().id("like_button").h_10().w_full().rounded_md().cursor_pointer().bg(if self.hover_id == "like_button" {black()}else {yellow_100()})
.on_hover(cx.listener(move |this,hovered,_window,cx|{
if *hovered {
println!("hoverd");
this.hover_id="like_button".to_string();
}else{
println!("not hoverd");
this.hover_id=String::new();
}