Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Documentation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
TDT4102
Documentation
Commits
606b7d88
Commit
606b7d88
authored
2 years ago
by
Iver Småge men bærbar
Browse files
Options
Downloads
Patches
Plain Diff
add example of method for callback function
parent
cf511d4f
No related branches found
No related tags found
No related merge requests found
Pipeline
#197933
failed
2 years ago
Stage: deploy
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
docs/animationwindow/gui.md
+30
-0
30 additions, 0 deletions
docs/animationwindow/gui.md
with
30 additions
and
0 deletions
docs/animationwindow/gui.md
+
30
−
0
View file @
606b7d88
...
...
@@ -94,6 +94,36 @@ Når vi kjører dette programmet og klikker på knappen ser vi at callback funks
<img
src=
"../../images/callback.png"
alt=
"Bilde som viser en kurve tegnet med draw_arc funksjonen og endret farge"
style=
"max-width:800px; width:100%;"
/>
### Objekt-orienterte callback funksjoner
Dersom man ønsker å sette callback-funksjonen til en klassemetode må man bruke
`std::bind`
for å gjøre funksjonen kompatibel.
```
c++
class
SuperManWindow
:
public
AnimationWindow
{
public:
SuperManWindow
();
void
superCallbackFunction
();
void
fly
();
private:
Button
flyButton
();
}
void
SuperManWindow
::
superCallbackFunction
()
{
std
::
cout
<<
"Thanks for clicking, im going to fly
\n
"
;
this
->
fly
();
// Do something else
}
SuperManWindow
::
SuperManWindow
()
:
AnimationWindow
(
100
,
100
,
100
,
100
,
"Super man window"
),
flyButton
{{
10
,
10
},
5
,
5
,
"fly"
}
{
// Here we convert the class method to a void function
// by binding this instance of the class to the function
flyButton
.
setCallback
(
std
::
bind
(
&
SuperManWindow
::
superCallbackFunction
,
this
));
}
```
## GUI Elementer
Hver GUI element som kan brukes i en AnimationWindow er definert i sin egen klasse. Det vil si at når du for eksempel ønsker å vise en knapp i vinduet, lager du en instans av
`TDT4102::Button`
klassen. I tillegg er det nødvendig å
...
...
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