Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/gui_vizia/components/add.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
common::{Component, ViziaComponent},
components::Add,
gui_vizia::{popup::NewPopup, tooltip::new_component_tooltip},
gui_vizia::{gui_components::popup::NewPopup, tooltip::new_component_tooltip},
};

use vizia::{
Expand Down
2 changes: 1 addition & 1 deletion src/gui_vizia/components/constant.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
common::{Component, ViziaComponent},
components::Constant,
gui_vizia::{popup::NewPopup, tooltip::new_component_tooltip},
gui_vizia::{gui_components::popup::NewPopup, tooltip::new_component_tooltip},
};

use vizia::{
Expand Down
2 changes: 1 addition & 1 deletion src/gui_vizia/components/mem.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
common::{Component, ViziaComponent},
components::Mem,
gui_vizia::{popup::NewPopup, tooltip::new_component_tooltip},
gui_vizia::{gui_components::popup::NewPopup, tooltip::new_component_tooltip},
};

use vizia::{
Expand Down
2 changes: 1 addition & 1 deletion src/gui_vizia/components/mux.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
common::{Component, Input, ViziaComponent},
components::Mux,
gui_vizia::{popup::NewPopup, tooltip::new_component_tooltip, GuiData},
gui_vizia::{gui_components::popup::NewPopup, tooltip::new_component_tooltip, GuiData},
};

use vizia::{
Expand Down
2 changes: 1 addition & 1 deletion src/gui_vizia/components/probe.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
common::{Component, ViziaComponent},
components::Probe,
gui_vizia::{popup::NewPopup, tooltip::new_component_tooltip, GuiData},
gui_vizia::{gui_components::popup::NewPopup, tooltip::new_component_tooltip, GuiData},
};

use vizia::{
Expand Down
2 changes: 1 addition & 1 deletion src/gui_vizia/components/register.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
common::{Component, ViziaComponent},
components::Register,
gui_vizia::{popup::NewPopup, tooltip::new_component_tooltip},
gui_vizia::{gui_components::popup::NewPopup, tooltip::new_component_tooltip},
};

