switch gpui -> iced

This commit is contained in:
Fabien Freling 2024-04-16 13:52:12 +02:00
parent a08b1f2071
commit 8072e8d01c
5 changed files with 1211 additions and 3023 deletions

4062
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -6,4 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
gpui = { git = "https://github.com/zed-industries/zed", tag = "v0.129.2" } iced = {version = "0.12.1"}

View file

@ -13,7 +13,7 @@
let pkgs = nixpkgs.legacyPackages.x86_64-linux; let pkgs = nixpkgs.legacyPackages.x86_64-linux;
in { in {
devShell.x86_64-linux = with pkgs; devShell.x86_64-linux = with pkgs;
mkShell { mkShell rec {
nativeBuildInputs = [ nativeBuildInputs = [
just just
pkg-config pkg-config
@ -22,28 +22,24 @@
dir = ./.; dir = ./.;
sha256 = "sha256-7QfkHty6hSrgNM0fspycYkRcB82eEqYa4CoAJ9qA3tU= "; sha256 = "sha256-7QfkHty6hSrgNM0fspycYkRcB82eEqYa4CoAJ9qA3tU= ";
}) })
fenix.packages.x86_64-linux.rust-analyzer
]; ];
buildInputs = [ buildInputs = [
curl
fontconfig fontconfig
freetype
libgit2 vulkan-headers
openssl
sqlite
zlib
zstd
vulkan-loader vulkan-loader
] ++ lib.optionals stdenv.isLinux [ libGL
alsa-lib
libxkbcommon libxkbcommon
wayland wayland
xorg.libxcb
]; ];
env = { env = {
WAYLAND_DISPLAY = ""; # Window has nor decoration on Wayland # WAYLAND_DISPLAY = ""; # Window has nor decoration on Wayland
LD_LIBRARY_PATH = with pkgs; lib.makeLibraryPath [ vulkan-loader ]; LD_LIBRARY_PATH = with pkgs; lib.makeLibraryPath buildInputs;
}; };
}; };

BIN
fonts/icons.ttf Normal file

Binary file not shown.

View file

@ -1,39 +1,123 @@
use gpui::*; use iced::{alignment, widget::{button, column, container, row, scrollable, text, text_input, Column}, Element, Length, Padding, Sandbox, Settings};
struct HelloWorld {
text: SharedString, #[derive(Debug, Clone)]
enum Message {
InputValue(String),
Submitted,
DeleteItem(usize),
} }
impl Render for HelloWorld { /**
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement { * This is your model. It contains all the data needed for your application to work properly.
div() * The model can only be updated with the `update` function.
.flex() */
.bg(rgb(0x2e7d32)) struct GroceryList {
.size(Length::Definite(Pixels(300.0).into())) grocery_items: Vec<String>,
.justify_center() input_value: String,
.items_center()
.shadow_lg() }
.border()
.border_color(rgb(0x0000ff)) impl Sandbox for GroceryList {
.text_xl() type Message = Message;
.text_color(rgb(0xffffff))
.child(format!("Hello, {}!", &self.text)) /* Initialize your app */
fn new() -> GroceryList {
Self {
grocery_items: vec![
"Eggs".to_owned(),
"Milk".to_owned(),
"Flour".to_owned()
],
input_value: String::default()
}
} }
/**
* The title of the window. It will show up on the top of your application window.
*/
fn title(&self) -> String {
String::from("Grocery List App")
}
fn update(&mut self, message: Self::Message) {
match message {
Message::InputValue(value) => self.input_value = value,
Message::Submitted => {
let input_value = self.input_value.clone();
self.input_value = String::default(); // Clear the input value
self.grocery_items.push(input_value);
}
Message::DeleteItem(item) => {
self.grocery_items.remove(item);
},
}
}
fn view(&self) -> Element<Self::Message> {
container(
column!(
items_list_view(&self.grocery_items),
row!(
text_input("Input grocery item", &self.input_value)
.on_input(|value| Message::InputValue(value))
.on_submit(Message::Submitted),
button("Submit")
.on_press(Message::Submitted)
)
.spacing(30)
.padding(Padding::from(30))
)
.align_items(iced::Alignment::Center)
)
.height(Length::Fill)
.width(Length::Fill)
.align_x(alignment::Horizontal::Center)
.align_y(alignment::Vertical::Center)
.into()
}
fn theme(&self) -> iced::Theme {
iced::Theme::Dark
}
} }
fn main() { fn items_list_view(items: &Vec<String>) -> Element<'static, Message> {
App::new().run(|cx: &mut AppContext| {
let bounds = Bounds::centered(None, size(px(600.0), px(600.0)), cx); let mut column = Column::new()
cx.open_window( .spacing(20)
WindowOptions { .align_items(iced::Alignment::Center)
bounds: Some(bounds), .width(Length::Fill);
..Default::default()
}, for (index, value) in items.into_iter().enumerate() {
|cx| { column = column.push(grocery_item(index, value));
cx.new_view(|_cx| HelloWorld { }
text: "World".into(),
}) scrollable(
}, container(
); column
}); )
)
.height(250.0)
.width(300)
.into()
}
fn grocery_item(index: usize, value: &str) -> Element<'static, Message> {
row!(
text(value),
button("Delete")
.on_press(Message::DeleteItem(index))
)
.align_items(iced::Alignment::Center)
.spacing(30)
.into()
}
pub fn main() -> iced::Result {
GroceryList::run(Settings::default())
} }