From 2632289fc88d6baff31a28aeeb09b40f977f3ac0 Mon Sep 17 00:00:00 2001 From: Adrian Wozniak Date: Sat, 5 Jan 2019 08:19:04 +0100 Subject: [PATCH] Add icon --- src/app/mod.rs | 15 +++++++++++++-- src/config/mod.rs | 2 +- src/lexer/mod.rs | 3 ++- src/lexer/rust_lang.rs | 14 +++++++++++--- src/main.rs | 3 --- src/themes/config_creator.rs | 8 ++++---- src/ui/file/editor_file_token.rs | 8 +------- 7 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/app/mod.rs b/src/app/mod.rs index 543d37c..f9c5124 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -13,13 +13,15 @@ use sdl2::event::Event; use sdl2::hint; use sdl2::keyboard::{Keycode, Mod}; use sdl2::mouse::MouseButton; -use sdl2::pixels::Color; +use sdl2::pixels::{Color, PixelFormatEnum}; +use sdl2::surface::Surface; use sdl2::rect::{Point, Rect}; use sdl2::render::Canvas; use sdl2::ttf::Sdl2TtfContext; use sdl2::video::Window; use sdl2::EventPump; use sdl2::{Sdl, TimerSubsystem, VideoSubsystem}; +use sdl2::rwops::RWops; pub mod app_state; pub mod caret_manager; @@ -61,6 +63,7 @@ impl Application { pub fn new() -> Self { let config = Rc::new(Config::new()); let sdl_context = sdl2::init().unwrap(); + hint::set("SDL_GL_MULTISAMPLEBUFFERS", "1"); hint::set("SDL_GL_MULTISAMPLESAMPLES", "8"); hint::set("SDL_GL_ACCELERATED_VISUAL", "1"); @@ -69,12 +72,20 @@ impl Application { let video_subsystem = sdl_context.video().unwrap(); - let window = video_subsystem + let mut window: Window = video_subsystem .window("Rider", config.width(), config.height()) .position_centered() .opengl() .build() .unwrap(); + let icon_bytes = include_bytes!("../../assets/gear-64x64.bmp").clone(); + let mut rw = RWops::from_bytes(&icon_bytes).unwrap(); + let mut icon = Surface::load_bmp_rw(&mut rw).unwrap(); +// let mut icon = Surface::from_data( +// &mut icon_bytes, +// 64, 64, 64, PixelFormatEnum::RGB24 +// ).unwrap(); + window.set_icon(&mut icon); let canvas = window.into_canvas().accelerated().build().unwrap(); diff --git a/src/config/mod.rs b/src/config/mod.rs index 3d17eec..c1206cc 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -23,7 +23,7 @@ impl EditorConfig { let mut default_font_path = directories::fonts_dir(); default_font_path.push("DejaVuSansMono.ttf"); Self { - character_size: 16, + character_size: 14, font_path: default_font_path.to_str().unwrap().to_string(), current_theme: "railscasts".to_string(), margin_left: 10, diff --git a/src/lexer/mod.rs b/src/lexer/mod.rs index 9de2b63..c1a11b5 100644 --- a/src/lexer/mod.rs +++ b/src/lexer/mod.rs @@ -148,10 +148,11 @@ impl Token { pub fn parse(text: String, language: &Language) -> Vec { match language { &Language::PlainText => plain::lexer::Lexer::new(text.as_str()) - // .inspect(|tok| println!("tok: {:?}", tok)) + .inspect(|tok| warn!("tok: {:?}", tok)) .map(|t| t.0) .collect(), &Language::Rust => rust_lang::lexer::Lexer::new(text.as_str()) + .inspect(|tok| warn!("tok: {:?}", tok)) .map(|t| t.0) .collect(), } diff --git a/src/lexer/rust_lang.rs b/src/lexer/rust_lang.rs index d412c98..00d38ba 100644 --- a/src/lexer/rust_lang.rs +++ b/src/lexer/rust_lang.rs @@ -7,11 +7,19 @@ pub mod lexer { lexer! { fn next_token(text: 'a) -> (TokenType, &'a str); - r"[ \t\r\n]" => (TokenType::Whitespace { + r"( +|\t+|\n+)" => (TokenType::Whitespace { token: Token::new(text.to_string(), 0, 0, 0, 0) }, text), - r"[+-/*%=]" => (TokenType::Operator { + r"(\d+|\d+\.\d+|'[\S]')" => (TokenType::Literal { + token: Token::new(text.to_string(), 0, 0, 0, 0) + }, text), + + r"[+-/*%=<>]" => (TokenType::Operator { + token: Token::new(text.to_string(), 0, 0, 0, 0) + }, text), + + r"(:|::|\{|\}|\[|\]|,)" => (TokenType::Separator { token: Token::new(text.to_string(), 0, 0, 0, 0) }, text), @@ -19,7 +27,7 @@ pub mod lexer { token: Token::new(text.to_string(), 0, 0, 0, 0) }, text), - r"[^ \t\r\n]+" => (TokenType::Identifier { + r"[^ \t\r\n:+-/*,]+" => (TokenType::Identifier { token: Token::new(text.to_string(), 0, 0, 0, 0) }, text), } diff --git a/src/main.rs b/src/main.rs index ce004f4..d1abbf4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,10 +46,7 @@ fn init_logger() { fn main() { let mut app = Application::new(); app.init(); - init_logger(); - - // app.open_file("./assets/examples/example.txt".to_string()); app.open_file("./assets/examples/test.rs".to_string()); app.run(); } diff --git a/src/themes/config_creator.rs b/src/themes/config_creator.rs index 0265b2c..9d0d4a1 100644 --- a/src/themes/config_creator.rs +++ b/src/themes/config_creator.rs @@ -132,7 +132,7 @@ fn railscasts_theme() -> Theme { }, operator: ThemeConfig { color: SerdeColor { - r: 0, + r: 200, g: 0, b: 0, a: 0, @@ -142,9 +142,9 @@ fn railscasts_theme() -> Theme { }, separator: ThemeConfig { color: SerdeColor { - r: 121, - g: 121, - b: 121, + r: 221, + g: 221, + b: 221, a: 0, }, italic: false, diff --git a/src/ui/file/editor_file_token.rs b/src/ui/file/editor_file_token.rs index 2511577..aaf33db 100644 --- a/src/ui/file/editor_file_token.rs +++ b/src/ui/file/editor_file_token.rs @@ -45,12 +45,6 @@ impl EditorFileToken { pub fn get_line(&self, line: &usize) -> Option> { let mut vec: Vec<&TextCharacter> = vec![]; for c in self.characters.iter() { - let _tmp = ( - line.clone(), - c.line().clone(), - self.token_type.is_new_line(), - c.text_character(), - ); match ( line.clone(), c.line().clone(), @@ -94,7 +88,7 @@ impl EditorFileToken { c.clone(), self.token_type.start() + index, self.token_type.line(), - color.clone(), + color, self.config.clone(), ); text_character.update_view(renderer);