File: create_label.adb

package info (click to toggle)
libgtkada 18-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 28,348 kB
  • sloc: ada: 61,514; xml: 7,709; python: 4,310; sh: 2,822; ansic: 1,598; makefile: 240; objc: 160; perl: 70
file content (187 lines) | stat: -rw-r--r-- 7,918 bytes parent folder | download
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
------------------------------------------------------------------------------
--               GtkAda - Ada95 binding for the Gimp Toolkit                --
--                                                                          --
--                     Copyright (C) 2000-2018, AdaCore                     --
--                                                                          --
-- This library is free software;  you can redistribute it and/or modify it --
-- under terms of the  GNU General Public License  as published by the Free --
-- Software  Foundation;  either version 3,  or (at your  option) any later --
-- version. This library is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY;  without even the implied warranty of MERCHAN- --
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE.                            --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
-- You should have received a copy of the GNU General Public License and    --
-- a copy of the GCC Runtime Library Exception along with this program;     --
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
-- <http://www.gnu.org/licenses/>.                                          --
--                                                                          --
------------------------------------------------------------------------------

with Gtk.Box;     use Gtk.Box;
with Gtk.Enums;   use Gtk.Enums;
with Gtk.Frame;   use Gtk.Frame;
with Gtk.Label;   use Gtk.Label;
with Glib.Convert; use Glib.Convert;
with Pango.Enums; use Pango.Enums;

package body Create_Label is

   ----------
   -- Help --
   ----------

   function Help return String is
   begin
      return "A @bGtk_Label@B is used to display any kind of text on the"
        & " screen, even on multiple line."
        & ASCII.LF
        & "This is a passive widget, in that it does not react to any event.";
   end Help;

   ---------
   -- Run --
   ---------

   procedure Run (Frame : access Gtk.Frame.Gtk_Frame_Record'Class) is
      Vbox, Hbox : Gtk_Box;
      Label      : Gtk_Label;
      Frame2     : Gtk_Frame;
   begin
      Set_Label (Frame, "Label");
      Gtk_New_Vbox (Vbox, False, 5);
      Gtk_New_Hbox (Hbox, False, 5);
      Add (Frame, Hbox);
      Pack_Start (Hbox, Vbox, False, False, 0);

      Gtk_New (Frame2, "Normal Label");
      Gtk_New (Label, "This is a Normal Label");
      Add (Frame2, Label);
      Pack_Start (Vbox, Frame2, False, False, 0);

      Gtk_New (Frame2, "Multi-line Label");
      Gtk_New (Label, "This is a Multi-line label."
               & ASCII.LF
               & "Second Line"
               & ASCII.LF
               & "Third line");
      Add (Frame2, Label);
      Pack_Start (Vbox, Frame2, False, False, 0);

      Gtk_New (Frame2, "Left Justified Label");
      Gtk_New (Label, "This is a Left-Justified"
               & ASCII.LF & "Multi-line label." & ASCII.LF
               & "Third      line");
      Set_Justify (Label, Justify_Left);
      Add (Frame2, Label);
      Pack_Start (Vbox, Frame2, False, False, 0);

      Gtk_New (Frame2, "Right Justified Label");
      Gtk_New (Label, "This is a Right-Justified"
               & ASCII.LF & "Multi-line label." & ASCII.LF
               & "Fourth      line");
      Set_Justify (Label, Justify_Right);
      Add (Frame2, Label);
      Pack_Start (Vbox, Frame2, False, False, 0);

      Gtk_New (Frame2, "Selectable Label");
      Gtk_New (Label, "This is a selectable label "
               & ASCII.LF
               & "you can select the text with the "
               & ASCII.LF
               & "mouse and paste it.");
      Set_Selectable (Label, True);
      Add (Frame2, Label);
      Pack_Start (Vbox, Frame2, False, False, 0);

      Gtk_New_Vbox (Vbox, False, 5);
      Pack_Start (Hbox, Vbox, False, False, 0);

      Gtk_New (Frame2, "Line wrapped Label");
      Gtk_New (Label,
               "This is an example of a line-wrapped label.  It should not "
               & "be taking up the entire             "
               & "width allocated to it, but automatically wraps the words "
               & "to fit.  The time has come, for all good men, to come to "
               & "the aid of their party.  The sixth sheik's six sheep's sick."
               & ASCII.LF
               & "     It supports multiple paragraphs correctly, and  "
               & "correctly   adds many          extra  spaces. ");
      Set_Line_Wrap (Label, True);
      Add (Frame2, Label);
      Pack_Start (Vbox, Frame2, False, False, 0);

      Gtk_New (Frame2, "Character mode wrapped label");
      Gtk_New (Label,
               "This is an example of a line-wrapped label.  Like the above "
               & "example, it will not be taking up the entire width "
               & "allocated to it, but instead of wrapping words to fit, it "
               & "wraps characters to fit.  "
               & "The time has come, for all good men, to come to "
               & "the aid of their party.  The sixth sheik's six sheep's sick."
               & ASCII.LF
               & "     It supports multiple paragraphs correctly, and  "
               & "correctly   adds many          extra  spaces. ");
      Set_Line_Wrap (Label, True);
      Set_Line_Wrap_Mode (Label, Pango_Wrap_Char);
      Add (Frame2, Label);
      Pack_Start (Vbox, Frame2, False, False, 0);

      Gtk_New (Frame2, "Filled, wrapped Label");
      Gtk_New (Label,
               "This is an example of a line-wrapped label.  It should "
               & "be taking up the entire             "
               & "width allocated to it, but automatically wraps the words "
               & "to fit.  The time has come, for all good men, to come to "
               & "the aid of their party.  The sixth sheik's six sheep's sick."
               & ASCII.LF
               & "     It supports multiple paragraphs correctly, and  "
               & "correctly   adds many          extra  spaces. ");
      Set_Line_Wrap (Label, True);
      Set_Justify (Label, Justify_Fill);
      Add (Frame2, Label);
      Pack_Start (Vbox, Frame2, False, False, 0);

      Gtk_New (Frame2, "Underlined Label");
      Gtk_New
        (Label, Locale_To_UTF8
         ("This label is underlined!"
          & ASCII.LF
          & "This one is underlined in ܸquite a funky fashion"));
      Set_Justify (Label, Justify_Left);
      Set_Pattern (Label,
                   "_________________________ _ _________ _ _____ _ __"
                   & " __  ___ ____ _____");
      Add (Frame2, Label);
      Pack_Start (Vbox, Frame2, False, False, 0);

      Gtk_New (Frame2, "Markup Label");
      Gtk_New (Label);

      Set_Markup (Label,
         ("<span size=""x-large"" weight=""ultrabold"""
          & "background=""darkblue"" color=""white"">"
          & "This label has <i>markup</i>!</span>"
          & ASCII.LF
          & "You can make text <b>bold</b> <i>italic</i> "
          & "<u>underline</u> <s>striken</s> <big>big</big>. "
          & ASCII.LF
          & "<tt>You can also use mono spaced font</tt>"
          & " and write H<sub><small>2</small></sub>O "
          & "and "
          & ASCII.LF
          & "<span weight=""light"" color=""red"" size=""xx-large"">"
          & "y=Σx<sub><small>i</small></sub>"
          & "<sup><small>2</small></sup> "
          & "+ 3</span>"
          & " besides other things..."));
      Add (Frame2, Label);
      Pack_Start (Vbox, Frame2, False, False, 0);

      Show_All (Frame);
   end Run;

end Create_Label;