Skip to content

Commit

Permalink
Update playground to latest vizia (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
geom3trik authored Sep 11, 2023
1 parent fe7c463 commit eb66a92
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 222 deletions.
1 change: 1 addition & 0 deletions playground/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
# vizia = {path = "../../vizia"}
vizia = {git = "https://github.com/vizia/vizia"}
morphorm-ecs = {path = "../ecs"}
morphorm = {path = ".."}
Expand Down
16 changes: 8 additions & 8 deletions playground/src/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl View for CanvasView {
fn event(&mut self, cx: &mut EventContext, event: &mut Event) {
event.map(|window_event, _| match window_event {
WindowEvent::GeometryChanged(geo) => {
if geo.contains(GeometryChanged::WIDTH_CHANGED) || geo.contains(GeometryChanged::HEIGHT_CHANGED) {
if geo.contains(GeoChanged::WIDTH_CHANGED) || geo.contains(GeoChanged::HEIGHT_CHANGED) {
cx.emit(AppEvent::SetCanvasSize(
cx.cache.get_width(cx.current()) - 100.0,
cx.cache.get_height(cx.current()) - 100.0,
Expand All @@ -43,11 +43,11 @@ impl View for CanvasView {
&app_data.world.cache,
posx,
posy,
cx.mouse.cursorx,
cx.mouse.cursory,
cx.mouse().cursorx,
cx.mouse().cursory,
);
// println!("selected: {:?}", selected);
if cx.modifiers.contains(Modifiers::SHIFT) {
if cx.modifiers().contains(Modifiers::SHIFT) {
if let Some(selected) = selected {
cx.emit(AppEvent::MultiSelectNode(*selected));
}
Expand All @@ -67,8 +67,8 @@ impl View for CanvasView {

let mut path = vg::Path::new();
path.rect(bounds.x, bounds.y, bounds.w, bounds.h);
let background_color = cx.background_color().copied().unwrap_or_default();
canvas.fill_path(&mut path, &vg::Paint::color(background_color.into()));
let background_color = cx.background_color();
canvas.fill_path(&path, &vg::Paint::color(background_color.into()));

draw_node(
&app_data.root_node,
Expand Down Expand Up @@ -145,14 +145,14 @@ fn draw_node<N: Node<CacheKey = ecs::Entity>>(
let mut path = vg::Path::new();
path.rect(parent_pos.0 + posx, parent_pos.1 + posy, width, height);
let paint = vg::Paint::color(vg::Color::rgb(*red, *green, *blue));
canvas.fill_path(&mut path, &paint);
canvas.fill_path(&path, &paint);

if let Some(selected_nodes) = selected_nodes {
for selected_node in selected_nodes {
if node.key() == selected_node.key() {
let mut selection_paint = vg::Paint::color(vg::Color::rgb(72, 113, 174));
selection_paint.set_line_width(4.0);
canvas.stroke_path(&mut path, &selection_paint);
canvas.stroke_path(&path, &selection_paint);
}
}
}
Expand Down
39 changes: 0 additions & 39 deletions playground/src/icons.rs

This file was deleted.

46 changes: 26 additions & 20 deletions playground/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ use canvas::*;
mod properties;
use properties::*;

mod icons;

pub enum AppEvent {
Relayout,
SetCanvasSize(f32, f32),
Expand Down Expand Up @@ -43,8 +41,8 @@ pub enum AppEvent {
AlignBottom,
FillHeight,

SetLayoutType(&'static str),
SetPositionType(&'static str),
SetLayoutType(usize),
SetPositionType(usize),

SetChildLeft(morph::Units),
SetColBetween(morph::Units),
Expand Down Expand Up @@ -92,11 +90,11 @@ pub struct AppData {
height: morph::Units,
bottom: morph::Units,

layout_type: morph::LayoutType,
selected_layout_type: usize,
layout_type_list: Vec<&'static str>,

position_type: morph::PositionType,
position_type_list: Vec<&'static str>,
selected_position_type: usize,

child_left: morph::Units,
col_between: morph::Units,
Expand Down Expand Up @@ -156,11 +154,11 @@ impl AppData {
height: morph::Units::Pixels(600.0),
bottom: morph::Units::Auto,

layout_type: morph::LayoutType::Column,
selected_layout_type: 0,
layout_type_list: vec!["Row", "Column"],

position_type: morph::PositionType::ParentDirected,
position_type_list: vec!["Parent Directed", "Self Directed"],
selected_position_type: 0,

child_left: morph::Units::Stretch(1.0),
col_between: morph::Units::Stretch(1.0),
Expand Down Expand Up @@ -194,8 +192,14 @@ impl AppData {
self.col_between = self.world.store.col_between.get(node).copied().unwrap_or_default();
self.row_between = self.world.store.row_between.get(node).copied().unwrap_or_default();

self.layout_type = self.world.store.layout_type.get(node).copied().unwrap_or_default();
self.position_type = self.world.store.position_type.get(node).copied().unwrap_or_default();
self.selected_layout_type = match self.world.store.layout_type.get(node).copied().unwrap_or_default() {
morph::LayoutType::Column => 0,
morph::LayoutType::Row => 1,
};
self.selected_position_type = match self.world.store.position_type.get(node).copied().unwrap_or_default() {
morph::PositionType::ParentDirected => 0,
morph::PositionType::SelfDirected => 1,
};

self.min_left = self.world.store.min_left.get(node).copied().unwrap_or_default();
self.min_width = self.world.store.min_width.get(node).copied().unwrap_or_default();
Expand Down Expand Up @@ -381,29 +385,29 @@ impl Model for AppData {
}
}

AppEvent::SetLayoutType(layout_type) => {
AppEvent::SetLayoutType(selected_layout_type) => {
if let Some(nodes) = &self.selected_nodes {
for selected in nodes {
let layout_type = match *layout_type {
"Row" => morph::LayoutType::Row,
let layout_type = match *selected_layout_type {
0 => morph::LayoutType::Row,
_ => morph::LayoutType::Column,
};
self.world.set_layout_type(*selected, layout_type);
self.layout_type = layout_type;
self.selected_layout_type = *selected_layout_type;
}
cx.emit(AppEvent::Relayout);
}
}

AppEvent::SetPositionType(position_type) => {
AppEvent::SetPositionType(selected_position_type) => {
if let Some(nodes) = &self.selected_nodes {
for selected in nodes {
let position_type = match *position_type {
"Parent Directed" => morph::PositionType::ParentDirected,
let position_type = match *selected_position_type {
0 => morph::PositionType::ParentDirected,
_ => morph::PositionType::SelfDirected,
};
self.world.set_position_type(*selected, position_type);
self.position_type = position_type;
self.selected_position_type = *selected_position_type;
}
cx.emit(AppEvent::Relayout);
}
Expand Down Expand Up @@ -706,8 +710,10 @@ impl Model for AppData {

fn main() {
Application::new(|cx| {
cx.add_stylesheet("playground/src/theme.css").expect("Failed to find stylesheet");
cx.add_fonts_mem(&[include_bytes!("tabler-icons.ttf")]);
cx.add_stylesheet(include_style!("src/theme.css")).expect("Failed to find stylesheet");

// cx.emit(EnvironmentEvent::SetThemeMode(ThemeMode::DarkMode));

AppData::new().build(cx);
HStack::new(cx, |cx| {
// Treeview
Expand Down
Loading

0 comments on commit eb66a92

Please sign in to comment.