Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
portapack-mayhem
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mcules
portapack-mayhem
Commits
b1707298
Commit
b1707298
authored
9 years ago
by
Jared Boone
Browse files
Options
Downloads
Patches
Plain Diff
Extract weird range-of-entries algorithm out of view.
parent
f8d9cb31
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
firmware/application/ais_app.cpp
+24
-16
24 additions, 16 deletions
firmware/application/ais_app.cpp
firmware/application/ais_app.hpp
+6
-1
6 additions, 1 deletion
firmware/application/ais_app.hpp
with
30 additions
and
17 deletions
firmware/application/ais_app.cpp
+
24
−
16
View file @
b1707298
...
@@ -161,6 +161,28 @@ void AISRecentEntries::truncate_entries() {
...
@@ -161,6 +161,28 @@ void AISRecentEntries::truncate_entries() {
}
}
}
}
AISRecentEntries
::
RangeType
AISRecentEntries
::
range_around
(
ContainerType
::
const_iterator
item
,
const
size_t
count
)
const
{
auto
start
=
item
;
auto
end
=
item
;
size_t
i
=
0
;
// Move start iterator toward first entry.
while
(
(
start
!=
std
::
begin
(
entries
))
&&
(
i
<
count
/
2
)
)
{
std
::
advance
(
start
,
-
1
);
i
++
;
}
// Move end iterator toward last entry.
while
(
(
end
!=
std
::
end
(
entries
))
&&
(
i
<
count
)
)
{
std
::
advance
(
end
,
1
);
i
++
;
}
return
{
start
,
end
};
}
namespace
ui
{
namespace
ui
{
AISRecentEntriesView
::
AISRecentEntriesView
(
AISRecentEntriesView
::
AISRecentEntriesView
(
...
@@ -207,23 +229,9 @@ void AISRecentEntriesView::paint(Painter& painter) {
...
@@ -207,23 +229,9 @@ void AISRecentEntriesView::paint(Painter& painter) {
selected
=
std
::
begin
(
recent
);
selected
=
std
::
begin
(
recent
);
}
}
auto
start
=
selected
;
auto
range
=
recent
.
range_around
(
selected
,
visible_item_count
);
auto
end
=
selected
;
size_t
i
=
0
;
// Move start iterator toward first entry.
while
(
(
start
!=
std
::
begin
(
recent
))
&&
(
i
<
visible_item_count
/
2
)
)
{
std
::
advance
(
start
,
-
1
);
i
++
;
}
// Move end iterator toward last entry.
while
(
(
end
!=
std
::
end
(
recent
))
&&
(
i
<
visible_item_count
)
)
{
std
::
advance
(
end
,
1
);
i
++
;
}
for
(
auto
p
=
start
;
p
!=
e
nd
;
p
++
)
{
for
(
auto
p
=
range
.
first
;
p
!=
range
.
seco
nd
;
p
++
)
{
const
auto
&
entry
=
*
p
;
const
auto
&
entry
=
*
p
;
const
auto
is_selected_key
=
(
selected_key
==
entry
.
mmsi
);
const
auto
is_selected_key
=
(
selected_key
==
entry
.
mmsi
);
ais_list_item_draw
(
entry
,
target_rect
,
painter
,
s
,
(
has_focus
()
&&
is_selected_key
));
ais_list_item_draw
(
entry
,
target_rect
,
painter
,
s
,
(
has_focus
()
&&
is_selected_key
));
...
...
This diff is collapsed.
Click to expand it.
firmware/application/ais_app.hpp
+
6
−
1
View file @
b1707298
...
@@ -68,7 +68,8 @@ struct AISRecentEntry {
...
@@ -68,7 +68,8 @@ struct AISRecentEntry {
class
AISRecentEntries
{
class
AISRecentEntries
{
public:
public:
using
ContainerType
=
std
::
list
<
AISRecentEntry
>
;
using
ContainerType
=
std
::
list
<
AISRecentEntry
>
;
using
RangeType
=
std
::
pair
<
ContainerType
::
const_iterator
,
ContainerType
::
const_iterator
>
;
void
on_packet
(
const
ais
::
Packet
&
packet
);
void
on_packet
(
const
ais
::
Packet
&
packet
);
ContainerType
::
const_reference
front
()
const
{
ContainerType
::
const_reference
front
()
const
{
...
@@ -89,6 +90,10 @@ public:
...
@@ -89,6 +90,10 @@ public:
return
entries
.
empty
();
return
entries
.
empty
();
}
}
RangeType
range_around
(
ContainerType
::
const_iterator
,
const
size_t
count
)
const
;
private
:
private
:
ContainerType
entries
;
ContainerType
entries
;
const
size_t
entries_max
=
64
;
const
size_t
entries_max
=
64
;
...
...
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