Commit dfb643c3de00d30143a3d517f89f3f9808b2560a

Make Screen::showCursor() accept focused widget
Accepts only Window widgets. This fixes an issue when cursor is moved
as a result of drawing other widgets after the current one. If Prompt
is the bottom, the bug won't be noticeable as it will be drawn last and
place cursor where it should be right before screen redrawing.
Author: xaizek
Author date (UTC): 2022-01-04 13:17
Committer name: xaizek
Committer date (UTC): 2022-01-04 13:19
Parent(s): 467743b39b68f759a8449e1ab53c087c8b6e098b
Signing key: 99DC5E4DB05F6BE2
Tree: 00ce054079256067b68dabafcbae0bfccb958a60
File Lines added Lines deleted
Prompt.cpp 6 0
Prompt.hpp 3 0
Screen.cpp 9 1
Screen.hpp 6 3
guts/WindowWidget.hpp 7 0
File Prompt.cpp changed (mode: 100644) (index 9c55a1a..8ee89df)
... ... Prompt::draw()
39 39 win.erase(); win.erase();
40 40 wmove(win, 0, 0); wmove(win, 0, 0);
41 41 win.print(text); win.print(text);
42 wnoutrefresh(win);
43 }
44
45 void
46 Prompt::updateCursor()
47 {
42 48 wmove(win, 0, pos); wmove(win, 0, pos);
43 49 wnoutrefresh(win); wnoutrefresh(win);
44 50 } }
File Prompt.hpp changed (mode: 100644) (index 9cd2332..bde6780)
... ... private:
44 44 // Updates state of this widget to be published on the screen. // Updates state of this widget to be published on the screen.
45 45 virtual void draw() override; virtual void draw() override;
46 46
47 // Moves hardware cursor onto this widget.
48 virtual void updateCursor() override;
49
47 50 // Retrieves vertical size policy. // Retrieves vertical size policy.
48 51 // Positive number or zero means exactly that much. // Positive number or zero means exactly that much.
49 52 // Negative number means at least that much in magnitude. // Negative number means at least that much in magnitude.
File Screen.cpp changed (mode: 100644) (index 2b1d4f5..14cc234)
24 24 #include "guts/Pos.hpp" #include "guts/Pos.hpp"
25 25 #include "guts/Size.hpp" #include "guts/Size.hpp"
26 26 #include "guts/Widget.hpp" #include "guts/Widget.hpp"
27 #include "guts/WindowWidget.hpp"
27 28
28 29 using namespace cursed; using namespace cursed;
29 30 using namespace cursed::guts; using namespace cursed::guts;
 
... ... Screen::draw()
77 78 for (Widget *widget : mainWidgets) { for (Widget *widget : mainWidgets) {
78 79 widget->draw(); widget->draw();
79 80 } }
81
82 if (cursorWidget != nullptr) {
83 cursorWidget->updateCursor();
84 }
85
80 86 doupdate(); doupdate();
81 87 } }
82 88
83 89 bool bool
84 Screen::showCursor()
90 Screen::showCursor(guts::WindowWidget *w)
85 91 { {
92 cursorWidget = w;
86 93 return (curs_set(1) == 0); return (curs_set(1) == 0);
87 94 } }
88 95
89 96 bool bool
90 97 Screen::hideCursor() Screen::hideCursor()
91 98 { {
99 cursorWidget = nullptr;
92 100 return (curs_set(0) != 0); return (curs_set(0) != 0);
93 101 } }
94 102
File Screen.hpp changed (mode: 100644) (index 37c0a07..f5d3c06)
... ... namespace cursed {
25 25
26 26 namespace guts { namespace guts {
27 27 class Widget; class Widget;
28 class WindowWidget;
28 29 } }
29 30
30 31 // Provides information about the whole screen. // Provides information about the whole screen.
 
... ... public:
45 46 // Draws main widget and makes screen updates visible on physical screen. // Draws main widget and makes screen updates visible on physical screen.
46 47 void draw(); void draw();
47 48
48 // Makes cursor visible. Returns `true` if cursor was hidden before the
49 // call.
50 bool showCursor();
49 // Makes cursor visible. Optionally sets widget that owns the cursor.
50 // Returns `true` if cursor was hidden before the call.
51 bool showCursor(guts::WindowWidget *w = nullptr);
51 52 // Makes cursor invisible. Returns `true` if cursor was visible before the // Makes cursor invisible. Returns `true` if cursor was visible before the
52 53 // call. // call.
53 54 bool hideCursor(); bool hideCursor();
 
... ... public:
58 59 private: private:
59 60 // Roots of all currently displayed layers of widgets. // Roots of all currently displayed layers of widgets.
60 61 std::vector<guts::Widget *> mainWidgets; std::vector<guts::Widget *> mainWidgets;
62 // Widget that has the cursor.
63 guts::WindowWidget *cursorWidget = nullptr;
61 64 }; };
62 65
63 66 } }
File guts/WindowWidget.hpp changed (mode: 100644) (index 5ab1efd..dbf9c98)
... ... public:
36 36 // with attributes and/or foreground). // with attributes and/or foreground).
37 37 void setBackground(Format format); void setBackground(Format format);
38 38
39 // Moves hardware cursor onto this widget.
40 virtual void updateCursor();
41
39 42 protected: protected:
40 43 // Resizes and moves window. // Resizes and moves window.
41 44 virtual void placed(Pos newPos, Size newSize) override; virtual void placed(Pos newPos, Size newSize) override;
 
... ... protected:
44 47 Window win; // Window object. Window win; // Window object.
45 48 }; };
46 49
50 inline void
51 WindowWidget::updateCursor()
52 { }
53
47 54 inline void inline void
48 55 WindowWidget::setBackground(Format format) WindowWidget::setBackground(Format format)
49 56 { win.setBackground(std::move(format)); } { win.setBackground(std::move(format)); }
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/libcursed

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/libcursed

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master