makepad_render/
liveclient.rs1use crate::cx::*;
2use std::collections::HashMap;
3use std::net::{TcpStream, SocketAddr};
4const LIVE_SERVER_DEFAULT_PORT:u16 = 45823;
6
7pub struct LiveClient{
8 pub colors: HashMap<String, HashMap<(usize,usize), Color>>
9}
10
11struct LiveError{
12 msg:String
13}
14
15type LiveResult<T> = Result<T, LiveError>;
16
17impl LiveClient{
18
19 pub fn connect_to_live_server(server_address: Option<SocketAddr>) -> Option<LiveClient> {
20 let addr = if let Some(addr) = server_address{
22 addr
23 }
24 else{
25 SocketAddr::from(([127, 0, 0, 1], LIVE_SERVER_DEFAULT_PORT))
26 };
27 let mut _tcp_stream = if let Ok(stream) = TcpStream::connect(addr) {
28 stream
29 }
30 else {
31 return None
32 };
33 None
34 }
35}
36
37impl Cx{
38 pub fn pick(&self, file:&str, line:usize, col:usize, inp:Color)->Color{
39 if let Some(lc) = &self.live_client{
40 if let Some(colors) = lc.colors.get(file){
41 if let Some(color) = colors.get(&(line, col)){
42 return *color
43 }
44 }
45 }
46 inp
47 }
48}
49
50#[macro_export]
51macro_rules!pick {
52 ( $ cx: ident, $col: literal) => {
53 $cx.pick(file!(), line!(), column!(), color($col))
54 }
55}
56