broken as hell
This commit is contained in:
parent
8cb8d510ca
commit
9d0a24d4cd
|
@ -1,5 +1,7 @@
|
||||||
use std::{
|
use std::{
|
||||||
cell::RefCell, collections::{HashMap, HashSet}, rc::Rc
|
cell::RefCell,
|
||||||
|
collections::{HashMap, HashSet},
|
||||||
|
rc::Rc,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub mod gui;
|
pub mod gui;
|
||||||
|
@ -16,7 +18,7 @@ use libopenbirch::node::{add::Add, constant::Constant, divide::Divide, multiply:
|
||||||
use raylib::{
|
use raylib::{
|
||||||
RaylibHandle, RaylibThread,
|
RaylibHandle, RaylibThread,
|
||||||
color::Color,
|
color::Color,
|
||||||
ffi::{MouseButton, TextLength, Vector2},
|
ffi::{LoadCodepoints, MouseButton, TextLength, TextureFilter, Vector2},
|
||||||
prelude::{Font, RaylibDraw, RaylibDrawHandle},
|
prelude::{Font, RaylibDraw, RaylibDrawHandle},
|
||||||
text::RaylibFont,
|
text::RaylibFont,
|
||||||
texture::Texture2D,
|
texture::Texture2D,
|
||||||
|
@ -28,7 +30,7 @@ struct FontStore {
|
||||||
fonts_to_be_loaded: HashSet<i32>,
|
fonts_to_be_loaded: HashSet<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
static CHAR_SET: &'static str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYZ1234567890(){}[]./,?><|\\=+-_*&^%$#@!~`·×≤≥±∞≈∝≠∅∈∉∩∪⊂⊃⊆⊇¬∧∨∃∀⇒⇔→↔↑↓ℵ";
|
static CHAR_SET: &'static str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYZ1234567890(){}[]./,:;'\"?><|\\=+-_*&^%$#@!~`·×≤≥±∞≈∝≠∅∈∉∩∪⊂⊃⊆⊇¬∧∨∃∀⇒⇔→↔↑↓ℵ \t\n\r";
|
||||||
|
|
||||||
impl FontStore {
|
impl FontStore {
|
||||||
// const SIZE_PARAGRAPH: f32 = 20.;
|
// const SIZE_PARAGRAPH: f32 = 20.;
|
||||||
|
@ -71,7 +73,7 @@ impl FontStore {
|
||||||
for size in self.fonts_to_be_loaded.clone() {
|
for size in self.fonts_to_be_loaded.clone() {
|
||||||
assert!(size != 0, "HOW IS THIS ZERO?");
|
assert!(size != 0, "HOW IS THIS ZERO?");
|
||||||
println!("Loading {} in {size}px", self.font);
|
println!("Loading {} in {size}px", self.font);
|
||||||
let font = Rc::new(handle.load_font_ex(&thread, &self.font, size, Some(CHAR_SET))?);
|
let font = Rc::new(handle.load_font_ex(&thread, &self.font, size, None)?);
|
||||||
self.fonts.insert(size, font.clone());
|
self.fonts.insert(size, font.clone());
|
||||||
}
|
}
|
||||||
self.fonts_to_be_loaded.clear();
|
self.fonts_to_be_loaded.clear();
|
||||||
|
@ -120,7 +122,7 @@ fn main() -> Result<(), String> {
|
||||||
let (mut rl, thread) = raylib::init()
|
let (mut rl, thread) = raylib::init()
|
||||||
.size(640, 480)
|
.size(640, 480)
|
||||||
.title("Openbirch GUI")
|
.title("Openbirch GUI")
|
||||||
.msaa_4x()
|
// .msaa_4x()
|
||||||
.resizable()
|
.resizable()
|
||||||
.build();
|
.build();
|
||||||
let mut clay = clay_layout::Clay::new((640., 480.).into());
|
let mut clay = clay_layout::Clay::new((640., 480.).into());
|
||||||
|
@ -138,7 +140,7 @@ fn main() -> Result<(), String> {
|
||||||
let meth3 = Multiply::new(meth2.into(), meth.into());
|
let meth3 = Multiply::new(meth2.into(), meth.into());
|
||||||
|
|
||||||
gui.document.add_line(Line {
|
gui.document.add_line(Line {
|
||||||
segments: vec![LineSegment::Math(Rc::new(meth3.into()), 16)],
|
segments: vec![LineSegment::Math("".into(), Rc::new(meth3.into()), 16)],
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut previous_left_button = false;
|
let mut previous_left_button = false;
|
||||||
|
|
|
@ -43,7 +43,7 @@ pub struct Theme {
|
||||||
pub enum LineSegment {
|
pub enum LineSegment {
|
||||||
Text(String, u16),
|
Text(String, u16),
|
||||||
// Link(String, Link),
|
// Link(String, Link),
|
||||||
Math(Rc<NodeEnum>, u16),
|
Math(String, Rc<NodeEnum>, u16),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LineSegment {
|
impl LineSegment {
|
||||||
|
@ -57,7 +57,7 @@ impl LineSegment {
|
||||||
.color(theme.text_color)
|
.color(theme.text_color)
|
||||||
.end(),
|
.end(),
|
||||||
),
|
),
|
||||||
LineSegment::Math(node_enum, font_size) => {
|
LineSegment::Math(_source, node_enum, font_size) => {
|
||||||
draw_math_enum(node_enum.clone(), clay, theme, *font_size, state);
|
draw_math_enum(node_enum.clone(), clay, theme, *font_size, state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
63
src/lib/node/if_else.rs
Normal file
63
src/lib/node/if_else.rs
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
use super::{Environment, Node, NodeEnum, Precedence};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, PartialOrd)]
|
||||||
|
pub enum Bool {
|
||||||
|
True,
|
||||||
|
False,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, PartialOrd)]
|
||||||
|
pub enum ElseBranchEnum {
|
||||||
|
ElseIf(Rc<IfElse>),
|
||||||
|
Block(Vec<Rc<NodeEnum>>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, PartialOrd)]
|
||||||
|
pub struct IfElse {
|
||||||
|
condition: Rc<NodeEnum>,
|
||||||
|
true_branch: Vec<Rc<NodeEnum>>,
|
||||||
|
else_branch: ElseBranchEnum,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Node for IfElse {
|
||||||
|
fn evaluate(&self, env: &mut Environment) -> Result<Rc<NodeEnum>, String> {
|
||||||
|
let condition_evaluated = self.condition.evaluate(env)?;
|
||||||
|
|
||||||
|
if let super::NodeEnum::Bool(bool) = condition_evaluated {
|
||||||
|
} else {
|
||||||
|
return Err(format!(
|
||||||
|
"Cannot evaluate {} to a bool",
|
||||||
|
condition_evaluated.as_string(Some(env))
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_string(&self, env: Option<&Environment>) -> String {
|
||||||
|
format!(
|
||||||
|
"if {} then\n{}\nelse\n{}",
|
||||||
|
self.condition.as_string(env),
|
||||||
|
self.true_branch
|
||||||
|
.iter()
|
||||||
|
.map(|x| x.as_string(env))
|
||||||
|
.reduce(|a, b| a + "\n" + &b)
|
||||||
|
.unwrap()
|
||||||
|
.as_str(),
|
||||||
|
match &self.else_branch {
|
||||||
|
ElseBranchEnum::ElseIf(if_else) => if_else.as_string(env),
|
||||||
|
ElseBranchEnum::Block(vec) =>
|
||||||
|
vec.iter()
|
||||||
|
.map(|x| x.as_string(env))
|
||||||
|
.reduce(|a, b| a + "\n" + &b)
|
||||||
|
.unwrap()
|
||||||
|
+ "\nend",
|
||||||
|
}
|
||||||
|
.as_str()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn precedence(&self) -> Precedence {
|
||||||
|
Precedence::Primary
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ use divide::Divide;
|
||||||
use empty::Empty;
|
use empty::Empty;
|
||||||
use enum_dispatch::enum_dispatch;
|
use enum_dispatch::enum_dispatch;
|
||||||
use function::Function;
|
use function::Function;
|
||||||
|
use if_else::{Bool, IfElse};
|
||||||
use multiply::Multiply;
|
use multiply::Multiply;
|
||||||
use node_ref::NodeRef;
|
use node_ref::NodeRef;
|
||||||
use subtract::Subtract;
|
use subtract::Subtract;
|
||||||
|
@ -26,6 +27,7 @@ mod assign;
|
||||||
mod empty;
|
mod empty;
|
||||||
mod function;
|
mod function;
|
||||||
mod call;
|
mod call;
|
||||||
|
mod if_else;
|
||||||
|
|
||||||
#[enum_dispatch]
|
#[enum_dispatch]
|
||||||
#[enum_dispatch(Debug, Clone, PartialEq, PartialOrd, ToString)]
|
#[enum_dispatch(Debug, Clone, PartialEq, PartialOrd, ToString)]
|
||||||
|
@ -46,6 +48,9 @@ pub enum NodeEnum {
|
||||||
Function,
|
Function,
|
||||||
Call,
|
Call,
|
||||||
|
|
||||||
|
Bool,
|
||||||
|
IfElse,
|
||||||
|
|
||||||
// Logical
|
// Logical
|
||||||
// In,
|
// In,
|
||||||
// Or,
|
// Or,
|
||||||
|
|
Loading…
Reference in a new issue