Add icon
This commit is contained in:
parent
3a39fab87a
commit
2632289fc8
@ -13,13 +13,15 @@ use sdl2::event::Event;
|
|||||||
use sdl2::hint;
|
use sdl2::hint;
|
||||||
use sdl2::keyboard::{Keycode, Mod};
|
use sdl2::keyboard::{Keycode, Mod};
|
||||||
use sdl2::mouse::MouseButton;
|
use sdl2::mouse::MouseButton;
|
||||||
use sdl2::pixels::Color;
|
use sdl2::pixels::{Color, PixelFormatEnum};
|
||||||
|
use sdl2::surface::Surface;
|
||||||
use sdl2::rect::{Point, Rect};
|
use sdl2::rect::{Point, Rect};
|
||||||
use sdl2::render::Canvas;
|
use sdl2::render::Canvas;
|
||||||
use sdl2::ttf::Sdl2TtfContext;
|
use sdl2::ttf::Sdl2TtfContext;
|
||||||
use sdl2::video::Window;
|
use sdl2::video::Window;
|
||||||
use sdl2::EventPump;
|
use sdl2::EventPump;
|
||||||
use sdl2::{Sdl, TimerSubsystem, VideoSubsystem};
|
use sdl2::{Sdl, TimerSubsystem, VideoSubsystem};
|
||||||
|
use sdl2::rwops::RWops;
|
||||||
|
|
||||||
pub mod app_state;
|
pub mod app_state;
|
||||||
pub mod caret_manager;
|
pub mod caret_manager;
|
||||||
@ -61,6 +63,7 @@ impl Application {
|
|||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let config = Rc::new(Config::new());
|
let config = Rc::new(Config::new());
|
||||||
let sdl_context = sdl2::init().unwrap();
|
let sdl_context = sdl2::init().unwrap();
|
||||||
|
|
||||||
hint::set("SDL_GL_MULTISAMPLEBUFFERS", "1");
|
hint::set("SDL_GL_MULTISAMPLEBUFFERS", "1");
|
||||||
hint::set("SDL_GL_MULTISAMPLESAMPLES", "8");
|
hint::set("SDL_GL_MULTISAMPLESAMPLES", "8");
|
||||||
hint::set("SDL_GL_ACCELERATED_VISUAL", "1");
|
hint::set("SDL_GL_ACCELERATED_VISUAL", "1");
|
||||||
@ -69,12 +72,20 @@ impl Application {
|
|||||||
|
|
||||||
let video_subsystem = sdl_context.video().unwrap();
|
let video_subsystem = sdl_context.video().unwrap();
|
||||||
|
|
||||||
let window = video_subsystem
|
let mut window: Window = video_subsystem
|
||||||
.window("Rider", config.width(), config.height())
|
.window("Rider", config.width(), config.height())
|
||||||
.position_centered()
|
.position_centered()
|
||||||
.opengl()
|
.opengl()
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.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();
|
let canvas = window.into_canvas().accelerated().build().unwrap();
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ impl EditorConfig {
|
|||||||
let mut default_font_path = directories::fonts_dir();
|
let mut default_font_path = directories::fonts_dir();
|
||||||
default_font_path.push("DejaVuSansMono.ttf");
|
default_font_path.push("DejaVuSansMono.ttf");
|
||||||
Self {
|
Self {
|
||||||
character_size: 16,
|
character_size: 14,
|
||||||
font_path: default_font_path.to_str().unwrap().to_string(),
|
font_path: default_font_path.to_str().unwrap().to_string(),
|
||||||
current_theme: "railscasts".to_string(),
|
current_theme: "railscasts".to_string(),
|
||||||
margin_left: 10,
|
margin_left: 10,
|
||||||
|
@ -148,10 +148,11 @@ impl Token {
|
|||||||
pub fn parse(text: String, language: &Language) -> Vec<TokenType> {
|
pub fn parse(text: String, language: &Language) -> Vec<TokenType> {
|
||||||
match language {
|
match language {
|
||||||
&Language::PlainText => plain::lexer::Lexer::new(text.as_str())
|
&Language::PlainText => plain::lexer::Lexer::new(text.as_str())
|
||||||
// .inspect(|tok| println!("tok: {:?}", tok))
|
.inspect(|tok| warn!("tok: {:?}", tok))
|
||||||
.map(|t| t.0)
|
.map(|t| t.0)
|
||||||
.collect(),
|
.collect(),
|
||||||
&Language::Rust => rust_lang::lexer::Lexer::new(text.as_str())
|
&Language::Rust => rust_lang::lexer::Lexer::new(text.as_str())
|
||||||
|
.inspect(|tok| warn!("tok: {:?}", tok))
|
||||||
.map(|t| t.0)
|
.map(|t| t.0)
|
||||||
.collect(),
|
.collect(),
|
||||||
}
|
}
|
||||||
|
@ -7,11 +7,19 @@ pub mod lexer {
|
|||||||
lexer! {
|
lexer! {
|
||||||
fn next_token(text: 'a) -> (TokenType, &'a str);
|
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)
|
token: Token::new(text.to_string(), 0, 0, 0, 0)
|
||||||
}, text),
|
}, 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)
|
token: Token::new(text.to_string(), 0, 0, 0, 0)
|
||||||
}, text),
|
}, text),
|
||||||
|
|
||||||
@ -19,7 +27,7 @@ pub mod lexer {
|
|||||||
token: Token::new(text.to_string(), 0, 0, 0, 0)
|
token: Token::new(text.to_string(), 0, 0, 0, 0)
|
||||||
}, text),
|
}, text),
|
||||||
|
|
||||||
r"[^ \t\r\n]+" => (TokenType::Identifier {
|
r"[^ \t\r\n:+-/*,]+" => (TokenType::Identifier {
|
||||||
token: Token::new(text.to_string(), 0, 0, 0, 0)
|
token: Token::new(text.to_string(), 0, 0, 0, 0)
|
||||||
}, text),
|
}, text),
|
||||||
}
|
}
|
||||||
|
@ -46,10 +46,7 @@ fn init_logger() {
|
|||||||
fn main() {
|
fn main() {
|
||||||
let mut app = Application::new();
|
let mut app = Application::new();
|
||||||
app.init();
|
app.init();
|
||||||
|
|
||||||
init_logger();
|
init_logger();
|
||||||
|
|
||||||
// app.open_file("./assets/examples/example.txt".to_string());
|
|
||||||
app.open_file("./assets/examples/test.rs".to_string());
|
app.open_file("./assets/examples/test.rs".to_string());
|
||||||
app.run();
|
app.run();
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ fn railscasts_theme() -> Theme {
|
|||||||
},
|
},
|
||||||
operator: ThemeConfig {
|
operator: ThemeConfig {
|
||||||
color: SerdeColor {
|
color: SerdeColor {
|
||||||
r: 0,
|
r: 200,
|
||||||
g: 0,
|
g: 0,
|
||||||
b: 0,
|
b: 0,
|
||||||
a: 0,
|
a: 0,
|
||||||
@ -142,9 +142,9 @@ fn railscasts_theme() -> Theme {
|
|||||||
},
|
},
|
||||||
separator: ThemeConfig {
|
separator: ThemeConfig {
|
||||||
color: SerdeColor {
|
color: SerdeColor {
|
||||||
r: 121,
|
r: 221,
|
||||||
g: 121,
|
g: 221,
|
||||||
b: 121,
|
b: 221,
|
||||||
a: 0,
|
a: 0,
|
||||||
},
|
},
|
||||||
italic: false,
|
italic: false,
|
||||||
|
@ -45,12 +45,6 @@ impl EditorFileToken {
|
|||||||
pub fn get_line(&self, line: &usize) -> Option<Vec<&TextCharacter>> {
|
pub fn get_line(&self, line: &usize) -> Option<Vec<&TextCharacter>> {
|
||||||
let mut vec: Vec<&TextCharacter> = vec![];
|
let mut vec: Vec<&TextCharacter> = vec![];
|
||||||
for c in self.characters.iter() {
|
for c in self.characters.iter() {
|
||||||
let _tmp = (
|
|
||||||
line.clone(),
|
|
||||||
c.line().clone(),
|
|
||||||
self.token_type.is_new_line(),
|
|
||||||
c.text_character(),
|
|
||||||
);
|
|
||||||
match (
|
match (
|
||||||
line.clone(),
|
line.clone(),
|
||||||
c.line().clone(),
|
c.line().clone(),
|
||||||
@ -94,7 +88,7 @@ impl EditorFileToken {
|
|||||||
c.clone(),
|
c.clone(),
|
||||||
self.token_type.start() + index,
|
self.token_type.start() + index,
|
||||||
self.token_type.line(),
|
self.token_type.line(),
|
||||||
color.clone(),
|
color,
|
||||||
self.config.clone(),
|
self.config.clone(),
|
||||||
);
|
);
|
||||||
text_character.update_view(renderer);
|
text_character.update_view(renderer);
|
||||||
|
Loading…
Reference in New Issue
Block a user