summaryrefslogtreecommitdiffstats
path: root/ui/views/examples/example_base.h
blob: 7d49586a0c4075b847298ade7049a639518128dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) 2011 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.

#ifndef UI_VIEWS_EXAMPLES_EXAMPLE_BASE_H_
#define UI_VIEWS_EXAMPLES_EXAMPLE_BASE_H_
#pragma once

#include <string>

#include "base/basictypes.h"

namespace views {
class View;
}

namespace examples {

class ExamplesMain;

class ExampleBase {
 public:
  virtual ~ExampleBase();

  // Sub-classes should creates and add the views to the given parent.
  virtual void CreateExampleView(views::View* parent) = 0;

  const std::string& example_title() const { return example_title_; }

  // This view is added as a tab to the example application.
  views::View* example_view() { return container_; }

 protected:
  ExampleBase(ExamplesMain* main, const char* title);

  // Prints a message in the status area, at the bottom of the window.
  void PrintStatus(const char* format, ...);

  // Converts an boolean value to "on" or "off".
  const char* BoolToOnOff(bool value) {
    return value ? "on" : "off";
  }

 private:
  // The runner actually running this example.
  ExamplesMain* main_;

  // Name of the example - used for the title of the tab.
  std::string example_title_;

  // The view containing example views.
  views::View* container_;

  DISALLOW_COPY_AND_ASSIGN(ExampleBase);
};

}  // namespace examples

#endif  // UI_VIEWS_EXAMPLES_EXAMPLE_BASE_H_