forked from owickstrom/gi-gtk-declarative
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Debugging and demo for the cursor drift
This is for owickstrom#53
- Loading branch information
Showing
6 changed files
with
125 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module LaggyUIDemo where | ||
|
||
import Control.Monad (void) | ||
import Control.Concurrent | ||
import qualified GI.Gtk as Gtk | ||
import qualified GI.Gdk as Gdk | ||
import qualified GI.GLib as GLib | ||
|
||
-- Demo of what happens when your render loop is too slow | ||
-- Type really fast and observe the cursor drifting to the beginning | ||
|
||
main :: IO () | ||
main = do | ||
void $ Gtk.init Nothing | ||
|
||
win <- Gtk.windowNew Gtk.WindowTypeToplevel | ||
void $ Gtk.onWidgetDestroy win Gtk.mainQuit | ||
|
||
box <- Gtk.boxNew Gtk.OrientationVertical 2 | ||
entry <- Gtk.entryNew | ||
chan <- newChan | ||
|
||
void $ Gtk.onEditableChanged entry $ do | ||
str <- Gtk.entryGetText entry | ||
writeChan chan str | ||
|
||
void $ forkOS $ sequence_ $ repeat $ do | ||
str <- readChan chan | ||
threadDelay 100000 -- some arbitrary delay, the equivalent of updating the | ||
-- state and generating a new view | ||
Gdk.threadsAddIdle GLib.PRIORITY_DEFAULT $ do | ||
Gtk.entrySetText entry str | ||
return False | ||
|
||
Gtk.containerAdd box entry | ||
Gtk.containerAdd win box | ||
|
||
Gtk.widgetShowAll win | ||
Gtk.main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters