
---------------------------------------------------------------------------------------
--# GtkTextBuffer
---------------------------------------------------------------------------------------

include GtkEngine.e

constant docs = `
Sharing a <b><u>Text Buffer</u></b> between entries:
First 3 input fields below share a single buffer.

Type up to 10 characters.`

constant update = call_back(routine_id("Update"))

constant win = create(GtkWindow,
    "size=300x-1,border_width=10,position=1,$destroy=Quit")
 
constant panel = create(GtkBox,VERTICAL)
    add(win,panel)

constant lbl0 = create(GtkLabel)
    set(lbl0,"markup",docs)
    add(panel,lbl0)

constant input1 = create(GtkEntry,"max length=10,tooltip text=Standard entry")
    add(panel,input1)

constant lbl1 = create(GtkLabel,"Password entry")
    add(panel,lbl1)

constant buffy = get(input1,"buffer")
    connect(buffy,"inserted-text",update)

constant input2 = create(GtkEntry,
    "visibility=FALSE,alignment=.5,tooltip text=Shown as a password")
    set(input2,"buffer",buffy)
    add(panel,input2)

constant lbl2 = create(GtkLabel,"RTL")
    add(panel,lbl2)

constant input3 = create(GtkEntry,"alignment=1.0")
    set(input3,"buffer",buffy)
    add(panel,input3)

constant lbl3 = create(GtkLabel,"Entry as progress")
    add(panel,lbl3)

-- following entry does not share buffer, but instead
-- is used to display progress bar and %;
constant input4 = create(GtkEntry,"text=percent done,alignment=0.5")
    add(panel,input4)

show_all(win)
main()

------------------------------------------------------------------------
function Update() -- compute & display progress;
------------------------------------------------------------------------
integer len = get(buffy,"length")
    set(input4,"progress fraction",len/10)
    set(input4,"text",sprintf("%d%% done",(len/10)*100))
    -- others update automatically when the buffer contents change;
return 1
end function