use vizia::{
Expand Down
2 changes: 1 addition & 1 deletion src/gui_vizia/components/sext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use crate::{
common::{Component, ViziaComponent},
components::Sext,
gui_vizia::{popup::NewPopup, tooltip::new_component_tooltip},
gui_vizia::{gui_components::popup::NewPopup, tooltip::new_component_tooltip},
};

use vizia::{
Expand Down
2 changes: 1 addition & 1 deletion src/gui_vizia/components/wire.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
common::{Component, ViziaComponent},
components::Wire,
gui_vizia::{popup::NewPopup, tooltip::new_component_tooltip},
gui_vizia::{gui_components::popup::NewPopup, tooltip::new_component_tooltip},
};

use vizia::{
Expand Down
144 changes: 9 additions & 135 deletions src/gui_vizia/gui.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use crate::common::{ComponentStore, Simulator};
use crate::gui_vizia::{grid::Grid, keymap::init_keymap, menu::Menu, transport::Transport};
use crate::gui_vizia::gui_components as gui_components;
use gui_components::*;
use crate::gui_vizia::{ keymap::init_keymap, transport::Transport};
use rfd::FileDialog;
use std::collections::HashSet;
use std::path::PathBuf;
use vizia::{icons, prelude::*};
use vizia::prelude::*;

use log::*;
use crate::gui_vizia::views::simulator::SimView;

#[derive(Lens, Clone)]
pub struct GuiData {
Expand Down Expand Up @@ -110,7 +113,6 @@ impl GuiData {
trace!("opened");
}
}

pub fn gui(cs: &ComponentStore, path: &PathBuf) {
let mut clock = 0;
let simulator = Simulator::new(cs, &mut clock);
Expand Down Expand Up @@ -139,7 +141,7 @@ pub fn gui(cs: &ComponentStore, path: &PathBuf) {

VStack::new(cx, |cx| {
// Menu
Menu::new(cx, |cx| {
menu::Menu::new(cx, |cx| {
HStack::new(cx, |cx| {
Transport::new(cx).size(Auto);
Label::new(cx, GuiData::clock.map(|clock| format!("Clock #{}", clock)))
Expand All @@ -155,138 +157,7 @@ pub fn gui(cs: &ComponentStore, path: &PathBuf) {
.background_color(Color::lightgray())
.height(Auto);

HStack::new(cx, |cx| {
HStack::new(cx, |cx| {
// Left pane
Binding::new(
cx,
GuiData::simulator.then(Simulator::ordered_components),
|cx, wrapper_oc| {
VStack::new(cx, |cx| {
Label::new(cx, "Left").top(Pixels(0.0));
let oc = wrapper_oc.get(cx);
for (i, c) in oc.iter().enumerate() {
VStack::new(cx, |cx| {
// left pane bar
HStack::new(cx, move |cx| {
Button::new(
cx,
move |cx| {
cx.emit(GuiEvent::ToggleExpandLeftPanel(i))
},
|cx| {
Label::new(
cx,
GuiData::expanded.map(move |expanded| {
if expanded.contains(&i) {
// expanded
icons::ICON_CHEVRON_DOWN
} else {
// folded
icons::ICON_CHEVRON_RIGHT
}
}),
)
.class("icon")
},
)
.left(Pixels(5.0))
.top(Stretch(1.0))
.bottom(Stretch(1.0))
.right(Stretch(1.0))
.size(Auto);
let (id, _) = c.get_id_ports();

Label::new(cx, &format!("Instance: {}", &id))
.left(Pixels(5.0))
.top(Stretch(1.0))
.bottom(Stretch(1.0))
.right(Stretch(1.0))
.size(Auto);

Button::new(
cx,
move |cx| cx.emit(GuiEvent::HideLeftPanel(i)),
|cx| Label::new(cx, icons::ICON_X).class("icon"),
)
.right(Pixels(1.0))
.top(Pixels(1.0))
.bottom(Pixels(1.0));
})
.background_color(Color::lightgrey())
.height(Auto)
.border_color(Color::darkgray())
.border_width(Pixels(1.0));
// left view expanded or folded
VStack::new(cx, |cx| c.left_view(cx)).display(
GuiData::expanded.map(move |hs_expanded| {
if hs_expanded.contains(&i) {
Display::Flex
} else {
Display::None
}
}),
);
})
.display(
GuiData::visible.map(move |hs_visible| {
if hs_visible.contains(&i) {
Display::Flex
} else {
Display::None
}
}),
);
}
})
.border_color(Color::black())
.border_width(Pixels(1.0));
},
);
});

ScrollView::new(cx, 0.0, 0.0, true, true, |cx| {
// Grid area
Grid::new(cx, |cx| {
// (re-)bind all components when simulator changed
Binding::new(
cx,
GuiData::simulator.then(Simulator::ordered_components),
|cx, wrapper_oc| {
VStack::new(cx, |cx| {
let oc = wrapper_oc.get(cx);
for (i, c) in oc.iter().enumerate() {
error!("comp id {}", i);
VStack::new(cx, |cx| {
c.view(cx);
})
.position_type(PositionType::SelfDirected)
.size(Auto)
.on_mouse_down(
move |ex, button| {
if button == MouseButton::Right {
error!("on_mouse_down {:?}", i);
ex.emit(GuiEvent::ShowLeftPanel(i))
}
},
);
}
})
.border_color(Color::black())
.border_width(Pixels(1.0))
.overflow(Overflow::Hidden);
},
)
})
.height(Pixels(1080.0))
.width(Pixels(1920.0));
})
// .size(Units::Pixels(300.0))
.class("bg-default");

// Right pane
Label::new(cx, "Right").top(Pixels(0.0));
});

//
// HStack::new(cx, |cx| {
Expand All @@ -310,7 +181,10 @@ pub fn gui(cs: &ComponentStore, path: &PathBuf) {
})
.on_blur(|cx| cx.emit(GuiEvent::HideAbout))
.class("modal");

SimView::new(cx, (30.0, 50.0, 20.0));
});

})
.title("SyncRim")
.run();
Expand Down
4 changes: 4 additions & 0 deletions src/gui_vizia/gui_components.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod menu;
pub mod simulator;
pub mod popup;
pub mod grid;
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub(crate) struct Menu {}
impl View for Menu {}

impl Menu {
pub(crate) fn new<F>(cx: &mut Context, content: F) -> Handle<'_, Self>
pub fn new<F>(cx: &mut Context, content: F) -> Handle<'_, Self>
where
F: FnOnce(&mut Context),
{
Expand Down
File renamed without changes.
Empty file.
5 changes: 2 additions & 3 deletions src/gui_vizia/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
mod grid;
mod gui;
pub mod hover;
mod keymap;
mod menu;
pub mod popup;
pub mod tooltip;
mod transport;
#[cfg(feature = "components")]
pub mod components;
pub mod gui_components;
mod views;

pub use gui::*;
1 change: 1 addition & 0 deletions src/gui_vizia/views.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod simulator;
100 changes: 100 additions & 0 deletions src/gui_vizia/views/simulator/leftpane.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
use vizia::icons;
use vizia::prelude::*;
use crate::common::Simulator;
use crate::gui_vizia::{GuiData, GuiEvent};

pub struct LeftPane {}

impl View for LeftPane {}

impl LeftPane {
pub fn new(cx: &mut Context) -> Handle<Self> {
Self {}.build(cx, |cx|{
Binding::new(
cx,
GuiData::simulator.then(Simulator::ordered_components),
|cx, wrapper_oc| {
VStack::new(cx, |cx| {
Label::new(cx, "Left").top(Pixels(0.0));
let oc = wrapper_oc.get(cx);
for (i, c) in oc.iter().enumerate() {
VStack::new(cx, |cx| {
// left pane bar
HStack::new(cx, move |cx| {
Button::new(
cx,
move |cx| {
cx.emit(GuiEvent::ToggleExpandLeftPanel(i))
},
|cx| {
Label::new(
cx,
GuiData::expanded.map(move |expanded| {
if expanded.contains(&i) {
// expanded
icons::ICON_CHEVRON_DOWN
} else {
// folded
icons::ICON_CHEVRON_RIGHT
}
}),
)
.class("icon")
},
)
.left(Pixels(5.0))
.top(Stretch(1.0))
.bottom(Stretch(1.0))
.right(Stretch(1.0))
.size(Auto);
let (id, _) = c.get_id_ports();

Label::new(cx, &format!("Instance: {}", &id))
.left(Pixels(5.0))
.top(Stretch(1.0))
.bottom(Stretch(1.0))
.right(Stretch(1.0))
.size(Auto);

Button::new(
cx,
move |cx| cx.emit(GuiEvent::HideLeftPanel(i)),
|cx| Label::new(cx, icons::ICON_X).class("icon"),
)
.right(Pixels(1.0))
.top(Pixels(1.0))
.bottom(Pixels(1.0));
})
.background_color(Color::lightgrey())
.height(Auto)
.border_color(Color::darkgray())
.border_width(Pixels(1.0));
// left view expanded or folded
VStack::new(cx, |cx| c.left_view(cx)).display(
GuiData::expanded.map(move |hs_expanded| {
if hs_expanded.contains(&i) {
Display::Flex
} else {
Display::None
}
}),
);
})
.display(
GuiData::visible.map(move |hs_visible| {
if hs_visible.contains(&i) {
Display::Flex
} else {
Display::None
}
}),
);
}
})
.border_color(Color::black())
.border_width(Pixels(1.0));
},
);
})
}
}
Loading