Example #1
0
void
BasicGrid::render_impl(
	UI::Widget::RenderData& rd
) noexcept {
	UI::GridRenderData grid_rd{
		rd,
		is_focused(),
		is_focused()
	};
	render_view(
		grid_rd,
		!enum_cast(queued_actions() & UI::UpdateActions::flag_noclear)
	);

	auto const& view = this->view();
	Rect const empty_frame{
		{view.content_frame.pos.x, view.content_frame.pos.y + view.row_count},
		{
			view.content_frame.size.width,
			max_ce(0, view.fit_count - view.row_count)
		}
	};
	if (0 < empty_frame.size.height) {
		grid_rd.rd.terminal.clear_back(empty_frame);
		grid_rd.rd.terminal.put_line(
			empty_frame.pos,
			empty_frame.size.height,
			Axis::vertical,
			tty::make_cell('~',
				tty::Color::blue | tty::Attr::bold,
				tty::Color::term_default
			)
		);
	}
}
Example #2
0
static json_object *get_focused_container_r(json_object *c) {
	json_object *name;
	json_object_object_get_ex(c, "name", &name);
	if (is_focused(c)) {
		return c;
	} else {
		json_object *nodes, *node, *child;
		json_object_object_get_ex(c, "nodes", &nodes);
		int i;
		for (i = 0; i < json_object_array_length(nodes); i++) {
			node = json_object_array_get_idx(nodes, i);

			if ((child = get_focused_container_r(node))) {
				return child;
			}
		}

		json_object_object_get_ex(c, "floating_nodes", &nodes);
		for (i = 0; i < json_object_array_length(nodes); i++) {
			node = json_object_array_get_idx(nodes, i);

			if ((child = get_focused_container_r(node))) {
				return child;
			}
		}

	}

	return NULL;
}
Example #3
0
bool
BasicGrid::handle_event_impl(
	UI::Event const& event
) noexcept {
	switch (event.type) {
	case UI::EventType::key_input:
		if (!has_input_control() && event.key_input.mod == KeyMod::none) {
			bool handled = true;
			switch (event.key_input.code) {
			case KeyCode::up   : row_step(-1); break;
			case KeyCode::down : row_step(+1); break;
			case KeyCode::left : col_step(-1); break;
			case KeyCode::right: col_step(+1); break;
			case KeyCode::home: row_abs(0); break;
			case KeyCode::end : row_abs(max_ce(0, row_count() - 1)); break;
			case KeyCode::pgup:
				row_step(min_ce(0, -view().fit_count - 1)); break;
			case KeyCode::pgdn:
				row_step(max_ce(0, +view().fit_count - 1)); break;

			default:
				switch (event.key_input.cp) {
				case 'k': row_step(-1); break;
				case 'j': row_step(+1); break;
				case 'h': col_step(-1); break;
				case 'l': col_step(+1); break;
				case 'a': select_all(); break;
				case 'A': select_none(); break;
				case 's': select_toggle(m_cursor.row, 1); break;
				default:
					handled = false;
					break;
				}
			}
			return handled;
		}
		break;

	case UI::EventType::focus_changed:
		queue_cell_render(
			m_cursor.row, m_cursor.row + 1,
			m_cursor.col, m_cursor.col + 1
		);
		if (is_focused()) {
			App::instance.m_ui.csline->set_location(
				std::to_string(m_cursor.row) + ", " +
				std::to_string(m_cursor.col)
			);
		} else {
			App::instance.m_ui.csline->clear_location();
		}
		return false;

	default:
		break;
	}
	return false;
}
Example #4
0
// if the widget is currently focused, chages the state to !focused and calls on_blur().
void UIWidget::set_as_unfocused()
{
   if (disabled) return;

   if (is_focused())
   {
      focused=false;
      on_blur();
   }
}
Example #5
0
void Icon::do_focus(void)
{
	if(is_focused())
		return;
	if(!accept_focus())
		return;
	if(!takesevents()) 
		return;

	printf("%s focused\n", label().c_str());
	infocus = true;
}
Example #6
0
static bool notifications_are_disabled(uint64_t flags)
{
    if (user_settings->alerts != ALERTS_ENABLED)
        return true;

    bool res = (flags & NT_RESTOL) && (Control.cooldown > get_unix_time());
#ifdef X11
    return res || ((flags & NT_NOFOCUS) && is_focused());
#else
    return res;
#endif
}
Example #7
0
// iterates through all siblings and sets all parent's children to unfocused.
// if the widget is not already focused, then set to focused and on_focus() is called
void UIWidget::set_as_focused()
{
   if (disabled) return;

   // TODO: this will need to "unfocus" all other elements in the tree

   if (!is_focused())
   {
      focused=true;
      on_focus();
   }
}
Example #8
0
	color text_entry::get_caret_color() const {
		if (is_focused()) {
			if (_is_read_only) {
				//no blinking when read only, looks like user can type if blinking.
				return _style->_caret_color_begin;
			}
			else {
				float t = calculate_oscillate_t(get_real_time_in_seconds(), _style->_caret_blink_time_period);
				return lerp(_style->_caret_color_begin, _style->_caret_color_end, t);
			}
		}
		return color(0.f, 0.f, 0.f, 0.f);
	}
