separator-box.zc

来自「实现树形结构」· ZC 代码 · 共 122 行

ZC
122
字号
//[of]:description
//[c]Displays an horizontal separator line
//[cf]
//[of]:license
//[c]Code Browser - a folding text editor for programmers
//[c]Copyright (C) 2003-07 Marc Kerbiquet
//[c]
//[c]This program is free software; you can redistribute it and/or modify
//[c]it under the terms of the GNU General Public License as published by
//[c]the Free Software Foundation; either version 2 of the License, or
//[c](at your option) any later version.
//[c]
//[c]This program is distributed in the hope that it will be useful,
//[c]but WITHOUT ANY WARRANTY; without even the implied warranty of
//[c]MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//[c]GNU General Public License for more details.
//[c]
//[c]You should have received a copy of the GNU General Public License
//[c]along with this program; if not, write to the Free Software
//[c]Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//[cf]
//[of]:imports
import "base/types"
import "base/memory-allocator"
//[c]
import "graphics/geometry"
import "graphics/graphics"
import "user/box"
import "user/container-box"
//[cf]
//[c]
//[of]:separator box
//[of]:type
public struct separator box : local container box

	private	
		light color : color
		dark color : color

end
//[cf]
//[of]:instance creation
//[of]:new separator box (parent box)
public func new separator box (parent: box)

	equ s = sizeof local separator box
	def b = allocate memory (s):separator box
	initialize (b, parent)
	return b

end
//[cf]
//[cf]
//[c]
//[of]:restricted
//[of]:initialize (parent)
//[c]
public func initialize (m: separator box, parent: box)

	initialize (super (m), parent)
	class (m) = separator box class
	dark color (m) = system color (color button shadow)
	light color (m) = system color (color button highlight)

end
//[cf]
//[c]
//[of]:actual compute min size
public func actual compute min size (m: separator box)

	// min width is 0
	// min height is 2 lines
	set min size (m, 0, 2)

end
//[cf]
//[c]
//[of]:handle size
//[c]Must repaint all when size changed
//[c]
public func handle size (m: separator box)
	invalidate (m)
end
//[cf]
//[of]:handle paint (canvas, clip)
public func handle paint (m: separator box, c: canvas, clip: rectangle)

	def r := rectangle (client rect (m))
	height (r) = 1
	fill rectangle (c, r, dark color (m))
	++ top (r)
	fill rectangle (c, r, light color (m))
		
end
//[cf]
//[cf]
//[cf]
//[of]:separator box class
//[of]:type
public struct separator box class : local container box class
end
//[cf]
//[of]:separator box class
public func separator box class

	def c = the separator box class
	if ~ initialized
		initialized = true
		c . copy (container box class)
		c . on size = ^handle size (separator box)
		c . compute min size = ^actual compute min size(separator box)
		c . on paint = ^handle paint(separator box, canvas, rectangle)
	end
	return c

end

private def initialized = false
private def the separator box class: local separator box class
//[cf]
//[cf]

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?