switch gpui -> iced
This commit is contained in:
parent
a08b1f2071
commit
8072e8d01c
4062
Cargo.lock
generated
4062
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -6,4 +6,4 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
gpui = { git = "https://github.com/zed-industries/zed", tag = "v0.129.2" }
|
||||
iced = {version = "0.12.1"}
|
||||
|
|
22
flake.nix
22
flake.nix
|
@ -13,7 +13,7 @@
|
|||
let pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
||||
in {
|
||||
devShell.x86_64-linux = with pkgs;
|
||||
mkShell {
|
||||
mkShell rec {
|
||||
nativeBuildInputs = [
|
||||
just
|
||||
pkg-config
|
||||
|
@ -22,28 +22,24 @@
|
|||
dir = ./.;
|
||||
sha256 = "sha256-7QfkHty6hSrgNM0fspycYkRcB82eEqYa4CoAJ9qA3tU= ";
|
||||
})
|
||||
fenix.packages.x86_64-linux.rust-analyzer
|
||||
];
|
||||
|
||||
buildInputs = [
|
||||
curl
|
||||
fontconfig
|
||||
freetype
|
||||
libgit2
|
||||
openssl
|
||||
sqlite
|
||||
zlib
|
||||
zstd
|
||||
|
||||
vulkan-headers
|
||||
vulkan-loader
|
||||
] ++ lib.optionals stdenv.isLinux [
|
||||
alsa-lib
|
||||
libGL
|
||||
|
||||
libxkbcommon
|
||||
|
||||
wayland
|
||||
xorg.libxcb
|
||||
];
|
||||
|
||||
env = {
|
||||
WAYLAND_DISPLAY = ""; # Window has nor decoration on Wayland
|
||||
LD_LIBRARY_PATH = with pkgs; lib.makeLibraryPath [ vulkan-loader ];
|
||||
# WAYLAND_DISPLAY = ""; # Window has nor decoration on Wayland
|
||||
LD_LIBRARY_PATH = with pkgs; lib.makeLibraryPath buildInputs;
|
||||
};
|
||||
};
|
||||
|
||||
|
|
BIN
fonts/icons.ttf
Normal file
BIN
fonts/icons.ttf
Normal file
Binary file not shown.
148
src/main.rs
148
src/main.rs
|
@ -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 {
|
||||
div()
|
||||
.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))
|
||||
.child(format!("Hello, {}!", &self.text))
|
||||
/**
|
||||
* This is your model. It contains all the data needed for your application to work properly.
|
||||
* The model can only be updated with the `update` function.
|
||||
*/
|
||||
struct GroceryList {
|
||||
grocery_items: Vec<String>,
|
||||
input_value: String,
|
||||
|
||||
}
|
||||
|
||||
impl Sandbox for GroceryList {
|
||||
type Message = Message;
|
||||
|
||||
/* 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() {
|
||||
App::new().run(|cx: &mut AppContext| {
|
||||
let bounds = Bounds::centered(None, size(px(600.0), px(600.0)), cx);
|
||||
cx.open_window(
|
||||
WindowOptions {
|
||||
bounds: Some(bounds),
|
||||
..Default::default()
|
||||
},
|
||||
|cx| {
|
||||
cx.new_view(|_cx| HelloWorld {
|
||||
text: "World".into(),
|
||||
})
|
||||
},
|
||||
);
|
||||
});
|
||||
fn items_list_view(items: &Vec<String>) -> Element<'static, Message> {
|
||||
|
||||
let mut column = Column::new()
|
||||
.spacing(20)
|
||||
.align_items(iced::Alignment::Center)
|
||||
.width(Length::Fill);
|
||||
|
||||
for (index, value) in items.into_iter().enumerate() {
|
||||
column = column.push(grocery_item(index, value));
|
||||
}
|
||||
|
||||
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())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue