Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
companion-software
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CATS
companion-software
Commits
a730921c
Commit
a730921c
authored
11 months ago
by
Stephen D
Browse files
Options
Downloads
Patches
Plain Diff
contact menus
parent
413684db
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/contact.rs
+3
-1
3 additions, 1 deletion
src/contact.rs
src/controller.rs
+43
-17
43 additions, 17 deletions
src/controller.rs
with
46 additions
and
18 deletions
src/contact.rs
+
3
−
1
View file @
a730921c
use
heapless
::{
String
,
Vec
};
pub
const
MAX_CONTACTS
:
usize
=
20
;
#[derive(Debug,
Clone)]
pub
struct
Contact
{
callsign
:
String
<
10
>
,
...
...
@@ -9,7 +11,7 @@ pub struct Contact {
#[derive(Debug)]
pub
struct
ContactGroup
{
pub
contacts
:
Vec
<
Contact
,
20
>
,
pub
contacts
:
Vec
<
Contact
,
MAX_CONTACTS
>
,
}
impl
Default
for
ContactGroup
{
...
...
This diff is collapsed.
Click to expand it.
src/controller.rs
+
43
−
17
View file @
a730921c
...
...
@@ -2,7 +2,7 @@ use embedded_graphics::{pixelcolor::Rgb565, prelude::DrawTarget};
use
heapless
::{
String
,
Vec
};
use
crate
::{
contact
::{
Contact
,
ContactGroup
},
contact
::{
Contact
Group
,
MAX_CONTACTS
},
gui
::{
chat
::
Chat
,
selector
::
Selector
,
status
::
StatusBar
,
Element
},
keyboard
::
KeyCode
,
voltage
::
VoltMeter
,
...
...
@@ -10,28 +10,35 @@ use crate::{
pub
enum
View
{
MainMenu
(
Selector
<&
'static
str
,
[
&
'static
str
;
3
]
>
),
Contacts
(
Selector
<
String
<
30
>
,
Vec
<
String
<
30
>
,
3
>>
),
Contacts
(
Selector
<
String
<
30
>
,
Vec
<
String
<
30
>
,
MAX_CONTACTS
>>
),
ContactOptions
(
Selector
<&
'static
str
,
[
&
'static
str
;
3
]
>
,
usize
),
Chat
(
Chat
),
}
impl
View
{
pub
fn
main_menu
_with_id
(
id
:
usize
)
->
Self
{
pub
fn
new_
main_menu
(
id
:
usize
)
->
Self
{
let
menu
=
Selector
::
new
([
"Contacts"
,
"Messages"
,
"Settings"
],
id
);
Self
::
MainMenu
(
menu
)
}
pub
fn
from_main_menu_id
(
id
:
usize
)
->
Option
<
Self
>
{
pub
fn
new_contacts
(
id
:
usize
,
contacts
:
&
ContactGroup
)
->
Self
{
let
mut
contact_names
:
Vec
<
_
,
MAX_CONTACTS
>
=
contacts
.contacts
.iter
()
.map
(|
c
|
c
.name
.clone
())
.collect
();
// If we run out of space, we automatically hide the "Add" button
let
_
=
contact_names
.push
(
String
::
try_from
(
"Add New"
)
.unwrap
());
Self
::
Contacts
(
Selector
::
new
(
contact_names
,
id
))
}
pub
fn
new_contact_options
(
contact_id
:
usize
)
->
Self
{
let
opts
=
Selector
::
new
([
"View"
,
"Edit"
,
"Message"
],
0
);
Self
::
ContactOptions
(
opts
,
contact_id
)
}
pub
fn
from_main_menu_id
(
id
:
usize
,
contacts
:
&
ContactGroup
)
->
Option
<
Self
>
{
match
id
{
0
=>
{
let
group
=
ContactGroup
::
default
();
let
contact_names
:
Vec
<
_
,
3
>
=
group
.contacts
.iter
()
.map
(|
c
|
c
.name
.clone
())
.collect
();
Some
(
Self
::
Contacts
(
Selector
::
new
(
contact_names
.try_into
()
.unwrap
(),
0
,
)))
}
0
=>
Some
(
Self
::
new_contacts
(
0
,
contacts
)),
1
=>
Some
(
Self
::
Chat
(
Chat
::
new
())),
_
=>
None
,
}
...
...
@@ -41,6 +48,7 @@ impl View {
match
self
{
View
::
MainMenu
(
_
)
=>
unreachable!
(),
View
::
Contacts
(
_
)
=>
0
,
View
::
ContactOptions
(
_
,
_
)
=>
unreachable!
(),
View
::
Chat
(
_
)
=>
1
,
}
}
...
...
@@ -48,7 +56,7 @@ impl View {
impl
Default
for
View
{
fn
default
()
->
Self
{
Self
::
main_menu
_with_id
(
0
)
Self
::
new_
main_menu
(
0
)
}
}
...
...
@@ -60,6 +68,7 @@ impl Element for View {
match
self
{
View
::
MainMenu
(
m
)
=>
m
.render
(
dt
),
View
::
Contacts
(
c
)
=>
c
.render
(
dt
),
View
::
ContactOptions
(
c
,
_
)
=>
c
.render
(
dt
),
View
::
Chat
(
c
)
=>
c
.render
(
dt
),
}
}
...
...
@@ -68,6 +77,7 @@ impl Element for View {
match
self
{
View
::
MainMenu
(
m
)
=>
m
.key_push
(
k
),
View
::
Contacts
(
c
)
=>
c
.key_push
(
k
),
View
::
ContactOptions
(
c
,
_
)
=>
c
.key_push
(
k
),
View
::
Chat
(
c
)
=>
c
.key_push
(
k
),
}
}
...
...
@@ -76,6 +86,7 @@ impl Element for View {
match
self
{
View
::
MainMenu
(
m
)
=>
m
.touchpad_scroll
(
x
,
y
),
View
::
Contacts
(
c
)
=>
c
.touchpad_scroll
(
x
,
y
),
View
::
ContactOptions
(
c
,
_
)
=>
c
.touchpad_scroll
(
x
,
y
),
View
::
Chat
(
c
)
=>
c
.touchpad_scroll
(
x
,
y
),
}
}
...
...
@@ -84,6 +95,9 @@ impl Element for View {
pub
struct
Controller
{
status
:
StatusBar
,
cur_view
:
View
,
// May belong in a DataStore struct
contacts
:
ContactGroup
,
}
impl
Controller
{
...
...
@@ -91,6 +105,8 @@ impl Controller {
Self
{
status
:
StatusBar
::
new
(
volt_meter
),
cur_view
:
View
::
default
(),
contacts
:
ContactGroup
::
default
(),
}
}
}
...
...
@@ -112,15 +128,25 @@ impl Element for Controller {
fn
key_push
(
&
mut
self
,
k
:
KeyCode
)
{
match
(
&
self
.cur_view
,
k
)
{
(
View
::
MainMenu
(
m
),
KeyCode
::
Touchpad
)
=>
{
if
let
Some
(
new_view
)
=
View
::
from_main_menu_id
(
m
.selected
())
{
if
let
Some
(
new_view
)
=
View
::
from_main_menu_id
(
m
.selected
()
,
&
self
.contacts
)
{
self
.cur_view
=
new_view
;
}
}
(
View
::
Contacts
(
c
),
KeyCode
::
Touchpad
)
=>
{
// TODO need to handle "Add New" button
self
.cur_view
=
View
::
new_contact_options
(
c
.selected
());
}
(
View
::
MainMenu
(
_
),
KeyCode
::
Back
)
=>
{}
(
View
::
ContactOptions
(
_
,
id
),
KeyCode
::
Back
)
=>
{
self
.cur_view
=
View
::
new_contacts
(
*
id
,
&
self
.contacts
);
}
(
_
,
KeyCode
::
Back
)
=>
{
let
id
=
self
.cur_view
.to_main_menu_id
();
self
.cur_view
=
View
::
main_menu
_with_id
(
id
);
self
.cur_view
=
View
::
new_
main_menu
(
id
);
}
(
_
,
k
)
=>
self
.cur_view
.key_push
(
k
),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment