Skip to content

Commit

Permalink
custom fonts etc etc
Browse files Browse the repository at this point in the history
  • Loading branch information
marci1175 committed Nov 19, 2023
1 parent 3751d08 commit 66a9fef
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
28 changes: 23 additions & 5 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use device_query::Keycode;
use egui::{vec2, Align, Align2, Area, Button, Layout, RichText};
use egui::{vec2, Align, Align2, Area, Button, Layout, RichText, FontSelection, FontDefinitions, FontData, FontId, FontFamily};
use rand::rngs::ThreadRng;
use rand::Rng;
use regex::Regex;
Expand Down Expand Up @@ -62,6 +62,7 @@ pub struct TemplateApp {
settings_window: bool,

//main
font: Option<FontData>,
#[serde(skip)]
keymap: Input,
#[serde(skip)]
Expand Down Expand Up @@ -143,6 +144,7 @@ impl Default for TemplateApp {
settings_window: false,

//main
font: FontDefinitions::default().font_data.insert("consola".to_owned(), FontData::from_static(include_bytes!("C:\\Windows\\fonts\\consola.ttf"))),
keymap: Input::default(),
bookmark_mode: false,
client_mode: false,
Expand Down Expand Up @@ -215,8 +217,26 @@ impl eframe::App for TemplateApp {
}

fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {

let input_keys = keymap(self.keymap.clone());

/*
:: custom font ::
let mut custom_font = FontDefinitions::default();
custom_font.font_data.insert("consola".to_owned(), FontData::from_static(include_bytes!("C:\\Windows\\fonts\\arial.ttf")));
custom_font.families.get_mut(&FontFamily::Proportional).unwrap()
.insert(0, "consola".to_owned());
// Put my font as last fallback for monospace:
custom_font.families.get_mut(&FontFamily::Monospace).unwrap()
.push("consola".to_owned());
ctx.set_fonts(custom_font);
*/

/*devlog:
TODO: MAKE CLIENT UI BETTER
Expand Down Expand Up @@ -670,7 +690,7 @@ impl eframe::App for TemplateApp {
},
);
});
dbg!(_frame.info().window_info.size);

Area::new("usr_msg_expand")
.anchor(
Align2::RIGHT_BOTTOM,
Expand Down Expand Up @@ -717,9 +737,7 @@ impl eframe::App for TemplateApp {
ui.available_size(),
egui::TextEdit::multiline(&mut self.usr_msg)
.hint_text(RichText::from(format!("Message : {}", self.send_on_ip)).size(self.font_size))
.font(
egui::FontId::proportional(self.font_size),
),
.font(FontId::new(self.font_size, FontFamily::default()))
);
},
);
Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#![warn(clippy::all, rust_2018_idioms)]
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release

use egui::{FontDefinitions, FontData};

#[cfg(not(target_arch = "wasm32"))]
#[tokio::main]
async fn main() -> eframe::Result<()> {
use eframe::IconData;

use eframe::IconData;

env_logger::init();

let native_options = eframe::NativeOptions {
Expand Down

0 comments on commit 66a9fef

Please sign in to comment.