mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-12-25 23:39:37 -05:00
Make Widget flags private, expose via methods.
This commit is contained in:
parent
9a33fc884a
commit
7cb3bbc9f8
@ -129,7 +129,7 @@ public:
|
|||||||
Entries& recent
|
Entries& recent
|
||||||
) : recent { recent }
|
) : recent { recent }
|
||||||
{
|
{
|
||||||
flags.focusable = true;
|
set_focusable(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void paint(Painter& painter) override {
|
void paint(Painter& painter) override {
|
||||||
|
@ -32,17 +32,19 @@ void MenuItemView::select() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MenuItemView::highlight() {
|
void MenuItemView::highlight() {
|
||||||
set_highlight(true);
|
set_highlighted(true);
|
||||||
|
set_dirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuItemView::unhighlight() {
|
void MenuItemView::unhighlight() {
|
||||||
set_highlight(false);
|
set_highlighted(false);
|
||||||
|
set_dirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuItemView::paint(Painter& painter) {
|
void MenuItemView::paint(Painter& painter) {
|
||||||
const auto r = screen_rect();
|
const auto r = screen_rect();
|
||||||
|
|
||||||
const auto paint_style = (flags.highlighted && parent()->has_focus()) ? style().invert() : style();
|
const auto paint_style = (highlighted() && parent()->has_focus()) ? style().invert() : style();
|
||||||
|
|
||||||
const auto font_height = paint_style.font.line_height();
|
const auto font_height = paint_style.font.line_height();
|
||||||
|
|
||||||
@ -58,11 +60,6 @@ void MenuItemView::paint(Painter& painter) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuItemView::set_highlight(const bool value) {
|
|
||||||
flags.highlighted = value;
|
|
||||||
set_dirty();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* MenuView **************************************************************/
|
/* MenuView **************************************************************/
|
||||||
|
|
||||||
MenuView::~MenuView() {
|
MenuView::~MenuView() {
|
||||||
|
@ -53,8 +53,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
const MenuItem item;
|
const MenuItem item;
|
||||||
|
|
||||||
void set_highlight(const bool value);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class MenuView : public View {
|
class MenuView : public View {
|
||||||
@ -62,7 +60,7 @@ public:
|
|||||||
std::function<void(void)> on_left;
|
std::function<void(void)> on_left;
|
||||||
|
|
||||||
MenuView() {
|
MenuView() {
|
||||||
flags.focusable = true;
|
set_focusable(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
~MenuView();
|
~MenuView();
|
||||||
|
@ -38,7 +38,7 @@ FrequencyField::FrequencyField(
|
|||||||
length_ { 11 },
|
length_ { 11 },
|
||||||
range(rf::tuning_range)
|
range(rf::tuning_range)
|
||||||
{
|
{
|
||||||
flags.focusable = true;
|
set_focusable(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
rf::Frequency FrequencyField::value() const {
|
rf::Frequency FrequencyField::value() const {
|
||||||
|
@ -130,6 +130,10 @@ bool Widget::focusable() const {
|
|||||||
return flags.focusable;
|
return flags.focusable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Widget::set_focusable(const bool value) {
|
||||||
|
flags.focusable = value;
|
||||||
|
}
|
||||||
|
|
||||||
bool Widget::has_focus() {
|
bool Widget::has_focus() {
|
||||||
return (context().focus_manager().focus_widget() == this);
|
return (context().focus_manager().focus_widget() == this);
|
||||||
}
|
}
|
||||||
@ -200,6 +204,14 @@ void Widget::visible(bool v) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Widget::highlighted() const {
|
||||||
|
return flags.highlighted;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Widget::set_highlighted(const bool value) {
|
||||||
|
flags.highlighted = value;
|
||||||
|
}
|
||||||
|
|
||||||
void Widget::dirty_overlapping_children_in_rect(const Rect& child_rect) {
|
void Widget::dirty_overlapping_children_in_rect(const Rect& child_rect) {
|
||||||
for(auto child : children()) {
|
for(auto child : children()) {
|
||||||
if( !child_rect.intersect(child->parent_rect).is_empty() ) {
|
if( !child_rect.intersect(child->parent_rect).is_empty() ) {
|
||||||
@ -322,7 +334,7 @@ void Text::paint(Painter& painter) {
|
|||||||
) : Widget { parent_rect },
|
) : Widget { parent_rect },
|
||||||
text_ { text }
|
text_ { text }
|
||||||
{
|
{
|
||||||
flags.focusable = true;
|
set_focusable(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::set_text(const std::string value) {
|
void Button::set_text(const std::string value) {
|
||||||
@ -337,7 +349,7 @@ std::string Button::text() const {
|
|||||||
void Button::paint(Painter& painter) {
|
void Button::paint(Painter& painter) {
|
||||||
const auto r = screen_rect();
|
const auto r = screen_rect();
|
||||||
|
|
||||||
const auto paint_style = (has_focus() || flags.highlighted) ? style().invert() : style();
|
const auto paint_style = (has_focus() || highlighted()) ? style().invert() : style();
|
||||||
|
|
||||||
painter.draw_rectangle(r, style().foreground);
|
painter.draw_rectangle(r, style().foreground);
|
||||||
|
|
||||||
@ -368,13 +380,13 @@ bool Button::on_key(const KeyEvent key) {
|
|||||||
bool Button::on_touch(const TouchEvent event) {
|
bool Button::on_touch(const TouchEvent event) {
|
||||||
switch(event.type) {
|
switch(event.type) {
|
||||||
case TouchEvent::Type::Start:
|
case TouchEvent::Type::Start:
|
||||||
flags.highlighted = true;
|
set_highlighted(true);
|
||||||
set_dirty();
|
set_dirty();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
||||||
case TouchEvent::Type::End:
|
case TouchEvent::Type::End:
|
||||||
flags.highlighted = false;
|
set_highlighted(false);
|
||||||
set_dirty();
|
set_dirty();
|
||||||
if( on_select ) {
|
if( on_select ) {
|
||||||
on_select(*this);
|
on_select(*this);
|
||||||
@ -454,7 +466,7 @@ void Image::set_background(const Color color) {
|
|||||||
void Image::paint(Painter& painter) {
|
void Image::paint(Painter& painter) {
|
||||||
if( bitmap_ ) {
|
if( bitmap_ ) {
|
||||||
// Code also handles ImageButton behavior.
|
// Code also handles ImageButton behavior.
|
||||||
const bool selected = (has_focus() || flags.highlighted);
|
const bool selected = (has_focus() || highlighted());
|
||||||
painter.draw_bitmap(
|
painter.draw_bitmap(
|
||||||
screen_pos(),
|
screen_pos(),
|
||||||
*bitmap_,
|
*bitmap_,
|
||||||
@ -475,7 +487,7 @@ ImageButton::ImageButton(
|
|||||||
const Color background
|
const Color background
|
||||||
) : Image { parent_rect, bitmap, foreground, background }
|
) : Image { parent_rect, bitmap, foreground, background }
|
||||||
{
|
{
|
||||||
flags.focusable = true;
|
set_focusable(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ImageButton::on_key(const KeyEvent key) {
|
bool ImageButton::on_key(const KeyEvent key) {
|
||||||
@ -492,13 +504,13 @@ bool ImageButton::on_key(const KeyEvent key) {
|
|||||||
bool ImageButton::on_touch(const TouchEvent event) {
|
bool ImageButton::on_touch(const TouchEvent event) {
|
||||||
switch(event.type) {
|
switch(event.type) {
|
||||||
case TouchEvent::Type::Start:
|
case TouchEvent::Type::Start:
|
||||||
flags.highlighted = true;
|
set_highlighted(true);
|
||||||
set_dirty();
|
set_dirty();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
||||||
case TouchEvent::Type::End:
|
case TouchEvent::Type::End:
|
||||||
flags.highlighted = false;
|
set_highlighted(false);
|
||||||
set_dirty();
|
set_dirty();
|
||||||
if( on_select ) {
|
if( on_select ) {
|
||||||
on_select(*this);
|
on_select(*this);
|
||||||
@ -520,7 +532,7 @@ OptionsField::OptionsField(
|
|||||||
length_ { length },
|
length_ { length },
|
||||||
options { options }
|
options { options }
|
||||||
{
|
{
|
||||||
flags.focusable = true;
|
set_focusable(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t OptionsField::selected_index() const {
|
size_t OptionsField::selected_index() const {
|
||||||
@ -595,7 +607,7 @@ NumberField::NumberField(
|
|||||||
length_ { length },
|
length_ { length },
|
||||||
fill_char { fill_char }
|
fill_char { fill_char }
|
||||||
{
|
{
|
||||||
flags.focusable = true;
|
set_focusable(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t NumberField::value() const {
|
int32_t NumberField::value() const {
|
||||||
|
@ -83,6 +83,7 @@ public:
|
|||||||
virtual void blur();
|
virtual void blur();
|
||||||
virtual void on_blur();
|
virtual void on_blur();
|
||||||
bool focusable() const;
|
bool focusable() const;
|
||||||
|
void set_focusable(const bool value);
|
||||||
bool has_focus();
|
bool has_focus();
|
||||||
virtual Widget* last_child_focus() const;
|
virtual Widget* last_child_focus() const;
|
||||||
virtual void set_last_child_focus(Widget* const child);
|
virtual void set_last_child_focus(Widget* const child);
|
||||||
@ -110,12 +111,18 @@ public:
|
|||||||
|
|
||||||
void visible(bool v);
|
void visible(bool v);
|
||||||
|
|
||||||
|
bool highlighted() const;
|
||||||
|
void set_highlighted(const bool value);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/* Widget rectangle relative to parent pos(). */
|
/* Widget rectangle relative to parent pos(). */
|
||||||
Rect parent_rect;
|
Rect parent_rect;
|
||||||
const Style* style_ { nullptr };
|
const Style* style_ { nullptr };
|
||||||
Widget* parent_ { nullptr };
|
Widget* parent_ { nullptr };
|
||||||
|
|
||||||
|
void dirty_overlapping_children_in_rect(const Rect& child_rect);
|
||||||
|
|
||||||
|
private:
|
||||||
struct flags_t {
|
struct flags_t {
|
||||||
bool dirty : 1; // Widget content has changed.
|
bool dirty : 1; // Widget content has changed.
|
||||||
bool hidden : 1; // Hide widget and children.
|
bool hidden : 1; // Hide widget and children.
|
||||||
@ -131,8 +138,6 @@ protected:
|
|||||||
.highlighted = false,
|
.highlighted = false,
|
||||||
.visible = false,
|
.visible = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
void dirty_overlapping_children_in_rect(const Rect& child_rect);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class View : public Widget {
|
class View : public Widget {
|
||||||
|
Loading…
Reference in New Issue
Block a user