Skip to content

Instantly share code, notes, and snippets.

@Chriscbr
Created February 23, 2024 21:10
Show Gist options
  • Save Chriscbr/d0a421e9d8b8262dd0bab91a69a3733e to your computer and use it in GitHub Desktop.
Save Chriscbr/d0a421e9d8b8262dd0bab91a69a3733e to your computer and use it in GitHub Desktop.
use gpui::prelude::*;
use gpui::*;
struct Counter {
count: usize,
}
impl Render for Counter {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
let mut button = div()
.id("counter")
.flex()
.bg(rgb(0x2e7d32))
.size(Length::Definite(Pixels(300.0).into()))
.justify_center()
.items_center()
.shadow_lg()
.border()
.border_color(rgb(0x0000ff))
.text_xl()
.text_color(rgb(0xffffff))
.cursor_pointer()
.child(format!("Count: {}", &self.count));
button.interactivity().on_click(cx.listener(|this, _, cx| {
this.count += 1;
}));
div()
.id("container")
.flex()
.flex_row()
.size(Length::Definite(relative(1.0)))
.justify_center()
.items_center()
.child(button)
}
}
fn main() {
App::new().run(|cx: &mut AppContext| {
cx.open_window(WindowOptions::default(), |cx| {
let counter: View<Counter> = cx.new_view(|_cx| Counter { count: 0 });
counter
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment