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
69f62b52
Commit
69f62b52
authored
5 months ago
by
Stephen D
Browse files
Options
Downloads
Patches
Plain Diff
symbols WIP
parent
aa6d9f7f
No related branches found
No related tags found
1 merge request
!5
Symbols
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
companion-software/src/controller.rs
+9
-0
9 additions, 0 deletions
companion-software/src/controller.rs
companion-software/src/gui/mod.rs
+1
-0
1 addition, 0 deletions
companion-software/src/gui/mod.rs
companion-software/src/gui/symbol.rs
+137
-0
137 additions, 0 deletions
companion-software/src/gui/symbol.rs
with
147 additions
and
0 deletions
companion-software/src/controller.rs
+
9
−
0
View file @
69f62b52
...
...
@@ -29,6 +29,7 @@ use crate::{
selector
::
Selector
,
settings
::
SettingsView
,
status
::
StatusBar
,
symbol
::
SymbolSelector
,
Element
,
},
keyboard
::
KeyCode
,
...
...
@@ -260,6 +261,7 @@ pub struct TxItem {
pub
struct
Controller
{
status
:
StatusBar
,
cur_view
:
View
,
symbol_selector
:
SymbolSelector
,
storage
:
Storage
,
tx_queue
:
Vec
<
TxItem
,
TX_QUEUE_SIZE
>
,
green_led
:
Option
<
Instant
>
,
...
...
@@ -298,6 +300,7 @@ impl Controller {
Self
{
status
:
StatusBar
::
new
(
volt_meter
),
cur_view
:
View
::
default
(),
symbol_selector
:
SymbolSelector
::
new
(),
storage
,
tx_queue
:
Vec
::
new
(),
green_led
:
None
,
...
...
@@ -725,6 +728,8 @@ impl Controller {
self
.status
.render
(
dt
,
&
self
.gps_data
,
self
.storage
.settings
())
?
;
self
.symbol_selector
.render
(
dt
)
?
;
}
Ok
(())
...
...
@@ -739,6 +744,10 @@ impl Controller {
return
;
}
if
self
.symbol_selector
.key_push
(
k
)
{
return
;
}
match
(
&
mut
self
.cur_view
,
k
)
{
(
View
::
MainMenu
(
m
),
KeyCode
::
Touchpad
)
=>
{
if
let
Some
(
new_view
)
=
...
...
This diff is collapsed.
Click to expand it.
companion-software/src/gui/mod.rs
+
1
−
0
View file @
69f62b52
...
...
@@ -14,6 +14,7 @@ pub mod selector;
pub
mod
settings
;
pub
mod
slider
;
pub
mod
status
;
pub
mod
symbol
;
pub
mod
textbox
;
pub
trait
Element
{
...
...
This diff is collapsed.
Click to expand it.
companion-software/src/gui/symbol.rs
0 → 100644
+
137
−
0
View file @
69f62b52
use
core
::
fmt
::
Write
;
use
embedded_graphics
::{
geometry
::{
Point
,
Size
},
mono_font
::{
ascii
::
FONT_10X20
,
MonoTextStyle
},
pixelcolor
::{
Rgb565
,
RgbColor
},
primitives
::{
Primitive
,
PrimitiveStyleBuilder
,
Rectangle
},
text
::{
renderer
::
TextRenderer
,
Baseline
},
Drawable
,
};
use
heapless
::
String
;
use
crate
::{
app
::{
HEIGHT
,
WIDTH
},
keyboard
::
KeyCode
,
};
use
super
::
Element
;
const
KEYBOARD_REFERENCE
:
[
&
str
;
3
]
=
[
"qwertyuiop"
,
"asdfghjkl"
,
"zxcvbnm"
];
const
PAGES
:
[[
&
str
;
3
];
1
]
=
[[
"[<{ ~= ^%"
,
"]>} `
\\
&"
,
"$ | "
]];
const
BOX_WIDTH
:
u32
=
240
;
const
BOX_HEIGHT
:
u32
=
190
;
const
BORDER_WIDTH
:
u32
=
1
;
const
BG_COLOR
:
Rgb565
=
Rgb565
::
BLACK
;
const
FG_COLOR
:
Rgb565
=
Rgb565
::
WHITE
;
const
CHAR_WIDTH
:
i32
=
10
;
const
CHAR_WIDTH_WITH_BORDER
:
i32
=
18
;
const
CHAR_HEIGHT
:
i32
=
20
;
pub
struct
SymbolSelector
{
page
:
usize
,
viewable
:
bool
,
}
impl
SymbolSelector
{
pub
fn
new
()
->
Self
{
Self
{
page
:
0
,
viewable
:
false
,
}
}
}
impl
Element
for
SymbolSelector
{
type
KeyPushReturn
=
bool
;
fn
render
<
E
,
DT
:
embedded_graphics
::
prelude
::
DrawTarget
<
Color
=
embedded_graphics
::
pixelcolor
::
Rgb565
,
Error
=
E
,
>
,
>
(
&
mut
self
,
dt
:
&
mut
DT
,
)
->
Result
<
(),
E
>
{
if
!
self
.viewable
{
return
Ok
(());
}
// render rectangle
let
rect_style
=
PrimitiveStyleBuilder
::
new
()
.stroke_color
(
FG_COLOR
)
.stroke_width
(
BORDER_WIDTH
)
.fill_color
(
BG_COLOR
)
.build
();
let
bounds
=
Rectangle
::
with_center
(
Point
::
new
(
WIDTH
.try_into
()
.unwrap
(),
HEIGHT
.try_into
()
.unwrap
())
/
2
,
Size
::
new
(
BOX_WIDTH
,
BOX_HEIGHT
),
);
bounds
.into_styled
(
rect_style
)
.draw
(
dt
)
?
;
let
character_style
=
MonoTextStyle
::
new
(
&
FONT_10X20
,
FG_COLOR
);
// render page #
let
mut
buf
:
String
<
10
>
=
String
::
new
();
write!
(
&
mut
buf
,
"Page {}/{}"
,
self
.page
+
1
,
PAGES
.len
())
.unwrap
();
character_style
.draw_string
(
&
buf
,
Point
::
new
(
bounds
.bottom_right
()
.unwrap
()
.x
-
CHAR_WIDTH
*
10
,
bounds
.top_left.y
+
CHAR_HEIGHT
+
4
,
),
Baseline
::
Bottom
,
dt
,
)
?
;
// render lines
let
border_style
=
PrimitiveStyleBuilder
::
new
()
.stroke_color
(
FG_COLOR
)
.stroke_width
(
BORDER_WIDTH
)
.build
();
for
(
i
,
line
)
in
KEYBOARD_REFERENCE
.iter
()
.enumerate
()
{
let
len
=
line
.chars
()
.count
();
let
x_start
=
(
i32
::
try_from
(
WIDTH
)
.unwrap
()
-
i32
::
try_from
(
len
)
.unwrap
()
*
CHAR_WIDTH_WITH_BORDER
)
/
2
;
let
y
=
bounds
.top_left.y
+
(
i32
::
try_from
(
i
)
.unwrap
()
+
1
)
*
(
CHAR_HEIGHT
+
8
)
*
2
+
CHAR_HEIGHT
;
for
(
j
,
c
)
in
line
.chars
()
.enumerate
()
{
let
x
=
x_start
+
i32
::
try_from
(
j
)
.unwrap
()
*
CHAR_WIDTH_WITH_BORDER
;
// Is there a better way to do char -> string?
let
mut
s
:
String
<
1
>
=
String
::
new
();
s
.push
(
c
.to_ascii_uppercase
())
.unwrap
();
character_style
.draw_string
(
&
s
,
Point
::
new
(
x
+
4
,
y
+
4
),
Baseline
::
Bottom
,
dt
)
?
;
Rectangle
::
new
(
Point
::
new
(
x
+
1
,
y
-
CHAR_HEIGHT
+
1
),
Size
::
new
(
u32
::
try_from
(
CHAR_WIDTH
)
.unwrap
()
+
6
,
u32
::
try_from
(
CHAR_HEIGHT
)
.unwrap
()
+
6
,
),
)
.into_styled
(
border_style
)
.draw
(
dt
)
?
;
}
}
Ok
(())
}
fn
key_push
(
&
mut
self
,
k
:
KeyCode
)
->
Self
::
KeyPushReturn
{
if
k
==
KeyCode
::
Sym
{
self
.viewable
=
true
;
}
self
.viewable
}
}
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