Ongoing work on supporting GTK, had to rework some concepts due to the way gtk-rs works.

This commit is contained in:
Ryan McGrath 2019-06-08 13:56:39 -07:00
parent f15cf258af
commit 0d8a14ce67
No known key found for this signature in database
GPG key ID: 811674B62B666830
20 changed files with 378 additions and 301 deletions

View file

@ -5,4 +5,4 @@ authors = ["Ryan McGrath <ryan@rymc.io>"]
edition = "2018"
[dependencies]
alchemy = { path = "../../alchemy", version = "0.2.0", features = ["cocoa"] }
alchemy = { path = "../../alchemy", version = "0.2.0", features = ["gtkrs"] }

View file

@ -8,40 +8,22 @@
/// @created March 26th, 2019
use alchemy::{
AppDelegate, Component, ComponentKey, Fragment, Error, Props, rsx, RSX, styles, text,
Text, View, Window, WindowDelegate
App, AppDelegate, Error, rsx,
RSX, text, Text, View, Window, WindowDelegate
};
pub struct AppState {
window: Window
window: Option<Window>
}
impl AppDelegate for AppState {
fn did_finish_launching(&mut self) {
self.window.set_title("Layout Test");
self.window.set_dimensions(100., 100., 600., 600.);
self.window.show();
}
}
#[derive(Default)]
struct BannerProps {}
#[derive(Props)]
struct Banner;
impl Component for Banner {
fn new(_key: ComponentKey) -> Banner {
Banner {}
}
fn render(&self, children: Vec<RSX>) -> Result<RSX, Error> {
Ok(rsx! {
<Fragment>
<View styles=["wut1"]></View>
{children}
</Fragment>
})
let mut window = Window::new(WindowState {});
window.set_title("Layout Test");
window.set_dimensions(100., 100., 600., 600.);
window.show();
self.window = Some(window);
println!("Should be showing");
}
}
@ -54,6 +36,7 @@ impl WindowDelegate for WindowState {
fn render(&self) -> Result<RSX, Error> {
let messages = vec!["LOL"]; //, "wut", "BERT"];
Ok(rsx! {
<View styles={&messages}>
<Text styles=["message"]>"Hello there, my name is Bert"</Text>
@ -61,64 +44,13 @@ impl WindowDelegate for WindowState {
{messages.iter().map(|message| rsx! {
<Text styles=["text"]>{text!("{}", message)}</Text>
})}
<View styles=["box1"]>
<Banner>
<View styles=["innermostBox"] />
</Banner>
</View>
</View>
})
}
}
fn main() {
let app = alchemy::shared_app();
app.register_styles("default", styles! {
root { background-color: #000; }
LOL {
background-color: #307ace;
width: 500;
height: 230;
padding-top: 20;
padding-left: 20;
padding-right: 40;
}
message { width: 500; height: 100; background-color: yellow; color: black; }
text { width: 500; height: 100; background-color: blue; color: white; }
boxxx {
background-color: rgba(245, 217, 28, .8);
width: 100;
height: 100;
margin-top: 40;
margin-right: 20;
}
box1 {
background-color: #f51c69;
width: 250;
height: 100;
}
wut1 {
background-color: black;
width: 50;
height: 230;
}
innermostBox {
background-color: green;
width: 20;
height: 20;
}
});
app.run(AppState {
window: Window::new(WindowState {
})
});
App::new(AppState {
window: None
}).run()
}