// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/views/examples/label_example.h" #include #include #include "base/memory/ptr_util.h" #include "base/stl_util.h" #include "base/strings/utf_string_conversions.h" #include "ui/gfx/geometry/insets.h" #include "ui/gfx/geometry/vector2d.h" #include "ui/views/background.h" #include "ui/views/border.h" #include "ui/views/controls/button/checkbox.h" #include "ui/views/controls/combobox/combobox.h" #include "ui/views/controls/label.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/examples/example_combobox_model.h" #include "ui/views/layout/box_layout.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/view.h" using base::ASCIIToUTF16; using base::WideToUTF16; namespace views { namespace examples { namespace { const char* kAlignments[] = {"Left", "Center", "Right", "Head"}; // A Label with a clamped preferred width to demonstrate eliding or wrapping. class ExamplePreferredSizeLabel : public Label { public: ExamplePreferredSizeLabel() { SetBorder(CreateSolidBorder(1, SK_ColorGRAY)); } ~ExamplePreferredSizeLabel() override = default; // Label: gfx::Size CalculatePreferredSize() const override { return gfx::Size(50, Label::CalculatePreferredSize().height()); } static const char* kElideBehaviors[]; private: DISALLOW_COPY_AND_ASSIGN(ExamplePreferredSizeLabel); }; // static const char* ExamplePreferredSizeLabel::kElideBehaviors[] = { "No Elide", "Truncate", "Elide Head", "Elide Middle", "Elide Tail", "Elide Email", "Fade Tail"}; } // namespace LabelExample::LabelExample() : ExampleBase("Label") {} LabelExample::~LabelExample() = default; void LabelExample::CreateExampleView(View* container) { // A very simple label example, followed by additional helpful examples. container->SetLayoutManager(std::make_unique( BoxLayout::Orientation::kVertical, gfx::Insets(), 10)); container->AddChildView( std::make_unique