gui start
This commit is contained in:
parent
5ab9cc93ac
commit
ead504a483
3992
Cargo.lock
generated
3992
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -5,4 +5,13 @@ edition = "2024"
|
|||
|
||||
[dependencies]
|
||||
enum_dispatch = "0.3.13"
|
||||
iced = "0.13.1"
|
||||
test-case = "3.3.1"
|
||||
|
||||
[lib]
|
||||
name = "libopenbirch"
|
||||
path = "src/lib/lib.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "openbirch_iced"
|
||||
path = "src/app/bin.rs"
|
||||
|
|
58
flake.nix
58
flake.nix
|
@ -9,26 +9,44 @@
|
|||
};
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, rust-overlay }:
|
||||
let
|
||||
# rust-overlay = import rust-overlay;
|
||||
pkgs = import nixpkgs
|
||||
{
|
||||
system = "x86_64-linux";
|
||||
overlays = [ rust-overlay.overlays.default ];
|
||||
};
|
||||
in
|
||||
{
|
||||
devShells.x86_64-linux.default = pkgs.mkShell {
|
||||
buildInputs = with pkgs;
|
||||
[
|
||||
rust-bin.nightly.latest.default
|
||||
rust-analyzer
|
||||
];
|
||||
|
||||
shell = ''
|
||||
echo "Hello from nix dev shell"
|
||||
'';
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
rust-overlay,
|
||||
}: let
|
||||
# rust-overlay = import rust-overlay;
|
||||
pkgs =
|
||||
import nixpkgs
|
||||
{
|
||||
system = "x86_64-linux";
|
||||
overlays = [rust-overlay.overlays.default];
|
||||
};
|
||||
in {
|
||||
devShells.x86_64-linux.default = pkgs.mkShell rec {
|
||||
buildInputs = with pkgs; [
|
||||
rust-bin.nightly.latest.default
|
||||
rust-analyzer
|
||||
|
||||
expat
|
||||
fontconfig
|
||||
freetype
|
||||
freetype.dev
|
||||
libGL
|
||||
pkg-config
|
||||
xorg.libX11
|
||||
xorg.libXcursor
|
||||
xorg.libXi
|
||||
xorg.libXrandr
|
||||
wayland
|
||||
libxkbcommon
|
||||
];
|
||||
|
||||
LD_LIBRARY_PATH =
|
||||
builtins.foldl' (a: b: "${a}:${b}/lib") "${pkgs.vulkan-loader}/lib" buildInputs;
|
||||
|
||||
shell = ''
|
||||
echo "Hello from nix dev shell"
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
7
src/app/bin.rs
Normal file
7
src/app/bin.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
use gui::GUI;
|
||||
|
||||
mod gui;
|
||||
|
||||
fn main() -> Result<(), iced::Error> {
|
||||
GUI::run("Openbirch GUI")
|
||||
}
|
4
src/app/gui/line.rs
Normal file
4
src/app/gui/line.rs
Normal file
|
@ -0,0 +1,4 @@
|
|||
#[derive(Debug, Clone)]
|
||||
pub enum Line {
|
||||
Text(String)
|
||||
}
|
96
src/app/gui/mod.rs
Normal file
96
src/app/gui/mod.rs
Normal file
|
@ -0,0 +1,96 @@
|
|||
use iced::{Element, Length, Task, widget::text};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
enum Message {
|
||||
CreateLine(Option<usize>, Line, bool),
|
||||
ChangeLine(usize, Line),
|
||||
}
|
||||
|
||||
mod line;
|
||||
use line::Line;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct GUI {
|
||||
lines: Vec<Line>,
|
||||
current_line: usize,
|
||||
}
|
||||
|
||||
impl GUI {
|
||||
pub fn run(title: &'static str) -> Result<(), iced::Error> {
|
||||
iced::application(title, Self::update, Self::view)
|
||||
.settings(iced::Settings {
|
||||
default_font: iced::font::Font::MONOSPACE,
|
||||
antialiasing: true,
|
||||
..Default::default()
|
||||
})
|
||||
.theme(|_| iced::Theme::Nord)
|
||||
.centered()
|
||||
.run_with(move || Self::new())
|
||||
}
|
||||
|
||||
fn new() -> (Self, Task<Message>) {
|
||||
let s = Self {
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
(
|
||||
s,
|
||||
Task::done(Message::CreateLine(
|
||||
None,
|
||||
Line::Text("Testline".to_owned()),
|
||||
true,
|
||||
)),
|
||||
)
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Message) -> Task<Message> {
|
||||
match message {
|
||||
Message::CreateLine(idx, line, focus) => {
|
||||
let idx = if let Some(idx) = idx {
|
||||
idx
|
||||
} else {
|
||||
self.lines.len()
|
||||
};
|
||||
self.lines.insert(idx, line);
|
||||
if focus {
|
||||
self.current_line = idx;
|
||||
}
|
||||
}
|
||||
Message::ChangeLine(idx, text) => {
|
||||
let r = self.lines.get_mut(idx);
|
||||
if let Some(r) = r {
|
||||
std::mem::replace(r, text);
|
||||
} else {
|
||||
// TODO: Error message to user
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Task::none()
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<Message> {
|
||||
iced::widget::Column::from_vec(
|
||||
self.lines
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(move |(i, line)| {
|
||||
match line {
|
||||
Line::Text(text) => iced::widget::text_input("", text)
|
||||
.width(Length::Fill)
|
||||
.on_input(move |s| Message::ChangeLine(i, Line::Text(s)))
|
||||
.on_submit(Message::CreateLine(
|
||||
Some(i + 1),
|
||||
Line::Text("".to_owned()),
|
||||
true,
|
||||
)),
|
||||
}
|
||||
.into()
|
||||
})
|
||||
.collect::<Vec<Element<Message>>>(),
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.into()
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
use std::io::{self, stdout, BufRead, Write};
|
||||
|
||||
mod node;
|
||||
mod environment;
|
||||
pub mod node;
|
||||
pub mod environment;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
Loading…
Reference in a new issue