Example #9
0
void Icon::draw(void)
{
	Fl_Flags f = 0;
    if(is_focused()) 
		f = FL_SELECTED;

	if(icon_img)
		icon_img->draw(0, 0, w(), h(),f);
	else
	{
		fl_color(FL_RED);
		fl_rect(0,0,w(),h());
		fl_color(FL_BLACK);
		fl_rectf(1,1,w()-2,h()-2);
		fl_color(FL_WHITE);
		fl_font(label_font()->bold(), 10);
		fl_draw(_("NO ICON FOUND!"), 1, 1, w()-2, h()-2, FL_ALIGN_TOP|FL_ALIGN_LEFT|FL_ALIGN_WRAP);
		return;
	}

	if(globals->label_draw)
	{
    	int X = w()-(w()/2)-(lwidth/2);
		int Y = h()+2;
		if(!globals->label_transparent) 
		{
        	fl_color(globals->label_background);
			fl_rectf(X,Y,lwidth,lheight);
		}

    	if(is_focused())
			focus_box()->draw(X, Y, lwidth, lheight, color(), 0);

    	fl_font(label_font(), label_size());
		fl_color(label_color());
		fl_draw(label(), X, Y, lwidth, lheight, flags());
    }
}
Example #10
0
void
BasicGrid::set_cursor(
	UI::index_type col,
	UI::index_type row
) noexcept {
	col = value_clamp(col, 0, max_ce(0, col_count() - 1));
	row = value_clamp(row, 0, max_ce(0, row_count() - 1));
	if (col != m_cursor.col || row != m_cursor.row) {
		if (
			value_in_bounds(m_cursor.row, 0, row_count()) &&
			value_in_bounds(m_cursor.col, 0, col_count())
		) {
			queue_cell_render(
				m_cursor.row, m_cursor.row + 1,
				m_cursor.col, m_cursor.col + 1
			);
		}
		if (row_count() > 0) {
			queue_cell_render(
				row, row + 1,
				col, col + 1
			);
		}
		enqueue_actions(
			UI::UpdateActions::render |
			UI::UpdateActions::flag_noclear
		);
		m_cursor.col = col;
		m_cursor.row = row;
		adjust_view();
		if (is_focused()) {
			App::instance.m_ui.csline->set_location(
				std::to_string(m_cursor.row) + ", " +
				std::to_string(m_cursor.col)
			);
		}
	}
}
Example #11
0
void DesktopIcon::draw(void) { 
	// draw_box(FL_UP_BOX, FL_BLACK);

	if(image() && (damage() & FL_DAMAGE_ALL)) {
		Fl_Image* im = image();

		/* center image in the box */
		int ix = (w()/2) - (im->w()/2);
		int iy = (h()/2) - (im->h()/2);
		ix += x();
		iy += y();

		/* darker_img is always present if image() is present */
		if(is_focused())
			darker_img->draw(ix, iy);
		else
			im->draw(ix, iy);

		E_DEBUG(E_STRLOC ": DesktopIcon icon redraw\n");
	}

	if(gsettings->label_draw && (damage() & (FL_DAMAGE_ALL | EDAMAGE_CHILD_LABEL))) {
		int X = x() + w()-(w()/2)-(lwidth/2);
		int Y = y() + h() + LABEL_OFFSET;

		Fl_Color old = fl_color();

		if(!gsettings->label_transparent) {
			fl_color(gsettings->label_background);
			fl_rectf(X, Y, lwidth, lheight);
		}

		int old_font = fl_font();
		int old_font_sz = fl_size();

		/* draw with icon's font */
		fl_font(labelfont(), labelsize());

		/* pseudo-shadow */
		fl_color(FL_BLACK);
		fl_draw(label(), X+1, Y+1, lwidth, lheight, align(), 0, 0);

		fl_color(gsettings->label_foreground);
		fl_draw(label(), X, Y, lwidth, lheight, align(), 0, 0);

		/* restore old font */
		fl_font(old_font, old_font_sz);

		if(is_focused()) {
			/* draw focused box on our way so later this can be used to draw customised boxes */
			fl_color(gsettings->label_foreground);
			fl_line_style(FL_DOT);

			fl_push_matrix();
			fl_begin_loop();
				fl_vertex(X, Y);
				fl_vertex(X + lwidth, Y);
				fl_vertex(X + lwidth, Y + lheight);
				fl_vertex(X, Y + lheight);
				fl_vertex(X, Y);
			fl_end_loop();
			fl_pop_matrix();

			/* revert to default line style */
			fl_line_style(0);
		}

		/* revert to old color whatever that be */
		fl_color(old);
		E_DEBUG(E_STRLOC ": DesktopIcon label redraw\n");
	}
}
Example #12
0
	bool text_entry::on_key_down(const window_key_event_params& params) {
		bool is_trapped = false;

		if (is_focused()) {
			//don't trap when ALT is down, this would prevent ALT-TAB
			if (!params.is_alt_down()) {
				is_trapped = true;

				if (params.is_ctrl_down()) {
					if (params.is_shift_down()) {
						if (params._key == keyboard_key::LEFT) {
							move_caret_left_to_next_word(params.is_shift_down());
						}
						else if (params._key == keyboard_key::RIGHT) {
							move_caret_right_to_next_word(params.is_shift_down());
						}
						else {
							is_trapped = false;
						}
					}
					else {
						if (params._key == keyboard_key::C) {
							copy_text_to_clipboard(params._clipboard);
						}
						else if (params._key == keyboard_key::X) {
							cut_text_to_clipboard(params._clipboard);
						}
						else if (params._key == keyboard_key::V) {
							paste_text_from_clipboard(params._clipboard);
						}
						else {
							is_trapped = false;
						}
					}
				}
				else {
					if (params._key == keyboard_key::BACKSPACE) {
						handle_backspace_key_down();
					}
					else if (params._key == keyboard_key::DEL) {
						handle_delete_key_down();
					}
					else if (params._key == keyboard_key::HOME) {
						move_caret_home(params.is_shift_down());
					}
					else if (params._key == keyboard_key::END) {
						move_caret_end(params.is_shift_down());
					}
					else if (params._key == keyboard_key::LEFT) {
						move_caret_left(1, params.is_shift_down());
					}
					else if (params._key == keyboard_key::RIGHT) {
						move_caret_right(1, params.is_shift_down());
					}
					else if (params._key == keyboard_key::ENTER) {
						if (_should_trap_enter) {
							try_apply_changes();
							move_caret_end(false);
						}
						else {
							is_trapped = false;
						}
					}
					else {
						//NOTE: trap all keys, needs to by symmetrical with on_char_received(). Alphanumeric keys
						//where being picked up by other windows even though on_char_received() was trapping the event.
						is_trapped = is_alpha_numeric(params._key) || (params._key == keyboard_key::SPACE);
					}
				}
			}
		}

		return is_trapped;
	}
Example #13
0
	bool text_entry::on_char_received(const window_char_event_params& params) {
		ASSERT(is_focused());
		try_add_char(params._char);
		return true;
	}