void UserPromptView::AddPrompt(std::string const& message, bool visible, PromiseAuthCodePtr const& promise) { auto* text_input = new unity::TextInput(); auto* text_entry = text_input->text_entry(); text_input->scale = scale(); text_input->input_hint = SanitizeMessage(message); text_input->hint_font_size = PROMPT_FONT_SIZE; text_input->show_caps_lock = true; text_input->show_activator = true; text_entry->SetPasswordMode(!visible); text_entry->SetPasswordChar("•"); text_entry->SetToggleCursorVisibilityOnKeyFocus(true); text_entry->clipboard_enabled = false; text_input->SetMinimumHeight(Settings::GRID_SIZE.CP(scale)); text_input->SetMaximumHeight(Settings::GRID_SIZE.CP(scale)); prompt_layout_->AddView(text_input, 1); focus_queue_.push_back(text_input); // Don't remove it, it helps with a11y. if (focus_queue_.size() == 1) nux::GetWindowCompositor().SetKeyFocusArea(text_entry); text_entry->activated.connect([this, text_input, promise](){ auto* text_entry = text_input->text_entry(); if (!text_entry->GetInputEventSensitivity()) return; if (focus_queue_.size() == 1) { text_input->SetSpinnerVisible(true); text_input->SetSpinnerState(STATE_SEARCHING); } focus_queue_.pop_front(); cached_focused_geo_ = text_entry->GetGeometry(); text_entry->SetInputEventSensitivity(false); QueueRelayout(); QueueDraw(); std::string const& password = text_entry->GetText(); if (promise) promise->set_value(password); }); GetLayout()->ComputeContentPosition(0, 0); ComputeContentSize(); QueueRelayout(); QueueDraw(); }
void UserPromptView::AddMessage(std::string const& message, nux::Color const& color) { auto* view = new unity::StaticCairoText(""); view->SetFont(Settings::Instance().font_name()); view->SetTextColor(color); view->SetText(message); msg_layout_->AddView(view); GetLayout()->ComputeContentPosition(0, 0); ComputeContentSize(); QueueRelayout(); QueueDraw(); }
void UserPromptView::UpdateSize() { auto width = 8 * Settings::GRID_SIZE.CP(scale); auto height = 3 * Settings::GRID_SIZE.CP(scale); SetMinimumWidth(width); SetMaximumWidth(width); SetMinimumHeight(height); if (nux::Layout* layout = GetLayout()) { layout->SetLeftAndRightPadding(PADDING.CP(scale)); layout->SetTopAndBottomPadding(PADDING.CP(scale)); static_cast<nux::VLayout*>(layout)->SetVerticalInternalMargin(LAYOUT_MARGIN.CP(scale)); } if (username_) username_->SetScale(scale); if (msg_layout_) { msg_layout_->SetVerticalInternalMargin(MSG_LAYOUT_MARGIN.CP(scale)); for (auto* area : msg_layout_->GetChildren()) { area->SetMaximumWidth(width); static_cast<StaticCairoText*>(area)->SetScale(scale); } } if (prompt_layout_) { prompt_layout_->SetVerticalInternalMargin(PROMPT_LAYOUT_MARGIN.CP(scale)); for (auto* area : prompt_layout_->GetChildren()) { auto* text_input = static_cast<TextInput*>(area); text_input->SetMinimumHeight(Settings::GRID_SIZE.CP(scale)); text_input->SetMaximumHeight(Settings::GRID_SIZE.CP(scale)); text_input->scale = scale(); } } bg_layer_.reset(); ComputeContentSize(); QueueRelayout(); QueueDraw(); }
void UserPromptView::AddMessage(std::string const& message, nux::Color const& color) { nux::Geometry const& geo = GetGeometry(); auto* view = new unity::StaticCairoText(""); view->SetScale(scale); view->SetFont(Settings::Instance().font_name()); view->SetTextColor(color); view->SetText(message); view->SetMaximumWidth(geo.width - PADDING.CP(scale)*2); msg_layout_->AddView(view); GetLayout()->ComputeContentPosition(0, 0); ComputeContentSize(); QueueRelayout(); QueueDraw(); }