Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Skyward Enhanced Ground Software
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Avionics
Software Development
Skyward Enhanced Ground Software
Commits
a84b706a
Commit
a84b706a
authored
7 months ago
by
Federico Lolli
Browse files
Options
Downloads
Patches
Plain Diff
[ui] Added utils.rs with vertical_centering helper function with double pass
parent
7da095ec
Branches
Branches containing commit
No related tags found
1 merge request
!4
Added reverse checkbox for every Y parameter
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/ui.rs
+1
-0
1 addition, 0 deletions
src/ui.rs
src/ui/panes/default.rs
+25
-42
25 additions, 42 deletions
src/ui/panes/default.rs
src/ui/utils.rs
+30
-0
30 additions, 0 deletions
src/ui/utils.rs
with
56 additions
and
42 deletions
src/ui.rs
+
1
−
0
View file @
a84b706a
mod
composable_view
;
mod
panes
;
mod
shortcuts
;
mod
utils
;
pub
use
composable_view
::
ComposableView
;
This diff is collapsed.
Click to expand it.
src/ui/panes/default.rs
+
25
−
42
View file @
a84b706a
use
super
::{
plot_2d
::
Plot2DPane
,
Pane
,
PaneBehavior
,
PaneKind
};
use
serde
::{
Deserialize
,
Serialize
};
use
crate
::
ui
::
composable_view
::{
PaneAction
,
PaneResponse
};
use
crate
::
ui
::{
composable_view
::{
PaneAction
,
PaneResponse
},
utils
::{
vertically_centered
,
SizingMemo
},
};
#[derive(Clone,
Debug,
Serialize,
Deserialize)]
pub
struct
DefaultPane
{
occupied
:
f32
,
fixed
:
bool
,
#[serde(skip)]
centering_memo
:
SizingMemo
,
contains_pointer
:
bool
,
}
impl
Default
for
DefaultPane
{
fn
default
()
->
Self
{
DefaultPane
{
occupied
:
0.0
,
fixed
:
false
,
centering_memo
:
SizingMemo
::
default
(),
contains_pointer
:
false
,
}
}
...
...
@@ -23,48 +25,29 @@ impl Default for DefaultPane {
impl
PaneBehavior
for
DefaultPane
{
fn
ui
(
&
mut
self
,
ui
:
&
mut
egui
::
Ui
)
->
PaneResponse
{
let
mut
response
=
PaneResponse
::
default
();
let
pane_rect
=
ui
.max_rect
();
let
parent
=
ui
.vertical_centered
(|
ui
|
{
let
hpad
=
(
pane_rect
.height
()
-
self
.occupied
)
/
2.0
;
if
self
.fixed
{
ui
.add_space
(
hpad
);
}
let
mut
height_occupied
=
0.0
;
let
btn
=
ui
.button
(
"Vertical Split"
);
if
btn
.clicked
()
{
let
parent
=
vertically_centered
(
ui
,
&
mut
self
.centering_memo
,
|
ui
|
{
ui
.vertical_centered
(|
ui
|
{
if
ui
.button
(
"Vertical Split"
)
.clicked
()
{
response
.set_action
(
PaneAction
::
SplitV
);
log
::
debug!
(
"Vertical Split button clicked"
);
}
height_occupied
+=
btn
.rect
.height
();
let
btn
=
ui
.button
(
"Horizontal Split"
);
if
btn
.clicked
()
{
if
ui
.button
(
"Horizontal Split"
)
.clicked
()
{
response
.set_action
(
PaneAction
::
SplitH
);
log
::
debug!
(
"Horizontal Split button clicked"
);
}
height_occupied
+=
btn
.rect
.height
();
let
btn
=
ui
.button
(
"Plot"
);
if
btn
.clicked
()
{
if
ui
.button
(
"Plot"
)
.clicked
()
{
response
.set_action
(
PaneAction
::
Replace
(
Pane
::
boxed
(
PaneKind
::
Plot2D
(
Plot2DPane
::
default
(),
))));
}
height_occupied
+=
btn
.rect
.height
();
if
!
self
.fixed
{
self
.occupied
=
height_occupied
;
ui
.ctx
()
.request_discard
(
"test"
);
self
.fixed
=
true
;
}
if
self
.fixed
{
ui
.add_space
(
hpad
);
}
ui
.set_min_height
(
pane_rect
.height
());
})
.response
});
self
.contains_pointer
=
parent
.
response
.
contains_pointer
();
self
.contains_pointer
=
parent
.contains_pointer
();
if
parent
.response
.interact
(
egui
::
Sense
::
click_and_drag
())
.on_hover_cursor
(
egui
::
CursorIcon
::
Grab
)
.dragged
()
...
...
This diff is collapsed.
Click to expand it.
src/ui/utils.rs
0 → 100644
+
30
−
0
View file @
a84b706a
use
egui
::{
Response
,
Ui
};
#[derive(Debug,
Default,
Clone)]
pub
struct
SizingMemo
{
occupied_height
:
f32
,
sizing_pass_done
:
bool
,
}
pub
fn
vertically_centered
(
ui
:
&
mut
Ui
,
memo
:
&
mut
SizingMemo
,
add_contents
:
impl
FnOnce
(
&
mut
Ui
)
->
Response
,
)
->
egui
::
Response
{
if
!
memo
.sizing_pass_done
{
let
r
=
add_contents
(
ui
);
memo
.occupied_height
=
r
.rect
.height
();
memo
.sizing_pass_done
=
true
;
ui
.ctx
()
.request_discard
(
"horizontally_centered requires a sizing pass"
);
r
}
else
{
let
spacing
=
(
ui
.available_height
()
-
memo
.occupied_height
)
/
2.0
;
ui
.vertical_centered
(|
ui
|
{
ui
.add_space
(
spacing
);
add_contents
(
ui
);
ui
.add_space
(
spacing
);
})
.response
}
}
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