Skip to content

Commit

Permalink
switch to livebody as procmacro
Browse files Browse the repository at this point in the history
  • Loading branch information
makepaddev committed Jan 9, 2021
1 parent fb4ad1b commit 55496e2
Show file tree
Hide file tree
Showing 49 changed files with 348 additions and 243 deletions.
5 changes: 2 additions & 3 deletions codeeditor/src/codeeditor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ impl CodeEditor {
}
}
pub fn style(cx: &mut Cx) {

live_body!(cx, r#"
live_body!(cx, {
self::layout_bg: Layout {}

self::text_style_label: TextStyle {
..makepad_widget::widgetstyle::text_style_fixed
}
"#);
});
}

pub fn handle_code_editor(&mut self, cx: &mut Cx, event: &mut Event) -> CodeEditorEvent {
Expand Down
91 changes: 9 additions & 82 deletions examples/bare_example/app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ pub struct BareExampleApp {
color_texture: Texture,
main_view: View,
quad: ButtonQuad,
text: ButtonText,
count: f32
}

Expand All @@ -34,7 +33,6 @@ impl BareExampleApp {
pass: Pass::default(),
color_texture: Texture::new(cx),
quad: ButtonQuad::new(cx, default_shader!()),
text: ButtonText::new(cx, default_shader!()),
main_view: View::new(),
count: 0.
}
Expand All @@ -45,7 +43,7 @@ impl BareExampleApp {
ButtonQuad::register_draw_input(cx);
ButtonText::register_draw_input(cx);

live_body!(cx, r#"
live_body!(cx, {
self::shader_quad: Shader {
use makepad_render::drawquad::shader::*;
draw_input: self::ButtonQuad;
Expand All @@ -62,7 +60,7 @@ impl BareExampleApp {
return mix(#f00, #0f0, abs(sin(counter + char_offset * 0.2)));
}
}
"#);
});
}

pub fn handle_app(&mut self, _cx: &mut Cx, event: &mut Event) {
Expand All @@ -78,100 +76,29 @@ impl BareExampleApp {
}

pub fn draw_app(&mut self, cx: &mut Cx) {

self.window.begin_window(cx);
self.pass.begin_pass(cx);
self.pass.add_color_texture(cx, self.color_texture, ClearColor::ClearWith(Vec4::color("300")));
if self.main_view.begin_view(cx, Layout::default()).is_ok() {
cx.profile_start(1);

//let x = 1.0f32;
//let y = x.sin();

self.quad.counter = 0.;

self.quad.begin_many(cx);
//self.quad.base.shader = live_shader!(cx, self::bg_shader);
//println!("{}", self.quad.base.slots);
self.text.counter += 0.01;

//self.text.begin_many(cx);
self.quad.counter = 0.;
self.quad.some += 1.1;
let msg = format!("HELLO WORLD");
self.quad.some = 0.;

for i in 0..1000000 {
for i in 0..1000 {
let v = 0.5 * (i as f32);
self.quad.counter += 0.01; //= (i as f32).sin();
let x = 0.0;//400. + (v + self.count).sin() * 400.;
let y = 0.0;//400. + (v * 1.12 + self.count * 18.).cos() * 400.;
let x = 400. + (v + self.count).sin() * 400.;
let y = 400. + (v * 1.12 + self.count * 18.).cos() * 400.;
self.quad.draw_quad_abs(cx, Rect {pos: vec2(x, y), size: vec2(10., 10.0)});

//self.text.draw_text_abs(cx, vec2(x, y), &msg);
}
//self.text.end_many(cx);

self.quad.end_many(cx);
self.count += 0.001;

cx.profile_end(1);

/*
cx.profile_start(2);
for i in 0..2500000 {
let v = 0.3 * (i as f32);
self.quad.draw_quad_scratch(Rect {
x: 300. + (v + self.count).sin() * 100.,
y: 300. + (v + self.count * 8.).cos() * 100.,
w: 10.,
h: 10.
});
self.quad.scratch[9] = v * 2. + self.count * 10.;
self.quad.draw_quad_scratch_final(cx, 10);
}
self.count += 0.001;
cx.profile_end(2);
cx.profile_start(3);
let inst = cx.new_instance(self.quad.shader, None, 1);
let mut data = Vec::new();
for i in 0..2500000 {
let inst_array = inst.get_instance_array(cx);
std::mem::swap(&mut data, inst_array);
let v = 0.3 * (i as f32);
self.quad.draw_quad_scratch(Rect {
x: 300. + (v + self.count).sin() * 100.,
y: 300. + (v + self.count * 8.).cos() * 100.,
w: 10.,
h: 10.
});
self.quad.scratch[9] = v * 2. + self.count * 10.;
data.extend_from_slice(&self.quad.scratch[0..10]);
std::mem::swap(inst_array, &mut data);
}
self.count += 0.001;
cx.profile_end(3);
*/
/*
cx.profile_start(4);
let inst = cx.new_instance(self.quad3.shader, None, 1);
let inst_array = inst.get_instance_array(cx);
for i in 0..2500000 {
let v = 0.3 * (i as f32);
self.quad3.rect = Rect {
x: 300. + (v + self.count).sin() * 100.,
y: 300. + (v + self.count * 8.).cos() * 100.,
w: 10.,
h: 10.
};
self.quad3.count = v * 2. + self.count * 10.;
self.quad3.draw_quad_direct(inst_array);
//inst_array.push();
}
self.count += 0.001;
cx.profile_end(4);
*/

self.main_view.redraw_view(cx);
self.main_view.end_view(cx);
}
Expand Down
2 changes: 0 additions & 2 deletions examples/editor_example/app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ impl EditorExampleApp {

pub fn handle_app(&mut self, cx: &mut Cx, event: &mut Event) {
self.desktop_window.handle_desktop_window(cx, event);

self.code_editor.handle_code_editor(cx,event);
}

Expand All @@ -44,7 +43,6 @@ impl EditorExampleApp {
};

self.code_editor.draw_code_editor(cx);

self.desktop_window.end_desktop_window(cx);
}
}
4 changes: 2 additions & 2 deletions makepad/app/src/codeicon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl CodeIcon {

pub fn style(cx: &mut Cx) {
self::DrawCodeIcon::register_draw_input(cx);
live_body!(cx, r#"
live_body!(cx, {
self::walk: Walk {
width: Fix(14.0),
height: Fix(14.0),
Expand Down Expand Up @@ -128,7 +128,7 @@ impl CodeIcon {
}
}

"#)
})
}

pub fn draw_icon(&mut self, cx: &mut Cx, icon_type: CodeIconType) {
Expand Down
4 changes: 2 additions & 2 deletions makepad/app/src/colorpicker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl ColorPicker {

pub fn style(cx: &mut Cx) {
self::DrawColorPicker::register_draw_input(cx);
live_body!(cx, r#"
live_body!(cx, {
self::anim_default: Anim {
play: Cut {duration: 0.2},
tracks: [
Expand Down Expand Up @@ -277,7 +277,7 @@ impl ColorPicker {
}

}
"#)
})
}
}

12 changes: 6 additions & 6 deletions makepad/app/src/filetree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,18 @@ impl FileTree {

pub fn style(cx: &mut Cx) {
DrawFileTreeFiller::register_draw_input(cx);
live_body!(cx, r#"
live_body!(cx, {
self::shadow_size: 6.0;
self::color_tree_folder: #f;
self::color_tree_file: #9D9D9D;
self::color_filler: #7f;
self::color_bg_marked: #11466e;
self::color_bg_selected: #28;
self::color_bg_marked: #x11466e;
self::color_bg_selected: #x28;
self::color_bg_odd: #25;
self::color_bg_marked_over: #11466e;
self::color_bg_marked_over: #x11466e;
self::color_bg_selected_over: #3d;
self::color_bg_odd_over: #38;
self::color_drag_bg: #11466e;
self::color_drag_bg: #x11466e;

self::layout_drag_bg: Layout {
padding: {l: 5., t: 5., r: 5., b: 5.},
Expand Down Expand Up @@ -164,7 +164,7 @@ impl FileTree {
}


"#)
})
}

pub fn apply_style(&mut self, cx: &mut Cx) {
Expand Down
4 changes: 2 additions & 2 deletions makepad/app/src/floatslider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl FloatSlider {

pub fn style(cx: &mut Cx) {
self::DrawFloatSlider::register_draw_input(cx);
live_body!(cx, r#"
live_body!(cx, {
self::anim_default: Anim {
play: Cut {duration: 0.2},
tracks: [
Expand Down Expand Up @@ -97,7 +97,7 @@ impl FloatSlider {
return df.result;
}
}
"#)
})
}

pub fn handle_finger(&mut self, cx: &mut Cx, rel: Vec2) -> FloatSliderEvent {
Expand Down
4 changes: 2 additions & 2 deletions makepad/app/src/homepage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl HomePage {

pub fn style(cx: &mut Cx) {

live_body!(cx, r#"
live_body!(cx, {
self::color_bg: #2;

self::text_style_heading: TextStyle {
Expand Down Expand Up @@ -80,7 +80,7 @@ impl HomePage {
new_line_padding: 15.,
line_wrap: MaxSize(550.),
}
"#)
})
}

pub fn handle_home_page(&mut self, cx: &mut Cx, event: &mut Event) {
Expand Down
4 changes: 2 additions & 2 deletions makepad/app/src/itemdisplay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl ItemDisplay {
}

pub fn style(cx: &mut Cx) {
live_body!(cx, r#"
live_body!(cx, {

self::text_style_title: TextStyle {
..makepad_widget::widgetstyle::text_style_normal
Expand All @@ -70,7 +70,7 @@ impl ItemDisplay {
makepad_widget::texteditor::padding_top: self::padding_top;
makepad_widget::texteditor::color_bg: self::color_bg;
}
"#)
})
}

pub fn display_message(&mut self, cx: &mut Cx, loc_message: &LocMessage) {
Expand Down
4 changes: 2 additions & 2 deletions makepad/app/src/liveitems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl LiveItemsView {
}

pub fn style(cx: &mut Cx) {
live_body!(cx, r#"
live_body!(cx, {
self::color_bg: #28;

self::text_style_value: TextStyle {
Expand All @@ -85,7 +85,7 @@ impl LiveItemsView {
}


"#)
})
}

pub fn handle_live_items(&mut self, cx: &mut Cx, event: &mut Event, mtb: &mut MakepadTextBuffer) {
Expand Down
8 changes: 4 additions & 4 deletions makepad/app/src/loglist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl LogList {

pub fn style(cx: &mut Cx) {

live_body!(cx, r#"
live_body!(cx, {
self::layout_item: Layout {
walk: Walk {width: Fill, height: Fix(20.)},
align: {fx: 0.0, fy: 0.5},
Expand All @@ -50,10 +50,10 @@ impl LogList {

self::color_path: #9;
self::color_message: #b;
self::color_bg_marked: #11466e;
self::color_bg_marked: #x11466E;
self::color_bg_selected: #28;
self::color_bg_odd: #25;
self::color_bg_marked_over: #11466e;
self::color_bg_marked_over: #11466F;
self::color_bg_selected_over: #3d;
self::color_bg_odd_over: #38;

Expand All @@ -70,7 +70,7 @@ impl LogList {
makepad_widget::texteditor::layout_bg: self::layout_bg;
}

"#)
})
}


Expand Down
20 changes: 10 additions & 10 deletions makepad/app/src/searchresults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ impl SearchResults {
}

pub fn style(cx: &mut Cx) {
live_body!(cx, r#"
self::color_path: #9;
self::color_message: #A67A32;
self::color_bg: #1e;
self::color_bg_marked: #11466e;
self::color_bg_odd: #25;
self::color_bg_odd_over: #3;
self::color_bg_marked_over: #11466e;
self::color_bg_selected: #28;
live_body!(cx, {
self::color_path: #x9;
self::color_message: #xA67A32;
self::color_bg: #x1e;
self::color_bg_marked: #x11466e;
self::color_bg_odd: #x25;
self::color_bg_odd_over: #x3;
self::color_bg_marked_over: #x11466e;
self::color_bg_selected: #x28;

self::text_input_layout_bg: Layout {
walk: Walk {
Expand Down Expand Up @@ -101,7 +101,7 @@ impl SearchResults {
makepad_widget::texteditor::padding_top: self::texteditor_padding_top;
}

"#)
})
}

pub fn set_search_input_value(
Expand Down
1 change: 1 addition & 0 deletions render/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ makepad-ttf-parser = { path = "./vector/ttf_parser", version = "0.1" }
makepad-path = { path = "./vector/path", version = "0.1" }
makepad-live-compiler = { path = "./live_compiler", version = "0.1" }
makepad-draw-derive = { path = "./draw_derive", version = "0.1" }
makepad-live-body = { path = "./live_body", version = "0.2" }

[target.aarch64-apple-darwin.dependencies]
makepad-objc-sys = { path = "./bind/objc-sys", version = "0.2" }
Expand Down
Loading

0 comments on commit 55496e2

Please sign in to comment.