1
1
#![ allow( dead_code, unused_variables) ]
2
2
3
+ use std:: rc:: Rc ;
4
+ use std:: sync:: Arc ;
5
+
6
+ use iced:: alignment:: Horizontal ;
3
7
use iced:: theme:: Palette ;
4
- use iced:: widget:: { button, column, container, horizontal_rule, row, text, text_input} ;
5
- use iced:: { executor, Application , Color , Command , Element , Length , Theme } ;
8
+ use iced:: widget:: { button, column, container, horizontal_rule, row, text, text_input, Text } ;
9
+ use iced:: { executor, font , Application , Color , Command , Element , Length , Padding , Theme } ;
6
10
7
11
use iced_aw:: native:: Split ;
8
- use iced_aw:: { modal, split, Card } ;
12
+ use iced_aw:: { modal, split, Card , BOOTSTRAP_FONT_BYTES } ;
9
13
10
14
mod course_database;
11
15
use course_database:: { CourseDatabase , CourseId } ;
16
+ use icons:: Icon ;
12
17
13
18
mod graph_widget;
19
+ mod icons;
14
20
15
21
#[ derive( Default ) ]
16
22
pub struct FinescaleApp {
@@ -26,22 +32,18 @@ struct UiStates {
26
32
course_input_val : String ,
27
33
}
28
34
29
- #[ derive( Default , Debug , Clone ) ]
30
- pub struct CourseGraph ;
31
-
32
35
#[ derive( Debug , Clone ) ]
33
36
pub enum Message {
34
- LoadedCourses ( CourseGraph ) ,
37
+ LoadedCourses ( Arc < anyhow :: Result < CourseDatabase > > ) ,
35
38
MainDividerResize ( u16 ) ,
36
39
CourseInputEvent ( String ) ,
37
40
CourseInputSubmit ,
41
+ IconsLoaded ( Result < ( ) , font:: Error > ) ,
38
42
ClearError ,
39
43
}
40
44
41
- async fn load_courses < P : AsRef < std:: path:: Path > > ( path : P ) -> CourseGraph {
42
- //let reader = std::fs::File::open(path).unwrap();
43
- //let _json: serde_json::Value = serde_json::from_reader(reader).unwrap();
44
- CourseGraph
45
+ async fn load_courses < P : AsRef < std:: path:: Path > > ( path : P ) -> Arc < anyhow:: Result < CourseDatabase > > {
46
+ CourseDatabase :: new ( "[]" ) . into ( )
45
47
}
46
48
47
49
impl Application for FinescaleApp {
@@ -53,7 +55,10 @@ impl Application for FinescaleApp {
53
55
fn new ( _: Self :: Flags ) -> ( Self , Command < Self :: Message > ) {
54
56
(
55
57
FinescaleApp :: default ( ) ,
56
- Command :: perform ( load_courses ( "data/courses.json" ) , Message :: LoadedCourses ) ,
58
+ Command :: batch ( [
59
+ Command :: perform ( load_courses ( "data/courses.ron" ) , Message :: LoadedCourses ) ,
60
+ iced:: font:: load ( icons:: Icon :: bytes ( ) ) . map ( Message :: IconsLoaded ) ,
61
+ ] ) ,
57
62
)
58
63
}
59
64
@@ -63,7 +68,6 @@ impl Application for FinescaleApp {
63
68
64
69
fn update ( & mut self , _message : Self :: Message ) -> Command < Self :: Message > {
65
70
match _message {
66
- Message :: LoadedCourses ( _) => { }
67
71
Message :: ClearError => self . ui_states . error_modal = None ,
68
72
// TODO: Limit the divider movement
69
73
Message :: MainDividerResize ( amt) => self . ui_states . main_divider_pos = Some ( amt) ,
@@ -79,23 +83,45 @@ impl Application for FinescaleApp {
79
83
}
80
84
}
81
85
}
86
+ _ => { }
82
87
}
83
88
84
89
Command :: none ( )
85
90
}
86
91
87
92
fn view ( & self ) -> Element < Self :: Message > {
88
93
let mut left = column ! [
89
- text( "Desired Classes" ) ,
94
+ text( "Desired Classes" )
95
+ . width( Length :: Fill )
96
+ . size( 40 )
97
+ . style( Color :: from_rgb( 0.5 , 0.5 , 0.5 ) )
98
+ . horizontal_alignment( Horizontal :: Center ) ,
90
99
text_input( "Start typing!" , & self . ui_states. course_input_val)
100
+ . padding( 15 )
91
101
. on_input( Message :: CourseInputEvent )
92
102
. on_submit( Message :: CourseInputSubmit ) ,
103
+ ]
104
+ . spacing ( 10 ) ;
105
+
106
+ let mut right = column ! [
107
+ row![ text( "Required Classes" )
108
+ . width( Length :: Fill )
109
+ . size( 40 )
110
+ . style( Color :: from_rgb( 0.5 , 0.5 , 0.5 ) )
111
+ . horizontal_alignment( iced:: alignment:: Horizontal :: Left ) , ] ,
112
+ horizontal_rule( 2 )
93
113
] ;
94
- let mut right = column ! [ row![ text( "Required Classes" ) , ] , horizontal_rule( 2 ) ] ;
95
114
96
115
for course in self . desired_courses . iter ( ) {
116
+ left = left. push (
117
+ row ! [
118
+ text( course) . width( Length :: Fill ) ,
119
+ button( Into :: <Text >:: into( Icon :: DeleteForever ) ) . padding( 10 )
120
+ ]
121
+ . spacing ( 20 )
122
+ . align_items ( iced:: Alignment :: Center ) ,
123
+ ) ;
97
124
right = right. push ( text ( course) ) ;
98
- left = left. push ( text ( course) ) ;
99
125
}
100
126
101
127
// Todo read and push courses.
@@ -108,26 +134,19 @@ impl Application for FinescaleApp {
108
134
) ;
109
135
110
136
let overlay = self . ui_states . error_modal . as_ref ( ) . map ( |err_msg| {
111
- Card :: new ( text ( "Error" ) , text ( err_msg) ) . foot (
112
- container ( button ( "Ok" ) . on_press ( Message :: ClearError ) )
113
- . width ( Length :: Fill )
114
- . align_x ( iced:: alignment:: Horizontal :: Right ) ,
115
- )
137
+ Card :: new ( text ( "Error" ) , text ( err_msg) )
138
+ . foot (
139
+ container ( button ( "Ok" ) . on_press ( Message :: ClearError ) )
140
+ . width ( Length :: Fill )
141
+ . align_x ( iced:: alignment:: Horizontal :: Right ) ,
142
+ )
143
+ . max_width ( 250.0 )
116
144
} ) ;
117
145
118
146
modal ( main_content, overlay) . into ( )
119
147
}
120
148
121
149
fn theme ( & self ) -> Self :: Theme {
122
- Theme :: custom (
123
- "apptheme" . to_string ( ) ,
124
- Palette {
125
- background : Color :: from_rgba8 ( 14 , 14 , 14 , 0.1 ) ,
126
- text : Color :: WHITE ,
127
- primary : Color :: WHITE ,
128
- success : Color :: WHITE ,
129
- danger : Color :: WHITE ,
130
- } ,
131
- )
150
+ iced:: Theme :: Light
132
151
}
133
152
}
0 commit comments