broken as hell
This commit is contained in:
parent
8cb8d510ca
commit
9d0a24d4cd
|
@ -1,5 +1,7 @@
|
|||
use std::{
|
||||
cell::RefCell, collections::{HashMap, HashSet}, rc::Rc
|
||||
cell::RefCell,
|
||||
collections::{HashMap, HashSet},
|
||||
rc::Rc,
|
||||
};
|
||||
|
||||
pub mod gui;
|
||||
|
@ -16,7 +18,7 @@ use libopenbirch::node::{add::Add, constant::Constant, divide::Divide, multiply:
|
|||
use raylib::{
|
||||
RaylibHandle, RaylibThread,
|
||||
color::Color,
|
||||
ffi::{MouseButton, TextLength, Vector2},
|
||||
ffi::{LoadCodepoints, MouseButton, TextLength, TextureFilter, Vector2},
|
||||
prelude::{Font, RaylibDraw, RaylibDrawHandle},
|
||||
text::RaylibFont,
|
||||
texture::Texture2D,
|
||||
|
@ -28,7 +30,7 @@ struct FontStore {
|
|||
fonts_to_be_loaded: HashSet<i32>,
|
||||
}
|
||||
|
||||
static CHAR_SET: &'static str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYZ1234567890(){}[]./,?><|\\=+-_*&^%$#@!~`·×≤≥±∞≈∝≠∅∈∉∩∪⊂⊃⊆⊇¬∧∨∃∀⇒⇔→↔↑↓ℵ";
|
||||
static CHAR_SET: &'static str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYZ1234567890(){}[]./,:;'\"?><|\\=+-_*&^%$#@!~`·×≤≥±∞≈∝≠∅∈∉∩∪⊂⊃⊆⊇¬∧∨∃∀⇒⇔→↔↑↓ℵ \t\n\r";
|
||||
|
||||
impl FontStore {
|
||||
// const SIZE_PARAGRAPH: f32 = 20.;
|
||||
|
@ -71,7 +73,7 @@ impl FontStore {
|
|||
for size in self.fonts_to_be_loaded.clone() {
|
||||
assert!(size != 0, "HOW IS THIS ZERO?");
|
||||
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_to_be_loaded.clear();
|
||||
|
@ -120,7 +122,7 @@ fn main() -> Result<(), String> {
|
|||
let (mut rl, thread) = raylib::init()
|
||||
.size(640, 480)
|
||||
.title("Openbirch GUI")
|
||||
.msaa_4x()
|
||||
// .msaa_4x()
|
||||
.resizable()
|
||||
.build();
|
||||
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());
|
||||
|
||||
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;
|
||||
|
|
|
@ -43,7 +43,7 @@ pub struct Theme {
|
|||
pub enum LineSegment {
|
||||
Text(String, u16),
|
||||
// Link(String, Link),
|
||||
Math(Rc<NodeEnum>, u16),
|
||||
Math(String, Rc<NodeEnum>, u16),
|
||||
}
|
||||
|
||||
impl LineSegment {
|
||||
|
@ -57,7 +57,7 @@ impl LineSegment {
|
|||
.color(theme.text_color)
|
||||
.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);
|
||||
}
|
||||
}
|
||||
|
|
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 enum_dispatch::enum_dispatch;
|
||||
use function::Function;
|
||||
use if_else::{Bool, IfElse};
|
||||
use multiply::Multiply;
|
||||
use node_ref::NodeRef;
|
||||
use subtract::Subtract;
|
||||
|
@ -26,6 +27,7 @@ mod assign;
|
|||
mod empty;
|
||||
mod function;
|
||||
mod call;
|
||||
mod if_else;
|
||||
|
||||
#[enum_dispatch]
|
||||
#[enum_dispatch(Debug, Clone, PartialEq, PartialOrd, ToString)]
|
||||
|
@ -46,6 +48,9 @@ pub enum NodeEnum {
|
|||
Function,
|
||||
Call,
|
||||
|
||||
Bool,
|
||||
IfElse,
|
||||
|
||||
// Logical
|
||||
// In,
|
||||
// Or,
|
||||
|
|
Loading…
Reference in a new issue