Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
Interactive model comparison
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
Container 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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Albin Heimerson
Interactive model comparison
Commits
6f5760d2
Commit
6f5760d2
authored
Nov 29, 2022
by
Martin Morin
Browse files
Options
Downloads
Patches
Plain Diff
Change from enum to trait objects for subapps
parent
b2c73725
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/lib.rs
+54
-12
54 additions, 12 deletions
src/lib.rs
with
54 additions
and
12 deletions
src/lib.rs
+
54
−
12
View file @
6f5760d2
...
@@ -6,13 +6,13 @@ use basic_print::basic_print; // basic print for print-debugging
...
@@ -6,13 +6,13 @@ use basic_print::basic_print; // basic print for print-debugging
pub
struct
ControlApp
{
pub
struct
ControlApp
{
cur_app_idx
:
Option
<
usize
>
,
cur_app_idx
:
Option
<
usize
>
,
apps
:
Vec
<
(
String
,
Sub
App
)
>
,
apps
:
Vec
<
Box
<
dyn
Central
App
>
>
,
}
}
#[derive(PartialEq)]
trait
CentralApp
{
enum
SubApp
{
fn
draw_app
(
&
mut
self
,
ui
:
&
mut
egui
::
Ui
);
PolePos
,
FreqResp
,
fn
get_label
(
&
self
)
->
&
str
;
}
}
impl
ControlApp
{
impl
ControlApp
{
...
@@ -20,12 +20,19 @@ impl ControlApp {
...
@@ -20,12 +20,19 @@ impl ControlApp {
// This is also where you can customized the look at feel of egui using
// This is also where you can customized the look at feel of egui using
// `cc.egui_ctx.set_visuals` and `cc.egui_ctx.set_fonts`.
// `cc.egui_ctx.set_visuals` and `cc.egui_ctx.set_fonts`.
let
pp
=
(
"Pole Positioning"
.to_string
(),
SubApp
::
PolePos
);
let
apps
:
Vec
<
Box
<
dyn
CentralApp
>>
=
vec!
[
let
fr
=
(
"Frequency Response"
.to_string
(),
SubApp
::
FreqResp
);
Box
::
new
(
PolePos
{
label
:
"Pole Positioning"
.to_string
(),
}),
Box
::
new
(
FreqResp
{
label
:
"Frequency Response"
.to_string
(),
}),
];
ControlApp
{
cur_app_idx
:
None
,
apps
:
vec!
[
pp
,
fr
]
}
ControlApp
{
cur_app_idx
:
None
,
apps
}
}
}
fn
top_bar
(
&
mut
self
,
ui
:
&
mut
egui
::
Ui
)
->
bool
{
fn
top_bar
(
&
mut
self
,
ui
:
&
mut
egui
::
Ui
)
->
bool
{
#[allow(unused_mut)]
#[allow(unused_mut)]
let
mut
quit
=
false
;
let
mut
quit
=
false
;
...
@@ -34,12 +41,12 @@ impl ControlApp {
...
@@ -34,12 +41,12 @@ impl ControlApp {
ui
.heading
(
"Control Apps"
);
ui
.heading
(
"Control Apps"
);
ui
.separator
();
ui
.separator
();
for
(
idx
,
(
label
,
_
app
)
)
in
self
.apps
.iter
()
.enumerate
()
{
for
(
idx
,
app
)
in
self
.apps
.iter
()
.enumerate
()
{
let
checked
=
match
self
.cur_app_idx
{
let
checked
=
match
self
.cur_app_idx
{
Some
(
cur
)
=>
cur
==
idx
,
Some
(
cur
)
=>
cur
==
idx
,
None
=>
false
,
None
=>
false
,
};
};
if
ui
.selectable_label
(
checked
,
label
)
.clicked
()
{
if
ui
.selectable_label
(
checked
,
app
.get_
label
()
)
.clicked
()
{
if
checked
{
if
checked
{
self
.cur_app_idx
=
None
;
self
.cur_app_idx
=
None
;
}
else
{
}
else
{
...
@@ -67,6 +74,7 @@ impl ControlApp {
...
@@ -67,6 +74,7 @@ impl ControlApp {
}
}
impl
eframe
::
App
for
ControlApp
{
impl
eframe
::
App
for
ControlApp
{
fn
update
(
&
mut
self
,
ctx
:
&
egui
::
Context
,
_frame
:
&
mut
eframe
::
Frame
)
{
fn
update
(
&
mut
self
,
ctx
:
&
egui
::
Context
,
_frame
:
&
mut
eframe
::
Frame
)
{
...
@@ -80,8 +88,8 @@ impl eframe::App for ControlApp {
...
@@ -80,8 +88,8 @@ impl eframe::App for ControlApp {
egui
::
CentralPanel
::
default
()
.show
(
ctx
,
|
ui
|
{
egui
::
CentralPanel
::
default
()
.show
(
ctx
,
|
ui
|
{
ui
.centered_and_justified
(
|
ui
|
{
ui
.centered_and_justified
(
|
ui
|
{
match
self
.cur_app_idx
{
match
self
.cur_app_idx
{
Some
(
idx
)
=>
ui
.label
(
self
.apps
[
idx
]
.0
.to_string
())
,
None
=>
{
ui
.label
(
"Select an application in the bar above."
);}
,
None
=>
ui
.label
(
"Select an application in the bar above."
)
,
Some
(
idx
)
=>
{
self
.apps
[
idx
]
.draw_app
(
ui
);}
,
};
};
});
});
});
});
...
@@ -89,6 +97,40 @@ impl eframe::App for ControlApp {
...
@@ -89,6 +97,40 @@ impl eframe::App for ControlApp {
}
}
struct
PolePos
{
label
:
String
,
}
impl
CentralApp
for
PolePos
{
fn
draw_app
(
&
mut
self
,
ui
:
&
mut
egui
::
Ui
)
{
ui
.label
(
"In app, Pole Pos"
);
}
fn
get_label
(
&
self
)
->
&
str
{
&
self
.label
}
}
struct
FreqResp
{
label
:
String
,
}
impl
CentralApp
for
FreqResp
{
fn
draw_app
(
&
mut
self
,
ui
:
&
mut
egui
::
Ui
)
{
ui
.label
(
"Frequency response app currently not implemented."
);
}
fn
get_label
(
&
self
)
->
&
str
{
&
self
.label
}
}
// impl eframe::App for TemplateApp {
// impl eframe::App for TemplateApp {
// fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
// fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
// let Self { label, value } = self;
// let Self { label, value } = self;
...
...
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